Modern Fortran Explained: Incorporating Fortran 2018

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Fortran marches on, remaining one of the principal programming languages used in high-performance scientific, numerical, and engineering computing. A series of significant revisions to the standard versions of the language have progressively enhanced its capabilities, and the latest standard — Fortran 2018 — includes many additions and improvements.

This edition of Modern Fortran Explained expands on the last. Given the release of updated versions of Fortran compilers, the separate descriptions of Fortran 2003 and Fortran 2008 have been incorporated into the main text, which thereby becomes a unified description of the full Fortran 2008 version of the language. This clearer standard has allowed many deficiencies and irregularities in the earlier language versions to be resolved.

Four new chapters describe the additional features of Fortran 2018, with its enhancements to coarrays for parallel programming, interoperability with C, IEEE arithmetic, and various other improvements.

Written by leading experts in the field, two of whom have actively contributed to Fortran 2018, this is a complete and authoritative description of Fortran in its latest form. It is intended for new and existing users of the language, and for all those involved in scientific and numerical computing. It is suitable as a textbook for teaching and, with its index, as a handy reference for practitioners.

Author(s): Michael Metcalf; John Reid; Malcolm Cohen
Series: Numerical mathematics and scientific computation
Publisher: Oxford University Press, USA
Year: 2018

Language: English
Commentary: Fixed and extended bookmarks.
Pages: 544
Tags: Fortran

Contents

1 Whence Fortran?
1.1 Introduction
1.2 Fortran’s early history
1.3 The drive for the Fortran 90 standard
1.4 Language evolution
1.5 Fortran 95
1.6 Extensions to Fortran 95
1.7 Fortran 2003
1.8 Extensions to Fortran 2003
1.9 Fortran 2008
1.10 Extensions to Fortran 2008
1.11 Fortran 2018
1.12 Conformance

2 Language elements
2.1 Introduction
2.2 Fortran character set
2.3 Tokens
2.4 Source form
2.5 Concept of type
2.6 Literal constants of intrinsic type
2.6.1 Integer literal constants
2.6.2 Real literal constants
2.6.3 Complex literal constants
2.6.4 Character literal constants
2.6.5 Logical literal constants
2.6.6 Binary, octal, and hexadecimal constants
2.7 Names
2.8 Scalar variables of intrinsic type
2.9 Derived data types
2.10 Arrays of intrinsic type
2.10.1 Declaring entities of differing shapes
2.10.2 Allocatable objects
2.11 Character substrings
2.12 Pointers
2.13 Objects and subobjects
2.14 Summary

3 Expressions and assignments
3.1 Introduction
3.2 Scalar numeric expressions
3.3 Defined and undefined variables
3.4 Scalar numeric assignment
3.5 Scalar relational operators
3.6 Scalar logical expressions and assignments
3.7 Scalar character expressions and assignments
3.7.1 ASCII character set
3.7.2 ISO 10646 character set
3.8 Structure constructors
3.9 Scalar defined operators
3.10 Scalar defined assignments
3.11 Array expressions
3.12 Array assignment
3.13 Pointers in expressions and assignments
3.14 The nullify statement
3.15 Summary

4 Control constructs
4.1 Introduction
4.2 The if construct and statement
4.3 The case construct
4.4 The do construct
4.5 Exit from nearly any construct
4.6 The go to statement
4.7 Summary

5 Program units and procedures
5.1 Introduction
5.2 Main program
5.3 The stop statement
5.4 External subprograms
5.5 Modules
5.6 Internal subprograms
5.7 Arguments of procedures
5.7.1 Assumed-shape arrays
5.7.2 Pointer arguments
5.7.3 Restrictions on actual arguments
5.7.4 Arguments with the target attribute
5.8 The return statement
5.9 Argument intent
5.10 Functions
5.10.1 Prohibited side-effects
5.11 Explicit and implicit interfaces
5.11.1 The import statement
5.12 Procedures as arguments
5.13 Keyword and optional arguments
5.14 Scope of labels
5.15 Scope of names
5.16 Direct recursion
5.17 Indirect recursion
5.18 Overloading and generic interfaces
5.19 Assumed character length
5.20 The subroutine and function statements
5.21 Summary

6 Allocation of data
6.1 Introduction
6.2 The allocatable attribute
6.3 Deferred type parameters
6.4 Allocatable scalars
6.5 The allocate statement
6.6 The deallocate statement
6.7 Automatic reallocation
6.8 Transferring an allocation
6.9 Allocatable dummy arguments
6.10 Allocatable functions
6.11 Allocatable components
6.11.1 Allocatable components of recursive type
6.12 Allocatable arrays vs. pointers
6.13 Summary

7 Array features
7.1 Introduction
7.2 Zero-sized arrays
7.3 Automatic objects
7.4 Elemental operations and assignments
7.5 Array-valued functions
7.6 The where statement and construct
7.7 Mask arrays
7.8 Pure procedures
7.9 Elemental procedures
7.10 Impure elemental procedures
7.11 Array elements
7.12 Array subobjects
7.13 Arrays of pointers
7.14 Pointers as aliases
7.15 Pointer assignment
7.16 Array constructors
7.17 The do concurrent construct
7.18 Performance-oriented features
7.18.1 The contiguous attribute
7.18.2 Simply contiguous array designators
7.18.3 Automatic pointer targetting
7.19 Summary

8 Specification statements
8.1 Introduction
8.2 Implicit typing
8.3 Named constants
8.4 Constant expressions
8.5 Initial values for variables
8.5.1 Initialization in type declaration statements
8.5.2 The data statement
8.5.3 Pointer initialization as disassociated
8.5.4 Pointer initialization as associated
8.5.5 Default initialization of components
8.6 Accessibility
8.6.1 The public and private attributes
8.6.2 More control of access from a module
8.7 Pointer functions denoting variables
8.8 The pointer, target, and allocatable statements
8.9 The intent and optional statements
8.10 The save attribute
8.11 Volatility
8.11.1 The volatile attribute
8.11.2 Volatile scoping
8.11.3 Volatile arguments
8.12 The asynchronous attribute
8.13 The block construct
8.14 The use statement
8.15 Derived-type definitions
8.16 The type declaration statement
8.17 Type and type parameter specification
8.18 Specification expressions
8.19 Structure constructors
8.20 The namelist statement
8.21 Summary

9 Intrinsic procedures and modules
9.1 Introduction
9.1.1 Keyword calls
9.1.2 Categories of intrinsic procedures
9.1.3 The intrinsic statement
9.1.4 Argument intents
9.2 Inquiry functions for any type
9.3 Elemental numeric functions
9.3.1 Elemental functions that may convert
9.3.2 Elemental functions that do not convert
9.4 Elemental mathematical functions
9.5 Transformational functions for Bessel functions
9.6 Elemental character and logical functions
9.6.1 Character–integer conversions
9.6.2 Lexical comparison functions
9.6.3 String-handling elemental functions
9.6.4 Logical conversion
9.7 Non-elemental string-handling functions
9.7.1 String-handling inquiry function
9.7.2 String-handling transformational functions
9.8 Character inquiry function
9.9 Numeric inquiry and manipulation functions
9.9.1 Models for integer and real data
9.9.2 Numeric inquiry functions
9.9.3 Elemental functions to manipulate reals
9.9.4 Transformational functions for kind values
9.10 Bit manipulation procedures
9.10.1 Model for bit data
9.10.2 Inquiry function
9.10.3 Basic elemental functions
9.10.4 Shift operations
9.10.5 Elemental subroutine
9.10.6 Bitwise (unsigned) comparison
9.10.7 Double-width shifting
9.10.8 Bitwise reductions
9.10.9 Counting bits
9.10.10 Producing bitmasks
9.10.11 Merging bits
9.11 Transfer function
9.12 Vector and matrix multiplication functions
9.13 Transformational functions that reduce arrays
9.13.1 Single argument case
9.13.2 Additional argument dim
9.13.3 Optional argument mask
9.14 Array inquiry functions
9.14.1 Contiguity
9.14.2 Bounds, shape, and size
9.15 Array construction and manipulation functions
9.15.1 The merge elemental function
9.15.2 Packing and unpacking arrays
9.15.3 Reshaping an array
9.15.4 Transformational function for replication
9.15.5 Array shifting functions
9.15.6 Matrix transpose
9.16 Transformational functions for geometric location
9.17 Transformational function for disassociated or unallocated
9.18 Non-elemental intrinsic subroutines
9.18.1 Real-time clock
9.18.2 CPU time
9.18.3 Random numbers
9.18.4 Executing another program
9.19 Access to the computing environment
9.19.1 Environment variables
9.19.2 Information about the program invocation
9.20 Elemental functions for I/O status testing
9.21 Size of an object in memory
9.22 Miscellaneous procedures
9.23 Intrinsic modules
9.24 Fortran environment
9.24.1 Named constants
9.24.2 Compilation information
9.24.3 Names for common kinds
9.24.4 Kind arrays
9.24.5 Lock type
9.25 Summary

10 Data transfer
10.1 Introduction
10.2 Number conversion
10.3 I/O lists
10.4 Format definition
10.5 Unit numbers
10.6 Internal files
10.7 Formatted input
10.8 Formatted output
10.9 List-directed I/O
10.10 Namelist I/O
10.11 Non-advancing I/O
10.12 Unformatted I/O
10.13 Direct-access files
10.14 UTF-8 files
10.15 Asynchronous input/output
10.15.1 Asynchronous execution
10.15.2 The asynchronous attribute
10.16 Stream access files
10.17 Execution of a data transfer statement
10.18 Summary

11 Edit descriptors
11.1 Introduction
11.2 Character string edit descriptor
11.3 Data edit descriptors
11.3.1 Repeat counts
11.3.2 Integer formatting
11.3.3 Real formatting
11.3.4 Complex formatting
11.3.5 Logical formatting
11.3.6 Character formatting
11.3.7 General formatting
11.3.8 Derived type formatting
11.4 Control edit descriptors
11.4.1 Scale factor
11.4.2 Tabulation and spacing
11.4.3 New records (slash editing)
11.4.4 Colon editing
11.5 Changeable file connection modes
11.5.1 Embedded blank interpretation
11.5.2 Input/output rounding mode
11.5.3 Signs on positive values
11.5.4 Decimal comma for input/output
11.6 Defined derived-type input/output
11.7 Recursive input/output
11.8 Summary

12 Operations on external files
12.1 Introduction
12.2 Positioning statements for sequential files
12.2.1 The backspace statement
12.2.2 The rewind statement
12.2.3 The endfile statement
12.2.4 Data transfer statements
12.3 The flush statement
12.4 The open statement
12.5 The close statement
12.6 The inquire statement
12.7 Summary

13 Advanced type parameter features
13.1 Type parameter inquiry
13.2 Parameterized derived types
13.2.1 Defining a parameterized derived type
13.2.2 Assumed and deferred type parameters
13.2.3 Default type parameter values
13.2.4 Derived type parameter inquiry
13.2.5 Structure constructor

14 Procedure pointers
14.1 Abstract interfaces
14.2 Procedure pointers
14.2.1 Named procedure pointers
14.2.2 Procedure pointer components
14.2.3 The pass attribute
14.2.4 Internal procedures as targets of a procedure pointer

15 Object-oriented programming
15.1 Introduction
15.2 Type extension
15.2.1 Type extension and type parameters
15.3 Polymorphic entities
15.3.1 Introduction to polymorphic entities
15.3.2 Establishing the dynamic type
15.3.3 Limitations on the use of a polymorphic variable
15.3.4 Polymorphic arrays and scalars
15.3.5 Unlimited polymorphic entities
15.3.6 Polymorphic entities and generic resolution
15.4 Typed and sourced allocation
15.4.1 Introduction
15.4.2 Typed allocation and deferred type parameters
15.4.3 Polymorphic variables and typed allocation
15.4.4 Sourced allocation
15.5 Assignment for allocatable polymorphic variables
15.6 The associate construct
15.7 The select type construct
15.8 Type-bound procedures
15.8.1 Specific type-bound procedures
15.8.2 Generic type-bound procedures
15.8.3 Type extension and type-bound procedures
15.9 Design for overriding
15.10 Deferred bindings and abstract types
15.11 Finalization
15.11.1 Type extension and final subroutines
15.12 Procedure encapsulation example
15.13 Type inquiry functions

16 Submodules
16.1 Introduction
16.2 Separate module procedures
16.3 Submodules of submodules
16.4 Submodule entities
16.5 Submodules and use association
16.6 The advantages of submodules

17 Coarrays
17.1 Introduction
17.2 Referencing images
17.3 The properties of coarrays
17.4 Accessing coarrays
17.5 The sync all statement
17.6 Allocatable coarrays
17.7 Coarrays with allocatable or pointer components
17.7.1 Data components
17.7.2 Procedure pointer components
17.8 Coarray components
17.9 Coarrays in procedures
17.10 References to polymorphic subobjects
17.11 Volatile and asynchronous attributes
17.12 Interoperability
17.13 Synchronization
17.13.1 Execution segments
17.13.2 The sync images statement
17.13.3 The lock and unlock statements
17.13.4 Critical sections
17.13.5 Atomic subroutines and the sync memory statement
17.13.6 The stat= and errmsg= specifiers in synchronization statements
17.13.7 The image control statements
17.14 Program termination
17.15 Input/output
17.16 Intrinsic procedures
17.16.1 Inquiry functions
17.16.2 Transformational functions
17.17 Arrays of different sizes on different images

18 Floating-point exception handling
18.1 Introduction
18.2 The IEEE standard
18.3 Access to the features
18.4 The Fortran flags
18.5 Halting
18.6 The rounding mode
18.7 The underflow mode
18.8 The module ieee_exceptions
18.8.1 Derived types
18.8.2 Inquiring about IEEE exceptions
18.8.3 Subroutines for the flags and halting modes
18.8.4 Subroutines for the whole of the floating-point status
18.9 The module ieee_arithmetic
18.9.1 Derived types
18.9.2 Inquiring about IEEE arithmetic
18.9.3 Elemental functions
18.9.4 Non-elemental subroutines
18.9.5 Transformational function for kind value
18.10 Examples
18.10.1 Dot product
18.10.2 Calling alternative procedures
18.10.3 Calling alternative in-line code
18.10.4 Reliable hypotenuse function
18.10.5 Access to IEEE arithmetic values

19 Interoperability with C
19.1 Introduction
19.2 Interoperability of intrinsic types
19.3 Interoperability with C pointer types
19.4 Interoperability of derived types
19.5 Shape and character length disagreement
19.6 Interoperability of variables
19.7 Function c_sizeof
19.8 The value attribute
19.9 Interoperability of procedures
19.10 Interoperability of global data
19.11 Invoking a C function from Fortran
19.12 Invoking Fortran from C
19.13 Enumerations

20 Fortran 2018 coarray enhancements
20.1 Teams
20.2 Image failure
20.3 Form team statement
20.4 Change team construct
20.5 Coarrays allocated in teams
20.6 Critical construct and image failure
20.7 Lock and unlock statements and image failure
20.8 Sync team statement
20.9 Image selectors
20.10 Procedure calls and teams
20.11 Intrinsic functions get_team and team_number
20.12 Intrinsic function image_index
20.13 Intrinsic function num_images
20.14 Intrinsic function this_image
20.15 Intrinsic function coshape
20.16 Intrinsic function move_alloc
20.17 Fail image statement
20.18 Detecting failed and stopped images
20.19 Collective subroutines
20.20 New atomic subroutines
20.21 Failed images and stat= specifiers
20.22 Events

21 Fortran 2018 enhancements to interoperability with C
21.1 Introduction
21.2 Optional arguments
21.3 Low-level C interoperability
21.4 Assumed character length
21.5 C descriptors
21.5.1 Introduction
21.5.2 Standard members
21.5.3 Argument classification (attribute codes)
21.5.4 Argument data type
21.5.5 Array layout information
21.6 Accessing Fortran objects
21.6.1 Traversing contiguous Fortran arrays
21.6.2 Generic programming with assumed type
21.6.3 Traversing discontiguous Fortran arrays
21.6.4 Fortran pointer operations
21.6.5 Allocatable objects
21.6.6 Handling arrays of any rank
21.6.7 Accessing individual array elements via a C descriptor
21.6.8 Handling errors from CFI functions
21.7 Calling Fortran with C descriptors
21.7.1 Allocating storage for a C descriptor
21.7.2 Establishing a C descriptor
21.7.3 Constructing an array section
21.7.4 Accessing components
21.8 Restrictions
21.8.1 Other limitations on C descriptors
21.8.2 Lifetimes of C descriptors
21.9 Miscellaneous C interoperability changes
21.9.1 Interoperability with the C type ptrdiff_t
21.9.2 Relaxation of interoperability requirements

22 Fortran 2018 conformance with ISO/IEC/IEEE 60559:2011
22.1 Introduction
22.2 Subnormal values
22.3 Type for floating-point modes
22.4 Rounding modes
22.5 Rounded conversions
22.6 Fused multiply-add
22.7 Test sign
22.8 Conversion to integer type
22.9 Remainder function
22.10 Maximum and minimum values
22.11 Adjacent machine numbers
22.12 Comparisons
22.13 Hexadecimal significand input/output

23 Minor Fortran 2018 features
23.1 Default accessibility for entities accessed from a module
23.2 Requiring explicit procedure declarations
23.3 Using the properties of an object in its initialization
23.4 Generic procedures
23.4.1 More concise generic specification
23.4.2 Rules for disambiguation
23.5 Enhancements to stop and error stop
23.6 New intrinsic procedures
23.6.1 Checking for unsafe conversions
23.6.2 Generalized array reduction
23.6.3 Controlling the random number generator
23.7 Existing intrinsic procedures
23.7.1 Intrinsic function sign
23.7.2 Intrinsic functions extends_type_of and same_type_as
23.7.3 Simplification of calls of the intrinsic function cmplx
23.7.4 Remove many argument dim restrictions
23.7.5 Kinds of arguments of intrinsic and IEEE procedures
23.7.6 Intrinsic subroutines that access the computing environment
23.8 Use of non-standard features
23.9 Kind of the do variable in implied-do loops
23.10 Improving do concurrent performance
23.11 Control of host association
23.12 Intent in requirements and the value attribute
23.13 Pure procedures
23.14 Recursive and non-recursive procedures
23.15 Input/output
23.15.1 More minimal field width editing
23.15.2 Recovering from input format errors
23.15.3 Advancing input with size=
23.15.4 Precision of stat= variables
23.15.5 Connect a file to more than one unit
23.15.6 Enhancements to inquire
23.15.7 Asynchronous communication
23.16 Assumed rank
23.16.1 Assumed-rank objects
23.16.2 The select rank construct

A Deprecated features
A.1 Introduction
A.2 Storage association
A.3 Alternative form of relational operator
A.4 The include line
A.5 The do while statement
A.6 Double precision real
A.7 The dimension, codimension, and parameter statements
A.8 Non-default mapping for implicit typing
A.9 Fortran 2008 deprecated features
A.9.1 The sync memory statement, and atomic_define and atomic_ref
A.9.2 Components of type c_ptr or c_funptr
A.9.3 Type declarations
A.9.4 Denoting absent arguments
A.9.5 Alternative form of complex constant

B Obsolescent and deleted features
B.1 Features obsolescent in Fortran 95
B.1.1 Fixed source form
B.1.2 Computed go to
B.1.3 Character length specification with character*
B.1.4 Data statements among executables
B.1.5 Statement functions
B.1.6 Assumed character length of function results
B.1.7 Alternate return
B.2 Feature obsolescent in Fortran 2008: Entry statement
B.3 Features obsolescent in Fortran 2018
B.3.1 The forall statement and construct
B.3.2 The equivalence statement
B.3.3 The common block
B.3.4 The block data program unit
B.3.5 The labelled do construct
B.3.6 Specific names of intrinsic procedures
B.4 Features deleted in Fortran 95
B.5 Feature deleted in Fortran 2003: Carriage control
B.6 Features deleted in Fortran 2018

C Object-oriented list example
D Solutions to exercises

Index