ebook img

Introduction to Programming with Fortran: With Coverage of Fortran 90, 95, 2003, 2008 and 77 PDF

642 Pages·2012·6.75 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 Introduction to Programming with Fortran: With Coverage of Fortran 90, 95, 2003, 2008 and 77

Introduction to Programming with Fortran Ian Chivers (cid:129) Jane Sleightholme Introduction to Programming with Fortran With Coverage of Fortran 90, 95, 2003, 2008 and 77 Ian Chivers Jane Sleightholme Rhymney Consulting Fortranplus UK UK ISBN 978-0-85729-232-2 e-ISBN 978-0-85729-233-9 DOI 10.1007/978-0-85729-233-9 Springer London Dordrecht Heidelberg New York British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Control Number: 2011941580 © Springer-Verlag London Limited 2012 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 licenses issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. The use of registered names, trademarks, etc., in this publication does not imply, even in the absence of a specifi c 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, with 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. Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com) Acknowledgement T he material in the book has evolved fi rstly from our combined experience of working in Computing Services within the University of London at (cid:129) King’s College, IDC (1986–2002) and JS (1985–2008) (cid:129) Chelsea College, JS (1978–1985) (cid:129) Imperial College, IDC (1978–1986) in the teaching, advice and support of Fortran and related areas, and secondly in the provision of commercial training courses. The following are some of the organisa- tions we’ve provided training for: (cid:129) AWE, Aldermaston. (cid:129) Centre for Ecology and Hydrology, Wallingford. (cid:129) DTU – Danish Technical University. (cid:129) Environment Agency, Worthing. (cid:129) JET – Joint European Torus. (cid:129) The Met Offi ce, Bracknell and Exeter. (cid:129) Natural Resources Canada, Ottowa. (cid:129) QinetiQ, Farnborough. (cid:129) Rolls Royce, Derby. (cid:129) SHMU, Slovak Hydrometeorological Institute, Bratislava, Slovakia. (cid:129) University of Ulster, Jordanstown, Northern Ireland. (cid:129) Veritas DGC Ltd., Crawley. (cid:129) Westland Helicopters, Yeovil. T he examples in the book are based on what will work with compilers that support the Fortran 2008 standard. Thanks are due to: (cid:129) The staff and students at King’s College, Chelsea College and Imperial College. (cid:129) The people who have attended the commercial courses. Its been great fun teaching you and things have been very lively at times. v vi Acknowledgement (cid:129) The people on the Fortran 90 list and comp.lang.fortran. Access to the expertise of several hundred people involved in the use and development of Fortran on a daily basis across a wide range of disciplines is inestimable. (cid:129) The people at NAG for the provision of beta test versions of their Fortran compilers. (cid:129) T he people at Intel for the provision of beta test versions of their Fortran compilers. (cid:129) The staff and facilities at PTR Associates. It is a pleasure training there. (cid:129) Helmut Michels at the Max-Planck-Institut for permission to use the dislin library. (cid:129) T he patience of our families during the time required to develop the courses upon which this book is based and whilst preparing the camera-ready copy. (cid:129) Finally Helen Desmond and Beverley Ford at Springer for their enthusiasm and encouragement! Our Fortran home page is: (cid:129) http://www.fortranplus.co.uk/ All of the program examples can be found there. If you would like to contact us our email addresses are: Ian D Chivers: [email protected] Jane Sleightholme: [email protected] Contents 1 Overview .................................................................................................. 1 1.1 Introduction ...................................................................................... 1 1.2 Program Examples ........................................................................... 5 1.3 Further Reading ............................................................................... 5 1.3.1 The Fortran Standard ........................................................... 5 1.3.2 J3 and WG5 Working Documents ....................................... 5 1.3.3 Compiler Documentation ..................................................... 5 1.3.4 Books ................................................................................... 7 2 Introduction to Problem Solving ........................................................... 9 2.1 Introduction ...................................................................................... 10 2.2 Natural Language ............................................................................. 10 2.3 Artifi cial Language .......................................................................... 10 2.3.1 Notations .............................................................................. 11 2.4 Resume ............................................................................................. 11 2.5 Algorithms ....................................................................................... 11 2.5.1 Top-Down ............................................................................ 12 2.5.2 Bottom-Up ........................................................................... 12 2.5.3 Stepwise Refi nement ............................................................ 13 2.6 Module Programming ...................................................................... 13 2.7 Object Oriented Programming ......................................................... 13 2.8 Systems Analysis and Design .......................................................... 13 2.8.1 Problem Defi nition ............................................................... 14 2.8.2 Feasibility Study and Fact Finding ...................................... 14 2.8.3 Analysis ................................................................................ 14 2.8.4 Design .................................................................................. 15 2.8.5 Detailed Design .................................................................... 15 2.8.6 Implementation .................................................................... 15 2.8.7 Evaluation and Testing ......................................................... 15 2.8.8 Maintenance ......................................................................... 16 2.9 Conclusions ...................................................................................... 16 vii viii Contents 2.10 Problems ........................................................................................ 16 2.11 Bibliography .................................................................................. 17 3 Introduction to Programming Languages ............................................ 19 3.1 Introduction .................................................................................... 19 3.2 Some Early Theoretical Work ........................................................ 20 3.3 What Is a Programming Language? ............................................... 20 3.4 Program Language Development and Engineering ....................... 20 3.5 The Early Days .............................................................................. 20 3.5.1 Fortran’s Origins .............................................................. 20 3.5.2 Fortran 77 ......................................................................... 21 3.5.3 Cobol ................................................................................ 21 3.5.4 Algol ................................................................................. 22 3.6 Chomsky and Program Language Development ............................ 22 3.7 Lisp ................................................................................................ 23 3.8 Snobol ............................................................................................ 23 3.9 Second-Generation Languages ...................................................... 24 3.9.1 PL/1 and Algol 68 ............................................................ 24 3.9.2 Simula .............................................................................. 24 3.9.3 Pascal ................................................................................ 24 3.9.4 APL .................................................................................. 25 3.9.5 Basic ................................................................................. 25 3.9.6 C ....................................................................................... 25 3.10 Some Other Strands in Language Development ............................ 26 3.10.1 Abstraction, Stepwise Refi nement and Modules ............. 26 3.10.2 Structured Programming .................................................. 26 3.10.3 Data Structuring and Procedural Programming ............... 26 3.10.4 Standardisation ................................................................. 27 3.11 Ada ................................................................................................. 27 3.12 Modula ........................................................................................... 28 3.13 Modula 2 ........................................................................................ 28 3.14 Other Language Developments ...................................................... 28 3.14.1 Logo ................................................................................. 29 3.14.2 Postscript, TeX and LaTeX .............................................. 29 3.14.3 Prolog ............................................................................... 29 3.14.4 SQL .................................................................................. 29 3.14.5 ICON ................................................................................ 30 3.15 Object Oriented Programming ....................................................... 30 3.15.1 Simula .............................................................................. 31 3.15.2 Smalltalk .......................................................................... 31 3.15.3 Oberon and Oberon 2 ....................................................... 31 3.15.4 Eiffel ................................................................................. 32 3.15.5 C++ ................................................................................... 32 3.15.6 Java ................................................................................... 33 3.15.7 C# ..................................................................................... 33 Contents ix 3.16 Back to Fortran! ............................................................................. 34 3.16.1 Fortran 90 ......................................................................... 34 3.16.2 Fortran 95 ......................................................................... 35 3.16.3 ISO Technical Reports TR15580 and TR15581 .............. 36 3.16.4 Fortran 2003 ..................................................................... 36 3.16.5 DTR 19767 Enhanced Module Facilities ......................... 37 3.16.6 Fortran 2008 ..................................................................... 37 3.16.7 The Future ........................................................................ 37 3.17 Internet Resources .......................................................................... 38 3.17.1 Standards Information ...................................................... 38 3.17.2 Fortran Discussion Lists ................................................... 38 3.17.3 Other Sources ................................................................... 39 3.18 Summary ........................................................................................ 39 3.19 Bibliography .................................................................................. 39 4 Introduction to Programming ................................................................ 45 4.1 Introduction .................................................................................... 45 4.2 Language Strengths and Weaknesses ............................................. 46 4.3 Elements of a Programming Language .......................................... 46 4.3.1 Data Description Statements ............................................ 47 4.3.2 Control Structures ............................................................ 47 4.3.3 Data-Processing Statements ............................................. 47 4.3.4 Input and Output (I/O) Statements ................................... 47 4.4 Variables—Name, Type and Value ................................................ 49 4.5 Notes .............................................................................................. 51 4.6 Some More Fortran Rules .............................................................. 52 4.7 Fortran Character Set ..................................................................... 52 4.8 Good Programming Guidelines ..................................................... 54 4.9 Compilers ....................................................................................... 54 4.10 Program Development ................................................................... 55 4.11 Problems ........................................................................................ 56 5 Arithmetic ................................................................................................ 57 5.1 An Introduction to Arithmetic in Fortran ....................................... 58 5.2 Example 1: Simple Arithmetic Expressions in Fortran ................. 58 5.3 Rounding and Truncation ............................................................... 61 5.3.1 Example 2: Type Conversion and Assignment ................ 61 5.3.2 Example 3: Integer Division and Real Assignment ......... 62 5.4 Example 4: Time Taken for Light to Travel from the Sun to Earth ..................................................................... 63 5.5 The parameter Attribute ........................................................... 64 5.6 Range, Precision and Size of Numbers .......................................... 65 5.7 Health Warning: Optional Reading, Beginners are Advised to Leave Until Later ....................................................................... 67 5.7.1 Example 5: Default Kinds ................................................ 67 5.7.2 Selecting Different Integer Kind Types ............................ 68

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.