PDF Introduction to Programming with Fortran Chivers download
PDF Introduction to Programming with Fortran Chivers download
com
https://textbookfull.com/product/introduction-to-
programming-with-fortran-chivers/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/introduction-to-programming-with-
fortran-ian-chivers/
textboxfull.com
https://textbookfull.com/product/fortran-2018-with-parallel-
programming-1st-edition-subrata-ray-author/
textboxfull.com
https://textbookfull.com/product/introduction-to-scientific-
programming-with-python-joakim-sundnes/
textboxfull.com
https://textbookfull.com/product/introduction-to-programming-
with-c-1st-edition-nhce/
textboxfull.com
Introduction to Linear Programming with MATLAB 1st Edition
Shashi Kant Mishra
https://textbookfull.com/product/introduction-to-linear-programming-
with-matlab-1st-edition-shashi-kant-mishra/
textboxfull.com
https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-with-application-to-understanding-data-
guttag/
textboxfull.com
https://textbookfull.com/product/learning-java-an-introduction-to-
real-world-programming-with-java-marc-loy/
textboxfull.com
https://textbookfull.com/product/modern-fortran-explained-
incorporating-fortran-2018-michael-metcalf/
textboxfull.com
Ian Chivers · Jane Sleightholme
Introduction to
Programming
with Fortran
Fourth Edition
Introduction to Programming with Fortran
Ian Chivers Jane Sleightholme
•
Introduction to Programming
with Fortran
Fourth Edition
123
Ian Chivers Jane Sleightholme
Rhymney Consulting Fortranplus
London London
UK UK
This Springer imprint is published by the registered company Springer International Publishing AG
part of Springer Nature
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
The Yorkshire connection dedicates the book
to Steve, Mark and Jonathan. The Welsh
connection dedicates the book to Joan,
Martin and Jenny.
Acknowledgements
vii
viii Acknowledgements
– VCS, Germany
– Veritas DGC Ltd., Crawley
– Westland Helicopters, Yeovil.
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 Institute 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 Nancy Wade-Jones at Springer for their enthusiasm and
encouragement when things were going wrong!
Our Fortran home page is:
https://www.fortranplus.co.uk/
All of the programme examples can be found there.
If you would like to contact us, our email addresses are:
Ian Chivers: ian@rhymneyconsulting.co.uk
Jane Sleightholme: jane@fortranplus.co.uk
The manuscript was produced using Springer’s LATEX style sheet. We used
proTEXt, MiKTEX and TEXnicCentre on the Windows platform. The graphs and
plots were produced using the dislin graphics library. We started using TEX at
Imperial College on several CDC systems in the 1980s. TEX and LATEX have come a
long way since then and plain TEX seems a distant memory.
Contents
1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Program Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Web Addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Introduction to Problem Solving . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Natural Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Artificial Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3.1 Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 Resume . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.5.1 Top-Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.5.2 Bottom-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.5.3 Stepwise Refinement . . . . . . . . . . . . . . . . . . . . . . . . 11
2.6 Modular Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.7 Object Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . 12
2.8 Systems Analysis and Design . . . . . . . . . . . . . . . . . . . . . . . . 12
2.8.1 Problem Definition . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.8.2 Feasibility Study and Fact Finding . . . . . . . . . . . . . . 13
2.8.3 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.8.4 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.8.5 Detailed Design . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.8.6 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.8.7 Evaluation and Testing . . . . . . . . . . . . . . . . . . . . . . 14
2.8.8 Maintenance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.9 Unified Modelling Language - UML . . . . . . . . . . . . . . . . . . . 14
2.10 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.11 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.12 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
ix
x Contents
20 Subroutines: 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
20.1 More on Parameter Passing . . . . . . . . . . . . . . . . . . . . . . . . . . 321
20.1.1 Assumed-Shape Array . . . . . . . . . . . . . . . . . . . . . . . 321
20.1.2 Deferred-Shape Array . . . . . . . . . . . . . . . . . . . . . . . 322
20.1.3 Automatic Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 322
20.1.4 Allocatable Dummy Arrays . . . . . . . . . . . . . . . . . . . 322
20.1.5 Keyword and Optional Arguments . . . . . . . . . . . . . . 322
20.2 Example 1: Assumed Shape Parameter Passing . . . . . . . . . . . . 323
20.2.1 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
20.3 Example 2: Character Arguments and Assumed-Length
Dummy Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
20.4 Example 3: Rank 2 and Higher Arrays as Parameters . . . . . . . 327
20.4.1 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
20.5 Example 4: Automatic Arrays and Median Calculation . . . . . . 329
20.5.1 Internal Subroutines and Scope . . . . . . . . . . . . . . . . 332
20.6 Example 5: Recursive Subroutines – Quicksort . . . . . . . . . . . . 332
20.6.1 Note — Recursive Subroutine . . . . . . . . . . . . . . . . . 335
20.6.2 Note — Flexible Design . . . . . . . . . . . . . . . . . . . . . 335
20.7 Example 6: Allocatable Dummy Arrays . . . . . . . . . . . . . . . . . 336
20.8 Example 7: Elemental Subroutines . . . . . . . . . . . . . . . . . . . . . 339
20.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
20.10 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
20.11 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
20.12 Commercial Numerical and Statistical Subroutine Libraries . . . 342
21 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
21.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
21.2 Basic Module Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
21.3 Modules for Global Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
21.4 Example 1: Modules for Precision Specification and Constant
Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
21.5 Example 2: Modules for Globally Sharing Data . . . . . . . . . . . 347
21.6 Modules for Derived Data Types . . . . . . . . . . . . . . . . . . . . . . 349
21.7 Example 3: Person Data Type . . . . . . . . . . . . . . . . . . . . . . . . 350
21.8 Example 4: A Module for Simple Timing of a Program . . . . . 352
21.9 private, public and protected Attributes . . . . . . . . . . 353
21.10 The use Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
21.11 Notes on Module Usage and Compilation . . . . . . . . . . . . . . . . 354
21.12 Example 5: Modules and Include Statements . . . . . . . . . . . . . 354
21.13 Formal Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
21.13.1 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
21.13.2 Implicit and Explicit Interfaces . . . . . . . . . . . . . . . . 356
21.13.3 Explicit Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Contents xxi
33 OpenMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
33.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
33.2 OpenMP Memory Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
33.3 Example 1: Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
33.4 Example 2: Hello World Using Default Variable Data
Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
33.5 Example 3: Hello World with Private
thread number variable . . . . . . . . . . . . . . . . . . . . . . . 612
33.6 Example 4: Parallel Solution for pi Calculation . . . . . . . . . . . . 613
33.7 Example 5: Comparing the Timing of Whole Array Syntax,
Simple Do Loops, Do Concurrent and an OpenMP
Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
33.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
33.9 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
34 Coarray Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
34.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
34.2 Some Basic Coarray Terminology . . . . . . . . . . . . . . . . . . . . . 622
34.3 Example 1: Hello World . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
34.4 Example 2: Broadcasting Data . . . . . . . . . . . . . . . . . . . . . . . . 624
34.5 Example 3: Parallel Solution for pi Calculation . . . . . . . . . . . . 625
34.6 Example 4: Work Sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
34.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
34.8 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
35 C Interop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
35.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
35.2 The iso_c_binding Module . . . . . . . . . . . . . . . . . . . . . . . 633
35.3 Named Constants and Derived Types in the Module . . . . . . . . 634
35.4 Character Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
35.5 Procedures in the Module . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
35.6 Interoperability of Intrinsic Types . . . . . . . . . . . . . . . . . . . . . 635
35.7 Other Aspects of Interoperability . . . . . . . . . . . . . . . . . . . . . . 636
35.7.1 Interoperability with C Pointer Types . . . . . . . . . . . . 636
35.7.2 Interoperability of Scalar Variables . . . . . . . . . . . . . 636
35.7.3 Interoperability of Array Variables . . . . . . . . . . . . . . 636
35.7.4 Interoperability of Procedures and Procedure
Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
35.7.5 Interoperation with C Global Variables . . . . . . . . . . 636
35.7.6 Binding Labels for Common Blocks
and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
35.7.7 Interoperation with C Functions . . . . . . . . . . . . . . . . 637
35.8 Compilers Used in the Examples . . . . . . . . . . . . . . . . . . . . . . 637
35.9 Example 1: Kind Type Support . . . . . . . . . . . . . . . . . . . . . . . 638
Contents xxvii
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com