ebook img

Introducing Fortran 95 PDF

472 Pages·2000·27.925 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Introducing Fortran 95

Introducing Fortran 95 Springer-Verlag London Ltd. Ian Chivers and Jane Sleightholme Introducing Fortran 95 Springer Ian Chivers, BSc, PGCEd, MSc Jane Sleightholme, MSc The Computer Centre, Kings College Strand Campus, London WC2R 2LS, UK ISBN 978-1-85233-276-1 British Library Cataloguing in Publication Data Chivers, I. D. (Ian David), 1952- Introducing Fortran 95 1. Fortran 95 (Computer language) I. Title II. Sleightholme, Jane 005.1' 33 ISBN 978-1-85233-276-1 Library of Congress Cataloging-in-Publication Data Chivers, I. D. (Ian David), 1952- Introducing Fortran 95 / Ian Chivers and Jane Sleightholme p. cm. Includes bibliographical references and index. ISBN 978-1-85233-276-1 ISBN 978-1-4471-0403-2 (eBook) DOI 10.1007/978-1-4471-0403-2 1. Fortran 95 (Computer program language) I. Sleightholme, Jane, 1950 -II. Title. QA76.73.F29 C482000 005.13' 3—dc21 00-034505 Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in accordance with the terms of licences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. © Springer-Verlag London 2000 Originally published by Springer-Verlag London Berlin Heidelberg in 2000 The use of registered names, trademarks etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, wiht regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Typesetting: Camera ready by authors 34/3830-543210 Printed on acid-free paper SPIN 10756213 Contents v 1 Overview ...........••.•. 1 1.1 Miscellanea . . . . . . . . . . . . 7 2 Introduction to Computer Systems 9 2.1 The core of a computer system . .10 2.1.1 Central Processor Unit - CPU .10 2.1.2 Memory ........... . .10 2.1.3 Bus ............. . .10 2.2 Other components of a computer system .11 2.2.1 Disks .11 2.2.2 Others .11 2.3 Software · 13 2.4 Problems · 14 2.5 Bibliography · 14 3 Introduction to Operating Systems .. 15 3.1 History of operating systems . .16' 3.l.l The 1940s . .16 3.1.2 The 1950s ...... . .16 3.1.3 The 1960s ...... . .16 3.1.4 The 1960s and 1970s . .16 3.1.5 The 1970s, 1980s and 1990s . .17 3.2 Networking . .17 3.3 Problems ............ . · 18 3.4 Bibliography . . . . . . . . . . . · 18 4 Introduction to Using a Computer System . . .19 4.1 Files ........ . .20 4.2 Editors ...... . .20 4.3 Single user systems . .20 4.4 Networked systems. .20 4.5 Multi-user systems . .21 4.6 Other useful things to know .21 4.7 Bibliography . . . . . . . . .22 5 Introduction to Problem Solving .••. 23 5.1 Naturallanguage . .24 5.2 Artificial language .25 5.2.1 Notations .25 5.3 Resume .... .25 5.4 Algorithms . . .26 5.4.1 Top-down. .26 5.4.2 Bottom-up. .26 5.4.3 Stepwise refinement .27 5.4.4 Modular programming .27 vi Contents 5.4.5 Object oriented programming . . . . . ..... 28 5.5 Systems analysis and design . . . . . . . . ..... 28 5.5.1 Problem definition . . . . . . . . .28 5.5.2 Feasibility study and fact finding · . 29 5.5.3 Analysis ... . · .29 5.5.4 Design .... . · .29 5.5.5 Detailed design .29 5.5.6 Implementation .29 5.5.7 Evaluation and testing .29 5.5.8 Maintenance .30 5.6 Conclusions . .30 5.7 Problems .... .30 5.8 Bibliography . . .31 6 Introduction to Programming Languages ................ 33 6.1 Some early theoretical work . . . . . . . . . . . . . . . . . . . 34 6.2 What is a programming language? . . . . . . . . 34 6.3 Program language development and engineering . 34 6.4 The early days . . 34 6.4.1 Fortran .35 6.4.2 Cobol . . . . .35 6.4.3 Algol .... .36 6.5 Chomsky and program language development . 37 6.6 Lisp. . . . . . . . . . . . . . .37 6.7 Snobol. . . . . . . . . . . . . .38 6.8 Second generation languages . . 38 6.8.1 PU1 and Algol 68 . . . 38 6.8.2 Simula. .38 6.8.3 Pascal .38 6.8.4 APL . .39 6.8.5 Basic .39 6.8.6 C. . . .39 6.9 Some other strands in language development . . . .40 6.9.1 Abstraction, stepwise refinement and modules · .40 6.9.2 Structured programming. . . . . . .40 6.9.3 Standardization . . .40 6.10 Ada .. . .41 6.11 Modula ....... . .41 6.12 Modula 2 ...... . .41 6.13 Other language developments . .42 6.13.1 Logo ............ . .42 6.13.2 Postscript, TeX and LaTeX .43 6.13.3 Prolog ........... . · .43 Contents vii 6.13.4 SQL ................ . .43 6.13.5 ICON ............... . .43 6.14 Object orientated programming - OOP .44 6.14.1 Oberon and Oberon 2 .44 6.14.2 Smalltalk .45 6.14.3 C++ .... . .45 6.15 Fortran 90 ... . .46 6.15.1 Fortran 1995 .46 6.15.2 ISO Technical Reports TR15580 and TR15581 . .47 6.15.3 High Performance Fortran - HPF .47 6.15.4 Internet resources . .48 6.16 Summary ................ . .49 6.17 Bibliography . . . . . . . . . . . . . . . .49 7 Introduction to Programming . . . . . . . . . . . . . . . . . . . . . . . SS 7.1 Language standardisation . 56 7.1.1 Fortran 66. . 56 7.1.2 Fortran 77 . . . . . 56 7.1.3 Fortran 90 . . . . . 56 7.1.3.1 Source form . . 56 7.1.3.2 Control structures . . 56 7.1.3.3 Numeric precision .57 7.1.3.4 Array processing . . . .57 7.1.3.5 Dynamic behaviour . . . .57 7.1.3.6 User defined data types and operators. .57 7.1.3.7 Procedures . . . . . . .57 7.1.3.8 Modules. .57 7.1.4 Fortran 95 ... .57 7.1.5 Fortran 2000 . .58 7.2 Language strengths and weaknesses . . . . .58 7.3 Elements of a programming language . . . . . . . . . .58 7.3.1 Data description statements .. .59 7.3.2 Control structures . . . . . . . . . . . . . . . . . . ...... 59 7.3.3 Data processing statements . . . . .59 7.3.4 Input and output (110) statements .59 7.4 Variables - name, type and value .. · .61 7.5 Notes ................ . · .63 7.6 Some more Fortran rules . . . . . . . · .64 7.7 Good programming guidelines . . . · .65 7.8 Fortran character set . . . .65 7.8.1 Notes ...... . .66 7.8.2 Compilers .... . .66 7.9 Program development .67 viii Contents 7.10 Problems. . . . . . . . . . . . . . . . . . ... 68 8 Arithmetic . . • • • . . • • • • • . . • . . • . . •• 69 8.1 Rounding and truncation . . . . . . . . .. ... . . .73 8.2 Example 1: Time taken for light to travel from the Sun to Earth .74 8.3 The PARAMETER statement . . . . . . . . . . . . . . . . . . . .76 8.4 Precision and size of numbers . . . . . . . . . . . . . . . . . . . .77 8.5 Health warning: optional reading, beginners are advised to leave until later . . . . . . . . . . . . . . . . .79 8.5.1 Selecting different INTEGER kinds . . . . . . . . . . . . . .81 8.5.2 Selecting different REAL kinds . . . . . . . . . . . . . . . .82 8.5.3 Specifying kind types for literal integer and real constants . .82 8.5.4 Positional number systems . . . . . . . . . .83 8.5.5 Bit data type and representation model . . .83 8.5.6 Integer data type and representation model .84 8.5.7 Real data type and representation model . .84 8.5.8 IEEE 754 ................. . .85 8.5.9 Example 2: Testing the numerical representation of different kind types on a system . . . . . . . . . . . . . . . . . . . . . .85 8.5.10 Example 3: Binary representation of different integer kind type numbers ........................ . .89 8.5.11 Summary of how to select the appropriate KIND type .91 8.6 Variable status .91 8.7 Summary .. .91 8.8 Problems ... .92 8.9 Bibliography . .95 9 Arrays 1: Some Fundamentals ..••... .97 9.1 Tables of data. . . . . . .98 9.1.1 Telephone directory ..... .98 9.1.2 Book catalogue . . . . . . . . .98 9.1.3 Examination marks or results .99 9.1.4 Monthly rainfall .... .99 9.2 Arrays in Fortran . . . . . . 100 9.3 The DIMENSION attribute 100 9.4 An index .... 101 9.5 Control structure . . . . 101 9.6 Monthly rainfall .... 101 9.6.1 Example 1: Rainfall 102 9.7 People's weights .... 103 9.7.1 Example 2: People's weights. 104 9.8 Summary 105 9.9 Problems ........•.... 106 Contents ix 10 Arrays 2: Further Examples • . . 109 1O.l Higher dimension arrays . . . . 110 10.1.1 Example 1: A map . . . . . . . . . . . 110 10.1.2 Example 2: Sensible tabular output . . . . . 112 10.1.3 Example 3: Average of three sets of values . 112 10.1.4 Example 4: Booking arrangements in a theatre or cinema 114 10.2 Additional forms of the DIMENSION attribute and DO loop statement ................... . 115 10.2.1 Example 5: Voltage from -20 to +20 volts 115 10.2.2 Example 6: Longitude from -180 to + 180 . 116 10.2.3 Notes ............... . 116 10.3 The DO loop and straight repetition . . . . . . 116 10.3.1 Example 7: Table of temperatures . . . . . 116 10.3.2 Example 7: Means and standard deviations 117 10.4 Summary .................. . 118, 10.5 Problems .................. . 119 11 Whole Array and Additional Array Features 123 11.1 Terminology 124 11.1.1 Rank .. 124 11.1.2 Bounds 124 11.1.3 Extent 124 11.1.4 Size .. 124 11.1.5 Shape . 124 11.1.6 Conformable 124 11.2 Whole array manipulation 124 11.2.1 Assignment 125 11.2.2 Expressions . . . 125 11.3 Array sections ... 127 11.3.1 Example 1: Ages 127 11.3.2 Example 2: Examination results 127 11.4 Allocatable arrays ........ . 127 11.4.1 Example 3: Height above sea level 128 11.5 Array element ordering. . . . . . . . . 129 11.5.1 Array element ordering and physical and virtual memory 130 11.6 Array constructors . . . . . . . . . . . . . . . . . . 130 11.7 Masked array assignment and the where statement . 131 11.7.1 Notes ..................... . 132 11.8 The FORALL statement and FORALL construct . 132 11.8.1 Syntax . 133 11.9 Summary .. 133 11.10 Problems .. 133 11.11 Bibliography 134 x Contents 12 Output of Results • . . . . . . 135 12.1 Integers, I fonnat . 136 12.2 Reals, F fonnat 137 12.2.1 Litres to Pints . 138 12.2.2 Pints To Litres 138 12.3 Reals, E fonnat 138 12.3.1 Simple E fonnat example 140 12.4 Spaces ........... . 140 12.5 Alphanumeric or character fonnat, A 141 12.5.1 Headings ............ . 141 12.6 Mixed type output in a FORMAT statement 142 12.7 Common mistakes . . . . 142 12.8 OPEN (and CLOSE) ... 143 12.8.1 The OPEN statement 143 12.8.2 Writing ..... . 144 12.9 Repetition . . . .. . . . 145 12.10 Some more examples . . 147 12.11 Implied DO loops and array sections for array output 148 12.12 Fonnatting for a line-printer . . . . . . . . . . . . . . 151 12.12.1 Mechanics of carriage control . . . . . . . . . . . 152 12.12.2 Generating a new line, on both line-printers and tenninals . 153 12.13 Summary ... . 153 12.14 Problems ....................... . 154 13 Reading in Data . . . . . . . . . . . . . . . . . . . . . . 157 13.1 Reading from the terminal versus reading from files 158 13.2 Fixed fields on input . . . . . . 158 13.2.1 Integers, the I fonnat . . . . 158 13.2.2 Reals, the F and E fonnats 158 13.3 Blanks, nulls and zeros 161 13.4 Characters. . . . . . . . . 162 13.5 Skipping spaces and lines 162 13.6 Reading ........ . 163 13.7 File manipulation again 163 13.8 Errors when reading 164 13.9 Summary ....... . 165 13.10 Problems ....... . 165 14 Functions .......................... . 167 14.1 An introduction to predefined functions and their use 168 14.1.1 Example 1: Simple function usage. . . 169 14.2 Generic functions . . . . . . . . . . . . . . 169 14.2.1 Example 2: The ABS generic function 170 14.3 Elemental functions ........... . 170

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.