Professional Documents
Culture Documents
(Download PDF) Modern Fortran Explained Incorporating Fortran 2018 Michael Metcalf Online Ebook All Chapter PDF
(Download PDF) Modern Fortran Explained Incorporating Fortran 2018 Michael Metcalf Online Ebook All Chapter PDF
https://textbookfull.com/product/modern-fortran-explained-
michael-metcalf/
https://textbookfull.com/product/fortran-2018-with-parallel-
programming-1st-edition-subrata-ray-author/
https://textbookfull.com/product/modern-fortran-building-
efficient-parallel-applications-1st-edition-milan-curcic/
https://textbookfull.com/product/modern-fortran-building-
efficient-parallel-applications-1st-edition-milan-curcic-2/
Introduction to Programming with Fortran Chivers
https://textbookfull.com/product/introduction-to-programming-
with-fortran-chivers/
https://textbookfull.com/product/introduction-to-programming-
with-fortran-ian-chivers/
https://textbookfull.com/product/fortran-for-scientists-and-
engineers-4th-edition-stephen-j-chapman/
https://textbookfull.com/product/the-second-world-war-explained-
michael-okelly/
https://textbookfull.com/product/c-core-guidelines-explained-
best-practices-for-modern-c-1st-edition-grimm/
NUMERICAL MATHEMATICS AND SCIENTIFIC COMPUTATION
Series Editors
A. M. STUART E. SÜLI
NUMERICAL MATHEMATICS AND SCIENTIFIC COMPUTATION
C. Schwab: p- and hp- Finite Element Methods: Theory and Applications in Solid and Fluid Mechanics
J. W. Jerome: Modelling and Computation for Applications in Mathematics, Science, and Engineering
A. Quarteroni and A. Valli: Domain Decomposition Methods for Partial Differential Equations
G. Em Karniadakis and S. J. Sherwin: Spectral/hp Element Methods for Computational Fluid Dynamics
I. Babuška and T. Strouboulis: The Finite Element Method and its Reliability
B. Mohammadi and O. Pironneau: Applied Shape Optimization for Fluids
S. Succi: The Lattice Boltzmann Equation for Fluid Dynamics and Beyond
P. Monk: Finite Element Methods for Maxwell’s Equations
A. Bellen and M. Zennaro: Numerical Methods for Delay Differential Equations
J. Modersitzki: Numerical Methods for Image Registration
M. Feistauer, J. Felcman, and I. Straškraba: Mathematical and Computational Methods for Compressible Flow
W. Gautschi: Orthogonal Polynomials: Computation and Approximation
M. K. Ng: Iterative Methods for Toeplitz Systems
M. Metcalf, J. Reid, and M. Cohen: Fortran 95/2003 Explained
G. Em Karniadakis and S. Sherwin: Spectral/hp Element Methods for Computational Fluid Dynamics,
Second Edition
D. A. Bini, G. Latouche, and B. Meini: Numerical Methods for Structured Markov Chains
H. Elman, D. Silvester, and A. Wathen: Finite Elements and Fast Iterative Solvers: With Applications
in Incompressible Fluid Dynamics
M. Chu and G. Golub: Inverse Eigenvalue Problems: Theory, Algorithms, and Applications
J.-F. Gerbeau, C. Le Bris, and T. Lelièvre: Mathematical Methods for the Magnetohydrodynamics of Liquid Metals
G. Allaire and A. Craig: Numerical Analysis and Optimization: An Introduction to Mathematical Modelling and
Numerical Simulation
K. Urban: Wavelet Methods for Elliptic Partial Differential Equations
B. Mohammadi and O. Pironneau: Applied Shape Optimization for Fluids, Second Edition
K. Boehmer: Numerical Methods for Nonlinear Elliptic Differential Equations: A Synopsis
M. Metcalf, J. Reid, and M. Cohen: Modern Fortran Explained
J. Liesen and Z. Strakoš: Krylov Subspace Methods: Principles and Analysis
R. Verfürth: A Posteriori Error Estimation Techniques for Finite Element Methods
H. Elman, D. Silvester, and A. Wathen: Finite Elements and Fast Iterative Solvers: With Applications in
Incompressible Fluid Dynamics, Second Edition
I. Duff, A. Erisman, and J. Reid: Direct Methods for Sparse Matrices, Second Edition
M. Metcalf, J. Reid, and M. Cohen: Modern Fortran Explained, Second Edition
Modern Fortran Explained
1
3
Great Clarendon Street, Oxford, OX2 6DP,
United Kingdom
Oxford University Press is a department of the University of Oxford.
It furthers the University’s objective of excellence in research, scholarship,
and education by publishing worldwide. Oxford is a registered trade mark of
Oxford University Press in the UK and in certain other countries
c Michael Metcalf, John Reid and Malcolm Cohen 2018
The moral rights of the authors have been asserted
First edition published 1987 as Fortran 8x Explained
Second edition published 1989
Third edition published in 1990 as Fortran 90 Explained
Fourth edition published 1996 as Fortran 90/95 Explained
Fifth edition published 1999
Sixth edition published 2004 as Fortran 95/2003 Explained
Seventh edition published 2011 as Modern Fortran Explained
This edition published 2018
Impression: 1
All rights reserved. No part of this publication may be reproduced, stored in
a retrieval system, or transmitted, in any form or by any means, without the
prior permission in writing of Oxford University Press, or as expressly permitted
by law, by licence or under terms agreed with the appropriate reprographics
rights organization. Enquiries concerning reproduction outside the scope of the
above should be sent to the Rights Department, Oxford University Press, at the
address above
You must not circulate this work in any other form
and you must impose this same condition on any acquirer
Published in the United States of America by Oxford University Press
198 Madison Avenue, New York, NY 10016, United States of America
British Library Cataloguing in Publication Data
Data available
Library of Congress Control Number: 2018947662
ISBN 978–0–19–881189–3 (hbk.)
ISBN 978–0–19–881188–6 (pbk.)
DOI 10.1093/oso/9780198811886.001.0001
Printed and bound by
CPI Group (UK) Ltd, Croydon, CR0 4YY
Preface
Fortran remains one of the principal languages used in the fields of scientific, numerical,
and engineering programming, and a series of revisions to the standard defining successive
versions of the language has progressively enhanced its power and kept it competitive with
several generations of rivals.
Beginning in 1978, the technical committee responsible for the development of Fortran
standards, X3J3 (now PL22.3 but still informally called J3), laboured to produce a new, much-
needed modern version of the language, Fortran 90. Its purpose was to ‘promote portability,
reliability, maintainability, and efficient execution . . . on a variety of computing systems’.
That standard was published in 1991, and work began in 1993 on a minor revision, known as
Fortran 95. Subsequently, and with the same purpose, a further major upgrade to the language
was prepared by J3 and the international committee, WG5. That revision, which included
object-oriented programming features, is now known as Fortran 2003. This was followed
by a further revision, Fortran 2008, including coarrays; and, most recently, a minor revision,
Fortran 2018, including further coarray features. Once again, we have prepared a definitive
informal description of the language that this latest standard defines. This continues the series
of editions of this book – the two editions of Fortran 8x Explained that described the two
drafts of the standard (1987 and 1989), Fortran 90 Explained that described the Fortran 90
standard (1990), two editions of Fortran 90/95 Explained that included Fortran 95 as well
(1996 and 1999) and Fortran 95/2003 (2004), with its added chapters on Fortran 2003. In
that endeavour, a third co-author was welcomed. Finally, the first edition of Modern Fortran
Explained (2011) added further chapters on Fortran 2008.
In this edition the basic language is Fortran 2008. An initial chapter sets out the background
to the work on new standards, and Chapters 2 to 19 describe Fortran 2008 in a manner
suitable both for grasping the implications of its features and for writing programs. The
remaining chapters describe the additional features of Fortran 2018. Some knowledge of
programming concepts is assumed. In order to reduce the number of forward references and
also to enable, as quickly as possible, useful programs to be written based on material already
absorbed, the order of presentation does not always follow that of the standard. In particular,
we have chosen to defer to appendices the description of features that are officially labelled
as redundant (some of which were deleted from the standard) and other features whose use
we deprecate. They may be encountered in old programs, but are not needed in new ones.
Note that, apart from a small number of deletions, each of the languages Fortran 77,
Fortran 90, Fortran 95, Fortran 2003, Fortran 2008, and Fortran 2018 is a subset of its
successor.
vi Preface
In order to make the book a complete reference work it concludes with four appendices.
They contain, successively, a description of various features whose use we deprecate and
do not describe in the body of the book, a description of obsolescent and deleted features,
an extended example illustrating the use of object orientation, and solutions to most of the
exercises.
It is our hope that this book, by providing complete descriptions of Fortran 2008 and
Fortran 2018, will continue the helpful role that earlier editions played for the corresponding
versions of the standard, and that it will serve as a long-term reference work for the modern
Fortran programming language.
Conventions used in this book
1 Whence Fortran? 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Fortran’s early history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 The drive for the Fortran 90 standard . . . . . . . . . . . . . . . . . . . . . 2
1.4 Language evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Fortran 95 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.6 Extensions to Fortran 95 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 Fortran 2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.8 Extensions to Fortran 2003 . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.9 Fortran 2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.10 Extensions to Fortran 2008 . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.11 Fortran 2018 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.12 Conformance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Language elements 9
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Fortran character set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Concept of type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.6 Literal constants of intrinsic type . . . . . . . . . . . . . . . . . . . . . . . 13
2.6.1 Integer literal constants . . . . . . . . . . . . . . . . . . . . . . . . 14
2.6.2 Real literal constants . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.6.3 Complex literal constants . . . . . . . . . . . . . . . . . . . . . . . 16
2.6.4 Character literal constants . . . . . . . . . . . . . . . . . . . . . . . 16
2.6.5 Logical literal constants . . . . . . . . . . . . . . . . . . . . . . . . 18
2.6.6 Binary, octal, and hexadecimal constants . . . . . . . . . . . . . . . 19
2.7 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.8 Scalar variables of intrinsic type . . . . . . . . . . . . . . . . . . . . . . . . 20
2.9 Derived data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.10 Arrays of intrinsic type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.10.1 Declaring entities of differing shapes . . . . . . . . . . . . . . . . . 25
2.10.2 Allocatable objects . . . . . . . . . . . . . . . . . . . . . . . . . . 25
x Contents
4 Control constructs 55
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.2 The if construct and statement . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.3 The case construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.4 The do construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.5 Exit from nearly any construct . . . . . . . . . . . . . . . . . . . . . . . . . 62
4.6 The go to statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
• Procedure pointers.
• Support for international usage: access to ISO 10646 four-byte characters and choice
of decimal point or comma in numeric formatted I/O.
• Enhanced integration with the host operating system: access to command line
arguments, environment variables, and processor error messages.