Introduction To Programming With Fortran Sleightholme
Introduction To Programming With Fortran Sleightholme
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
Introduction to
Programming
with Fortran
With Coverage of Fortran 90, 95, 2003,
2008 and 77
Third Edition
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
Introduction to Programming
with Fortran
With Coverage of Fortran 90, 95, 2003,
2008 and 77
Third Edition
123
This Book is Available on YakiBooki.com
ing with Fortran (With Coverage of Fortran 90, 95, 2003, 2008 and 77) (
Ian Chivers Jane Sleightholme
Rhymney Consulting Fortranplus
London London
UK UK
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
vii
This Book is Available on YakiBooki.com
viii Acknowledgments
ing with Fortran (With Coverage of Fortran 90, 95, 2003, 2008 and 77) (
– VCS, Germany.
– Veritas DGC Ltd., Crawley.
– Westland Helicopters, Yeovil.
The examples in the book are based on what will work with compilers that
support the Fortran 2008 standard.
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
Thanks are due to:
• The staff and students at King’s College, Chelsea College and Imperial College.
• The people who have attended the commercial courses. It has been great fun
teaching you and things have been very lively at times.
• 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.
• The people at NAG for the provision of beta test versions of their Fortran
compilers and technical help and support.
• The people at Intel for the provision of beta test versions of their Fortran
compilers and technical help and support.
• The people running the Archer service for their help.
• The people at Oracle who helped with the C Interop examples.
• The staff and facilities at PTR Associates. It is a pleasure training there.
• Helmut Michels at the Max-Planck-Institut for permission to use the dislin
library.
• The 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.
• Helen Desmond and James Robinson at Springer for their enthusiasm and
encouragement when things were going wrong!
Our Fortran home page is:
http://www.fortranplus.co.uk/
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Program Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Web Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ix
This Book is Available on YakiBooki.com
x Contents
ing with Fortran (With Coverage of Fortran 90, 95, 2003, 2008 and 77) (
3
Introduction to Programming Languages. . . . . . . . . . . . . . . . . . . 17
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Some Early Theoretical Work . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 What Is a Programming Language? . . . . . . . . . . . . . . . . . . . 18
3.4 Program Language Development and Engineering . . . . . . . . . 18
ad/introduction-to-programming-with-fortran-with-coverage-of-fortran-90
3.5 The Early Days. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5.1 Fortran’s Origins . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5.2 Fortran 77 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.5.3 Cobol. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.5.4 Algol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.6 Chomsky and Program Language Development. . . . . . . . . . . 20
3.7 Lisp. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.8 Snobol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.9 Second-Generation Languages. . . . . . . . . . . . . . . . . . . . . . . 22
3.9.1 PL/1 and Algol 68. . . . . . . . . . . . . . . . . . . . . . . . 22
3.9.2 Simula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.9.3 Pascal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.9.4 APL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.9.5 Basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.9.6 C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.10 Some Other Strands in Language Development . . . . . . . . . . . 24
3.10.1 Abstraction, Stepwise Refinement and Modules. . . . 24
3.10.2 Structured Programming . . . . . . . . . . . . . . . . . . . . 24
3.10.3 Data Structuring and Procedural Programming . . . . 25
3.10.4 Standardisation . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.11 Ada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.12 Modula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.13 Modula 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.14 Other Language Developments . . . . . . . . . . . . . . . . . . . . . . 27
3.14.1 Logo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.14.2 Postscript, TEX and LATEX . . . . . . . . . . . . . . . . . 28
3.14.3 Prolog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.14.4 SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.14.5 ICON. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.15 Object Oriented Programming. . . . . . . . . . . . . . . . . . . . . . . 29
3.15.1 Simula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.15.2 Smalltalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.15.3 Oberon and Oberon 2 . . . . . . . . . . . . . . . . . . . . . 30
3.15.4 Eiffel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.15.5 C++. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.15.6 Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.15.7 C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4 Introduction to Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.2 Language Strengths and Weaknesses . . . . . . . . . . . . . . . . . . 48
4.3 Elements of a Programming Language . . . . . . . . . . . . . . . . . 48
4.3.1 Data Description Statements . . . . . . . . . . . . . . . . . 49
4.3.2 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . 49
4.3.3 Data-Processing Statements. . . . . . . . . . . . . . . . . . 49
4.3.4 Input and Output (I/O) Statements . . . . . . . . . . . . . 49
4.4 Example 1: Simple Text I/O . . . . . . . . . . . . . . . . . . . . . . . . 50
4.5 Variables—Name, Type and Value . . . . . . . . . . . . . . . . . . . 51
4.6 Example 2: Simple Numeric I/O and Arithmetic . . . . . . . . . . 52
4.7 Some More Fortran Rules . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.8 Fortran Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.9 Good Programming Guidelines . . . . . . . . . . . . . . . . . . . . . . 55
4.10 Compilers Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.11 Compiler Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.11.1 Gfortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.11.2 IBM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.11.3 Intel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.11.4 Nag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.11.5 Oracle/Sun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.12 Program Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.13 Reference Text for the Fortran 2003 Standard . . . . . . . . . . . . 61
4.14 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62