ConceptioArchiveISO/IEC JTC 1 (SC22)
ISO/IEC JTC 1 (SC22)open access

Fortran 2023 (working draft) — ISO/IEC 1539 (N2184)

ISO/IEC JTC 1 (SC22) · ISO/IEC JTC 1 (SC22)
ISO/IEC JTC 1 (SC22) · Standards · License: Open Access
Open Source ↗Direct PDF ↓
fortraniso/ieciso/iecjtc1jtc1
jtc1, iso/iec, standard, iso/iec jtc 1, ISO/IEC 1539, ISO/IEC 1539 2023, Fortran 2023, N2184, fortran 2023 (working draft), 2023, fortran

WD 1539-1

ISO/IEC JTC 1/SC 22/ WG5/N2184

21st May 2021 16:38

Fortran 202x Working Draft (J3/21-007r1) This is an internal document of PL22.3 and WG5.

NOTE: This Working Draft is only available as a PDF file.

This page intentionally left nonblank.

2021-05-21

WD 1539-1

J3/21-007r1

Contents Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii 1

Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1

2

Normative references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

3

Terms and definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3

4

Notation, conformance, and compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1 Notation, symbols and abbreviated terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.1 Syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.2 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.3 Assumed syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.4 Syntax conventions and characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1.5 Text conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Conformance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.1 Previous Fortran standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.2 New intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.3 Fortran 2018 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.4 Fortran 2008 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.5 Fortran 2003 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.6 Fortran 95 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.7 Fortran 90 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.8 FORTRAN 77 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Deleted and obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.2 Nature of deleted features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4.3 Nature of obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24 24 24 25 25 25 26 26 27 27 27 27 28 29 30 30 30 31 31 31 31

5

Fortran concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1 High level syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Program unit concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1 Program units and scoping units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.3 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.4 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.5 Submodule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Execution concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1 Statement classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.2 Statement order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.3 The END statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.4 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.5 Execution sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32 32 35 35 35 35 36 36 36 36 36 37 37 38

ISO/IEC JTC 1/SC 22/WG5/N2184

iii

J3/21-007r1

WD 1539-1

2021-05-21

5.3.6 Image execution states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.7 Termination of execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1 Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2 Data value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.3 Data entity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.4 Definition of objects and pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.5 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.6 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.7 Coarray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.8 Established coarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.9 Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.10 Allocatable variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.11 Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Fundamental concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1 Names and designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.2 Statement keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.3 Other keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.4 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.5 Intrinsic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.6 Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.7 Companion processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

38 39 39 39 40 40 41 42 42 42 43 43 43 43 44 44 44 44 44 44 44 45

6

Lexical tokens and source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1 Processor character set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.1 Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.2 Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.3 Digits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.4 Underscore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.5 Special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.1.6 Other characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Low-level syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.1 Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.2 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.5 Statement labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.6 Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3 Source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.1 Program units, statements, and lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.2 Free source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.3.3 Fixed source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.4 Including source text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

46 46 46 46 46 46 46 47 47 47 47 48 48 49 49 50 50 50 51 52

7

Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1 Characteristics of types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.1 The concept of type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.2 Type classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.3 Set of values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.4 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.1.5 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3 Types, type specifiers, and values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3.1 Relationship of types and values to objects . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3.2 Type specifiers and type compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3.3 Type compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

54 54 54 54 54 54 54 55 55 55 56 58

iv

ISO/IEC JTC 1/SC 22/WG5/N2184

5.4

5.5

2021-05-21

7.4

7.5

7.6

7.7 7.8 8

WD 1539-1

J3/21-007r1

Intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4.1 Classification and specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4.2 Intrinsic operations on intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4.3 Numeric intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4.4 Character type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4.5 Logical type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Derived types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.1 Derived type concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.2 Derived-type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.3 Derived-type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.4 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.5 Type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.6 Final subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.7 Type extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.8 Derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.9 Derived-type specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.10 Construction of derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.11 Derived-type operations and assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . Other user-defined types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.6.1 Interoperable enumerations and enum types . . . . . . . . . . . . . . . . . . . . . . . . . 7.6.2 Enumeration types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Binary, octal, and hexadecimal literal constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . Construction of array values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

58 58 59 59 62 66 66 66 67 70 72 79 81 83 85 85 86 88 88 88 90 93 93

Attribute declarations and specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.1 Attributes of procedures and data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.2 Type declaration statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 8.3 Automatic data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 8.4 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 8.5 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 8.5.1 Attribute specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 8.5.2 Accessibility attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.5.3 ALLOCATABLE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.5.4 ASYNCHRONOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 8.5.5 BIND attribute for data entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 8.5.6 CODIMENSION attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 8.5.7 CONTIGUOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 8.5.8 DIMENSION attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 8.5.9 EXTERNAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 8.5.10 INTENT attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 8.5.11 INTRINSIC attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 8.5.12 OPTIONAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 8.5.13 PARAMETER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 8.5.14 POINTER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 8.5.15 PROTECTED attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 8.5.16 SAVE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 8.5.17 RANK clause . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 8.5.18 TARGET attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8.5.19 VALUE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8.5.20 VOLATILE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 8.6 Attribute specification statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 8.6.1 Accessibility statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 8.6.2 ALLOCATABLE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 8.6.3 ASYNCHRONOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 8.6.4 BIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 8.6.5 CODIMENSION statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

ISO/IEC JTC 1/SC 22/WG5/N2184

v

J3/21-007r1

8.7 8.8 8.9 8.10

9

WD 1539-1

2021-05-21

8.6.6 CONTIGUOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 8.6.7 DATA statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 8.6.8 DIMENSION statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 8.6.9 INTENT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 8.6.10 OPTIONAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 8.6.11 PARAMETER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 8.6.12 POINTER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 8.6.13 PROTECTED statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 8.6.14 SAVE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 8.6.15 TARGET statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 8.6.16 VALUE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 8.6.17 VOLATILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 IMPLICIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 IMPORT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 NAMELIST statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Storage association of data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 8.10.1 EQUIVALENCE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 8.10.2 COMMON statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 8.10.3 Restrictions on common and equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Use of data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 9.1 Designator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 9.2 Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 9.3 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 9.4 Scalars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 9.4.1 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 9.4.2 Structure components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 9.4.3 Coindexed named objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 9.4.4 Complex parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 9.4.5 Type parameter inquiry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 9.5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 9.5.1 Order of reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 9.5.2 Whole arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 9.5.3 Array elements and array sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 9.5.4 Simply contiguous array designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 9.6 Image selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 9.7 Dynamic association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 9.7.1 ALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 9.7.2 NULLIFY statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 9.7.3 DEALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 9.7.4 STAT= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 9.7.5 ERRMSG= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

10 Expressions and assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 10.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 10.1.1 Expression semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 10.1.2 Form of an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 10.1.3 Precedence of operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 10.1.4 Evaluation of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 10.1.5 Intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 10.1.6 Defined operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 10.1.7 Evaluation of operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 10.1.8 Integrity of parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 10.1.9 Type, type parameters, and shape of an expression . . . . . . . . . . . . . . . . . . . . . 164 10.1.10 Conformability rules for elemental operations . . . . . . . . . . . . . . . . . . . . . . . . 165 10.1.11 Specification expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

vi

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

10.2

WD 1539-1

J3/21-007r1

10.1.12 Constant expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 10.2.1 Assignment statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 10.2.2 Pointer assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 10.2.3 Masked array assignment – WHERE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 10.2.4 FORALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

11 Execution control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 11.1 Executable constructs containing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 11.1.1 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 11.1.2 Rules governing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 11.1.3 ASSOCIATE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 11.1.4 BLOCK construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 11.1.5 CHANGE TEAM construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 11.1.6 CRITICAL construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 11.1.7 DO construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 11.1.8 IF construct and statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198 11.1.9 SELECT CASE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 11.1.10 SELECT RANK construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 11.1.11 SELECT TYPE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 11.1.12 EXIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 11.2 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 11.2.1 Branch concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 11.2.2 GO TO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 11.2.3 Computed GO TO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 11.3 CONTINUE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 11.4 STOP and ERROR STOP statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 11.5 FAIL IMAGE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 11.6 NOTIFY WAIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 11.7 Image execution control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 11.7.1 Image control statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 11.7.2 Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 11.7.3 SYNC ALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 11.7.4 SYNC IMAGES statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 11.7.5 SYNC MEMORY statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 11.7.6 SYNC TEAM statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 11.7.7 EVENT POST statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 11.7.8 EVENT WAIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 11.7.9 FORM TEAM statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 11.7.10 LOCK and UNLOCK statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 11.7.11 STAT= and ERRMSG= specifiers in image control statements . . . . . . . . . . . . . . . 219 12 Input/output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 12.1 Input/output concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 12.2 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 12.2.1 Definition of a record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 12.2.2 Formatted record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 12.2.3 Unformatted record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 12.2.4 Endfile record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 12.3 External files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 12.3.1 External file concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 12.3.2 File existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 12.3.3 File access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 12.3.4 File position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 12.3.5 File storage units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 12.4 Internal files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228

ISO/IEC JTC 1/SC 22/WG5/N2184

vii

J3/21-007r1

WD 1539-1

2021-05-21

12.5

File connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 12.5.1 Referring to a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 12.5.2 Connection modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 12.5.3 Unit existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 12.5.4 Connection of a file to a unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 12.5.5 Preconnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 12.5.6 OPEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 12.5.7 CLOSE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 12.6 Data transfer statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 12.6.1 Form of input and output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 12.6.2 Control information list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 12.6.3 Data transfer input/output list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 12.6.4 Execution of a data transfer input/output statement . . . . . . . . . . . . . . . . . . . . 244 12.6.5 Termination of data transfer statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 12.7 Waiting on pending data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 12.7.1 Wait operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 12.7.2 WAIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 12.8 File positioning statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 12.8.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 12.8.2 BACKSPACE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 12.8.3 ENDFILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 12.8.4 REWIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 12.9 FLUSH statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 12.10 File inquiry statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 12.10.1 Forms of the INQUIRE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 12.10.2 Inquiry specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 12.10.3 Inquire by output list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 12.11 Error, end-of-record, and end-of-file conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 12.11.1 Occurrence of input/output conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 12.11.2 Error conditions and the ERR= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 12.11.3 End-of-file condition and the END= specifier . . . . . . . . . . . . . . . . . . . . . . . . . 266 12.11.4 End-of-record condition and the EOR= specifier . . . . . . . . . . . . . . . . . . . . . . . 267 12.11.5 IOSTAT= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 12.11.6 IOMSG= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 12.12 Restrictions on input/output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 13 Input/output editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.1 Format specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.2 Explicit format specification methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.2.1 FORMAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.2.2 Character format specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 13.3 Form of a format item list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 13.3.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 13.3.2 Edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 13.3.3 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 13.4 Interaction between input/output list and format . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 13.5 Positioning by format control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 13.6 Decimal symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 13.7 Data edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 13.7.1 Purpose of data edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 13.7.2 Numeric editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 13.7.3 Logical editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 13.7.4 Character editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 13.7.5 Generalized editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 13.7.6 User-defined derived-type editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 13.8 Control edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284

viii

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

13.8.1 Position edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 13.8.2 Slash editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 13.8.3 Colon editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 13.8.4 SS, SP, and S editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 13.8.5 LZS, LZP and LZ editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 13.8.6 P editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 13.8.7 BN and BZ editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 13.8.8 RU, RD, RZ, RN, RC, and RP editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 13.8.9 DC and DP editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 13.9 Character string edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 13.10 List-directed formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 13.10.1 Purpose of list-directed formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 13.10.2 Values and value separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 13.10.3 List-directed input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 13.10.4 List-directed output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 13.11 Namelist formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 13.11.1 Purpose of namelist formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 13.11.2 Name-value subsequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 13.11.3 Namelist input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 13.11.4 Namelist output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 14 Program units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 14.1 Main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 14.2 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 14.2.1 Module syntax and semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 14.2.2 The USE statement and use association . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 14.2.3 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 14.3 Block data program units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 15 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 15.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 15.2 Procedure classifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 15.2.1 Procedure classification by reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 15.2.2 Procedure classification by means of definition . . . . . . . . . . . . . . . . . . . . . . . . 303 15.3 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 15.3.1 Characteristics of procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 15.3.2 Characteristics of dummy arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 15.3.3 Characteristics of function results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 15.4 Procedure interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 15.4.1 Interface and abstract interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 15.4.2 Implicit and explicit interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 15.4.3 Specification of the procedure interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 15.5 Procedure reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 15.5.1 Syntax of a procedure reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 15.5.2 Actual arguments, dummy arguments, and argument association . . . . . . . . . . . . . . 317 15.5.3 Function reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 15.5.4 Subroutine reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 15.5.5 Resolving named procedure references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 15.5.6 Resolving type-bound procedure references . . . . . . . . . . . . . . . . . . . . . . . . . . 330 15.6 Procedure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 15.6.1 Intrinsic procedure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 15.6.2 Procedures defined by subprograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 15.6.3 Definition and invocation of procedures by means other than Fortran . . . . . . . . . . . 337 15.6.4 Statement function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 15.7 Pure procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338 15.8 Simple procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340

ISO/IEC JTC 1/SC 22/WG5/N2184

ix

J3/21-007r1

15.9

WD 1539-1

2021-05-21

Elemental procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 15.9.1 Elemental procedure declaration and interface . . . . . . . . . . . . . . . . . . . . . . . . 341 15.9.2 Elemental function actual arguments and results . . . . . . . . . . . . . . . . . . . . . . . 341 15.9.3 Elemental subroutine actual arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

16 Intrinsic procedures and modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 16.1 Classes of intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 16.2 Arguments to intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 16.2.1 General rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 16.2.2 The shape of array arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 16.2.3 Mask arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 16.2.4 DIM arguments and reduction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 16.3 Bit model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 16.3.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 16.3.2 Bit sequence comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 16.3.3 Bit sequences as arguments to INT and REAL . . . . . . . . . . . . . . . . . . . . . . . . 345 16.4 Numeric models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 16.5 Atomic subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 16.6 Collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 16.7 Standard generic intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 16.8 Specific names for standard intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 16.9 Specifications of the standard intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 16.9.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 16.10 Standard intrinsic modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 16.10.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 16.10.2 The ISO_FORTRAN_ENV intrinsic module . . . . . . . . . . . . . . . . . . . . . . . . 450 17 Exceptions and IEEE arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 17.1 Overview of IEEE arithmetic support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 17.2 Derived types, constants, and operators defined in the modules . . . . . . . . . . . . . . . . . . . 458 17.3 The exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458 17.4 The rounding modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 17.5 Underflow mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 17.6 Halting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 17.7 The floating-point modes and status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 17.8 Exceptional values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 17.9 IEEE arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 17.10 Summary of the procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 17.11 Specifications of the procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 17.11.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 17.12 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 18 Interoperability with C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 18.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 18.2 The ISO_C_BINDING intrinsic module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 18.2.1 Summary of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 18.2.2 Named constants and derived types in the module . . . . . . . . . . . . . . . . . . . . . . 494 18.2.3 Procedures in the module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495 18.3 Interoperability between Fortran and C entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 18.3.1 Interoperability of intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 18.3.2 Interoperability with C pointer types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502 18.3.3 Interoperability of derived types and C structure types . . . . . . . . . . . . . . . . . . . 502 18.3.4 Interoperability of scalar variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 18.3.5 Interoperability of array variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504 18.3.6 Interoperability of procedures and procedure interfaces . . . . . . . . . . . . . . . . . . . 504 18.4 C descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507

x

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

18.5

The source file ISO_Fortran_binding.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 18.5.1 Summary of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 18.5.2 The CFI_dim_t structure type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 18.5.3 The CFI_cdesc_t structure type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508 18.5.4 Macros and typedefs in ISO_Fortran_binding.h . . . . . . . . . . . . . . . . . . . . . . . 509 18.5.5 Functions declared in ISO_Fortran_binding.h . . . . . . . . . . . . . . . . . . . . . . . . 511 18.6 Restrictions on C descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 18.7 Restrictions on formal parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 18.8 Restrictions on lifetimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 18.9 Interoperation with C global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 18.9.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 18.9.2 Binding labels for common blocks and variables . . . . . . . . . . . . . . . . . . . . . . . 521 18.10 Interoperation with C functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521 18.10.1 Definition and reference of interoperable procedures . . . . . . . . . . . . . . . . . . . . . 521 18.10.2 Binding labels for procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522 18.10.3 Exceptions and IEEE arithmetic procedures . . . . . . . . . . . . . . . . . . . . . . . . . 523 18.10.4 Asynchronous communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 19 Scope, association, and definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 19.1 Scopes, identifiers, and entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 19.2 Global identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 19.3 Local identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 19.3.1 Classes of local identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 19.3.2 Local identifiers that are the same as common block names . . . . . . . . . . . . . . . . . 526 19.3.3 Function results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 19.3.4 Components, type parameters, and bindings . . . . . . . . . . . . . . . . . . . . . . . . . 526 19.3.5 Argument keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 19.4 Statement and construct entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 19.5 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 19.5.1 Name association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 19.5.2 Pointer association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532 19.5.3 Storage association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 19.5.4 Inheritance association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 19.5.5 Establishing associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 19.6 Definition and undefinition of variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 19.6.1 Definition of objects and subobjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 19.6.2 Variables that are always defined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 19.6.3 Variables that are initially defined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 19.6.4 Variables that are initially undefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 19.6.5 Events that cause variables to become defined . . . . . . . . . . . . . . . . . . . . . . . . 539 19.6.6 Events that cause variables to become undefined . . . . . . . . . . . . . . . . . . . . . . . 541 19.6.7 Variable definition context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 19.6.8 Pointer association context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544 Annex A

(informative) Processor dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545

Annex B

(informative) Deleted and obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551

Annex C

(informative) Extended notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631

ISO/IEC JTC 1/SC 22/WG5/N2184

xi

J3/21-007r1

WD 1539-1

2021-05-21

Foreword 1 ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commis-

sion) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-governmental, in liaison with ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. 2 The procedures used to develop this document and those intended for its further maintenance are described in

the ISO/IEC Directives, Part 1. In particular the different approval criteria needed for the different types of document should be noted. This document was drafted in accordance with the editorial rules of the ISO/IEC Directives, Part 2 (see www.iso.org/directives). 3 Attention is drawn to the possibility that some of the elements of this document may be the subject of patent

rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights. Details of any patent rights identified during the development of the document will be in the Introduction and/or on the ISO list of patent declarations received (see www.iso.org/patents). 4 Any trade name used in this document is information given for the convenience of users and does not constitute

an endorsement. 5 For an explanation on the voluntary nature of standards, the meaning of ISO specific terms and expressions related

to conformity assessment, as well as information about ISO’s adherence to the World Trade Organization (WTO) principles in the Technical Barriers to Trade (TBT) see the following URL: www.iso.org/iso/foreword.html. 6 This document was prepared by Technical Committee ISO/IEC JTC 1, Information technology, Subcommittee

SC 22, Programming languages, their environments and system software interfaces. 7 This fifth edition cancels and replaces the fourth edition (ISO 1539-1:2018), which has been technically revised. 8 A list of all parts in the ISO 1539 series can be found on the ISO website. 9 Any feedback or questions on this document should be directed to the user’s national standards body. A complete

listing of these bodies can be found at www.iso.org/members.html.

xii

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Introduction 1 This document comprises the specification of the base Fortran language, informally known as Fortran 202x. With

the limitations noted in 4.3.3, the syntax and semantics of Fortran 2018 are contained entirely within Fortran 202x. Therefore, any standard-conforming Fortran 2018 program not affected by such limitations is a standardconforming Fortran 202x program. New features of Fortran 202x can be compatibly incorporated into such Fortran 2018 programs, with any exceptions indicated in the text of this document. 2 Fortran 202x contains several extensions to Fortran 2018; these are listed below.

• Source form: The maximum length of a line in free form source has been increased. The maximum length of a statement has been increased. The limit on the number of continuation lines has been removed. • Data declaration: A data object with a coarray component can be an array or allocatable. BIND(C) ENUM are now referred to as interoperable enumerations, and noninteroperable enumeration types are available. An interoperable enumeration can be given a type name. TYPEOF and CLASSOF type specifiers can be used to declare one or more entities to have the same type and type parameters as another entity. A PUBLIC namelist group can have a PRIVATE namelist group object. The DIMENSION attribute can be declared with a syntax that does not depend on the rank (8.5.8, 8.5.17). • Data usage and computation: Binary, octal, and hexadecimal literal constants can be used in additional contexts. A deferred-length allocatable errmsg-variable is allocated by the processor to the length of the explanatory message. An ALLOCATE statement can specify the bounds of an array allocation with array expressions. A pointer assignment statement can specify lower bounds or rank remapping with array expressions. Arrays can be used to specify multiple subscripts or subscript triplets (9.5.3.2). • Input/output: The AT edit descriptor provides output of character values with trailing blanks trimmed. The LEADING_ZERO= specifier in the OPEN and WRITE statements, and the LZP, LZS and LZ control edit descriptors, provide control of optional leading zeros during formatted output. A deferred-length allocatable iomsgvariable is allocated by the processor to the length of the explanatory message. A deferred-length allocatable io-unit in a WRITE statement is allocated by the processor to the length of the record to be written. • Execution control: The REDUCE locality specifier for the DO CONCURRENT construct specifies reduction variables for the loop. The NOTIFY WAIT statement, NOTIFY= specifier on an image selector, and the NOTIFY_TYPE from the intrinsic module ISO_FORTRAN_ENV provide one-sided data-oriented synchronization between images. • Intrinsic procedures and modules: The intrinsic functions ACOSD, ASIND, ATAND, ATAN2D, COSD, SIND, and TAND are trigonometric functions in which angles are specified in degrees. The intrinsic functions ACOSPI, ASINPI, ATANPI, ATAN2PI, COSPI, SINPI, and TANPI are trigonometric functions in which angles are specified in halfrevolutions (that is, as multiples of π). The intrinsic function SELECTED_LOGICAL_KIND returns kind type parameter values for type logical. The intrinsic subroutine SPLIT parses a string into tokens, one at time. The intrinsic subroutine SYSTEM_CLOCK supports more than one system clock for an image. The intrinsic subroutine TOKENIZE parses a string into tokens. The procedures C_F_STRPOINTER and F_C_STRING have been added to the intrinsic module ISO_C_BINDING to assist in the use of null-terminated strings. The subroutine C_F_POINTER in the intrinsic module ISO_C_BINDING has an extra optional dummy argument, LOWER, that specifies the lower bounds for FPTR. Additional named constants LOGICAL8, LOGICAL16, LOGICAL32, LOGICAL64, and REAL16 have been added to the intrinsic module ISO_FORTRAN_ENV. When a deferred-length allocatable actual argument of an intrinsic procedure is to be assigned character data, it is allocated by the processor to the length of the data. Execution of a collective subroutine can be successful on an image even when an error condition occurs for the corresponding execution on another image. • Changes to the intrinsic module IEEE_ARITHMETIC for conformance with ISO/IEC 60559:2020: The new functions IEEE_MAX, IEEE_MAX_MAG, IEEE_MIN, and IEEE_MIN_MAG perform the the

ISO/IEC JTC 1/SC 22/WG5/N2184

xiii

J3/21-007r1

WD 1539-1

2021-05-21

operations maximum, maximumMagnitude, minimum, and miminumMagnitude in ISO/IEC 60559:2020. The functions IEEE_MAX_NUM, IEEE_MAX_NUM_MAG, IEEE_MIN_NUM, and IEEE_MIN_NUM_MAG now conform to the operations maximumNumber, maximumMagnitudeNumber, minimumNumber and minimumMagnitudeNumber in ISO/IEC 60559:2020; the changes affect the treatment of zeroes and NaNs. • Program units and procedures: A procedure can be specified to be a simple procedure; a simple procedure references or defines nonlocal variables only via its dummy arguments. 3 This document is organized in 19 clauses, dealing with 8 conceptual areas. These 8 areas, and the clauses in

which they are treated, are: High/low level concepts Data concepts Computations Execution control Input/output Program units Interoperability with C Scoping and association rules

Clauses 4, 5, 6 Clauses 7, 8, 9 Clauses 10, 16, 17 Clause 11 Clauses 12, 13 Clauses 14, 15 Clause 18 Clause 19

4 It also contains the following nonnormative material:

Processor dependencies Deleted and obsolescent features Extended notes Index

xiv

Annex A Annex B Annex C Index

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

J3/21-007r1

Information technology — Programming languages — Fortran —

4

Part 1: Base language

5

1 Scope

3

WD 1539-1

6 7 8

1 This document specifies the form and establishes the interpretation of programs expressed in the base Fortran

9 10

2 This document specifies

11 12 13

language. The purpose of this document is to promote portability, reliability, maintainability, and efficient execution of Fortran programs for use on a variety of computing systems. • the forms that a program written in the Fortran language can take, • the rules for interpreting the meaning of a program and its data, • the form of the input data to be processed by such a program, and • the form of the output data resulting from the use of such a program.

14 15

3 Except where stated otherwise, requirements and prohibitions specified by this document apply to programs

16

4 This document does not specify

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

rather than processors.

• the mechanism by which programs are transformed for use on computing systems, • the operations required for setup and control of the use of programs on computing systems, • the method of transcription of programs or their input or output data to or from a storage medium, • the program and processor behavior when this document fails to establish an interpretation except for the processor detection and reporting requirements in items (2) to (10) of 4.2, • the maximum number of images, or the size or complexity of a program and its data that will exceed the capacity of any particular computing system or the capability of a particular processor, • the mechanism for determining the number of images of a program, • the physical properties of an image or the relationship between images and the computational elements of a computing system, • the physical properties of the representation of quantities and the method of rounding, approximating, or computing numeric values on a particular processor, except by reference to ISO/IEC 60559:2020 under conditions specified in Clause 17, • the physical properties of input/output records, files, and units, or • the physical properties and implementation of storage.

ISO/IEC JTC 1/SC 22/WG5/N2184

1

J3/21-007r1

WD 1539-1

2021-05-21

1

2 Normative references

2 3 4

The following documents are referred to in the text in such a way that some or all of their content constitutes requirements of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.

5 6

ISO/IEC 646:1991 (International Reference Version), Information technology—ISO 7-bit coded character set for information interchange

7

ISO/IEC 9899:2011, Programming languages—C

8

ISO/IEC 10646, Information technology—Universal Multiple-Octet Coded Character Set (UCS)

9

ISO/IEC/IEEE 60559:2011, Information technology — Microprocessor Systems — Floating-Point arithmetic

2

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

3 Terms and definitions

2

For the purposes of this document, the following terms and definitions apply.

3 5

ISO and IEC maintain terminological databases for use in standardization at the following addresses: — ISO Online browsing platform: available at https://www.iso.org/obp — IEC Electropedia: available at http://www.electropedia.org/

6 7 8

3.1 actual argument entity (R1524) that appears in a procedure reference

9 10 11

3.2 allocatable having the ALLOCATABLE attribute (8.5.3)

12 13 14 15

3.3 array set of scalar data, all of the same type and type parameters, whose individual elements are arranged in a rectangular pattern (8.5.8, 9.5)

16 17 18

3.3.1 array element scalar individual element of an array

19 20 21

3.3.2 array pointer array with the POINTER attribute (8.5.14)

22 23 24

3.3.3 array section array subobject designated by array-section, and which is itself an array (9.5.3.4)

25 26 27

3.3.4 assumed-shape array nonallocatable nonpointer dummy argument array that takes its shape from its effective argument (8.5.8.3)

28 29 30

3.3.5 assumed-size array dummy argument array whose size is assumed from that of its effective argument (8.5.8.5)

31 32 33

3.3.6 deferred-shape array allocatable array or array pointer (8.5.8.4)

34 35 36 37

3.3.7 explicit-shape array array declared with an explicit-shape-spec-list or explicit-shape-bounds-spec, which specifies explicit values for the bounds in each dimension of the array (8.5.8.2)

38

3.4 ASCII character character whose representation method corresponds to ISO/IEC 646:1991 (International Reference Version)

4

39 40

ISO/IEC JTC 1/SC 22/WG5/N2184

3

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

3.5 associate name name of construct entity associated with a selector of an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT TYPE construct (11.1.3, 11.1.5, 11.1.10, 11.1.11)

5 6 7 8

3.6 associating entity ⟨in a dynamically-established association⟩ the entity that did not exist prior to the establishment of the association (19.5.5)

9 10 11

3.7 association inheritance association, name association, pointer association, or storage association.

12 13 14

3.7.1 argument association association between an effective argument and a dummy argument (15.5.2)

15 16 17 18

3.7.2 construct association association between a selector and an associate name in an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT TYPE construct(11.1.3, 11.1.5, 11.1.10, 11.1.11, 19.5.1.6)

19 20 21 22

3.7.3 host association name association, other than argument association, between entities in a submodule or contained scoping unit and entities in its host (19.5.1.4)

23 24 25 26

3.7.4 inheritance association association between the inherited components of an extended type and the components of its parent component (19.5.4)

27 28 29

3.7.5 linkage association association between a variable or common block with the BIND attribute and a C global variable (18.9, 19.5.1.5)

30 31 32

3.7.6 name association argument association, construct association, host association, linkage association, or use association (19.5.1)

33 34 35

3.7.7 pointer association association between a pointer and an entity with the TARGET attribute (19.5.2)

36 37 38

3.7.8 storage association association between storage sequences (19.5.3)

39 40 41 42

3.7.9 use association association between entities in a module and entities in a scoping unit or construct that references that module, as specified by a USE statement (14.2.2)

43 44 45

3.8 assumed-rank dummy data object dummy data object that assumes the rank, shape, and size of its effective argument (8.5.8.7)

4

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3.9 assumed-type declared with a TYPE(*) type specifier (7.3.2)

4 5 6

3.10 attribute property of an entity that determines its uses (8.1)

7 8 9 10

3.11 automatic data object nondummy data object with a type parameter or array bound that depends on the value of a specification-expr that is not a constant expression (8.3)

11 12 13

3.12 base object ⟨data-ref ⟩ object designated by the leftmost part-name (9.4.2)

14 15 16

3.13 binding type-bound procedure or final subroutine (7.5.5)

17 18 19

3.14 binding name name given to a specific or generic type-bound procedure in the type definition (7.5.5)

20 21 22 23

3.15 binding label default character value specifying the name by which a global entity with the BIND attribute is known to the companion processor (18.10.2, 18.9.2)

24 25 26 27

3.16 block sequence of executable constructs formed by the syntactic class block and which is treated as a unit by the executable constructs described in 11.1

28

3.17 bound array bound limit of a dimension of an array (8.5.8)

29 30 31 32 33 34 35 36 37 38 39 40 41 42

3.18 branch target statement action-stmt, associate-stmt, end-associate-stmt, if-then-stmt, end-if-stmt, select-case-stmt, end-select-stmt, selectrank-stmt, end-select-rank-stmt, select-type-stmt, end-select-type-stmt, do-stmt, end-do-stmt, block-stmt, endblock-stmt, critical-stmt, end-critical-stmt, forall-construct-stmt , where-construct-stmt, end-function-stmt, end-mpsubprogram-stmt, end-program-stmt, or end-subroutine-stmt, whose statement label appears as a label in a GO TO statement, computed GO TO statement, alt-return-spec, END= specifier, EOR= specifier, or ERR= specifier (11.2.1) 3.19 C address ⟨variable or procedure⟩ value of type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING identifying the location Note 1 to entry: This is the concept that ISO/IEC 9899:2011 calls the address.

ISO/IEC JTC 1/SC 22/WG5/N2184

5

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

3.20 C descriptor C structure of type CFI_cdesc_t defined in the source file ISO_Fortran_binding.h (18.4, 18.5)

4 5 6

3.21 character context within a character literal constant (7.4.4) or within a character string edit descriptor (13.3.2)

7 8 9

3.22 characteristics ⟨dummy argument⟩ being a dummy data object, dummy procedure, or an asterisk (alternate return indicator)

10 11 12

3.23 characteristics ⟨dummy data object⟩ properties listed in 15.3.2.2

13 14 15

3.24 characteristics ⟨dummy procedure or dummy procedure pointer⟩ properties listed in 15.3.2.3

16 17 18

3.25 characteristics ⟨function result⟩ properties listed in 15.3.3

19 20 21

3.26 characteristics ⟨procedure⟩ properties listed in 15.3.1

22 23 24

3.27 coarray data entity that has nonzero corank (5.4.7)

25 26 27

3.27.1 established coarray coarray that is accessible using an image-selector (5.4.8)

28 29 30

3.28 cobound bound (limit) of a codimension (8.5.6)

31 32 33

3.29 codimension dimension of the pattern formed by a set of corresponding coarrays (8.5.6)

34 35 36

3.30 coindexed object data object whose designator includes an image-selector (R926, 9.6)

37 38 39

3.31 collating sequence one-to-one mapping from a character set into the nonnegative integers (7.4.4.4)

40

3.32

41 42

common block block of physical storage specified by a COMMON statement (8.10.2)

43 44 45

3.32.1 blank common unnamed common block

6

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3.33 companion processor processor-dependent mechanism by which global data and procedures may be referenced or defined (5.5.7)

4 5 6

3.34 component part of a derived type, or of an object of derived type, defined by a component-def-stmt (7.5.4)

7 8 9

3.34.1 direct component one of the components, or one of the direct components of a nonpointer nonallocatable component (7.5.1)

10 11 12 13

3.34.2 parent component component of an extended type whose type is that of the parent type and whose components are inheritance associated with the inherited components of the parent type (7.5.7.2)

14 15 16

3.34.3 potential subobject component nonpointer component, or potential subobject component of a nonpointer component (7.5.1)

17 18 19

3.34.4 subcomponent ⟨structure⟩ direct component that is a subobject of the structure (9.4.2)

20 21 22 23

3.34.5 ultimate component component that is of intrinsic type, a pointer, or allocatable; or an ultimate component of a nonpointer nonallocatable component of derived type

24 25 26 27

3.35 component order ordering of the nonparent components of a derived type that is used for intrinsic formatted input/output and structure constructors (where component keywords are not used) (7.5.4.7)

28 29 30

3.36 conformable ⟨of two data entities⟩ having the same shape, or one being an array and the other being scalar

31 32 33

3.37 connected relationship between a unit and a file: each is connected if and only if the unit refers to the file (12.5.4)

34 35 36 37

3.38 constant data object that has a value and which cannot be defined, redefined, or become undefined during execution of a program (6.2.3, 9.3)

38 39 40

3.38.1 literal constant constant that does not have a name (R605, 7.4)

41 42 43

3.38.2 named constant named data object with the PARAMETER attribute (8.5.13)

ISO/IEC JTC 1/SC 22/WG5/N2184

7

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

3.39 construct entity entity whose identifier has the scope of a construct (19.1, 19.4)

4 5 6

3.40 constant expression expression satisfying the requirements specified in 10.1.12, thus ensuring that its value is constant

7 8 9

3.41 contiguous ⟨array⟩ having array elements in order that are not separated by other data objects, as specified in 8.5.7

10 11 12

3.42 contiguous ⟨multi-part data object⟩ that the parts in order are not separated by other data objects

13 14 15

3.43 corank number of codimensions of a coarray (zero for objects that are not coarrays) (8.5.6)

16 17 18

3.44 cosubscript (R927) scalar integer expression in an image-selector (R926)

19 20 21

3.45 data entity data object, result of the evaluation of an expression, or the result of the execution of a function reference

22

3.46 data object object constant (7.1.4), variable (9), or subobject of a constant (5.4.3.2.4)

23 24 25 26 27 28 29

3.47 decimal symbol character that separates the whole and fractional parts in the decimal representation of a real number in a file (13.6) 3.48 declaration specification of attributes for various program entities Note 1 to entry: Often this involves specifying the type of a named data object or specifying the shape of a named array object.

30 31 32 33

3.49 default initialization mechanism for automatically initializing pointer components to have a defined pointer association status, and nonpointer components to have a particular value (7.5.4.6)

34 35 36

3.50 default-initialized ⟨subcomponent⟩ subject to a default initialization specified in the type definition for that component (7.5.4.6)

37 38 39

3.51 definable capable of definition and permitted to become defined

8

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3.52 defined ⟨data object⟩ has a valid value

4 5 6

3.53 defined ⟨pointer⟩ has a pointer association status of associated or disassociated (19.5.2.2)

7 8 9

3.54 defined assignment assignment defined by a procedure (10.2.1.4, 15.4.3.4.3)

10 11 12

3.55 defined input/output input/output defined by a procedure and accessed via a defined-io-generic-spec (R1509, 12.6.4.8)

13 14 15

3.56 defined operation operation defined by a procedure (10.1.6.1, 15.4.3.4.2)

16 17 18

3.57 definition ⟨data object⟩ process by which the data object becomes defined (19.6.5)

19 20 21 22

3.58 definition ⟨derived type (7.5.2), enumeration (7.6.1), or procedure (15.6)⟩ specification of the type, enumeration, or procedure

23 24 25 26

3.59 descendant ⟨module or submodule⟩ submodule that extends that module or submodule or that extends another descendant thereof (14.2.3)

27 28 29 30

3.60 designator name followed by zero or more component selectors, complex part selectors, array section selectors, array element selectors, image selectors, and substring selectors (9.1)

31 32 33 34

3.60.1 complex part designator designator that designates the real or imaginary part of a complex data object, independently of the other part (9.4.4) 3.60.2 object designator data object designator designator for a data object Note 1 to entry: An object name is a special case of an object designator.

35 36 37

3.60.3 procedure designator designator for a procedure

ISO/IEC JTC 1/SC 22/WG5/N2184

9

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

3.61 disassociated ⟨pointer association⟩ pointer association status of not being associated with any target and not being undefined (19.5.2.2)

5 6 7

3.62 disassociated ⟨pointer⟩ has a pointer association status of disassociated

8 9 10 11 12

3.63 dummy argument entity whose identifier appears in a dummy argument list (R1536) in a FUNCTION, SUBROUTINE, ENTRY, or statement function statement, or whose name can be used as an argument keyword in a reference to an intrinsic procedure or a procedure in an intrinsic module

13 14 15

3.63.1 dummy data object dummy argument that is a data object

16 17 18

3.63.2 dummy function dummy procedure that is a function

19 20 21

3.64 effective argument entity that is argument-associated with a dummy argument (15.5.2.3)

22 23 24

3.65 effective item scalar object resulting from the application of the rules in 12.6.3 to an input/output list

25 26 27 28

3.66 elemental independent scalar application of an action or operation to elements of an array or corresponding elements of a set of conformable arrays and scalars, or possessing the capability of elemental operation Note 1 to entry: Combination of scalar and array operands or arguments combine the scalar operand(s) with each element of the array operand(s).

30 31

3.66.1 elemental assignment assignment that operates elementally

32 33 34

3.66.2 elemental operation operation that operates elementally

35 36 37

3.66.3 elemental operator operator in an elemental operation

38 39 40

3.66.4 elemental procedure elemental intrinsic procedure or procedure defined by an elemental subprogram (15.9)

41

3.66.5 elemental reference reference to an elemental procedure with at least one array actual argument

29

42 43

10

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1 2 3

3.66.6 elemental subprogram subprogram with the ELEMENTAL prefix (15.9.1)

4

3.67 END statement

5 6 7

J3/21-007r1

end-block-data-stmt, end-function-stmt, end-module-stmt, end-mp-subprogram-stmt, end-program-stmt, end-submodule-stmt, or end-subroutine-stmt

8 9 10

3.68 explicit initialization initialization of a data object by a specification statement (8.4, 8.6.7)

11 12 13

3.69 extent number of elements in a single dimension of an array

14 15 16

3.70 external file file that exists in a medium external to the program (12.3)

17 18 19 20

3.71 external unit external input/output unit entity that can be connected to an external file (12.5.3, 12.5.4)

21 22 23

3.72 file storage unit unit of storage in a stream file or an unformatted record file (12.3.5)

24 25 26 27

3.73 final subroutine subroutine whose name appears in a FINAL statement (7.5.6) in a type definition, and which can be automatically invoked by the processor when an object of that type is finalized (7.5.6.2)

28 29 30

3.74 finalizable ⟨type⟩ has a final subroutine or a nonpointer nonallocatable component of finalizable type

31 32 33

3.75 finalizable ⟨nonpointer data entity⟩ of finalizable type

34 35 36

3.76 finalization process of calling final subroutines when one of the events listed in 7.5.6.3 occurs

37 38 39

3.77 function procedure that is invoked by an expression

40

3.78 function result entity that returns the value of a function (15.6.2.2)

41 42

ISO/IEC JTC 1/SC 22/WG5/N2184

11

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

3.79 generic identifier lexical token sequence that identifies a generic set of procedures, intrinsic operations, and/or intrinsic assignments (15.4.3.4)

5 6 7 8

3.80 host instance ⟨internal procedure, or dummy procedure or procedure pointer associated with an internal procedure⟩ instance of the host procedure that supplies the host environment of the internal procedure (15.6.2.4)

9 10 11 12

3.81 host scoping unit host scoping unit immediately surrounding another scoping unit, or the scoping unit extended by a submodule

13 14 15

3.82 IEEE infinity ISO/IEC/IEEE 60559:2011 conformant infinite floating-point value

16 17 18

3.83 IEEE NaN ISO/IEC/IEEE 60559:2011 conformant floating-point datum that does not represent a number

19 20 21

3.84 image instance of a Fortran program (5.3.4)

22 23 24

3.84.1 active image image that has not failed or stopped (5.3.6)

25 26 27

3.84.2 failed image image that has not initiated termination but which has ceased to participate in program execution (5.3.6)

28 29 30

3.84.3 stopped image image that has initiated normal termination (5.3.6)

31 32 33

3.85 image index integer value identifying an image within a team

34 35 36

3.86 image control statement statement that affects the execution ordering between images (11.7)

37 38 39 40

3.87 inclusive scope nonblock scoping unit plus every block scoping unit whose host is that scoping unit or that is nested within such a block scoping unit Note 1 to entry: That is, inclusive scope is the scope as if BLOCK constructs were not scoping units.

41 42 43 44

3.88 inherit ⟨extended type⟩ acquire entities (components, type-bound procedures, and type parameters) through type extension from the parent type (7.5.7.2)

12

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

3.89 inquiry function intrinsic function, or function in an intrinsic module, whose result depends on the properties of one or more of its arguments instead of their values

5 6 7 8

3.90 interface ⟨procedure⟩ name, procedure characteristics, dummy argument names, binding label, and generic identifiers (15.4.1)

9 10 11

3.90.1 abstract interface set of procedure characteristics with dummy argument names (15.4.1)

12 13 14 15

3.90.2 explicit interface interface of a procedure that includes all the characteristics of the procedure and names for its dummy arguments except for asterisk dummy arguments (15.4.2)

16 17 18

3.90.3 generic interface set of procedure interfaces identified by a generic identifier

19 20 21

3.90.4 implicit interface interface of a procedure that is not an explicit interface (15.4.2, 15.4.3.8)

22 23 24

3.90.5 specific interface interface identified by a nongeneric name

25 26 27

3.91 interface block abstract interface block, generic interface block, or specific interface block (15.4.3.2)

28 29 30

3.91.1 abstract interface block interface block with the ABSTRACT keyword; collection of interface bodies that specify named abstract interfaces

31 32 33 34

3.91.2 generic interface block interface block with a generic-spec; collection of interface bodies and procedure statements that are to be given that generic identifier

35 36 37 38

3.91.3 specific interface block interface block with no generic-spec or ABSTRACT keyword; collection of interface bodies that specify the interfaces of procedures

39 40

3.92 interoperable ⟨Fortran entity⟩ equivalent to an entity defined by or definable by the companion processor (18.3)

41 42 43 44 45 46

3.93 intrinsic type, procedure, module, assignment, operator, or input/output operation defined in this document and accessible without further definition or specification, or a procedure or module provided by a processor but not defined in this document

ISO/IEC JTC 1/SC 22/WG5/N2184

13

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

3.93.1 standard intrinsic ⟨procedure or module⟩ defined in this document (16)

4 5 6

3.93.2 nonstandard intrinsic ⟨procedure or module⟩ provided by a processor but not defined in this document

7 8 9

3.94 internal file character variable that is connected to an internal unit (12.4)

10 11 12

3.95 internal unit input/output unit that is connected to an internal file (12.5.4)

13 14 15

3.96 ISO 10646 character character whose representation method corresponds to UCS-4 in ISO/IEC 10646

16 17 18

3.97 keyword statement keyword, argument keyword, type parameter keyword, or component keyword

19 20 21

3.97.1 argument keyword word that identifies the corresponding dummy argument in an actual argument list (15.5.2.1)

22 23 24

3.97.2 component keyword word that identifies a component in a structure constructor (7.5.10)

25 26 27

3.97.3 statement keyword word that is part of the syntax of a statement (5.5.2)

28 29 30

3.97.4 type parameter keyword word that identifies a type parameter in a type-param-spec

31 32 33 34

3.98 lexical token keyword, name, literal constant other than a complex literal constant, operator, label, delimiter, comma, =, =>, :, ::, ;, or % (6.2)

35 36 37

3.99 line sequence of zero or more characters

38 39 40

3.100 main program program unit that is not a subprogram, module, submodule, or block data program unit (14.1)

41 42 43

3.101 masked array assignment assignment statement in a WHERE statement or WHERE construct (10.2.3)

14

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

3.102 module program unit containing (or accessing from other modules) definitions that are to be made accessible to other program units (14.2)

5 6 7

3.103 name identifier of a program constituent, formed according to the rules given in 6.2.2

8 9 10

3.104 NaN Not a Number, a symbolic floating-point datum (ISO/IEC/IEEE 60559:2011)

11 12 13

3.105 operand data value that is the subject of an operator

14 15 16

3.106 operator intrinsic-operator, defined-unary-op, or defined-binary-op (R608, R1003, R1023)

17 18 19 20

3.107 passed-object dummy argument dummy argument of a type-bound procedure or procedure pointer component that becomes associated with the object through which the procedure is invoked (7.5.4.5)

21 22 23

3.108 pointer data pointer or procedure pointer

24 25 26

3.108.1 data pointer data entity with the POINTER attribute (8.5.14)

27 28 29

3.108.2 procedure pointer procedure with the POINTER attribute (8.5.14)

30 31 32 33

3.108.3 local procedure pointer procedure pointer that is part of a local variable, or a named procedure pointer that is not a dummy argument or accessed by use or host association

34 35 36 37

3.109 pointer assignment association of a pointer with a target, by execution of a pointer assignment statement (10.2.2) or an intrinsic assignment statement (10.2.1.2) for a derived-type object that has the pointer as a subobject

38 39 40

3.110 polymorphic ⟨data entity⟩ able to be of differing dynamic types during program execution (7.3.2.3)

41 42 43

3.111 preconnected ⟨file or unit⟩ connected at the beginning of execution of the program (12.5.5)

ISO/IEC JTC 1/SC 22/WG5/N2184

15

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

3.112 procedure entity encapsulating an arbitrary sequence of actions that can be invoked directly during program execution

4 5 6

3.112.1 dummy procedure procedure that is a dummy argument (15.2.2.3)

7 8 9

3.112.2 external procedure procedure defined by an external subprogram (R503) or by means other than Fortran (15.6.3)

10 11 12

3.112.3 internal procedure procedure defined by an internal subprogram (R512)

13 14 15

3.112.4 module procedure procedure defined by a module subprogram, or a specific procedure provided by an intrinsic module (R1408)

16 17 18

3.112.5 pure procedure procedure declared or defined to be pure (15.7)

19 20 21

3.112.6 simple procedure procedure declared or defined to be simple (15.8)

22 23 24

3.112.7 type-bound procedure procedure that is bound to a derived type and referenced via an object of that type (7.5.5)

25 26 27 28

3.113 processor combination of a computing system and mechanism by which programs are transformed for use on that computing system

29 30 31

3.114 processor dependent not completely specified in this document, having methods and semantics determined by the processor

32 33 34 35

3.115 program set of Fortran program units and entities defined by means other than Fortran that includes exactly one main program

36 37 38

3.116 program unit main program, external subprogram, module, submodule, or block data program unit (5.2.1)

39 40 41

3.117 rank number of array dimensions of a data entity (zero for a scalar entity)

42 43 44

3.118 record sequence of values or characters in a file (12.2)

16

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3.119 record file file composed of a sequence of records (12.1)

4 5 6

3.120 reference data object reference, procedure reference, or module reference

7 8 9

3.120.1 data object reference appearance of a data object designator (9.1) in a context requiring its value at that point during execution

10 11 12 13

3.120.2 function reference appearance of the procedure designator for a function, or operator symbol for a defined operation, in a context requiring execution of the function during expression evaluation (15.5.3)

14 15 16

3.120.3 module reference appearance of a module name in a USE statement (14.2.2)

17 18 19 20 21

3.120.4 procedure reference appearance of a procedure designator, operator symbol, or assignment symbol in a context requiring execution of the procedure at that point during execution; or occurrence of defined input/output (13.7.6) or derived-type finalization (7.5.6.2)

22 23 24

3.121 saved having the SAVE attribute (8.5.16)

25 26 27

3.122 scalar data entity that can be represented by a single value of the type and that is not an array (9.5)

28 29 30 31

3.123 scoping unit BLOCK construct, derived-type definition, interface body, program unit, or subprogram, excluding all nested scoping units in it

32 33 34

3.123.1 block scoping unit scoping unit of a BLOCK construct

35 36 37

3.124 sequence set of elements ordered by a one-to-one correspondence with the numbers 1, 2, to n

38 39 40

3.125 sequence structure scalar data object of a sequence type (7.5.2.3)

41 42 43

3.126 sequence type derived type with the SEQUENCE attribute (7.5.2.3)

ISO/IEC JTC 1/SC 22/WG5/N2184

17

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

3.126.1 character sequence type sequence type with no allocatable or pointer components, and whose components are all default character or of another character sequence type

5 6 7 8

3.126.2 numeric sequence type sequence type with no allocatable or pointer components, and whose components are all default complex, default integer, default logical, default real, double precision real, or of another numeric sequence type

9 10

3.127 shape array dimensionality of a data entity, represented as a rank-one array whose size is the rank of the data entity and whose elements are the extents of the data entity

11 12

Note 1 to entry: Thus the shape of a scalar data entity is an array with rank one and size zero.

13 14 15

3.128 simply contiguous ⟨array designator or variable⟩ satisfying the conditions specified in 9.5.4 Note 1 to entry: These conditions are simple ones which make it clear that the designator or variable designates a contiguous array.

16 17 18

3.129 size ⟨array⟩ total number of elements in the array

19 20 21

3.130 specification expression expression satisfying the requirements specified in 10.1.11, thus being suitable for use in specifications

22 23 24

3.131 specific name name that is not a generic name

25 26 27 28

3.132 standard-conforming program program that uses only those forms and relationships described in, and has an interpretation according to, this document

29 30 31

3.133 statement sequence of one or more complete or partial lines satisfying a syntax rule that ends in -stmt (6.3)

32 33

3.133.1 executable statement end-function-stmt, end-mp-subprogram-stmt, end-program-stmt, end-subroutine-stmt, or statement that is a member of the syntactic class executable-construct, excluding those in the block-specification-part of a BLOCK construct

34 35 36 37 38 39

3.133.2 nonexecutable statement statement that is not an executable statement

18

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3.134 statement entity entity whose identifier has the scope of a statement or part of a statement (19.1, 19.4)

4 5 6 7

3.135 statement label label unsigned positive number of up to five digits that refers to an individual statement (6.2.5)

8 9 10

3.136 storage sequence contiguous sequence of storage units (19.5.3.2)

11 12 13

3.137 storage unit character storage unit, numeric storage unit, file storage unit, or unspecified storage unit (19.5.3.2)

14 15 16

3.137.1 character storage unit unit of storage that holds a default character value (19.5.3.2)

17 18 19

3.137.2 numeric storage unit unit of storage that holds a default real, default integer, or default logical value (19.5.3.2)

20 21 22 23

3.137.3 unspecified storage unit unit of storage that holds a value that is not default character, default real, double precision real, default logical, or default complex (19.5.3.2)

24 25 26

3.138 stream file file composed of a sequence of file storage units (12.1)

27 28 29

3.139 structure scalar data object of derived type (7.5)

30 31 32

3.139.1 structure component component of a structure

33 34 35

3.139.2 structure constructor syntax (structure-constructor, 7.5.10) that specifies a structure value or creates such a value

36 37 38

3.140 submodule program unit that extends a module or another submodule (14.2.3)

39 40 41 42

3.141 subobject portion of data object that can be referenced, and if it is a variable defined, independently of any other portion (9.4.2)

43 44 45

3.142 subprogram function-subprogram (R1529) or subroutine-subprogram (R1534)

ISO/IEC JTC 1/SC 22/WG5/N2184

19

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

3.142.1 external subprogram subprogram that is not contained in a main program, module, submodule, or another subprogram

4 5 6

3.142.2 internal subprogram subprogram that is contained in a main program or another subprogram

7 8 9

3.142.3 module subprogram subprogram that is contained in a module or submodule but is not an internal subprogram

10 11 12

3.143 subroutine procedure invoked by a CALL statement, by defined assignment, or by some operations on derived-type entities

13 14 15

3.143.1 atomic subroutine intrinsic subroutine that performs an action on its ATOM argument atomically (16.5)

16 17 18

3.143.2 collective subroutine intrinsic subroutine that performs a calculation on a team of images without requiring synchronization (16.6)

19 20 21 22

3.144 target entity that is pointer associated with a pointer (19.5.2.2), entity on the right-hand-side of a pointer assignment statement (R1033), or entity with the TARGET attribute (8.5.18)

23 24 25

3.145 team ordered set of images created by execution of a FORM TEAM statement, or the initial ordered set of all images

26 27 28 29

3.145.1 current team team specified by the most recently executed CHANGE TEAM statement of a CHANGE TEAM construct that has not completed execution (11.1.5), or initial team if no CHANGE TEAM construct is being executed

30 31 32

3.145.2 initial team team existing at the beginning of program execution, consisting of all images

33 34 35 36

3.145.3 parent team ⟨team except for initial team⟩ current team at time of execution of the FORM TEAM statement that created the team (11.7.9)

37 38 39

3.145.4 sibling teams teams created by a single set of corresponding executions of the FORM TEAM statement (11.7.9)

40 41 42

3.145.5 team number −1 which identifies the initial team, or positive integer that identifies a team among its sibling teams

43 44 45

3.146 transformational function intrinsic function, or function in an intrinsic module, that is neither elemental nor an inquiry function

20

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

5

3.147 type data type named category of data characterized by a set of values, a syntax for denoting these values, and a set of operations that interpret and manipulate the values (7.1)

6 7 8

3.147.1 abstract type type with the ABSTRACT attribute (7.5.7.1)

9 10 11

3.147.2 declared type type that a data entity is declared to have, either explicitly or implicitly (7.3.2, 10.1.9)

12 13 14

3.147.3 derived type type defined by a type definition (7.5) or by an intrinsic module

15 16 17

3.147.4 dynamic type type of a data entity at a particular point during execution of a program (7.3.2.3, 10.1.9)

18 19 20

3.147.5 extended type type with the EXTENDS attribute (7.5.7.1)

21 22 23

3.147.6 extensible type type that may be extended using the EXTENDS clause (7.5.7.1)

24 25 26 27

3.147.7 extension type ⟨of one type with respect to another⟩ is the same type or is an extended type whose parent type is an extension type of the other type

28 29 30

3.147.8 intrinsic type type defined by this document that is always accessible (7.4)

31 32 33

3.147.9 numeric type one of the types integer, real, and complex

34 35 36

3.147.10 parent type ⟨extended type⟩ type named in the EXTENDS clause

37 38 39 40

3.147.11 type compatible compatibility of the type of one entity with respect to another for purposes such as argument association, pointer association, and allocation (7.3.2)

41 42 43

3.147.12 type parameter value used to parameterize a type (7.2)

1 2 3 4

ISO/IEC JTC 1/SC 22/WG5/N2184

21

J3/21-007r1

1 2 3

WD 1539-1

2021-05-21

3.147.12.1 assumed type parameter length type parameter that assumes the type parameter value from another entity Note 1 to entry: The other entity is • the selector for an associate name, • the constant-expr for a named constant of type character, or • the effective argument for a dummy argument.

4 5 6 7

3.147.12.2 deferred type parameter length type parameter whose value can change during execution of a program and whose type-param-value is a colon

8 9 10

3.147.12.3 kind type parameter type parameter whose value is required to be defaulted or given by a constant expression

11 12 13

3.147.12.4 length type parameter type parameter whose value is permitted to be assumed, deferred, or given by a specification expression

14 15 16

3.147.12.5 type parameter inquiry syntax (type-param-inquiry) that is used to inquire the value of a type parameter of a data object (9.4.5)

17 18 19

3.147.12.6 type parameter order ordering of the type parameters of a type (7.5.3.2) used for derived-type specifiers (derived-type-spec, 7.5.9)

20 21 22

3.148 ultimate argument nondummy entity with which a dummy argument is associated via a chain of argument associations (15.5.2.3)

23 24 25

3.149 undefined ⟨data object⟩ does not have a valid value

26 27 28

3.150 undefined ⟨pointer⟩ does not have a pointer association status of associated or disassociated (19.5.2.2)

29 30 31 32

3.151 unit input/output unit means, specified by an io-unit, for referring to a file (12.5.1)

33 34 35

3.152 unlimited polymorphic able to have any dynamic type during program execution (7.3.2.3)

36 37

3.153 unsaved not having the SAVE attribute (8.5.16)

38

22

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3.154 variable data entity that can be defined and redefined during execution of a program

4 5 6

3.154.1 event variable scalar variable of type EVENT_TYPE (16.10.2.10) from the intrinsic module ISO_FORTRAN_ENV

7 8 9 10

3.154.2 local variable variable in a scoping unit that is not a dummy argument or part thereof, is not a global entity or part thereof, and is not an entity or part of an entity that is accessible outside that scoping unit

11 12 13

3.154.3 lock variable scalar variable of type LOCK_TYPE (16.10.2.19) from the intrinsic module ISO_FORTRAN_ENV

14 15 16

3.154.4 notify variable scalar variable of type NOTIFY_TYPE (16.10.2.22) from the intrinsic module ISO_FORTRAN_ENV

17 18 19

3.154.5 team variable scalar variable of type TEAM_TYPE (16.10.2.34) from the intrinsic module ISO_FORTRAN_ENV

20 21 22

3.155 vector subscript section-subscript that is an array (9.5.3.4.3)

23 24 25

3.156 whole array array component or array name without further qualification (9.5.2)

ISO/IEC JTC 1/SC 22/WG5/N2184

23

J3/21-007r1

WD 1539-1

2021-05-21

1

4 Notation, conformance, and compatibility

2

4.1

Notation, symbols and abbreviated terms

3

4.1.1

Syntax rules

4 5

1 Syntax rules describe the forms that Fortran lexical tokens, statements, and constructs may take. These syntax

6

• Characters from the Fortran character set (6.1) are interpreted literally as shown, except where otherwise noted. • Lower-case italicized letters and words (often hyphenated and abbreviated) represent general syntactic classes for which particular syntactic entities shall be substituted in actual statements. Common abbreviations used in syntactic terms are:

7 8 9 10

rules are expressed in a variation of Backus-Naur form (BNF) with the following conventions.

arg decl desc int spec 11

for for for for for

15 16 17 18 19

attr def expr op stmt

for for for for for

attribute definition expression operator statement

• The syntactic metasymbols used are: is or [] [ ] ...

12 13 14

argument declaration descriptor integer specifier

introduces a syntactic class definition introduces a syntactic class alternative encloses an optional item encloses an optionally repeated item that may occur zero or more times continues a syntax rule

• Each syntax rule is given a unique identifying number of the form Rsnn, where s is a one- or two-digit clause number and nn is a two-digit sequence number within that clause. The syntax rules are distributed as appropriate throughout the text, and are referenced by number as needed. Some rules in Clauses 5 and 6 are more fully described in later clauses; in such cases, the clause number s is the number of the later clause where the rule is repeated. • The syntax rules are not a complete and accurate syntax description of Fortran, and cannot be used to generate a Fortran parser automatically; where a syntax rule is incomplete, it is restricted by corresponding constraints and text. NOTE 1 An example of the use of the syntax rules is: is

digit-string

digit [ digit ] ...

The following are examples of forms for a digit string allowed by the above rule: digit digit digit digit digit digit digit digit digit digit digit digit digit digit digit Some examples of digit-string are:

24

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) 4 67 1999 10243852

1 2 3

4.1.2

Constraints

1 Each constraint is given a unique identifying number of the form Csnn, where s is a one- or two-digit clause

number and nn is a two- or three-digit sequence number within that clause.

4 5 6

2 Often a constraint is associated with a particular syntax rule. Where that is the case, the constraint is annotated

7 8

3 Some constraints are not associated with particular syntax rules. The effect of such a constraint is similar to

with the syntax rule number in parentheses. A constraint that is associated with a syntax rule constitutes part of the definition of the syntax term defined by the rule. It thus applies in all places where the syntax term appears.

9 10 11 12

that of a restriction stated in the text, except that a processor is required to have the capability to detect and report violations of constraints (4.2). In some cases, a broad requirement is stated in text and a subset of the same requirement is also stated as a constraint. This indicates that a standard-conforming program is required to adhere to the broad requirement, but that a standard-conforming processor is required only to have the capability of diagnosing violations of the constraint.

13

4.1.3

14 15

Assumed syntax rules

1 In order to minimize the number of additional syntax rules and convey appropriate constraint information, the

following rules, where the letters xyz stand for any syntactic class phrase, are assumed.

16

R401

xyz-list

is

xyz [ , xyz ] ...

17

R402

xyz-name

is

name

18

R403

scalar-xyz

is

xyz

19

C401

(R403) scalar-xyz shall be scalar.

20 21

2 An explicit syntax rule for a term overrides an assumed rule.

4.1.4

Syntax conventions and characteristics

22 23 24 25

1 Any syntactic class name ending in “-stmt” follows the source form statement rules: it shall be delimited by

26 27

2 The rules on statement ordering are described rigorously in the definition of program-unit (R502). Expression

28 29

3 The suffix “-spec” is used consistently for specifiers, such as input/output statement specifiers. It also is used for

30 31

4 Where reference is made to a type parameter, including the surrounding parentheses, the suffix “-selector” is

end-of-line or semicolon, and may be labeled unless it forms part of another statement (such as an IF or WHERE statement). Conversely, everything considered to be a source form statement is given a “-stmt” ending in the syntax rules. hierarchy is described rigorously in the definition of expr (R1022). type declaration attribute specifications (for example, “array-spec” in R815), and in a few other cases. used. See, for example, “kind-selector” (R706) and “length-selector” (R722).

ISO/IEC JTC 1/SC 22/WG5/N2184

25

J3/21-007r1

1 2 3 4

4.1.5

WD 1539-1

2021-05-21

Text conventions

1 In descriptive text, an equivalent English word is frequently used in place of a syntactic term. Particular state-

ments and attributes are identified in the text by an upper-case keyword, e.g., “END statement”. The descriptions of obsolescent features appear in a smaller type size. NOTE 1 This sentence is an example of the type size used for obsolescent features.

5

4.2

Conformance

6 7 8

1 A program (5.2.2) is a standard-conforming program if it uses only those forms and relationships described herein

9

2 A processor conforms to this document if:

and if the program has an interpretation according to this document. A program unit (5.2.1) conforms to this document if it can be included in a program in a manner that allows the program to be standard conforming.

(1)

it executes any standard-conforming program in a manner that fulfills the interpretations herein, subject to any limits that the processor may impose on the size and complexity of the program; (2) it contains the capability to detect and report the use within a submitted program unit of a form designated herein as obsolescent, insofar as such use can be detected by reference to the numbered syntax rules and constraints; (3) it contains the capability to detect and report the use within a submitted program unit of a form or relationship that is not permitted by the numbered syntax rules or constraints, including the deleted features described in Annex B; (4) it contains the capability to detect and report the use within a submitted program unit of an intrinsic type with a kind type parameter value not supported by the processor (7.4); (5) it contains the capability to detect and report the use within a submitted program unit of source form or characters not permitted by Clause 6; (6) it contains the capability to detect and report the use within a submitted program of name usage not consistent with the scope rules for names, labels, operators, and assignment symbols in Clause 19; (7) it contains the capability to detect and report the use within a submitted program unit of a nonstandard intrinsic procedure (including one with the same name as a standard intrinsic procedure but with different requirements); (8) it contains the capability to detect and report the use within a submitted program unit of a nonstandard intrinsic module; (9) it contains the capability to detect and report the use within a submitted program unit of a procedure from a standard intrinsic module, if the procedure is not defined by this document or the procedure has different requirements from those specified by this document; and (10) it contains the capability to detect and report the reason for rejecting a submitted program.

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

3 However, in a format specification that is not part of a FORMAT statement (13.2.1), a processor need not detect

36 37 38 39 40

4 A standard-conforming processor may allow additional forms and relationships provided that such additions

41 42 43 44

or report the use of deleted or obsolescent features, or the use of additional forms or relationships. do not conflict with the standard forms and relationships. However, a standard-conforming processor may allow additional intrinsic procedures even though this could cause a conflict with the name of a procedure in a standardconforming program. If such a conflict occurs and involves the name of an external procedure, the processor is permitted to use the intrinsic procedure unless the name has the EXTERNAL attribute (8.5.9) where it is used. A standard-conforming program shall not use nonstandard intrinsic procedures or modules that have been added by the processor. 5 Because a standard-conforming program may place demands on a processor that are not within the scope of this

document or may include standard items that are not portable, such as external procedures defined by means

26

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

other than Fortran, conformance to this document does not ensure that a program will execute consistently on all or any standard-conforming processors.

3 4

6 The semantics of facilities that are identified as processor dependent are not completely specified in this document.

5 6 7 8 9

7 The processor should be accompanied by documentation that specifies the limits it imposes on the size and com-

10

8 The processor should be accompanied by documentation that specifies the methods or semantics of processor-

They shall be provided, with methods or semantics determined by the processor. plexity of a program and the means of reporting when these limits are exceeded, that defines the additional forms and relationships it allows, and that defines the means of reporting the use of additional forms and relationships and the use of deleted or obsolescent forms. In this context, the use of a deleted form is the use of an additional form.

11

dependent facilities.

12

4.3

Compatibility

13

4.3.1

Previous Fortran standards

14

1 Table 4.3 lists the previous editions of the Fortran International Standard, along with their informal names.

Table 4.3: Previous editions of the Fortran International Standard

15 16 17 18 19 20 21 22 23 24

4.3.2

Official designation ISO R 1539-1972 ISO 1539-1980 ISO/IEC 1539:1991

Informal name Fortran 66 Fortran 77 Fortran 90

ISO/IEC 1539-1:1997 ISO/IEC 1539-1:2004 ISO/IEC 1539-1:2010 ISO/IEC 1539-1:2018

Fortran 95 Fortran 2003 Fortran 2008 Fortran 2018

New intrinsic procedures

1 Each Fortran International Standard since ISO 1539:1980 (Fortran 77), defines more intrinsic procedures than

the previous one. Therefore, a Fortran program conforming to an older standard might have a different interpretation under a newer standard if it invokes an external procedure having the same name as one of the new standard intrinsic procedures, unless that procedure is specified to have the EXTERNAL attribute.

4.3.3

Fortran 2018 compatibility

1 Except as identified in this subclause, this document is an upward compatible extension to the preceding Fortran

International Standard, ISO/IEC 1539-1:2018 (Fortran 2018). A standard-conforming Fortran 2018 program that does not use any feature identified in this subclause as being no longer permitted remains standard-conforming under this document.

25 26 27 28

2 Fortran 2018 allowed integer arguments to the intrinsic subroutine SYSTEM_CLOCK to be of any kind. This

29

3 The following Fortran 2018 features might have a different interpretation under this document.

30 31

document requires integer arguments to SYSTEM_CLOCK to have a decimal exponent range at least as large as a default integer, and requires that all integer arguments in a reference to SYSTEM_CLOCK have the same kind type parameter.

• After an allocatable deferred length character variable is assigned a value by an IOMSG= or ERRMSG= clause, is the unit in an internal WRITE statement, or is an INTENT (OUT) argument in a reference to

ISO/IEC JTC 1/SC 22/WG5/N2184

27

J3/21-007r1

1 2 3 4 5 6 7 8 9

10

WD 1539-1

2021-05-21

an intrinsic subroutine, that variable might be of shorter or longer length under this document than under Fortran 2018, since this document specifies intrinsic assignment semantics for these assignments. • This document permits the intrinsic subroutine SYSTEM_CLOCK to use two or more clocks, with different characteristics based on the type and kind type parameters of its arguments. A program that invokes SYSTEM_CLOCK with different argument types or kinds in different references, could have a different interpretation under this document. • The result of a reference to IEEE_MAX_NUM, IEEE_MAX_NUM_MAG, IEEE_MIN_NUM, or IEEE_MIN_NUM_MAG where one argument is a number and the other is a signaling NaN is specified to be the number in this document. Fortran 2018 specified that the result is a NaN.

4.3.4

Fortran 2008 compatibility

11 12 13 14

1 Except as identified in this subclause, and except for the deleted features noted in Annex B.2, this document

15 16

2 Fortran 2008 specifies that the IOSTAT= variable shall be set to a processor-dependent negative value if the flush

17 18

is an upward compatible extension to ISO/IEC 1539-1:2010 (Fortran 2008). Any standard-conforming Fortran 2008 program that does not use any deleted features, and does not use any feature identified in this subclause as being no longer permitted, remains standard-conforming under this document. operation is not supported for the unit specified. This document specifies that the processor-dependent negative integer value shall be different from the named constants IOSTAT_EOR or IOSTAT_END from the intrinsic module ISO_FORTRAN_ENV.

19 20 21

3 Fortran 2008 permitted a noncontiguous array that was supplied as an actual argument corresponding to a

22

4 Fortran 2008 permitted a pure statement function to reference a volatile variable, and permitted a local variable

23 24

of a pure subprogram or of a BLOCK construct within a pure subprogram to be volatile (provided it was not used); this document does not permit that.

25 26

5 Fortran 2008 permitted a pure function to have a result that has a polymorphic allocatable ultimate component;

27 28

6 Fortran 2008 permitted a PROTECTED TARGET variable accessed by use association to be used as an initial-

29 30

7 Fortran 2008 permitted a named constant to have declared type LOCK_TYPE, or have a noncoarray potential

31 32

8 Fortran 2008 permitted a polymorphic object to be finalized within a DO CONCURRENT construct; this docu-

33 34

9 Fortran 2008 permitted an unallocated allocatable coarray or coindexed object to be allocated by an assignment

35

contiguous INTENT (INOUT) dummy argument in one iteration of a DO CONCURRENT construct, without being previously defined in that iteration, to be defined in another iteration; this document does not permit this.

this document does not permit that. data-target; this document does not permit that. subobject component with declared type LOCK_TYPE; this document does not permit that. ment does not permit that. statement, provided it was scalar, nonpolymorphic, and had no deferred type parameters; this document does not permit that.

36 37

10 Fortran 2008 permitted the processor to use a common pseudorandom number generator for all images. This

38 39 40

11 Fortran 2008 required ACOSH of a complex value to have the imaginary part nonnegative and had no requirement

41 42 43 44

12 Fortran 2008 allowed integer arguments to the intrinsic subroutine SYSTEM_CLOCK to be of any kind. This

document requires separate seeds on each image for the pseudorandom number generator. on the real part. This document requires ACOSH of a complex value to have a nonnegative real part and has no such requirement on the imaginary part. document requires integer arguments to SYSTEM_CLOCK to have a decimal exponent range at least as large as a default integer, and requires that all integer arguments in a reference to SYSTEM_CLOCK have the same kind type parameter.

28

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9

10 11 12 13

WD 1539-1

J3/21-007r1

13 The following Fortran 2008 features might have a different interpretation under this document.

• After an allocatable deferred length character variable is assigned a value by an IOMSG= or ERRMSG= clause, is the unit in an internal WRITE statement, or is an INTENT (OUT) argument in a reference to an intrinsic subroutine, that variable might be of shorter or longer length under this document than under Fortran 2008, since this document specifies intrinsic assignment semantics for these assignments. • This document permits the intrinsic subroutine SYSTEM_CLOCK to use two or more clocks, with different characteristics based on the type and kind type parameters of its arguments. A program that invokes SYSTEM_CLOCK with different argument types or kinds in different references, could have a different interpretation under this document.

4.3.5

Fortran 2003 compatibility

1 Except as identified in this subclause, this document is an upward compatible extension to ISO/IEC 1539-1:2004

(Fortran 2003). Except as identified in this subclause, any standard-conforming Fortran 2003 program remains standard-conforming under this document.

14

2 Fortran 2003 permitted a sequence type to have type parameters; that is not permitted by this document.

15 16

3 Fortran 2003 specified that array constructors and structure constructors of finalizable type are finalized. This

17 18

4 The form produced by the G edit descriptor for some values and some input/output rounding modes differs from

19 20 21

5 Fortran 2003 required an explicit interface only for a procedure that was actually referenced in the scope, not

22 23 24

6 Fortran 2003 permitted the function result of a pure function to be a polymorphic allocatable variable, to have

25 26

7 Fortran 2003 permitted an INTENT (OUT) argument of a pure subroutine to be polymorphic; that is not

27 28 29

8 Fortran 2003 interpreted assignment to an allocatable variable from a nonconformable array as intrinsic assign-

30

9 Fortran 2003 permitted a statement function to be of parameterized derived type; this document does not permit

31

document specifies that these constructors are not finalized. that specified by Fortran 2003. merely passed as an actual argument. This document requires an explicit interface for a procedure under the conditions listed in 15.4.2.2, regardless of whether the procedure is referenced in the scope. a polymorphic allocatable ultimate component, or to be finalizable by an impure final subroutine. These are not permitted by this document. permitted by this document. ment, even when an elemental defined assignment was in scope; this document does not permit assignment from a nonconformable array in this context. that.

32 33

10 Fortran 2003 permitted a pure statement function to reference a volatile variable, and permitted a local variable

34 35 36

11 Fortran 2003 allowed integer arguments to the intrinsic subroutine SYSTEM_CLOCK to be of any kind. This

37 38 39 40 41 42 43 44

of a pure subprogram to be volatile (provided it was not used); this document does not permit that. document requires integer arguments to SYSTEM_CLOCK to have a decimal exponent range at least as large as a default integer, and requires that all integer arguments in a reference to SYSTEM_CLOCK have the same kind type parameter. 12 The following Fortran 2003 features might have a different interpretation under this document.

• After an allocatable deferred length character variable is assigned a value by an IOMSG= or ERRMSG= clause, is the unit in an internal WRITE statement, or is an INTENT (OUT) argument in a reference to an intrinsic subroutine, that variable might be of shorter or longer length under this document than under Fortran 2003, since this document specifies intrinsic assignment semantics for these assignments. • This document permits the intrinsic subroutine SYSTEM_CLOCK to use two or more clocks, with different characteristics based on the type and kind type parameters of its arguments. A program that invokes

ISO/IEC JTC 1/SC 22/WG5/N2184

29

J3/21-007r1

4 5 6

2021-05-21

SYSTEM_CLOCK with different argument types or kinds in different references, could have a different interpretation under this document.

1 2

3

WD 1539-1

4.3.6

Fortran 95 compatibility

1 Except as identified in this subclause, this document is an upward compatible extension to ISO/IEC 1539-1:1997

(Fortran 95). Except as identified in this subclause, any standard-conforming Fortran 95 program remains standard-conforming under this document.

7 8

2 Fortran 95 permitted defined assignment between character strings of the same rank and different kinds. This

9

3 The following Fortran 95 features might have different interpretations in this document.

10 11 12 13 14 15 16 17 18 19 20 21

22

document does not permit that if both of the different kinds are ASCII, ISO 10646, or default kind.

• Earlier Fortran standards had the concept of printing, meaning that column one of formatted output had special meaning for a processor-dependent (possibly empty) set of external files. This could be neither detected nor specified by a standard-specified means. The interpretation of the first column is not specified by this document. • This document specifies a different output format for real zero values in list-directed and namelist output. • If the processor distinguishes between positive and negative real zero, this document requires different returned values for ATAN2(Y,X) when X < 0 and Y is negative real zero and for LOG(X) and SQRT(X) when X is complex with X%RE < 0 and X%IM is negative real zero. • This document has fewer restrictions on constant expressions than Fortran 95; this affects whether a variable is considered to be an automatic data object. • The form produced by the G edit descriptor with d equal to zero differs from that specified by Fortran 95 for some values.

4.3.7

Fortran 90 compatibility

23 24 25

1 Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this document

26 27

2 The PAD= specifier in the INQUIRE statement in this document returns the value UNDEFINED if there is no

28

3 Fortran 90 specified that if the second argument to MOD or MODULO was zero, the result was processor

29

is an upward compatible extension to ISO/IEC 1539:1991 (Fortran 90). Any standard-conforming Fortran 90 program that does not use one of the deleted features remains standard-conforming under this document. connection or the connection is for unformatted input/output. Fortran 90 specified YES. dependent. This document specifies that the second argument shall not be zero.

30 31

4 Fortran 90 permitted defined assignment between character strings of the same rank and different kinds. This

32

5 The following Fortran 90 features have different interpretations in this document:

33 34 35 36 37 38

39 40 41 42

document does not permit that if both of the different kinds are ASCII, ISO 10646, or default kind.

• if the processor distinguishes between positive and negative real zero, the result value of the intrinsic function SIGN when the second argument is a negative real zero; • formatted output of negative real values (when the output value is zero); • whether an expression is a constant expression (thus whether a variable is considered to be an automatic data object); • the G edit descriptor with d equal to zero for some values.

4.3.8

FORTRAN 77 compatibility

1 Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this document is an

upward compatible extension to ISO 1539:1980 (Fortran 77). Any standard-conforming Fortran 77 program that does not use one of the deleted features noted in Annex B.1 and that does not depend on the differences

30

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

WD 1539-1

J3/21-007r1

specified here remains standard-conforming under this document. This document restricts the behavior for some features that were processor dependent in Fortran 77. Therefore, a standard-conforming Fortran 77 program that uses one of these processor-dependent features might have a different interpretation under this document, yet remain a standard-conforming program. The following Fortran 77 features might have different interpretations in this document. • Fortran 77 permitted a processor to supply more precision derived from a default real constant than can be represented in a default real datum when the constant is used to initialize a double precision real data object in a DATA statement. This document does not permit a processor this option. • If a named variable that was not in a common block was initialized in a DATA statement and did not have the SAVE attribute specified, Fortran 77 left its SAVE attribute processor dependent. This document specifies (8.6.7) that this named variable has the SAVE attribute. • Fortran 77 specified that the number of characters required by the input list was to be less than or equal to the number of characters in the record during formatted input. This document specifies (12.6.4.5.3) that the input record is logically padded with blanks if there are not enough characters in the record, unless the PAD= specifier with the value ’NO’ is specified in an appropriate OPEN or READ statement. • A value of 0 for a list item in a formatted output statement will be formatted in a different form for some G edit descriptors. In addition, this document specifies how rounding of values will affect the output field form, but Fortran 77 did not address this issue. Therefore, the form produced for certain combinations of values and G edit descriptors might differ from that produced by some Fortran 77 processors. • Fortran 77 did not permit a processor to distinguish between positive and negative real zero; if the processor does so distinguish, the result will differ for the intrinsic function SIGN when the second argument is negative real zero, and formatted output of negative real zero will be different.

23

4.4

Deleted and obsolescent features

24

4.4.1

General

25

1 This document protects the users’ investment in existing software by including all but six of the language elements

26 27 28 29

of Fortran 90 that are not processor dependent. This document identifies two categories of outmoded features. The first category, deleted features, consists of features considered to have been redundant in Fortran 77 and largely unused in Fortran 90. Those in the second category, obsolescent features, are considered to have been redundant in Fortran 90 and Fortran 95, but are still frequently used.

30

4.4.2

31 32 33

Nature of deleted features

1 There are two groups of deleted features. The first group contains features for which better methods existed in

34

Fortran 77; these features were not included in Fortran 95, Fortran 2003, or Fortran 2008, and are not included in this document. The second group contains features for which better methods existed in Fortran 90; these features were included in Fortran 2008, but are not included in this document.

35

4.4.3

36

Nature of obsolescent features

1 Better methods existed in Fortran 90 and Fortran 95 for each obsolescent feature. It is recommended that

37

programmers use these better methods in new programs and convert existing code to these methods.

38

2 The obsolescent features are identified in the text of this document by a distinguishing type font (4.1.5).

39

3 A future revision of this document might delete an obsolescent feature if its use has become insignificant.

ISO/IEC JTC 1/SC 22/WG5/N2184

31

J3/21-007r1

WD 1539-1

1

5 Fortran concepts

2

5.1

3 4

2021-05-21

High level syntax

1 This subclause introduces the syntax associated with program units and other Fortran concepts above the con-

struct, statement, and expression levels and illustrates their relationships. NOTE 1 Constraints and other information related to the rules that do not begin with R5 appear in the appropriate clause. R501

program

is

program-unit [ program-unit ] ...

7 8 9 10 11

R502

program-unit

is or or or

main-program external-subprogram module submodule

or

block-data

12 13 14 15 16

R1401 main-program

is

[ program-stmt ] [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-program-stmt

17

R503

is function-subprogram or subroutine-subprogram

5 6

external-subprogram

18 19 20 21 22 23

R1529 function-subprogram

is

function-stmt [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-function-stmt

24 25 26 27 28

R1534 subroutine-subprogram

is

subroutine-stmt [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-subroutine-stmt

29

R1404 module

is

module-stmt [ specification-part ] [ module-subprogram-part ] end-module-stmt

R1416 submodule

is

submodule-stmt [ specification-part ] [ module-subprogram-part ] end-submodule-stmt

R1420

is

block-data-stmt [ specification-part ]

30 31 32 33 34 35 36 37 38

32

block-data

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

end-block-data-stmt

R504

specification-part

is

[ use-stmt ] ... [ import-stmt ] ... [ implicit-part ] [ declaration-construct ] ...

6 7

R505

implicit-part

is

[ implicit-part-stmt ] ... implicit-stmt

8 9 10

R506

implicit-part-stmt

is or or or

implicit-stmt parameter-stmt format-stmt

is or or or or

specification-construct data-stmt format-stmt

2 3 4 5

11

declaration-construct

entry-stmt

12 13 14 15 16

R507

17 18 19 20 21 22

R508

specification-construct

is or or or or or or or

derived-type-def enum-def generic-stmt interface-block parameter-stmt procedure-declaration-stmt other-specification-stmt type-declaration-stmt

25 26

R509

execution-part

is

executable-construct [ execution-part-construct ] ...

27 28

R510

execution-part-construct

is or or or

executable-construct format-stmt

contains-stmt [ internal-subprogram ] ...

23 24

29 30

entry-stmt stmt-function-stmt

entry-stmt data-stmt

31 32

R511

internal-subprogram-part

is

33 34

R512

internal-subprogram

is function-subprogram or subroutine-subprogram

35 36

R1407 module-subprogram-part

is

37 38 39

R1408 module-subprogram

is function-subprogram or subroutine-subprogram or separate-module-subprogram

40

R1538 separate-module-subprogram is

41 42 43 44 45 46

J3/21-007r1

R513

other-specification-stmt

contains-stmt [ module-subprogram ] ...

mp-subprogram-stmt [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-mp-subprogram-stmt

is access-stmt or allocatable-stmt

ISO/IEC JTC 1/SC 22/WG5/N2184

33

J3/21-007r1

WD 1539-1

11 12 13 14 15 16

or or or or or or or or or or or or or or or or

asynchronous-stmt bind-stmt codimension-stmt contiguous-stmt dimension-stmt external-stmt intent-stmt intrinsic-stmt namelist-stmt optional-stmt pointer-stmt protected-stmt save-stmt target-stmt volatile-stmt value-stmt

17 18

or or

common-stmt equivalence-stmt

is or or or or or or or or or or or

action-stmt associate-construct block-construct case-construct change-team-construct critical-construct do-construct if-construct select-rank-construct select-type-construct where-construct

is or or or or or or or or or or or or or or or or or or or or or or or

allocate-stmt assignment-stmt backspace-stmt call-stmt close-stmt continue-stmt cycle-stmt deallocate-stmt endfile-stmt error-stop-stmt event-post-stmt event-wait-stmt exit-stmt fail-image-stmt flush-stmt form-team-stmt goto-stmt if-stmt inquire-stmt lock-stmt notify-wait-stmt nullify-stmt open-stmt pointer-assignment-stmt

1 2 3 4 5 6 7 8 9 10

19 20 21 22

R514

executable-construct

23 24 25 26 27 28 29 30 31 32 33

R515

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

34

action-stmt

forall-construct

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2021-05-21

WD 1539-1

or or or or or or or or or or or or or or or

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

J3/21-007r1

print-stmt read-stmt return-stmt rewind-stmt stop-stmt sync-all-stmt sync-images-stmt sync-memory-stmt sync-team-stmt unlock-stmt wait-stmt where-stmt write-stmt computed-goto-stmt forall-stmt

16

5.2

Program unit concepts

17

5.2.1

Program units and scoping units

18 19

1 Program units are the fundamental components of a Fortran program. A program unit is a main program, an

20 21 22 23

2 A subprogram is a function subprogram or a subroutine subprogram. A module contains definitions that can be

24

3 Each type of program unit is described in Clause 14 or 15.

25

4 A program unit consists of a set of nonoverlapping scoping units.

external subprogram, a module, a submodule, or a block data program unit. made accessible to other program units. A submodule is an extension of a module; it may contain the definitions of procedures declared in a module or another submodule. A block data program unit is used to specify initial values for data objects in named common blocks.

NOTE 1 The module or submodule containing a module subprogram is the host scoping unit of the module subprogram. The containing main program or subprogram is the host scoping unit of an internal subprogram. An internal procedure is local to its host in the sense that its name is accessible within the host scoping unit and all its other internal procedures but is not accessible elsewhere. 26

5.2.2

Program

27

1 A program shall consist of exactly one main program, any number (including zero) of other kinds of program units,

28 29 30

any number (including zero) of external procedures, and any number (including zero) of other entities defined by means other than Fortran. The main program shall be defined by a Fortran main-program program-unit or by means other than Fortran, but not both.

31

5.2.3

Procedure

32 33

1 A procedure is either a function or a subroutine. Invocation of a function in an expression causes a value to be

34 35

2 A procedure that is not pure may change the program state by changing the value of accessible data objects or

36

3 Procedures are described further in Clause 15.

computed which is then used in evaluating the expression. procedure pointers.

ISO/IEC JTC 1/SC 22/WG5/N2184

35

J3/21-007r1

1 2 3

5.2.4

WD 1539-1

2021-05-21

Module

1 A module contains (or accesses from other modules) definitions that can be made accessible to other program units.

4

These definitions include data object declarations, type definitions, procedure definitions, and interface blocks. Modules are further described in Clause 14.

5

5.2.5

Submodule

6

1 A submodule extends a module or another submodule.

7 8 9 10

2 It may provide definitions (15.6) for procedures whose interfaces are declared (15.4.3.2) in an ancestor module

or submodule. It may also contain declarations and definitions of other entities, which are accessible in its descendants. An entity declared in a submodule is not accessible by use association unless it is a module procedure whose interface is declared in the ancestor module. Submodules are further described in Clause 14. NOTE 1 A submodule has access to entities in its parent module or submodule by host association.

11

5.3

Execution concepts

12

5.3.1

Statement classification

13

1 Each Fortran statement is classified as either an executable statement or a nonexecutable statement.

14 15

2 An executable statement is an instruction to perform or control an action. Thus, the executable statements of a

16

3 Nonexecutable statements are used to configure the program environment in which actions take place.

17

program unit determine the behavior of the program unit.

5.3.2

Statement order Table 5.1: Requirements on statement ordering PROGRAM, FUNCTION, SUBROUTINE, MODULE, SUBMODULE, or BLOCK DATA statement USE statements IMPORT statements IMPLICIT NONE PARAMETER IMPLICIT statements statements Derived-type definitions, FORMAT interface blocks, and PARAMETER type declaration statements, ENTRY and DATA enumeration definitions, statements statements procedure declarations, specification statements, and statement function statements DATA

Executable constructs CONTAINS statement Internal subprograms or module subprograms END statement

statements

36

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8

WD 1539-1

J3/21-007r1

1 The syntax rules of 5.1 specify the statement order within program units and subprograms. These rules are

illustrated in Table 5.1 and Table 5.2. Table 5.1 shows the ordering rules for statements and applies to all program units, subprograms, and interface bodies. Vertical lines delineate varieties of statements that can be interspersed and horizontal lines delineate varieties of statements that shall not be interspersed. Internal or module subprograms shall follow a CONTAINS statement. Between USE and CONTAINS statements in a subprogram, nonexecutable statements generally precede executable statements, although the ENTRY statement, FORMAT statement, and DATA statement may appear among the executable statements. Table 5.2 shows which statements are allowed in some kinds of scoping units. Table 5.2: Statements allowed in scoping units Kind of scoping unit Main

Module or

Block

External

Module

Internal

Interface

program

submodule

data

subprogram

subprogram

subprogram

body

USE IMPORT

Yes No

Yes Submodule

Yes No

Yes No

Yes Yes

Yes Yes

Yes Yes

ENTRY

No

No

No

Yes

Yes

No

No

Yes

No

No

Yes

Yes

Yes

No

Statement type

FORMAT 1

Yes

Yes

Yes

Yes

Yes

Yes

Yes

DATA

Yes

Yes

Yes

Yes

Yes

Yes

No

Derived-type

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Interface

Yes

Yes

No

Yes

Yes

Yes

Yes

Executable

Yes

No

No

Yes

Yes

Yes

No

CONTAINS

Yes

Yes

No

Yes

Yes

No

No

Statement function

Yes

No

No

Yes

Yes

Yes

No

Misc. decl.s

(1) Miscellaneous declarations are PARAMETER statements, IMPLICIT statements, type declaration statements, enumeration definitions, procedure declaration statements, and specification statements.

9 10 11 12 13 14 15 16

5.3.3

The END statement

1 Each program unit, module subprogram, and internal subprogram shall have exactly one END statement. The

end-program-stmt, end-function-stmt, end-subroutine-stmt, and end-mp-subprogram-stmt statements are executable, and may be branch target statements (11.2). Executing an end-program-stmt initiates normal termination. Executing an end-function-stmt, end-subroutine-stmt, or end-mp-subprogram-stmt is equivalent to executing a return-stmt with no scalar-int-expr . 2 The end-module-stmt, end-submodule-stmt, and end-block-data-stmt statements are nonexecutable.

5.3.4

Program execution

17 18 19 20

1 Execution of a program consists of the asynchronous execution of a fixed number (which may be one) of its images.

21 22 23 24

2 A team is an ordered set of images that is either the initial team, consisting of all images, or a subset of a parent

25 26

3 During execution, each image has a current team, which is only changed by execution of CHANGE TEAM

Each image has its own execution state, floating-point status (17.7), and set of data objects, input/output units, and procedure pointers. The image index that identifies an image is an integer value in the range one to the number of images in a team. team formed by execution of a FORM TEAM statement. The initial team has no parent; every other team has a unique parent team. Among its sibling teams, each team is identified by its team number; this is the integer value that was specified in the FORM TEAM statement. and END TEAM statements. Image indices, and thus coindexing of variable names with an image-selector, are

ISO/IEC JTC 1/SC 22/WG5/N2184

37

J3/21-007r1

1

WD 1539-1

2021-05-21

relative to the current team unless a different team is specified. Initially, the current team is the initial team. NOTE 1 Fortran control constructs (11.1, 11.2) control the progress of execution in each image. Image control statements (11.7.1) affect the relative progress of execution between images. Coarrays (5.4.7) provide a mechanism for accessing data on one image from another image. NOTE 2 A processor might allow the number of images to be chosen at compile time, link time, or run time. It might be the same as the number of CPUs but this is not required. Compiling for a single image might permit the optimizer to eliminate overhead associated with parallel execution. A program that makes assumptions about the number of images is unlikely to be portable.

2

5.3.5

Execution sequence

3

1 Following the creation of a fixed number of images, execution begins on each image. Image execution is a

4 5 6

sequence, in time, of actions. Actions take place during execution of the statement that performs them (except when explicitly stated otherwise). Segments (11.7.2) executed by a single image are totally ordered, and segments executed by separate images are partially ordered by image control statements (11.7.1).

7 8 9

2 If the program contains a Fortran main program, each image begins execution with the first executable construct

10 11 12 13 14 15 16 17 18 19 20 21 22

23

of the main program. The execution of a main program or subprogram involves execution of the executable constructs within its scoping unit. When a Fortran procedure is invoked, the specification expressions within the specification-part of the invoked procedure, if any, are evaluated in a processor dependent order. Thereafter, execution proceeds to the first executable construct appearing within the scoping unit of the procedure after the invoked entry point. With the following exceptions, the effect of execution is as if the executable constructs are executed in the order in which they appear in the main program or subprogram until a STOP, ERROR STOP, RETURN, or END statement is executed. • Execution of a branching statement (11.2) changes the execution sequence. These statements explicitly specify a new starting place for the execution sequence. • DO constructs, IF constructs, SELECT CASE constructs, SELECT RANK constructs, and SELECT TYPE constructs contain an internal statement structure and execution of these constructs involves implicit internal transfer of control. See Clause 11 for the detailed semantics of each of these constructs. • A BLOCK construct may contain specification expressions; see 11.1.4 for detailed semantics of this construct. • An END=, ERR=, or EOR= specifier (12.11) can result in a branch. • An alternate return can result in a branch.

5.3.6

Image execution states

24 25 26

1 There are three image execution states: active, stopped, and failed. An image that has initiated normal termin-

27 28 29

2 A failed image remains failed for the remainder of the execution of the program. The conditions that cause an

30 31 32

3 Defining a coindexed object on a failed image has no effect other than defining the stat-variable, if one appears,

33 34 35 36

4 When an image fails during the execution of a segment, a data object on a nonfailed image becomes undefined

ation of execution is a stopped image. An image that has ceased participating in program execution but has not initiated termination is a failed image. All other images are active images. image to fail are processor dependent. It is processor dependent whether the processor has the ability to detect that an image has failed. with the value STAT_FAILED_IMAGE (16.10.2.28). The value of a reference to a coindexed object on a failed image is processor dependent. Execution continues after such a reference. if it is not a lock variable, notify variable, or event variable, and it might be defined or become undefined by execution of a statement of the segment other than an invocation of an atomic subroutine with the object as an actual argument corresponding to the ATOM dummy argument.

38

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

5.3.7

WD 1539-1

J3/21-007r1

Termination of execution

1 Termination of execution of a program is either normal termination or error termination. Normal termination

4 5 6 7 8

occurs only when all images initiate normal termination and occurs in three steps: initiation, synchronization, and completion. In this case, all images synchronize execution at the second step so that no image starts the completion step until all images have finished the initiation step. Error termination occurs when any image initiates error termination. Once error termination has been initiated on an image, error termination is initiated on all images that have not already initiated error termination. Termination of execution of the program occurs when all images have terminated execution or failed.

9

2 Normal termination of execution of an image is initiated when a STOP statement or end-program-stmt is executed.

10 11 12 13 14

Normal termination of execution of an image can also be initiated during execution of a procedure defined by a companion processor (ISO/IEC 9899:2011, 5.1.2.2.3 and 7.22.4.4). If normal termination of execution is initiated within a Fortran program unit and the program incorporates procedures defined by a companion processor, the process of execution termination shall include the effect of executing the C exit() function (ISO/IEC 9899:2011, 7.22.4.4) during the completion step.

15

3 Error termination of execution of an image is initiated if an ERROR STOP statement is executed or as specified

16 17

elsewhere in this document. When error termination on an image has been initiated, the processor should initiate error termination on other images as quickly as possible.

18 19 20

4 If the processor supports the concept of a process exit status, it is recommended that error termination initiated

other than by an ERROR STOP statement supplies a processor-dependent nonzero value as the process exit status. NOTE 1 As well as in the circumstances specified in this document, error termination might be initiated by means other than Fortran. NOTE 2 If an image has initiated normal termination, its data remain available for possible reference or definition by other images that are still executing.

21

5.4

Data concepts

22

5.4.1

Type

23

5.4.1.1

General

24 25 26

1 A type is a named categorization of data that, together with its type parameters, determines the set of values,

27

2 A type is either an intrinsic type or a derived type.

28

syntax for denoting these values, and the set of operations that interpret and manipulate the values. This central concept is described in 7.1.

5.4.1.2

Intrinsic type

29 30

1 The intrinsic types are integer, real, complex, character, and logical. The properties of intrinsic types are described

31 32

2 All intrinsic types have a kind type parameter called KIND, which determines the representation method for the

33

in 7.4. specified type. The intrinsic type character also has a length type parameter called LEN, which determines the length of the character string.

ISO/IEC JTC 1/SC 22/WG5/N2184

39

J3/21-007r1

1 2 3 4 5 6 7 8 9 10 11

5.4.1.3

WD 1539-1

2021-05-21

Derived type

1 Derived types can be parameterized. A scalar object of derived type is a structure; assignment of structures

is defined intrinsically (10.2.1.3), but there are no intrinsic operations for structures. For each derived type, a structure constructor is available to create values (7.5.10). In addition, objects of derived type can be used as procedure arguments and function results, and can appear in input/output lists. If additional operations are needed for a derived type, they can be defined by procedures (10.1.6). 2 Derived types are described further in 7.5.

5.4.2

Data value

1 Each intrinsic type has associated with it a set of values that a datum of that type can take, depending on the

12

values of the type parameters. The values for each intrinsic type are described in 7.4. The values that objects of a derived type can assume are determined by the type definition, type parameter values, and the sets of values of its components.

13

5.4.3

Data entity

14

5.4.3.1

General

15 16

1 A data entity has a type and type parameters; it might have a data value (an exception is an undefined variable).

17

2 A data entity that is the result of the execution of a function reference is called the function result.

Every data entity has a rank and is thus either a scalar or an array.

18

5.4.3.2

19

5.4.3.2.1

Data object Data object classification

20 21

1 A data object is either a constant, variable, or a subobject of a constant. The type and type parameters of a

22 23

2 Subobjects are portions of data objects that can be referenced and defined (variables only) independently of the

24 25 26 27

3 These include portions of arrays (array elements and array sections), portions of character strings (substrings),

28

4 The following objects are referenced by a name:

named data object can be specified explicitly (8.2) or implicitly (8.7). other portions. portions of complex objects (real and imaginary parts), and portions of structures (components). Subobjects are themselves data objects, but subobjects are referenced only by object designators or intrinsic functions. A subobject of a variable is a variable. Subobjects are described in Clause 9. • a named scalar • a named array

29 30

5 The following subobjects are referenced by an object designator:

• an array element • an array section • a complex part designator • a structure component • a substring

31

32 33 34

(a scalar object); (an array object).

5.4.3.2.2

(a scalar subobject); (an array subobject); (the real or imaginary part of a complex object); (a scalar or an array subobject); (a scalar subobject).

Variable

1 A variable can have a value or be undefined; during execution of a program it can be defined, redefined, or become

undefined.

40

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

2 A local variable of a module, submodule, main program, subprogram, or BLOCK construct is accessible only in

that scoping unit or construct and in any contained scoping units and constructs. NOTE 1 A subobject of a local variable is also a local variable. A local variable cannot be in COMMON or have the BIND attribute, because common blocks and variables with the BIND attribute are global entities.

3

5.4.3.2.3

Constant

4

1 A constant is either a named constant or a literal constant.

5

2 Named constants are defined using the PARAMETER attribute (8.5.13, 8.6.11). The syntax of literal constants

6

is described in 7.4.

7

5.4.3.2.4

Subobject of a constant

8

1 A subobject of a constant is a portion of a constant.

9

2 In an object designator for a subobject of a constant, the portion referenced may depend on the value of a variable.

NOTE 1 For example, given: CHARACTER (LEN = 10), PARAMETER :: DIGITS = ’0123456789’ CHARACTER (LEN = 1) :: DIGIT INTEGER :: I ... DIGIT = DIGITS (I:I) DIGITS is a named constant and DIGITS (I:I) designates a subobject of the constant DIGITS. 10 11 12 13 14

5.4.3.3

Expression

1 An expression (10.1) produces a data entity when evaluated. An expression represents either a data object

reference or a computation; it is formed from operands, operators, and parentheses. The type, type parameters, value, and rank of an expression result are determined by the rules in Clause 10. 5.4.3.4

Function reference

15

1 A function reference produces a data entity when the function is executed during expression evaluation. The

16 17

type, type parameters, and rank of a function result are determined by the interface of the function (15.3.3). The value of a function result is determined by execution of the function.

18

5.4.4

Definition of objects and pointers

19 20 21

1 When an object is given a valid value during program execution, it becomes defined. This is often accomplished

22 23

2 Similarly, when a pointer is associated with a target or nullified, its pointer association status becomes defined.

24

3 Clause 19 describes the ways in which variables become defined and undefined and the association status of

25

by execution of an assignment or input statement. When a variable does not have a predictable value, it is undefined. When the association status of a pointer is not predictable, its pointer association status is undefined. pointers becomes defined and undefined.

ISO/IEC JTC 1/SC 22/WG5/N2184

41

J3/21-007r1

1

5.4.5

WD 1539-1

2021-05-21

Reference

2 3

1 A data object is referenced when its value is required during execution. A procedure is referenced when it is

4 5 6

2 The appearance of a data object designator or procedure designator as an actual argument does not constitute

7 8 9 10 11 12 13

executed. a reference to that data object or procedure unless such a reference is necessary to complete the specification of the actual argument.

5.4.6

Array

1 An array may have up to fifteen dimensions minus its corank, and any extent in any dimension. The size of an

array is the total number of elements, which is equal to the product of the extents. An array may have zero size. The shape of an array is determined by its rank and its extent in each dimension, and is represented as a rank-one array whose elements are the extents. All named arrays shall be declared, and the rank of a named array is specified in its declaration. Except for an assumed-rank array, the rank of a named array, once declared, is constant.

14 15 16 17

2 Any intrinsic operation defined for scalar objects may be applied to conformable objects. Such operations are

18 19

3 A rank-one array can be constructed from scalars and other arrays and can be reshaped into any allowable array

20

4 Arrays are described further in 9.5.

21

performed elementally to produce a resultant array conformable with the array operands. If an elemental operation is intrinsically pure or is implemented by a pure elemental function (15.9), the element operations can be performed simultaneously or in any order. shape (7.8).

5.4.7

Coarray

22 23

1 A coarray is a data entity that has nonzero corank; it can be directly referenced or defined by other images. It

24 25

2 For each coarray on an image, there is a corresponding coarray with the same type, type parameters, and bounds

26

3 The set of corresponding coarrays on all images in a team is arranged in a rectangular pattern. The dimensions of

27 28

this pattern are the codimensions; the number of codimensions is the corank. The bounds for each codimension are the cobounds.

may be a scalar or an array. on every other image of a team in which it is established (5.4.8).

NOTE 1 If the total number of images is not a multiple of the product of the sizes of each but the rightmost of the codimensions, the rectangular pattern will be incomplete. 29 30

4 A coarray on any image can be accessed directly by using cosubscripts. On its own image, a coarray can also be

31 32

5 A subobject of a coarray is a coarray if it does not have any cosubscripts, vector subscripts, allocatable component

33 34

6 For a coindexed object, its cosubscript list determines the image index (9.6) in the same way that a subscript list

35

7 Intrinsic procedures are provided for mapping between an image index and a list of cosubscripts.

accessed without use of cosubscripts. selection, or pointer component selection. determines the subscript order value for an array element (9.5.3.3).

42

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 The mechanism for an image to reference and define a coarray on another image might vary according to the hardware. On a shared-memory machine, a coarray on an image and the corresponding coarrays on other images could be implemented as a sequence of arrays with evenly spaced starting addresses. On a distributed-memory machine with separate physical memory for each image, a processor might store a coarray at the same virtual address in each physical memory. NOTE 3 Except in contexts where coindexed objects are disallowed, accessing a coarray on its own image by using a set of cosubscripts that specify that image has the same effect as accessing it without cosubscripts. In particular, the segment ordering rules (11.7.2) apply whether or not cosubscripts are used to access the coarray. 1

5.4.8

Established coarrays

2

1 A nonallocatable coarray with the SAVE attribute is established in the initial team.

3 4

2 An allocated allocatable coarray is established in the team in which it was allocated. An unallocated allocatable

5 6

3 A coarray that is an associating entity in a coarray-association of a CHANGE TEAM statement is established

7 8

4 A nonallocatable coarray that is an associating entity in an ASSOCIATE, SELECT RANK, or SELECT TYPE

9 10 11 12 13

coarray is not established. in the team of its CHANGE TEAM construct. construct is established in the team in which the ASSOCIATE, SELECT RANK, or SELECT TYPE statement is executed. 5 A nonallocatable coarray that is a dummy argument or host associated with a dummy argument is established

in the team in which the procedure was invoked. A coarray dummy argument is not established in any ancestor team even if the corresponding actual argument is established in one or more of them.

5.4.9

Pointer

14

1 A pointer has an association status which is either associated, disassociated, or undefined (19.5.2.2).

15

2 A pointer that is not associated shall not be referenced or defined.

16 17

3 If a data pointer is an array, the rank is declared, but the bounds are determined when it is associated with a

18 19 20

target.

5.4.10

Allocatable variables

1 The allocation status of an allocatable variable is either allocated or unallocated. An allocatable variable becomes

allocated as described in 9.7.1.3. It becomes unallocated as described in 9.7.3.2.

21

2 An unallocated allocatable variable shall not be referenced or defined.

22 23

3 If an allocatable variable is an array, the rank is declared, but the bounds are determined when it is allocated. If

24 25 26 27

an allocatable variable is a coarray, the corank is declared, but the cobounds are determined when it is allocated.

5.4.11

Storage

1 Many of the facilities of this document make no assumptions about the physical storage characteristics of data

objects. However, program units that include storage association dependent features shall observe the storage restrictions described in 19.5.3.

ISO/IEC JTC 1/SC 22/WG5/N2184

43

J3/21-007r1

WD 1539-1

1

5.5

Fundamental concepts

2

5.5.1

Names and designators

2021-05-21

3 4

1 A name is used to identify a program constituent, such as a program unit, named variable, named constant,

5

2 A designator is used to identify a program constituent or a part thereof.

6 7 8 9 10

dummy argument, or derived type.

5.5.2

Statement keyword

1 A statement keyword is not a reserved word; that is, a name with the same spelling is allowed. In the syntax

rules, such keywords appear literally. In descriptive text, this meaning is denoted by the term “keyword” without any modifier. Examples of statement keywords are IF, READ, UNIT, KIND, and INTEGER.

5.5.3

Other keywords

11 12

1 Other keywords denote names that identify items in a list. In this case, items are identified by a preceding

13 14 15 16

2 An argument keyword is the name of a dummy argument in the interface for the procedure being referenced, and

17

keyword= rather than their position within the list. can appear in an actual argument list. A type parameter keyword is the name of a type parameter in the type being specified, and can appear in a type-param-spec. A component keyword is the name of a component in a structure constructor. R516

keyword

is

name

NOTE 1 Use of keywords rather than position to identify items in a list can make such lists more readable and allows them to be reordered. This facilitates specification of a list in cases where optional items are omitted. 18 19 20

5.5.4

Association

1 Name association (19.5.1) permits an entity to be identified by different names in the same scoping unit or by

the same name or different names in different scoping units.

21

2 Pointer association (19.5.2) between a pointer and a target allows the target to be denoted by the pointer.

22

3 Storage association (19.5.3) causes different entities to use the same storage.

23 24

4 Inheritance association (19.5.4) occurs between components of the parent component and components inherited

25 26 27 28 29 30 31

by type extension.

5.5.5

Intrinsic

1 All intrinsic types, procedures, assignments, and operators may be used in any scoping unit without further

definition or specification. Intrinsic modules (16.10, 17, 18.2) may be accessed by use association.

5.5.6

Operator

1 This document specifies a number of intrinsic operators (e.g., the arithmetic operators +, –, *, /, and ** with

numeric operands and the logical operators .AND., .OR., etc. with logical operands). Additional operators can be defined within a program (7.5.5, 15.4.3.4).

44

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8

5.5.7

WD 1539-1

J3/21-007r1

Companion processors

1 A processor has one or more companion processors. A companion processor can be a mechanism that references

and defines such entities by a means other than Fortran (15.6.3), it can be the Fortran processor itself, or it can be another Fortran processor. If there is more than one companion processor, the means by which the Fortran processor selects among them are processor dependent. 2 If a procedure is defined by means of a companion processor that is not the Fortran processor itself, this document

refers to the C function that defines the procedure, although the procedure need not be defined by means of the C programming language. NOTE 1 A companion processor might or might not be a mechanism that conforms to the requirements of ISO/IEC 9899:2011. If it does, 5.3.7 states that a program unit that is defined by means other than Fortran and that initiates normal termination is required to include the effect of executing the C exit() function. For example, a processor might allow a procedure defined by some language other than Fortran or C to be invoked if it can be described by a C prototype as defined in ISO/IEC 9899:2011, 6.7.6.3.

ISO/IEC JTC 1/SC 22/WG5/N2184

45

J3/21-007r1

WD 1539-1

1

6 Lexical tokens and source form

2

6.1

Processor character set

3

6.1.1

Characters

2021-05-21

4 5 6

1 The processor character set is processor dependent. Each character in a processor character set is either a control

7 8

2 The letters, digits, underscore, and special characters make up the Fortran character set. Together, the set of

character or a graphic character. The set of graphic characters is further divided into letters (6.1.2), digits (6.1.3), underscore (6.1.4), special characters (6.1.5), and other characters (6.1.6). letters, digits, and underscore define the syntax class alphanumeric-character. R601

9 10 11 12

alphanumeric-character

is letter or digit or underscore

3 Except for the currency symbol, the graphics used for the characters shall be as given in 6.1.2, 6.1.3, 6.1.4, and

13

6.1.5. However, the style of any graphic is not specified.

14

6.1.2

Letters

15

1 The twenty-six letters are:

16

2

17 18 19

3 The set of letters defines the syntactic class letter. The processor character set shall include lower-case and upper-

ABCDEFGHIJKLMNOPQRSTUVWXYZ case letters. A lower-case letter is equivalent to the corresponding upper-case letter in program units except in a character context (3.21). NOTE 1 The following statements are equivalent: CALL BIG_COMPLEX_OPERATION (NDATE) call big_complex_operation (ndate) Call Big_Complex_Operation (NDate)

6.1.3

20

Digits

21

1 The ten digits are:

22

2

23

3 The ten digits define the syntactic class digit.

0123456789

24

6.1.4

Underscore

25

R602

underscore

26

6.1.5

Special characters

27

is

_

1 The special characters are shown in Table 6.1.

46

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

Character = + * / \ ( ) [ ] { } , . :

1 2 3 4 5

Table 6.1: Special characters Name of character Character Name of character Blank ; Semicolon Equals ! Exclamation point Plus " Quotation mark or quote Minus % Percent Asterisk & Ampersand Slash ~ Tilde Backslash < Less than Left parenthesis > Greater than Right parenthesis ? Question mark Left square bracket ’ Apostrophe Right square bracket ` Grave accent Left curly bracket ^ Circumflex accent Right curly bracket | Vertical line Comma $ Currency symbol Decimal point or period # Number sign Colon @ Commercial at

2 Some of the special characters are used for operator symbols, bracketing, and various forms of separating and

delimiting other lexical tokens.

6.1.6

Other characters

1 Additional characters may be representable in the processor, but shall appear only in comments (6.3.2.3, 6.3.3.2),

character constants (7.4.4), input/output records (12.2.2), and character string edit descriptors (13.3.2).

6

6.2

Low-level syntax

7

6.2.1

Tokens

8 9 10 11 12 13

J3/21-007r1

1 The low-level syntax describes the fundamental lexical tokens of a program unit. A lexical token is a keyword,

name, literal constant other than a complex literal constant, operator, statement label, delimiter, comma, =, =>, :, ::, ;, .., or %.

6.2.2

Names

1 Names are used for various entities such as variables, program units, dummy arguments, named constants, and

derived types. is

14

R603

name

letter [ alphanumeric-character ] ...

15

C601

(R603) The maximum length of a name is 63 characters.

NOTE 1 Examples of names: A1 NAME_LENGTH S_P_R_E_A_D__O_U_T TRAILER_

(single underscore) (two consecutive underscores) (trailing underscore)

ISO/IEC JTC 1/SC 22/WG5/N2184

47

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 The word “name” always denotes this particular syntactic form. The word “identifier” is used where entities can be identified by other syntactic forms or by values; its particular meaning depends on the context in which it is used. 1

6.2.3

Constants

2 3

R604

constant

is literal-constant or named-constant

4 5 6 7

R605

literal-constant

is or or or or or

int-literal-constant real-literal-constant complex-literal-constant logical-literal-constant char-literal-constant boz-literal-constant

10

R606

named-constant

is

name

11

R607

int-constant

is

constant

12

C602

(R607) int-constant shall be of type integer.

13

6.2.4

Operators

14 15 16

R608

intrinsic-operator

8 9

17 18 19 20 21 22

is or or or or or or or or

power-op mult-op add-op concat-op rel-op not-op and-op or-op equiv-op **

23

R1007 power-op

is

24 25

R1008 mult-op

is * or /

26 27

R1009 add-op

is + or –

28

R1011 concat-op

is

//

29 30 31 32 33 34

R1013 rel-op

is or or or or or or or or or or or

.EQ. .NE. .LT. .LE. .GT. .GE. == /= < <= > >=

35 36 37 38 39 40

48

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

R1018 not-op

is

.NOT.

2

R1019 and-op

is

.AND.

3

R1020 or-op

is

.OR.

4 5

R1021 equiv-op

is .EQV. or .NEQV.

6 7 8

R609

is defined-unary-op or defined-binary-op or extended-intrinsic-op

9

R1003 defined-unary-op

is

. letter [ letter ] ... .

10

R1023 defined-binary-op

is

. letter [ letter ] ... .

11

R610

extended-intrinsic-op

is

intrinsic-operator

12

6.2.5

Statement labels

13

defined-operator

1 A statement label provides a means of referring to an individual statement.

is

14

R611

label

15

C603

(R611) At least one digit in a label shall be nonzero.

16 17 18 19 20

J3/21-007r1

digit [ digit [ digit [ digit [ digit ] ] ] ]

2 If a statement is labeled, the statement shall contain a nonblank character. The same statement label shall not

be given to more than one statement in its scope. Leading zeros are not significant in distinguishing between statement labels. There are 99999 possible unique statement labels and a processor shall accept any of them as a statement label. However, a processor may have a limit on the total number of unique statement labels in one program unit. NOTE 1 For example: 99999 10 010 are all statement labels. The last two are equivalent.

21 22

3 Any statement that is not part of another statement, and that is not preceded by a semicolon in fixed form, may begin

23 24

• The label on a branch target statement (11.2) is used to identify that statement as the possible destination of a branch. • The label on a FORMAT statement (13.2.1) is used to identify that statement as the format specification for a data transfer statement (12.6). • In some forms of the DO construct (11.1.7), the terminal statement of the construct is identified by a label.

25 26 27

28 29

with a statement label, but the labels are used only in the following ways.

6.2.6

Delimiters

1 A lexical token that is a delimiter is a (, ), /, [, ], (/, or /).

ISO/IEC JTC 1/SC 22/WG5/N2184

49

J3/21-007r1

WD 1539-1

1

6.3

Source form

2

6.3.1

Program units, statements, and lines

2021-05-21

3 4 5

1 A Fortran program unit is a sequence of one or more lines, organized as Fortran statements, comments, and

6

2 A comment may contain any character that may occur in any character context.

7

3 There are two source forms. The rules in 6.3.2 apply only to free form source. The rules in 6.3.3 apply only to fixed source

8 9

form. Free form and fixed form shall not be mixed in the same program unit. The means for specifying the source form of a program unit are processor dependent.

10

6.3.2

Free source form

11

6.3.2.1

Free form line length

12 13 14

INCLUDE lines. A line is a sequence of zero or more characters. Lines following a program unit END statement are not part of that program unit. A Fortran statement is a sequence of one or more complete or partial lines.

1 In free source form there are no restrictions on where a statement (or portion of a statement) can appear within

a line. A line may contain zero characters. A line shall contain at most ten thousand characters. 6.3.2.2

Blank characters in free form

15 16 17 18

1 In free source form blank characters shall not appear within lexical tokens other than in a character context or in

19

2 A blank shall be used to separate names, constants, or labels from adjacent keywords, names, constants, or labels.

a format specification. Blanks may be inserted freely between tokens to improve readability; for example, blanks may occur between the tokens that form a complex literal constant. A sequence of blank characters outside of a character context is equivalent to a single blank character.

NOTE 1 For example, the blanks after REAL, READ, 30, and DO are required in the following: REAL X READ 10 30 DO K=1,3 20 21

3 One or more blanks shall be used to separate adjacent keywords except in the following cases, where blanks are

optional: Table 6.2: Adjacent keywords where separating blanks are optional BLOCK DATA

END FILE

DOUBLE PRECISION ELSE IF ELSE WHERE END ASSOCIATE END BLOCK

END FORALL

END BLOCK DATA

END CRITICAL END DO END ENUM

50

END FUNCTION END IF END INTERFACE END MODULE END PROCEDURE END PROGRAM END SELECT END SUBMODULE

END SUBROUTINE END TEAM END TYPE END WHERE GO TO IN OUT SELECT CASE SELECT TYPE

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6

6.3.2.3

WD 1539-1

J3/21-007r1

Free form commentary

1 The character “!” initiates a comment except where it appears within a character context. The comment extends

to the end of the line. If the first nonblank character on a line is an “!”, the line is a comment line. Lines containing only blanks or containing no characters are also comment lines. Comments may appear anywhere in a program unit and may precede the first statement of a program unit or follow the last statement of a program unit. Comments have no effect on the interpretation of the program unit. NOTE 1 This document does not restrict the number of consecutive comment lines.

7 8 9 10 11 12

6.3.2.4

Free form statement continuation

1 The character “&” is used to indicate that the statement is continued on the next line that is not a comment

line. Comment lines cannot be continued; an “&” in a comment has no effect. Comments may occur within a continued statement. When used for continuation, the “&” is not part of the statement. No line shall contain a single “&” as the only nonblank character or as the only nonblank character before an “!” that initiates a comment.

13 14 15 16

2 If a noncharacter context is to be continued, an “&” shall be the last nonblank character on the line, or the last

17

3 If a lexical token is split across the end of a line, the first nonblank character on the first following noncomment

18 19 20 21 22

nonblank character before an “!”. There shall be a later line that is not a comment; the statement is continued on the next such line. If the first nonblank character on that line is an “&”, the statement continues at the next character position following that “&”; otherwise, it continues with the first character position of that line. line shall be an “&” immediately followed by the successive characters of the split token. 4 If a character context is to be continued, an “&” shall be the last nonblank character on the line. There shall be

a later line that is not a comment; an “&” shall be the first nonblank character on the next such line and the statement continues with the next character following that “&”. 6.3.2.5

Free form statement termination

23

1 If a statement is not continued, a comment or the end of the line terminates the statement.

24 25 26 27

2 A statement may alternatively be terminated by a “;” character that appears other than in a character context

28 29

or in a comment. The “;” is not part of the statement. After a “;” terminator, another statement may appear on the same line, or begin on that line and be continued. A sequence consisting only of zero or more blanks and one or more “;” terminators, in any order, is equivalent to a single “;” terminator. 6.3.2.6

Free form statements

1 A label may precede any statement not forming part of another statement.

NOTE 1 No Fortran statement begins with a digit. 30

2 A statement shall not have more than one million characters.

31

6.3.3

Fixed source form

32

6.3.3.1

General

33 34

1 In fixed source form, there are restrictions on where a statement can appear within a line. If a source line contains only characters

35

2 Except in a character context, blanks are insignificant and may be used freely throughout the program.

of default kind, it shall contain exactly 72 characters; otherwise, its maximum number of characters is processor dependent.

ISO/IEC JTC 1/SC 22/WG5/N2184

51

J3/21-007r1

1 2 3 4 5 6

6.3.3.2

WD 1539-1

2021-05-21

Fixed form commentary

1 The character “!” initiates a comment except where it appears within a character context or in character position 6. The comment extends to the end of the line. If the first nonblank character on a line is an “!” in any character position other than character position 6, the line is a comment line. Lines beginning with a “C” or “*” in character position 1 and lines containing only blanks are also comment lines. Comments may appear anywhere in a program unit and may precede the first statement of the program unit or follow the last statement of a program unit. Comments have no effect on the interpretation of the program unit. NOTE 1 This document does not restrict the number of consecutive comment lines.

7 8 9 10

6.3.3.3

Fixed form statement continuation

1 Except within commentary, character position 6 is used to indicate continuation. If character position 6 contains a blank or zero, the

line is the initial line of a new statement, which begins in character position 7. If character position 6 contains any character other than blank or zero, character positions 7–72 of the line constitute a continuation of the preceding noncomment line. NOTE 1 An “!” or “;” in character position 6 is interpreted as a continuation indicator unless it appears within commentary indicated by a “C” or “*” in character position 1 or by an “!” in character positions 1–5.

11 12

2 Comment lines cannot be continued. Comment lines may occur within a continued statement.

6.3.3.4

Fixed form statement termination

13

1 If a statement is not continued, a comment or the end of the line terminates the statement.

14 15 16 17

2 A statement may alternatively be terminated by a “;” character that appears other than in a character context, in a comment, or in

18 19 20 21 22 23

24

character position 6. The “;” is not part of the statement. After a “;” terminator, another statement may begin on the same line, or begin on that line and be continued. A “;” shall not appear as the first nonblank character on an initial line. A sequence consisting only of zero or more blanks and one or more “;” terminators, in any order, is equivalent to a single “;” terminator.

6.3.3.5

Fixed form statements

1 A label, if it appears, shall occur in character positions 1 through 5 of the first line of a statement; otherwise, positions 1 through 5 shall be blank. Blanks may appear anywhere within a label. A statement following a “;” on the same line shall not be labeled. Character positions 1 through 5 of any continuation lines shall be blank. A statement shall not have more than one million characters. The program unit END statement shall not be continued. A statement whose initial line appears to be a program unit END statement shall not be continued.

6.4

Including source text

25 26 27

1 Additional text can be incorporated into the source text of a program unit during processing. This is accomplished

28

2 The char-literal-constant shall not have a kind type parameter value that is a named-constant.

29

3 An INCLUDE line is not a Fortran statement.

30

4 An INCLUDE line shall appear on a single source line where a statement can appear; it shall be the only nonblank

31 32 33 34 35 36

with the INCLUDE line, which has the form INCLUDE char-literal-constant

text on this line other than an optional trailing comment. Thus, a statement label is not allowed. 5 The effect of the INCLUDE line is as if the referenced source text physically replaced the INCLUDE line prior

to program processing. Included text may contain any source text, including additional INCLUDE lines; such nested INCLUDE lines are similarly replaced with the specified source text. The maximum depth of nesting of any nested INCLUDE lines is processor dependent. Inclusion of the source text referenced by an INCLUDE line shall not, at any level of nesting, result in inclusion of the same source text.

52

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

6 When an INCLUDE line is resolved, the first included statement line shall not be a continuation line and the last

3 4

7 The interpretation of char-literal-constant is processor dependent. An example of a possible valid interpretation

included statement line shall not be continued. is that char-literal-constant is the name of a file that contains the source text to be included. NOTE 1 In some circumstances, for example where source code is maintained in an INCLUDE file for use in programs whose source form might be either fixed or free, observing the following rules allows the code to be used with either source form.

• Confine statement labels to character positions 1 to 5 and statements to character positions 7 to 72. • Treat blanks as being significant. • Use only the exclamation mark (!) to indicate a comment, but do not start the comment in character position 6. • For continued statements, place an ampersand (&) in both character position 73 of a continued line and character position 6 of a continuation line.

ISO/IEC JTC 1/SC 22/WG5/N2184

53

J3/21-007r1

WD 1539-1

1

7 Types

2

7.1

Characteristics of types

3

7.1.1

The concept of type

2021-05-21

4 5

1 Fortran provides an abstract means whereby data can be categorized without relying on a particular physical

6

2 A type has a name, a set of valid values, a means to denote such values (constants), and a set of operations to

representation. This abstract means is the concept of type.

7

manipulate the values.

8

7.1.2

Type classification

9

1 A type is either an intrinsic type or a derived type.

10

2 This document defines five intrinsic types: integer, real, complex, character, and logical.

11 12

3 A derived type is one that is defined by a derived-type definition (7.5.2) or by an intrinsic module. It shall be

13 14 15 16 17 18

used only where it is accessible (7.5.2.2). An intrinsic type is always accessible.

7.1.3

Set of values

1 For each type, there is a set of valid values. The set of valid values for logical is completely determined by this

document. The sets of valid values for integer, character, and real are processor dependent. The set of valid values for complex consists of the set of all the combinations of the values of the real and imaginary parts. The set of valid values for a derived type is as defined in 7.5.8.

7.1.4

Constants

19

1 The syntax for denoting a value indicates the type, type parameters, and the particular value.

20

2 The syntax for literal constants of each intrinsic type is specified in 7.4.

21 22 23

3 A structure constructor (7.5.10) that is a constant expression (10.1.12) denotes a scalar constant value of derived

24

4 A constant value can be named (8.5.13, 8.6.11).

25

type. An array constructor (7.8) that is a constant expression denotes a constant array value of intrinsic or derived type.

7.1.5

Operations

26 27 28

1 For each of the intrinsic types, a set of operations and corresponding operators is defined intrinsically. These are

29

2 For derived types, there are no intrinsic operations. Operations on derived types can be defined by the program

30

described in Clause 10. The intrinsic set can be augmented with operations and operators defined by functions with the OPERATOR interface (15.4.3.2). Operator definitions are described in Clauses 10 and 15. (7.5.11).

54

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

7.2

WD 1539-1

J3/21-007r1

Type parameters

2 3

1 If a type has type parameters, the set of values, the syntax for denoting the values, and the set of operations on

4 5

2 A type parameter is either a kind type parameter or a length type parameter. All type parameters are of type

6

the values of the type depend on the values of the parameters. integer. A kind type parameter participates in generic resolution (15.5.5.2), but a length type parameter does not.

7 8

3 Each intrinsic type has a kind type parameter named KIND. The intrinsic character type has a length type

9

4 A type parameter value can be specified by a type specification (7.4, 7.5.9).

parameter named LEN. A derived type can have type parameters.

is scalar-int-expr or * or :

R701

type-param-value

13

C701

(R701) The type-param-value for a kind type parameter shall be a constant expression.

14 15

C702

(R701) A colon shall not be used as a type-param-value except in the declaration of an entity that has the POINTER or ALLOCATABLE attribute.

10 11 12

16

5 A colon as a type-param-value specifies a deferred type parameter.

17

6 The values of the deferred type parameters of an object are determined by successful execution of an ALLOCATE

18 19

statement (9.7.1), execution of an intrinsic assignment statement (10.2.1.3), execution of a pointer assignment statement (10.2.2), or by argument association (15.5.2). NOTE 1 Deferred type parameters of functions, including function procedure pointers, have no values. Instead, they indicate that those type parameters of the function result will be determined by execution of the function, if it returns an allocated allocatable result or an associated pointer result.

20 21 22 23

7 An asterisk as a type-param-value specifies that a length type parameter is an assumed type parameter. It is used

for a dummy argument to assume the type parameter value from the effective argument, for an associate name in a SELECT TYPE construct to assume the type parameter value from the corresponding selector, and for a named constant of type character to assume the character length from the constant-expr. NOTE 2 The value of a kind type parameter is always known at compile time. Some parameterizations that involve multiple representation forms need to be distinguished at compile time for practical implementation and performance. Examples include the multiple precisions of the intrinsic real type and the possible multiple character sets of the intrinsic character type. The adjective “length” is used for type parameters other than kind type parameters because they often specify a length, as for intrinsic character type. However, they can be used for other purposes. The important difference from kind type parameters is that their values need not be known at compile time and might change during execution.

24

7.3

Types, type specifiers, and values

25

7.3.1

Relationship of types and values to objects

26

1 The name of a type serves as a type specifier and can be used to declare objects of that type. A declaration can

27

specify the type of a named object. A data object can be declared explicitly or implicitly. A data object has

ISO/IEC JTC 1/SC 22/WG5/N2184

55

J3/21-007r1

WD 1539-1

2021-05-21

1 2

attributes in addition to its type. Clause 8 describes the way in which a data object is declared and how its type and other attributes are specified.

3 4

2 An array is formed of scalar data of an intrinsic or derived type, and has the same type and type parameters as

5 6

3 A variable is a data object. The type and type parameters of a variable determine which values that variable can

7

4 The type of a variable determines the operations that can be used to manipulate the variable.

its elements. take. Assignment (10.2) provides one means of changing the value of a variable.

8

7.3.2

Type specifiers and type compatibility

9

7.3.2.1

Type specifier syntax

10

1 A type specifier specifies a type and type parameter values. It is either a type-spec or a declaration-type-spec.

is or or or

R702

type-spec

15

C703

(R702) The derived-type-spec shall not specify an abstract type (7.5.7).

16 17 18

R703

declaration-type-spec

26 27

C704

(R703) In a declaration-type-spec, every type-param-value that is not a colon or an asterisk shall be a specification expression.

28 29

C705

(R703) In a declaration-type-spec that uses the CLASS keyword, derived-type-spec shall specify an extensible type (7.5.7).

30

C706

(R703) TYPE(derived-type-spec) shall not specify an abstract type (7.5.7).

31

C707

(R702) In TYPE(intrinsic-type-spec) the intrinsic-type-spec shall not end with a comma.

32 33

C708

An entity declared with the CLASS or CLASSOF keyword shall be a dummy argument or have the ALLOCATABLE or POINTER attribute.

34

C709

A TYPEOF or CLASSOF specifier shall appear only in a type declaration statement or component definition statement.

36 37

C710

The data-ref in a TYPEOF or CLASSOF specifier shall have its type and type parameters previously declared or established by the implicit typing rules.

38

C711

The data-ref in a TYPEOF specifier shall not be unlimited polymorphic or of abstract type.

39

C712

The data-ref in a CLASSOF specifier shall not be assumed-type or of intrinsic type.

40

C713

If the data-ref in a TYPEOF or CLASSOF specifier has the OPTIONAL attribute, it shall not have a deferred or assumed type parameter.

11 12 13 14

19 20 21 22 23 24 25

35

41

56

is or or or or or or or or or

intrinsic-type-spec derived-type-spec enum-type-spec enumeration-type-spec

intrinsic-type-spec TYPE ( intrinsic-type-spec ) TYPE ( derived-type-spec ) TYPE ( enum-type-spec ) TYPE ( enumeration-type-spec ) CLASS ( derived-type-spec ) CLASS ( * ) TYPE ( * ) TYPEOF ( data-ref ) CLASSOF ( data-ref )

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

2 An intrinsic-type-spec specifies the named intrinsic type and its type parameter values. A derived-type-spec

4

3 TYPEOF and CLASSOF with a data-ref that is not unlimited polymorphic specify the same type and type

5 6 7 8

parameter values as the declared type and type parameter values of data-ref , except that they specify that a type parameter is deferred if it is deferred in data-ref . An entity declared with CLASSOF is polymorphic, and one declared with TYPEOF is not polymorphic. If a data-ref is CLASS (*), CLASSOF (data-ref ) is equivalent to a CLASS (*) specifier.

specifies the named derived type and its type parameter values. An enum-type-spec specifies the named enum type. An enumeration-type-spec specifies the named enumeration type.

NOTE 1 A type-spec is used in an array constructor, a SELECT TYPE construct, or an ALLOCATE statement. An integer-type-spec is used in a DO CONCURRENT or FORALL statement. Elsewhere, a declaration-type-spec is used. NOTE 2 Note that TYPEOF and CLASSOF declare entities whose type parameters depend on those of the data-ref , they are not equivalent to simply repeating the declaration of the data-ref . For example, if the data-ref has an assumed type parameter, the entities declared have the same values for that type parameter as data-ref , they are not assumed (even if they are dummy arguments). 9

7.3.2.2

TYPE type specifier

10 11

1 A TYPE type specifier is used to declare entities that are assumed-type, or of an intrinsic, derived, or other

12 13 14 15

2 A derived-type-spec in a TYPE type specifier in a type declaration statement shall specify a previously defined

16 17 18 19 20 21

user-defined type. derived type. If the data entity is a function result, the derived type may be specified in the FUNCTION statement provided the derived type is defined within the body of the function or is accessible there by use or host association. If the derived type is specified in the FUNCTION statement and is defined within the body of the function, it is as if the function result were declared with that derived type immediately following the derived-type-def of the specified derived type. 3 An entity that is declared using the TYPE(*) type specifier is assumed-type and is an unlimited polymorphic

entity. It is not declared to have a type, and is not considered to have the same declared type as any other entity, including another unlimited polymorphic entity. Its dynamic type and type parameters are assumed from its effective argument.

22 23

C714

An assumed-type entity shall be a dummy data object that does not have the ALLOCATABLE, CODIMENSION, INTENT (OUT), POINTER, or VALUE attribute and is not an explicit-shape array.

24 25 26 27

C715

An assumed-type variable name shall not appear in a designator or expression except as an actual argument corresponding to a dummy argument that is assumed-type, or as the first argument to the intrinsic function IS_CONTIGUOUS, LBOUND, PRESENT, RANK, SHAPE, SIZE, or UBOUND, or the function C_LOC from the intrinsic module ISO_C_BINDING.

28 29

C716

An assumed-type actual argument that corresponds to an assumed-rank dummy argument shall be assumed-shape or assumed-rank.

30

7.3.2.3

CLASS type specifier

31 32 33 34 35

1 The CLASS type specifier is used to declare polymorphic entities. A polymorphic entity is a data entity that is

able to be of differing dynamic types during program execution. 2 A derived-type-spec in a CLASS type specifier in a type declaration statement shall specify a previously defined

derived type. If the data entity is a function result, the derived type may be specified in the FUNCTION statement provided the derived type is defined within the body of the function or is accessible there by use or

ISO/IEC JTC 1/SC 22/WG5/N2184

57

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

host association. If the derived type is specified in the FUNCTION statement and is defined within the body of the function, it is as if the function result were declared with that derived type immediately following its derived-type-def .

4

3 The declared type of a polymorphic entity is the specified type if the CLASS type specifier contains a type name.

5 6 7

4 An entity declared with the CLASS(*) specifier is an unlimited polymorphic entity. It is not declared to have

8 9 10

5 The dynamic type of an allocated allocatable polymorphic object is the type with which it was allocated. The

a type, and is not considered to have the same declared type as any other entity, including another unlimited polymorphic entity.

11 12 13

dynamic type of an associated polymorphic pointer is the dynamic type of its target. The dynamic type of a nonallocatable nonpointer polymorphic dummy argument is the dynamic type of its effective argument. The dynamic type of an unallocated allocatable object or a disassociated pointer is the same as its declared type. The dynamic type of an entity identified by an associate name (11.1.3) is the dynamic type of the selector with which it is associated. The dynamic type of an object that is not polymorphic is its declared type.

14

7.3.3

15 16 17 18 19 20

Type compatibility

1 A nonpolymorphic entity is type compatible only with entities of the same declared type, except that an entity

of an interoperable enum type is also type compatible with an expression of type integer if the expression has a primary that is an enumerator of that enum type. A polymorphic entity that is not an unlimited polymorphic entity is type compatible with entities of the same declared type or any of its extensions. Even though an unlimited polymorphic entity is not considered to have a declared type, it is type compatible with all entities. An entity is type compatible with a type if it is type compatible with entities of that type. NOTE 1 Given TYPE TROOT ... TYPE,EXTENDS(TROOT) :: TEXTENDED ... CLASS(TROOT) A CLASS(TEXTENDED) B ... A is type compatible with B but B is not type compatible with A.

21 22 23

2 A polymorphic allocatable object may be allocated to be of any type with which it is type compatible. A

polymorphic pointer or dummy argument may, during program execution, be associated with objects with which it is type compatible.

24

7.4

Intrinsic types

25

7.4.1

Classification and specification

26 27

1 Each intrinsic type is classified as a numeric type or a nonnumeric type. The numeric types are integer, real, and

28

2 Each intrinsic type has a kind type parameter named KIND; this type parameter is of type integer with default

29

complex. The nonnumeric intrinsic types are character and logical. kind.

58

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

R704

intrinsic-type-spec

is or or or or or

integer-type-spec REAL [ kind-selector ] DOUBLE PRECISION COMPLEX [ kind-selector ] CHARACTER [ char-selector ] LOGICAL [ kind-selector ]

7

R705

integer-type-spec

is

INTEGER [ kind-selector ]

8

R706

kind-selector

is

( [ KIND = ] scalar-int-constant-expr )

9 10

C717

(R706) The value of scalar-int-constant-expr shall be nonnegative and shall specify a representation method that exists on the processor.

11

7.4.2

Intrinsic operations on intrinsic types

1 2 3 4 5 6

12 13

1 Intrinsic numeric operations are defined as specified in 10.1.5.2.1 for the numeric intrinsic types. Relational

14 15

intrinsic operations are defined as specified in 10.1.5.5 for numeric and character intrinsic types. The intrinsic concatenation operation is defined as specified in 10.1.5.3 for the character type. Logical intrinsic operations are defined as specified in 10.1.5.4 for the logical type.

16

7.4.3

Numeric intrinsic types

17

7.4.3.1

Integer type

18 19 20

1 The set of values for the integer type is a subset of the mathematical integers. The processor shall provide one or

21 22 23 24 25

more representation methods that define sets of values for data of type integer. Each such method is characterized by a value for the kind type parameter KIND. The kind type parameter of a representation method is returned by the intrinsic function KIND (16.9.118). The decimal exponent range of a representation method is returned by the intrinsic function RANGE (16.9.170). The intrinsic function SELECTED_INT_KIND (16.9.181) returns a kind value based on a specified decimal exponent range requirement. The integer type includes a zero value, which is considered to be neither negative nor positive. The value of a signed integer zero is the same as the value of an unsigned integer zero.

26

2 The processor shall provide at least one representation method with a decimal exponent range greater than or

27

equal to 18.

28

3 The type specifier for the integer type uses the keyword INTEGER.

29 30

4 The keyword INTEGER with no kind-selector specifies type integer with default kind; the kind type parameter

31

5 Any integer value can be represented as a signed-int-literal-constant.

value is equal to KIND (0). The decimal exponent range of default integer shall be at least 5.

32

R707

signed-int-literal-constant

is

[ sign ] int-literal-constant

33

R708

int-literal-constant

is

digit-string [ _ kind-param ]

34 35

R709

kind-param

is digit-string or scalar-int-constant-name

36

R710

signed-digit-string

is

[ sign ] digit-string

37

R711

digit-string

is

digit [ digit ] ...

38

R712

sign

is + or –

C718

(R709) A scalar-int-constant-name shall be a named constant of type integer.

39 40

ISO/IEC JTC 1/SC 22/WG5/N2184

59

J3/21-007r1

WD 1539-1

2021-05-21

1

C719

(R709) The value of kind-param shall be nonnegative.

2

C720

(R708) The value of kind-param shall specify a representation method that exists on the processor.

3 4

6 The optional kind type parameter following digit-string specifies the kind type parameter of the integer constant;

5

7 An integer constant is interpreted as a decimal value.

if it does not appear, the constant is default integer.

NOTE 1 Examples of signed integer literal constants are: 473 +56 -101 21_2 21_SHORT 1976354279568241_8 where SHORT is a scalar integer named constant. A program that uses a digit-string as a kind-param is unlikely to be portable. 6

7.4.3.2

Real type

7 8 9 10

1 The real type has values that approximate the mathematical real numbers. The processor shall provide two

11

2 The decimal precision, decimal exponent range, and radix of an approximation method are returned by the

12 13 14

intrinsic functions PRECISION (16.9.162), RANGE (16.9.170), and RADIX (16.9.166). The intrinsic function SELECTED_REAL_KIND (16.9.183) returns a kind value based on specified precision, range, and radix requirements.

or more approximation methods that define sets of values for data of type real. Each such method has a representation method and is characterized by a value for the kind type parameter KIND. The kind type parameter of an approximation method is returned by the intrinsic function KIND (16.9.118).

NOTE 1 See C.3.1 for remarks concerning selection of approximation methods. 15 16

3 The real type includes a zero value. Processors that distinguish between positive and negative zeros shall treat

17

• in all intrinsic relational operations, and • as actual arguments to intrinsic procedures other than those for which it is explicitly specified that negative zero is distinguished.

18 19

them as mathematically equivalent

NOTE 2 On a processor that distinguishes between 0.0 and −0.0, ( X >= 0.0 ) evaluates to true if X = 0.0 or if X = −0.0, ( X < 0.0 ) evaluates to false for X = −0.0.

60

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) In order to distinguish between 0.0 and −0.0, a program can use the intrinsic function SIGN. SIGN (1.0, X) will return −1.0 if X < 0.0 or if the processor distinguishes between 0.0 and −0.0 and X has the value −0.0. 1 2

4 The type specifier for the real type uses the keyword REAL. The keyword DOUBLE PRECISION is an alternative

3 4 5

5 If the type keyword REAL is used without a kind type parameter, the real type with default real kind is specified

6 7 8 9

specifier for one kind of real type. and the kind value is KIND (0.0). The type specifier DOUBLE PRECISION specifies type real with double precision kind; the kind value is KIND (0.0D0). The decimal precision of the double precision real approximation method shall be greater than that of the default real method. 6 The decimal precision of double precision real shall be at least 10, and its decimal exponent range shall be at

least 37. It is recommended that the decimal precision of default real be at least 6, and that its decimal exponent range be at least 37.

10

R713

signed-real-literal-constant

is

11

R714

real-literal-constant

is significand [ exponent-letter exponent ] [ _ kind-param ] or digit-string exponent-letter exponent [ _ kind-param ]

13 14

R715

significand

is digit-string . [ digit-string ] or . digit-string

15 16

R716

exponent-letter

is E or D

17

R717

exponent

is

18

C721

(R714) If both kind-param and exponent-letter appear, exponent-letter shall be E.

19

C722

(R714) The value of kind-param shall specify an approximation method that exists on the processor.

12

[ sign ] real-literal-constant

signed-digit-string

20 21 22

7 A real literal constant without a kind type parameter is a default real constant if it is without an exponent part

23

8 The exponent represents the power of ten scaling to be applied to the significand or digit string. The meaning of

24 25 26

or has exponent letter E, and is a double precision real constant if it has exponent letter D. A real literal constant written with a kind type parameter is a real constant with the specified kind type parameter. these constants is as in decimal scientific notation. 9 The significand may be written with more digits than a processor will use to approximate the value of the constant.

NOTE 3 Examples of signed real literal constants are: -12.78 +1.6E3 2.1 -16.E4_8 0.45D-4 10.93E7_QUAD .123 3E4 where QUAD is a scalar integer named constant.

ISO/IEC JTC 1/SC 22/WG5/N2184

61

J3/21-007r1

1 2 3 4

7.4.3.3

WD 1539-1

2021-05-21

Complex type

1 The complex type has values that approximate the mathematical complex numbers. The values of a complex

type are ordered pairs of real values. The first real value is called the real part, and the second real value is called the imaginary part.

5 6 7 8

2 Each approximation method used to represent data entities of type real shall be available for both the real and

imaginary parts of a data entity of type complex. The (default integer) kind type parameter KIND for a complex entity specifies for both parts the real approximation method characterized by this kind type parameter value. The kind type parameter of an approximation method is returned by the intrinsic function KIND (16.9.118).

9

3 The type specifier for the complex type uses the keyword COMPLEX. There is no keyword for double precision

10 11

complex. If the type keyword COMPLEX is used without a kind type parameter, the complex type with default complex kind is specified, the kind value is KIND (0.0), and both parts are default real.

12

R718

complex-literal-constant

is

13 14 15

R719

real-part

is signed-int-literal-constant or signed-real-literal-constant or named-constant

16 17 18

R720

imag-part

is signed-int-literal-constant or signed-real-literal-constant or named-constant

19

C723

(R718) Each named constant in a complex literal constant shall be of type integer or real.

20 21 22 23 24 25 26 27 28

( real-part , imag-part )

4 If the real part and the imaginary part of a complex literal constant are both real, the kind type parameter value

of the complex literal constant is the kind type parameter value of the part with the greater decimal precision; if the precisions are the same, it is the kind type parameter value of one of the parts as determined by the processor. If a part has a kind type parameter value different from that of the complex literal constant, the part is converted to the approximation method of the complex literal constant. 5 If both the real and imaginary parts are integer, they are converted to the default real approximation method

and the constant is default complex. If only one of the parts is an integer, it is converted to the approximation method selected for the part that is real and the kind type parameter value of the complex literal constant is that of the part that is real. NOTE 1 Examples of complex literal constants are: (1.0, -1.0) (3, 3.1E6) (4.0_4, 3.6E7_8) ( 0., PI)

! where PI is a previously declared named real constant.

29

7.4.4

Character type

30

7.4.4.1

Character sets

31

1 The character type has a set of values composed of character strings. A character string is a sequence of characters,

32 33 34

numbered from left to right 1, 2, 3, ... up to the number of characters in the string. The number of characters in the string is called the length of the string. The length is a type parameter; its kind is processor dependent and its value is greater than or equal to zero.

35 36

2 The processor shall provide one or more representation methods that define sets of values for data of type

character. Each such method is characterized by a value for the (default integer) kind type parameter KIND.

62

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

The kind type parameter of a representation method is returned by the intrinsic function KIND (16.9.118). The intrinsic function SELECTED_CHAR_KIND (16.9.180) returns a kind value based on the name of a character type. Any character of a particular representation method representable in the processor may occur in a character string of that representation method.

5 6 7 8

3 The character set specified in ISO/IEC 646:1991 (International Reference Version) is referred to as the ASCII

9

character set and its corresponding representation method is ASCII character kind. The character set UCS-4 as specified in ISO/IEC 10646 is referred to as the ISO 10646 character set and its corresponding representation method is the ISO 10646 character kind. 7.4.4.2

Character type specifier

10

1 The type specifier for the character type uses the keyword CHARACTER.

11 12

2 If the type keyword CHARACTER is used without a kind type parameter, the character type with default

13 14 15 16

3 The default character kind shall support a character set that includes the characters in the Fortran character

character kind is specified and the kind value is KIND (’A’). set (6.1). The processor may support additional character sets by supplying nondefault character kinds. The characters available in nondefault character kinds are not specified by this document, except that one character in each nondefault character set shall be designated as a blank character to be used as a padding character. R721

char-selector

is length-selector or ( LEN = type-param-value , KIND = scalar-int-constant-expr ) or ( type-param-value , [ KIND = ] scalar-int-constant-expr ) or ( KIND = scalar-int-constant-expr [ , LEN =type-param-value ] )

24 25

R722

length-selector

is ( [ LEN = ] type-param-value ) or * char-length [ , ]

26 27

R723

char-length

is ( type-param-value ) or int-literal-constant

28

C724

(R721) The value of scalar-int-constant-expr shall be nonnegative and shall specify a representation method that exists on the processor.

30

C725

(R723) The int-literal-constant shall not include a kind-param.

31

C726

(R721 R722 R723) A type-param-value of * shall be used only

17 18 19 20 21 22 23

29

32

• to declare a dummy argument,

33

• to declare a named constant,

34 35

• in the type-spec of an ALLOCATE statement wherein each allocate-object is a dummy argument of type CHARACTER with an assumed character length,

36

• in the type-spec or derived-type-spec of a type guard statement (11.1.11), or

37

• in an external function, to declare the character length parameter of the function result.

38 39

C727

A function name shall not be declared with an asterisk type-param-value unless it is of type CHARACTER and is the name of a dummy function or the name of the result of an external function.

40 41

C728

A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function name declared with an asterisk type-param-value shall not have the RECURSIVE attribute.

42

C729

(R722) The optional comma in a length-selector is permitted only in a declaration-type-spec in a type-declaration-stmt.

ISO/IEC JTC 1/SC 22/WG5/N2184

63

J3/21-007r1

WD 1539-1

2021-05-21

1 2

C730

(R722) The optional comma in a length-selector is permitted only if no double-colon separator appears in the typedeclaration-stmt.

3 4

C731

(R721) The length specified for a character statement function or for a statement function dummy argument of type character shall be a constant expression.

5 6 7 8 9

4 The char-selector in a CHARACTER intrinsic-type-spec and the * char-length in an entity-decl or in a component-

10

5 If the character length parameter value evaluates to a negative value, the length of character entities declared

11 12

is zero. A character length parameter value of : indicates a deferred type parameter (7.2). A char-length type parameter value of * has the following meanings.

13 14

• If used to declare a dummy argument of a procedure, the dummy argument assumes its length from its effective argument. • If used to declare a named constant, the length is that of the constant value. • If used in the type-spec of an ALLOCATE statement, each allocate-object assumes its length from its effective argument. • If used in the type-spec of a type guard statement, the associating entity assumes its length from the selector. • If used to specify the character length parameter of a function result, any scoping unit invoking the function or passing it as an actual argument shall declare the function name with a character length parameter value other than * or access such a

15 16 17 18 19 20 21

decl of a type definition specify character length. The * char-length in an entity-decl or a component-decl specifies an individual length and overrides the length specified in the char-selector, if any. If a * char-length is not specified in an entity-decl or a component-decl, the length-selector or type-param-value specified in the char-selector is the character length. If the length is not specified in a char-selector or a * char-length, the length is 1.

definition by argument, host, or use association. When the function is invoked, the length of the function result is assumed from the value of this type parameter.

22

23 24

7.4.4.3

Character literal constant

1 The syntax of a character literal constant is given by R724.

is [ kind-param _ ] ’ [ rep-char ] ... ’ or [ kind-param _ ] " [ rep-char ] ... "

25 26

R724

char-literal-constant

27

C732

(R724) The value of kind-param shall specify a representation method that exists on the processor.

28 29

2 The optional kind type parameter preceding the leading delimiter specifies the kind type parameter of the char-

30

3 For the type character with kind kind-param, if it appears, and for default character otherwise, a representable

31 32 33

acter constant; if it does not appear, the constant is default character. character, rep-char, is defined as follows. • In free source form, it is any graphic character in the processor-dependent character set. • In fixed source form, it is any character in the processor-dependent character set. A processor may restrict the occurrence of some or all of the control characters.

34

35

4 The delimiting apostrophes or quotation marks are not part of the value of the character literal constant.

36 37 38

5 An apostrophe character within a character constant delimited by apostrophes is represented by two consecutive

39 40 41 42

apostrophes (without intervening blanks); in this case, the two apostrophes are counted as one character. Similarly, a quotation mark character within a character constant delimited by quotation marks is represented by two consecutive quotation marks (without intervening blanks) and the two quotation marks are counted as one character. 6 A zero-length character literal constant is represented by two consecutive apostrophes (without intervening blanks)

or two consecutive quotation marks (without intervening blanks) outside of a character context.

64

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 Examples of character literal constants are: "DON’T" ’DON’’T’ both of which have the value DON’T and ’’ which has the zero-length character string as its value. NOTE 2 An example of a nondefault character literal constant, where the processor supports the corresponding character set, is: 



NIHONGO_’













where NIHONGO is a named constant whose value is the kind type parameter for Nihongo (Japanese) characters. This means “Without her, nothing is possible”. 1

7.4.4.4

Collating sequence

2

1 The processor defines a collating sequence for the character set of each kind of character. The collating sequence

3 4 5

is an isomorphism between the character set and the set of integers {I : 0 ≤ I < N }, where N is the number of characters in the set. The intrinsic functions CHAR (16.9.52) and ICHAR (16.9.105) provide conversions between the characters and the integers according to this mapping. NOTE 1 For example: ICHAR ( ’X’ ) returns the integer value of the character ’X’ according to the collating sequence of the processor.

6 7 8 9 10 11 12 13

2 The collating sequence of the default character kind shall satisfy the following constraints.

• ICHAR (’A’) < ICHAR (’B’) < ... < ICHAR (’Z’) for the twenty-six upper-case letters. • ICHAR (’0’) < ICHAR (’1’) < ... < ICHAR (’9’) for the ten digits. • ICHAR (’ ’) < ICHAR (’0’) < ICHAR (’9’) < ICHAR (’A’) or ICHAR (’ ’) < ICHAR (’A’) < ICHAR (’Z’) < ICHAR (’0’). • ICHAR (’a’) < ICHAR (’b’) < ... < ICHAR (’z’) for the twenty-six lower-case letters. • ICHAR (’ ’) < ICHAR (’0’) < ICHAR (’9’) < ICHAR (’a’) or ICHAR (’ ’) < ICHAR (’a’) < ICHAR (’z’) < ICHAR (’0’).

14 15

3 There are no constraints on the location of any other character in the collating sequence, nor is there any specified

16

4 The collating sequence for the ASCII character kind is as specified in ISO/IEC 646:1991 (International Reference

17 18

Version); this collating sequence is called the ASCII collating sequence in this document. The collating sequence for the ISO 10646 character kind is as specified in ISO/IEC 10646.

collating sequence relationship between the upper-case and lower-case letters.

NOTE 2 The intrinsic functions ACHAR (16.9.3) and IACHAR (16.9.98) provide conversions between characters and corresponding integer values according to the ASCII collating sequence.

ISO/IEC JTC 1/SC 22/WG5/N2184

65

J3/21-007r1

1 2 3 4

WD 1539-1

2021-05-21

5 The intrinsic functions LGT, LGE, LLE, and LLT (16.9.124-16.9.127) provide comparisons between strings based

on the ASCII collating sequence. International portability is guaranteed if the set of characters used is limited to the Fortran character set (6.1).

7.4.5

Logical type

5

1 The logical type has two values, which represent true and false.

6 7

2 The processor shall provide one or more representation methods for data of type logical. Each such method

8

is characterized by a value for the (default integer) kind type parameter KIND. The kind type parameter of a representation method is returned by the intrinsic function KIND (16.9.118).

9

3 The type specifier for the logical type uses the keyword LOGICAL.

10 11

4 The keyword LOGICAL with no kind-selector specifies type logical with default kind; the kind type parameter

value is equal to KIND (.FALSE.). is .TRUE. [ _ kind-param ] or .FALSE. [ _ kind-param ]

12 13

R725

logical-literal-constant

14

C733

(R725) The value of kind-param shall specify a representation method that exists on the processor.

15 16

5 The optional kind type parameter specifies the kind type parameter of the logical constant; if it does not appear,

the constant has the default logical kind.

17

7.5

Derived types

18

7.5.1

Derived type concepts

19 20

1 Additional types can be derived from the intrinsic types and other derived types. A type definition defines the

21

2 A derived type can be parameterized by one or more type parameters, each of which is defined to be either a

22

name of the type and the names and attributes of its components and type-bound procedures. kind or length type parameter and can have a default value.

23 24 25

3 The ultimate components of a derived type are the components that are of intrinsic type or have the ALLOC-

26 27

4 The direct components of a derived type are the components of that type, plus the direct components of the

28 29 30

5 The potential subobject components of a derived type are the nonpointer components of that type together with

31 32 33

6 The components, direct components, potential subobject components, and ultimate components of an object of

34 35 36

7 By default, no storage sequence is implied by the order of the component definitions. However, a storage sequence

37 38

8 A scalar entity of derived type is a structure. If a derived type has the SEQUENCE attribute, a scalar entity of

ATABLE or POINTER attribute, plus the ultimate components of the components that are of derived type and have neither the ALLOCATABLE nor POINTER attribute. components that are of derived type and have neither the ALLOCATABLE nor POINTER attribute. the potential subobject components of the nonpointer components that are of derived type. This includes all the components that could be a subobject of an object of the type (9.4.2). derived type are the components, direct components, potential subobject components, and ultimate components of its type, respectively. is implied for a sequence type (7.5.2.3). If the derived type has the BIND attribute, the storage sequence is that required by the companion processor (5.5.7, 18.3.3). the type is a sequence structure.

66

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 The ultimate components of an object of the derived type kids defined below are oldest_child%name, oldest_child%age, and other_kids. The direct components of such an object are oldest_child%name, oldest_child%age, other_kids, and oldest_child. type :: person character(len=20) :: name integer :: age end type person type :: kids type(person) :: oldest_child type(person), allocatable, dimension(:) :: other_kids end type kids 1

7.5.2

Derived-type definition

2

7.5.2.1

Syntax of a derived-type definition

3 4 5

R726

derived-type-def

is

derived-type-stmt [ type-param-def-stmt ] ... [ private-or-sequence ] ... [ component-part ] [ type-bound-procedure-part ] end-type-stmt

9 10

R727

derived-type-stmt

is

TYPE [ [ , type-attr-spec-list ] :: ] type-name [ ( type-param-name-list ) ]

11

R728

type-attr-spec

is or or or

ABSTRACT access-spec BIND (C) EXTENDS ( parent-type-name )

15 16

C734

(R727) A derived type type-name shall not be DOUBLEPRECISION or the same as the name of any intrinsic type defined in this document.

17

C735

(R727) The same type-attr-spec shall not appear more than once in a given derived-type-stmt.

18

C736

The same type-param-name shall not appear more than once in a given derived-type-stmt.

19

C737

(R728) A parent-type-name shall be the name of a previously defined extensible type (7.5.7).

20 21

C738

(R726) If the type definition contains or inherits (7.5.7.2) a deferred type-bound procedure (7.5.5), ABSTRACT shall appear.

22

C739

(R726) If ABSTRACT appears, the type shall be extensible.

23

C740

(R726) If EXTENDS appears, SEQUENCE shall not appear.

24 25

C741

(R726) If EXTENDS appears and the type being defined has a coarray ultimate component, its parent type shall have a coarray ultimate component.

26 27 28 29

C742

(R726) If EXTENDS appears and the type being defined has a potential subobject component of type EVENT_TYPE, LOCK_TYPE, or NOTIFY_TYPE from the intrinsic module ISO_FORTRAN_ENV, its parent type shall be EVENT_TYPE, LOCK_TYPE, or NOTIFY_TYPE, or have a potential subobject component of type EVENT_TYPE, LOCK_TYPE, or NOTIFY_TYPE.

6 7 8

12 13 14

ISO/IEC JTC 1/SC 22/WG5/N2184

67

J3/21-007r1

WD 1539-1

2021-05-21

is private-components-stmt or sequence-stmt

1 2

R729

private-or-sequence

3

C743

(R726) The same private-or-sequence shall not appear more than once in a given derived-type-def .

4

R730

end-type-stmt

5

C744

(R730) If END TYPE is followed by a type-name, the type-name shall be the same as that in the corresponding derived-type-stmt.

6 7

is

END TYPE [ type-name ]

1 Derived types with the BIND attribute are subject to additional constraints as specified in 18.3.3.

NOTE 1 An example of a derived-type definition is: TYPE PERSON INTEGER AGE CHARACTER (LEN = 50) NAME END TYPE PERSON An example of declaring a variable CHAIRMAN of type PERSON is: TYPE (PERSON) :: CHAIRMAN 8

7.5.2.2

Accessibility

9 10

1 The accessibility of a type name is determined as specified in 8.5.2. The accessibility of a type name does not

11 12

2 If a derived type is defined in the scoping unit of a module, and its name is private in that module, then the type

13

affect, and is not affected by, the accessibility of its components and type-bound procedures. name, and thus the structure constructor (7.5.10) for the type, are accessible only within that module and its descendants. NOTE 1 An example of a type with a private name is: TYPE, PRIVATE :: AUXILIARY LOGICAL :: DIAGNOSTIC CHARACTER (LEN = 20) :: MESSAGE END TYPE AUXILIARY Such a type would be accessible only within the module in which it is defined, and within its descendants.

14

7.5.2.3

Sequence type

15

R731

sequence-stmt

16 17 18

C745

(R726) If SEQUENCE appears, the type shall have at least one component, each data component shall be declared to be of an intrinsic type or of a sequence type, the derived type shall not have any type parameter, and a type-bound-procedure-part shall not appear.

19 20 21 22 23 24

is

SEQUENCE

1 If the SEQUENCE statement appears, the type has the SEQUENCE attribute and is a sequence type. The order

of the component definitions in a sequence type specifies a storage sequence for objects of that type. The type is a numeric sequence type if there are no pointer or allocatable components, and each component is default integer, default real, double precision real, default complex, default logical, or of numeric sequence type. The type is a character sequence type if there are no pointer or allocatable components, and each component is default character or of character sequence type.

68

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 An example of a numeric sequence type is: TYPE NUMERIC_SEQ SEQUENCE INTEGER :: INT_VAL REAL :: REAL_VAL LOGICAL :: LOG_VAL END TYPE NUMERIC_SEQ NOTE 2 A structure resolves into a sequence of components. Unless the structure includes a SEQUENCE statement, the use of this terminology in no way implies that these components are stored in this, or any other, order. Nor is there any requirement that contiguous storage be used. The sequence merely refers to the fact that in writing the definitions there will necessarily be an order in which the components appear, and this will define a sequence of components. This order is of limited significance because a component of an object of derived type will always be accessed by a component name except in the following contexts: • the sequence of expressions in a derived-type value constructor, • intrinsic assignment, • the sequence of data values in namelist input data, and • and the inclusion of the structure in an input/output list of a formatted data transfer, where it is expanded to this sequence of components. Provided the processor adheres to the defined order in these cases, it is otherwise free to organize the storage of the components for any nonsequence structure in memory as best suited to the particular architecture. 1 2 3 4 5 6 7 8 9

7.5.2.4

Determination of derived types

1 Derived-type definitions with the same type name may appear in different scoping units, in which case they might

be independent and describe different derived types or they might describe the same type. 2 Two data entities have the same type if they are declared with reference to the same derived-type definition. Data

entities also have the same type if they are declared with reference to different derived-type definitions that specify the same type name, all have the SEQUENCE attribute or all have the BIND attribute, have no components with PRIVATE accessibility, and have components that agree in order, name, and attributes. Otherwise, they are of different derived types. A data entity declared using a type with the SEQUENCE attribute or with the BIND attribute is not of the same type as an entity of a type that has any components that are PRIVATE. NOTE 1 An example of declaring two entities with reference to the same derived-type definition is: TYPE POINT REAL X, Y END TYPE POINT TYPE (POINT) :: X1 CALL SUB (X1) ... CONTAINS SUBROUTINE SUB (A) TYPE (POINT) :: A ... END SUBROUTINE SUB The definition of derived type POINT is known in subroutine SUB by host association. Because the

ISO/IEC JTC 1/SC 22/WG5/N2184

69

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) declarations of X1 and A both reference the same derived-type definition, X1 and A have the same type. X1 and A also would have the same type if the derived-type definition were in a module and both SUB and its containing program unit accessed that derived type from the module. NOTE 2 An example of data entities in different scoping units having the same type is: PROGRAM PGM TYPE EMPLOYEE SEQUENCE INTEGER ID_NUMBER CHARACTER (50) NAME END TYPE EMPLOYEE TYPE (EMPLOYEE) PROGRAMMER CALL SUB (PROGRAMMER) ... END PROGRAM PGM SUBROUTINE SUB (POSITION) TYPE EMPLOYEE SEQUENCE INTEGER ID_NUMBER CHARACTER (50) NAME END TYPE EMPLOYEE TYPE (EMPLOYEE) POSITION ... END SUBROUTINE SUB The actual argument PROGRAMMER and the dummy argument POSITION have the same type because they are declared with reference to a derived-type definition with the same name, the SEQUENCE attribute, and components that agree in order, name, and attributes. Suppose the component name ID_NUMBER was ID_NUM in the subroutine. Because all the component names are not identical to the component names in derived type EMPLOYEE in the main program, the actual argument PROGRAMMER would not be of the same type as the dummy argument POSITION. Thus, the program would not be standard-conforming. NOTE 3 The requirement that the two types have the same name applies to the type-names in the respective derived type definitions, not to local names introduced via renaming in USE statements. 1

7.5.3

Derived-type parameters

2

7.5.3.1

Type parameter definition statement

3 4

R732

type-param-def-stmt

is

integer-type-spec, type-param-attr-spec :: type-param-decl-list

5

R733

type-param-decl

is

type-param-name [ = scalar-int-constant-expr ]

6 7

C746

(R732) A type-param-name in a type-param-def-stmt in a derived-type-def shall be one of the type-paramnames in the derived-type-stmt of that derived-type-def .

8 9

C747

(R732) Each type-param-name in the derived-type-stmt in a derived-type-def shall appear exactly once as a type-param-name in a type-param-def-stmt in that derived-type-def .

70

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

R734

type-param-attr-spec

WD 1539-1

J3/21-007r1

is KIND or LEN

3

1 The derived type is parameterized if the derived-type-stmt has any type-param-names.

4

2 Each type parameter is itself of type integer. If its kind selector is omitted, the kind type parameter is default

5

integer.

6

3 The type-param-attr-spec explicitly specifies whether a type parameter is a kind parameter or a length parameter.

7 8 9

4 If a type-param-decl has a scalar-int-constant-expr, the type parameter has a default value which is specified by

10

5 A type parameter may be used as a primary in a specification expression (10.1.11) in the derived-type-def . A

11

kind type parameter may also be used as a primary in a constant expression (10.1.12) in the derived-type-def .

the expression. If necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value of the same kind as the type parameter.

NOTE 1 The following example uses derived-type parameters. TYPE humongous_matrix(k, d) INTEGER, KIND :: k = KIND (0.0) INTEGER (SELECTED_INT_KIND (12)), LEN :: d !-- Specify a potentially nondefault kind for d. REAL (k) :: element (d, d) END TYPE In the following example, dim is declared to be a kind parameter, allowing generic overloading of procedures distinguished only by dim. TYPE general_point(dim) INTEGER, KIND :: dim REAL :: coordinates(dim) END TYPE 12

7.5.3.2

Type parameter order

13

1 Type parameter order is an ordering of the type parameters of a derived type; it is used for derived-type specifiers.

14 15 16 17

2 The type parameter order of a nonextended type is the order of the type-param-name-list in the derived-type

definition. The type parameter order of an extended type (7.5.7) consists of the type parameter order of its parent type followed by any additional type parameters in the order of the type-param-name-list in the derivedtype definition. NOTE 1 Given TYPE :: t1 (k1, k2) INTEGER, KIND :: k1, k2 REAL (k1) a (k2) END TYPE TYPE, EXTENDS(t1) :: t2 (k3) INTEGER, KIND :: k3 LOGICAL (k3) flag END TYPE the type parameter order for type t1 is k1 then k2, and the type parameter order for type t2 is k1 then k2 then k3.

ISO/IEC JTC 1/SC 22/WG5/N2184

71

J3/21-007r1

WD 1539-1

2021-05-21

1

7.5.4

Components

2

7.5.4.1

Component definition statement

3

R735

component-part

is

4 5

R736

component-def-stmt

is data-component-def-stmt or proc-component-def-stmt

6 7

R737

data-component-def-stmt

is

declaration-type-spec [ [ , component-attr-spec-list ] :: ] component-decl-list

8

R738

component-attr-spec

is or or or or or

access-spec ALLOCATABLE CODIMENSION lbracket coarray-spec rbracket CONTIGUOUS DIMENSION ( component-array-spec ) POINTER

R739

component-decl

is

component-name [ ( component-array-spec ) ] [ lbracket coarray-spec rbracket ] [ * char-length ] [ component-initialization ]

17 18 19

R740

component-array-spec

is explicit-shape-spec-list or deferred-shape-spec-list

20

C748

(R737) No component-attr-spec shall appear more than once in a given component-def-stmt.

21 22 23

C749

(R737) If neither the POINTER nor the ALLOCATABLE attribute is specified, the declaration-typespec in the component-def-stmt shall specify an intrinsic type, or a previously defined derived, enum, or enumeration type.

24 25

C750

(R737) If the POINTER or ALLOCATABLE attribute is specified, each component-array-spec shall be a deferred-shape-spec-list.

26

C751

(R737) If a coarray-spec appears, it shall be a deferred-coshape-spec-list and the component shall have the ALLOCATABLE attribute.

28 29 30

C752

(R737) If a coarray-spec appears, the component shall not be of type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING (18.2), or of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV (16.10.2).

31 32

C753

A data component whose type has a coarray ultimate component shall be a nonpointer nonallocatable scalar and shall not be a coarray.

33 34

C754

(R737) If neither the POINTER nor the ALLOCATABLE attribute is specified, each component-arrayspec shall be an explicit-shape-spec-list.

35 36 37

C755

(R740) Each bound in the explicit-shape-spec shall be a specification expression in which there are no references to specification functions or the intrinsic functions ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT, or SAME_TYPE_AS, every specification inquiry reference is a constant expression, and the value does not depend on the value of a variable.

39

C756

(R737) A component shall not have both the ALLOCATABLE and POINTER attributes.

40 41

C757

(R737) If the CONTIGUOUS attribute is specified, the component shall be an array with the POINTER attribute.

42

C758

(R739) The * char-length option is permitted only if the component is of type character.

9 10 11 12 13 14 15 16

27

38

72

[ component-def-stmt ] ...

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

C759

WD 1539-1

J3/21-007r1

(R736) Each type-param-value within a component-def-stmt shall be a colon or a specification expression in which there are no references to specification functions or the intrinsic functions ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT, or SAME_TYPE_AS, every specification inquiry reference is a constant expression, and the value does not depend on the value of a variable.

NOTE 1 Because a type parameter is not an object, a type-param-value or a bound in an explicit-shape-spec can contain a type-param-name. 5 6

R741

is

proc-component-def-stmt

PROCEDURE ( [ proc-interface ] ) , proc-component-attr-spec-list :: proc-decl-list

NOTE 2 See 15.4.3.6 for definitions of proc-interface and proc-decl. is or or or

7 8 9 10

R742

proc-component-attr-spec

11 12

C760

(R741) The same proc-component-attr-spec shall not appear more than once in a given proc-componentdef-stmt.

13

C761

(R741) POINTER shall appear in each proc-component-attr-spec-list.

14 15

C762

(R741) If the procedure pointer component has an implicit interface or has no arguments, NOPASS shall be specified.

16

C763

(R741) If PASS (arg-name) appears, the interface of the procedure pointer component shall have a dummy argument named arg-name.

C764

(R741) PASS and NOPASS shall not both appear in the same proc-component-attr-spec-list.

17 18 19 20 21 22

access-spec NOPASS PASS [ (arg-name) ] POINTER

1 The declaration-type-spec in the data-component-def-stmt specifies the type and type parameters of the com-

23 24 25

ponents in the component-decl-list, except that the character length parameter can be specified or overridden for a component by the appearance of * char-length in its entity-decl. The component-attr-spec-list in the datacomponent-def-stmt specifies the attributes whose keywords appear for the components in the component-decl-list, except that the DIMENSION attribute can be specified or overridden for a component by the appearance of a component-array-spec in its component-decl, and the CODIMENSION attribute can be specified or overridden for a component by the appearance of a coarray-spec in its component-decl.

26

7.5.4.2

27 28 29 30

Array components

1 A data component is an array if its component-decl contains a component-array-spec or its data-component-def-

stmt contains a DIMENSION clause. If the component-decl contains a component-array-spec, it specifies the array rank, and if the array is explicit shape (8.5.8.2), the array bounds; otherwise, the component-array-spec in the DIMENSION clause specifies the array rank, and if the array is explicit shape, the array bounds. NOTE 1 An example of a derived type definition with an array component is: TYPE LINE REAL, DIMENSION (2, 2) :: COORD

REAL

:: WIDTH

! ! COORD(:,1) has the value of [X1, Y1] ! COORD(:,2) has the value of [X2, Y2] ! Line width in centimeters

ISO/IEC JTC 1/SC 22/WG5/N2184

73

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) INTEGER END TYPE LINE

:: PATTERN

! 1 for solid, 2 for dash, 3 for dot

An example of declaring a variable LINE_SEGMENT to be of the type LINE is: TYPE (LINE)

:: LINE_SEGMENT

The scalar variable LINE_SEGMENT has a component that is an array. In this case, the array is a subobject of a scalar. The double colon in the definition for COORD is required; the double colon in the definition for WIDTH and PATTERN is optional. NOTE 2 An example of a derived type definition with an allocatable component is: TYPE STACK INTEGER :: INDEX INTEGER, ALLOCATABLE :: CONTENTS (:) END TYPE STACK For each scalar variable of type STACK, the shape of the component CONTENTS is determined by execution of an ALLOCATE statement or assignment statement, or by argument association. NOTE 3 Default initialization of an explicit-shape array component can be specified by a constant expression consisting of an array constructor (7.8), or of a single scalar that becomes the value of each array element. 1 2 3 4

7.5.4.3

Coarray components

1 A data component is a coarray if its component-decl contains a coarray-spec or its data-component-def-stmt

contains a CODIMENSION clause. If the component-decl contains a coarray-spec it specifies the corank; otherwise, the coarray-spec in the CODIMENSION clause specifies the corank. NOTE 1 An example of a derived type definition with a coarray component is: TYPE GRID_TYPE REAL, ALLOCATABLE, CODIMENSION [:, :, :] :: GRID (:, :, :) END TYPE GRID_TYPE An object of type grid_type cannot be an array, an allocatable object, a coarray, or a pointer.

5 6 7

7.5.4.4

Pointer components

1 A data component is a data pointer (5.4.9) if its component-attr-spec-list contains the POINTER keyword. A

procedure pointer component has the POINTER keyword in its proc-component-attr-spec-list. NOTE 1 An example of a derived type definition with a pointer component is: TYPE REFERENCE INTEGER :: VOLUME, YEAR, PAGE CHARACTER (LEN = 50) :: TITLE PROCEDURE (printer_interface), POINTER :: PRINT => NULL() CHARACTER, DIMENSION (:), POINTER :: SYNOPSIS

74

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) END TYPE REFERENCE Any object of type REFERENCE will have the four nonpointer components VOLUME, YEAR, PAGE, and TITLE, the procedure pointer PRINT, which has an explicit interface the same as printer_interface, plus a pointer to an array of characters holding SYNOPSIS. The size of this target array will be determined by the length of the synopsis. The space for the target could be allocated (9.7.1) or the pointer component could be associated with a target by a pointer assignment statement (10.2.2). 1

7.5.4.5

The passed-object dummy argument

2 3

1 A passed-object dummy argument is a distinguished dummy argument of a procedure pointer component or

4 5

2 If NOPASS is specified, the procedure pointer component or type-bound procedure has no passed-object dummy

6 7

3 If neither PASS nor NOPASS is specified or PASS is specified without arg-name, the first dummy argument of a

8 9

4 If PASS (arg-name) is specified, the dummy argument named arg-name is the passed-object dummy argument of

10 11 12 13

type-bound procedure (7.5.5). It affects procedure overriding (7.5.7.3) and argument association (15.5.2.2). argument. procedure pointer component or type-bound procedure is its passed-object dummy argument. the procedure pointer component or named type-bound procedure. C765

The passed-object dummy argument shall be a scalar, nonpointer, nonallocatable dummy data object with the same declared type as the type being defined; all of its length type parameters shall be assumed; it shall be polymorphic (7.3.2.3) if and only if the type being defined is extensible (7.5.7). It shall not have the VALUE attribute.

NOTE 1 If a procedure is bound to several types as a type-bound procedure, different dummy arguments might be the passed-object dummy argument in different contexts. 14

7.5.4.6

Default initialization for components

15 16 17

1 Default initialization provides a means of automatically initializing pointer components to be disassociated or

18 19

2 A pointer variable or component is data-pointer-initialization compatible with a target if the pointer is type

20 21

associated with specific targets, and nonpointer nonallocatable components to have a particular value. Allocatable components are always initialized to unallocated. compatible with the target, they have the same rank, all nondeferred type parameters of the pointer have the same values as the corresponding type parameters of the target, and the target is contiguous if the pointer has the CONTIGUOUS attribute.

22 23 24

R743

component-initialization

is = constant-expr or => null-init or => initial-data-target

25

R744

initial-data-target

is

26 27

C766

(R737) If component-initialization appears, a double-colon separator shall appear before the componentdecl-list.

28 29

C767

(R737) If component-initialization appears, every type parameter and array bound of the component shall be a colon or constant expression.

30 31

C768

(R737) If => appears in component-initialization, POINTER shall appear in the component-attr-speclist. If = appears in component-initialization, neither POINTER nor ALLOCATABLE shall appear in the component-attr-spec-list.

32

designator

ISO/IEC JTC 1/SC 22/WG5/N2184

75

J3/21-007r1

WD 1539-1

2021-05-21

1 2

C769

If initial-data-target appears in a component-initialization in a component-decl, component-name shall be data-pointer-initialization compatible with it.

3 4

C770

A designator that is an initial-data-target shall designate a nonallocatable, noncoindexed variable that has the TARGET and SAVE attributes and does not have a vector subscript. Every subscript, section subscript, substring starting point, and substring ending point in designator shall be a constant expression.

5 6 7 8

3 If null-init appears for a pointer component, that component in any object of the type has an initial association

9 10

4 If initial-data-target appears for a data pointer component, that component in any object of the type is initially

11 12 13

5 If initial-proc-target (15.4.3.6) appears in proc-decl for a procedure pointer component, that component in any

14 15 16

6 If constant-expr appears for a nonpointer component, that component in any object of the type is initially defined

17 18 19 20 21 22

status of disassociated (3.61) or becomes disassociated as specified in 19.5.2.4. associated with the target or becomes associated with the target as specified in 19.5.2.3. object of the type is initially associated with the target or becomes associated with the target as specified in 19.5.2.3. (19.6.3) or becomes defined as specified in 19.6.5 with the value determined from constant-expr. If necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type, type parameters, and shape with the component. If the component is of a type for which default initialization is specified for a component, the default initialization specified by constant-expr overrides the default initialization specified for that component. When one initialization overrides another it is as if only the overriding initialization were specified (see NOTE 2). Explicit initialization in a type declaration statement (8.2) overrides default initialization (see NOTE 1). Unlike explicit initialization, default initialization does not imply that the object has the SAVE attribute.

23 24 25

7 A subcomponent (9.4.2) is default-initialized if the type of the object of which it is a component specifies default

26 27

8 A type has default initialization if component-initialization is specified for any direct component of the type. An

initialization for that component, and the subcomponent is not a subobject of an object that is default-initialized or explicitly initialized. object has default initialization if it is of a type that has default initialization. NOTE 1 It is not required that initialization be specified for each component of a derived type. For example: TYPE DATE INTEGER DAY CHARACTER (LEN = 5) MONTH INTEGER :: YEAR = 2008 END TYPE DATE

! Partial default initialization

In the following example, the default initial value for the YEAR component of TODAY is overridden by explicit initialization in the type declaration statement: TYPE (DATE), PARAMETER :: TODAY = DATE (21, "Feb.", 2009) NOTE 2 The default initial value of a component of derived type can be overridden by default initialization specified in the definition of the type. Continuing the example of NOTE 1: TYPE SINGLE_SCORE TYPE(DATE) :: PLAY_DAY = TODAY INTEGER SCORE TYPE(SINGLE_SCORE), POINTER :: NEXT => NULL ( ) END TYPE SINGLE_SCORE

76

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) TYPE(SINGLE_SCORE) SETUP The PLAY_DAY component of SETUP receives its initial value from TODAY, overriding the initialization for the YEAR component. NOTE 3 Arrays of structures can be declared with elements that are partially or totally initialized by default. Continuing the example of NOTE 2: TYPE MEMBER (NAME_LEN) INTEGER, LEN :: NAME_LEN CHARACTER (LEN = NAME_LEN) :: NAME = ’’ INTEGER :: TEAM_NO, HANDICAP = 0 TYPE (SINGLE_SCORE), POINTER :: HISTORY => NULL ( ) END TYPE MEMBER TYPE (MEMBER(9)) LEAGUE (36) ! Array of partially initialized elements TYPE (MEMBER(9)) :: ORGANIZER = MEMBER (9) ("I. Manage",1,5,NULL ( )) ORGANIZER is explicitly initialized, overriding the default initialization for an object of type MEMBER. Allocated objects can also be initialized partially or totally. For example: ALLOCATE (ORGANIZER % HISTORY)

! A partially initialized object of type ! SINGLE_SCORE is created.

NOTE 4 A pointer component of a derived type can have as its target an object of that derived type. The type definition can specify that in objects declared to be of this type, such a pointer is default initialized to disassociated. For example: TYPE NODE INTEGER :: VALUE = 0 TYPE (NODE), POINTER :: NEXT_NODE => NULL ( ) END TYPE A type such as this can be used to construct linked lists of objects of type NODE. Linked lists can also be constructed using allocatable components. NOTE 5 A pointer component of a derived type can be default initialized to have an initial target. TYPE NODE INTEGER :: VALUE = 0 TYPE (NODE), POINTER :: NEXT_NODE => SENTINEL END TYPE TYPE(NODE), SAVE, TARGET :: SENTINEL

1

7.5.4.7

Component order

2

1 Component order is an ordering of the nonparent components of a derived type; it is used for intrinsic format-

3 4

ted input/output and structure constructors where component keywords are not used. Parent components are excluded from the component order of an extended type (7.5.7).

5

2 The component order of a nonextended type is the order of the declarations of the components in the derived-type

ISO/IEC JTC 1/SC 22/WG5/N2184

77

J3/21-007r1

1 2

WD 1539-1

2021-05-21

definition. The component order of an extended type consists of the component order of its parent type followed by any additional components in the order of their declarations in the extended derived-type definition. NOTE 1 Given the same type definitions as in 7.5.3.2, NOTE 1, the component order of type T1 is just A (there is only one component), and the component order of type T2 is A then FLAG. The parent component (T1) does not participate in the component order.

3

7.5.4.8

Component accessibility

4

R745

private-components-stmt

5 6

C771

(R745) A private-components-stmt is permitted only if the type definition is within the specification part of a module.

7 8 9 10 11 12

is

PRIVATE

1 The default accessibility for the components that are declared in a type’s component-part is private if the type

definition contains a private-components-stmt, and public otherwise. The accessibility of a component can be explicitly declared by an access-spec; otherwise its accessibility is the default for the type definition in which it is declared. 2 If a component is private, that component name is accessible only within the module containing the definition,

and within its descendants. NOTE 1 Type parameters are not components. They are effectively always public. NOTE 2 The accessibility of the components of a type is independent of the accessibility of the type name. It is possible to have all four combinations of public and private type names with public and private components. NOTE 3 An example of a public type with private components is: TYPE, PUBLIC :: POINT PRIVATE REAL :: X, Y END TYPE POINT Such a type definition can be accessed by use association; however, the components X and Y are accessible only within the module and its descendants. NOTE 4 An example that uses an individual component access-spec to override the default accessibility is: TYPE MIXED PRIVATE INTEGER :: I INTEGER, PUBLIC :: J END TYPE MIXED TYPE (MIXED) :: M The component M%J is accessible in any scoping unit where M is accessible; M%I is accessible only within the module containing the TYPE MIXED definition, and within its descendants.

78

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

7.5.5

Type-bound procedures

2 3

R746

type-bound-procedure-part

is

contains-stmt [ binding-private-stmt ] [ type-bound-proc-binding ] ...

5

R747

binding-private-stmt

is

PRIVATE

6 7

C772

(R746) A binding-private-stmt is permitted only if the type definition is within the specification part of a module.

8 9

R748

type-bound-proc-binding

is type-bound-procedure-stmt or type-bound-generic-stmt or final-procedure-stmt

11 12

R749

type-bound-procedure-stmt

is PROCEDURE [ [ , binding-attr-list ] :: ] type-bound-proc-decl-list or PROCEDURE (interface-name), binding-attr-list :: binding-name-list

13

R750

type-bound-proc-decl

is

14

C773

(R749) If => procedure-name appears in a type-bound-proc-decl, the double-colon separator shall appear.

15

C774

(R750) The procedure-name shall be the name of an accessible module procedure or an external procedure that has an explicit interface.

C775

A binding-name in a type-bound-proc-decl in a derived type definition shall not be the same as any other binding-name within that derived type definition.

4

10

16 17 18 19 20

binding-name [ => procedure-name ]

1 If => procedure-name does not appear in a type-bound-proc-decl, it is as though => procedure-name had appeared

with a procedure name the same as the binding name. is

21

R751

type-bound-generic-stmt

22 23 24

C776

(R751) Within the specification-part of a module, each type-bound-generic-stmt shall specify, either implicitly or explicitly, the same accessibility as every other type-bound-generic-stmt with that generic-spec in the same derived type.

25

C777

(R751) Each binding-name in binding-name-list shall be the name of a specific binding of the type.

26 27

C778

A binding-name in a type-bound GENERIC statement shall not specify a specific binding that was inherited or specified previously for the same generic identifier in that derived type definition.

28 29

C779

(R751) If generic-spec is not generic-name, each of its specific bindings shall have a passed-object dummy argument (7.5.4.5).

30 31

C780

(R751) If generic-spec is OPERATOR ( defined-operator ), the interface of each binding shall be as specified in 15.4.3.4.2.

32 33

C781

(R751) If generic-spec is ASSIGNMENT ( = ), the interface of each binding shall be as specified in 15.4.3.4.3.

34 35

C782

(R751) If generic-spec is defined-io-generic-spec, the interface of each binding shall be as specified in 12.6.4.8. The type of the dtv argument shall be type-name.

36 37 38 39

R752

binding-attr

40

is or or or or

GENERIC [ , access-spec ] :: generic-spec => binding-name-list

access-spec DEFERRED NON_OVERRIDABLE NOPASS PASS [ (arg-name) ]

ISO/IEC JTC 1/SC 22/WG5/N2184

79

J3/21-007r1

WD 1539-1

2021-05-21

1

C783

(R752) The same binding-attr shall not appear more than once in a given binding-attr-list.

2 3

C784

(R749) If the interface of the binding has no dummy argument of the type being defined, NOPASS shall appear.

4

C785

(R749) If PASS (arg-name) appears, the interface of the binding shall have a dummy argument named arg-name.

6

C786

(R752) PASS and NOPASS shall not both appear in the same binding-attr-list.

7

C787

(R752) NON_OVERRIDABLE and DEFERRED shall not both appear in the same binding-attr-list.

8

C788

(R752) DEFERRED shall appear if and only if interface-name appears.

9 10

C789

(R749) An overriding binding (7.5.7.3) shall have the DEFERRED attribute only if the binding it overrides is deferred.

11

C790

(R749) A binding shall not override an inherited binding (7.5.7.2) that has the NON_OVERRIDABLE attribute.

5

12 13 14 15 16

2 A type-bound procedure statement declares one or more specific type-bound procedures. A specific type-bound

17

3 A GENERIC statement declares a generic type-bound procedure, which is a type-bound generic interface for its

18

procedure can have a passed-object dummy argument (7.5.4.5). A type-bound procedure with the DEFERRED attribute is a deferred type-bound procedure. The DEFERRED keyword shall appear only in the definition of an abstract type. specific type-bound procedures.

19 20

4 A binding of a type is a type-bound procedure (specific or generic), a generic type-bound interface, or a final

21 22 23

5 A type-bound procedure can be identified by a binding name in the scope of the type definition. This name is the

24

subroutine. These are referred to as specific bindings, generic bindings, and final bindings respectively. binding-name for a specific type-bound procedure, and the generic-name for a generic binding whose generic-spec is generic-name. A final binding, or a generic binding whose generic-spec is not generic-name, has no binding name.

25 26

6 The interface of a specific type-bound procedure is that of the procedure specified by procedure-name or the

27 28

7 The same generic-spec may be used in several GENERIC statements within a single derived-type definition. Each

interface specified by interface-name. additional GENERIC statement with the same generic-spec extends the generic interface. NOTE 1 Unlike the situation with generic procedure names, a generic type-bound procedure name is not permitted to be the same as a specific type-bound procedure name in the same type (19.3).

29 30 31

8 The default accessibility for the type-bound procedures of a type is private if the type definition contains a binding-

32

9 A public type-bound procedure is accessible via any accessible object of the type. A private type-bound procedure

33

private-stmt, and public otherwise. The accessibility of a type-bound procedure can be explicitly declared by an access-spec; otherwise its accessibility is the default for the type definition in which it is declared. is accessible only within the module containing the type definition, and within its descendants. NOTE 2 The accessibility of a type-bound procedure is not affected by a PRIVATE statement in the component-part; the accessibility of a component is not affected by a PRIVATE statement in the type-bound-procedure-part.

80

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 3 An example of a type and a type-bound procedure is: TYPE POINT REAL :: X, Y CONTAINS PROCEDURE, PASS :: LENGTH => POINT_LENGTH END TYPE POINT ... and in the module-subprogram-part of the same module: REAL FUNCTION POINT_LENGTH (A, B) CLASS (POINT), INTENT (IN) :: A, B POINT_LENGTH = SQRT ( (A%X - B%X)**2 + (A%Y - B%Y)**2 ) END FUNCTION POINT_LENGTH 1

7.5.6

Final subroutines

2

7.5.6.1

FINAL statement

3

R753

final-procedure-stmt

4 5 6

C791

(R753) A final-subroutine-name shall be the name of a module procedure with exactly one dummy argument. That argument shall be nonoptional and shall be a noncoarray, nonpointer, nonallocatable, nonpolymorphic variable of the derived type being defined. All length type parameters of the dummy argument shall be assumed. The dummy argument shall not have the INTENT (OUT) or VALUE attribute.

9

C792

(R753) A final-subroutine-name shall not be one previously specified as a final subroutine for that type.

10 11

C793

(R753) A final subroutine shall not have a dummy argument with the same kind type parameters and rank as the dummy argument of another final subroutine of that type.

12

C794

(R753) If a final subroutine has an assumed-rank dummy argument, no other final subroutine of that type shall have a dummy argument with the same kind type parameters.

7 8

13

is

FINAL [ :: ] final-subroutine-name-list

14 15

1 The FINAL statement specifies that each procedure it names is a final subroutine. A final subroutine might be

16 17 18

2 A derived type is finalizable if and only if it has a final subroutine or a nonpointer, nonallocatable component of

executed when a data entity of that type is finalized (7.5.6.2). finalizable type. A nonpointer data entity is finalizable if and only if it is of finalizable type. No other entity is finalizable. NOTE 1 Final subroutines are effectively always “accessible”. They are called for entity finalization regardless of the accessibility of the type, its other type-bound procedures, or the subroutine name itself. NOTE 2 Final subroutines are not inherited through type extension and cannot be overridden. The final subroutines of the parent type are called after any additional final subroutines of an extended type are called.

19 20 21

7.5.6.2

The finalization process

1 Only finalizable entities are finalized. When an entity is finalized, the following steps are carried out in sequence.

(1)

If the dynamic type of the entity has a final subroutine whose dummy argument has the same kind

ISO/IEC JTC 1/SC 22/WG5/N2184

81

J3/21-007r1

1 2 3 4 5

(2)

6 7 8

(3)

9

WD 1539-1

2021-05-21

type parameters and rank as the entity being finalized, it is called with the entity as an actual argument. Otherwise, if there is an elemental final subroutine whose dummy argument has the same kind type parameters as the entity being finalized, or a final subroutine whose dummy argument is assumed-rank with the same kind type parameters as the entity being finalized, it is called with the entity as an actual argument. Otherwise, no subroutine is called at this point. All nonallocatable finalizable components that appear in the type definition are finalized in a processordependent order. If the entity being finalized is an array, each finalizable component of each element of that entity is finalized separately. If the entity is of extended type and the parent type is finalizable, the parent component is finalized.

10

2 If several entities are to be finalized as a consequence of an event specified in 7.5.6.3, the order in which they

11 12

are finalized is processor dependent. During this process, execution of a final subroutine for one of these entities shall not reference or define any of the other entities that have already been finalized. NOTE 1 An implementation might need to ensure that when an event causes more than one coarray to be deallocated, they are deallocated in the same order on all images in the current team.

13

7.5.6.3

When finalization occurs

14

1 When an intrinsic assignment statement is executed (10.2.1.3), if the variable is not an unallocated allocatable

15 16 17

variable, it is finalized after evaluation of expr and before the definition of the variable. If the variable is an allocated allocatable variable, or has an allocated allocatable subobject, that would be deallocated by intrinsic assignment, the finalization occurs before the deallocation.

18 19 20

2 When a pointer is deallocated its target is finalized. When an allocatable entity is deallocated, it is finalized

21 22

3 A nonpointer, nonallocatable object that is not a dummy argument or function result is finalized immediately

23 24

4 A nonpointer nonallocatable local variable of a BLOCK construct is finalized immediately before it would become

25 26

5 If an executable construct references a nonpointer function, the result is finalized after execution of the innermost

27 28

6 If a specification expression in a scoping unit references a function, the result is finalized before execution of the

29 30 31 32

7 When a procedure is invoked, a nonpointer, nonallocatable, INTENT (OUT) dummy argument of that procedure

33 34 35

8 If an object is allocated via pointer allocation and later becomes unreachable due to all pointers associated with

unless it is the variable in an intrinsic assignment statement. If an error condition occurs during deallocation, it is processor dependent whether finalization occurs. before it would become undefined due to execution of a RETURN or END statement (19.6.6, item (3)). undefined due to termination of the BLOCK construct (19.6.6, item (23)). executable construct containing the reference. executable constructs in the scoping unit. is finalized before it becomes undefined. The finalization caused by INTENT (OUT) is considered to occur within the invoked procedure; so for elemental procedures, an INTENT (OUT) argument will be finalized only if a scalar or elemental final subroutine is available, regardless of the rank of the actual argument. that object having their pointer association status changed, it is processor dependent whether it is finalized. If it is finalized, it is processor dependent as to when the final subroutines are called. NOTE 1 If finalization is used for storage management, it often needs to be combined with defined assignment.

82

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

7.5.6.4

WD 1539-1

J3/21-007r1

Entities that are not finalized

1 If image execution is terminated, either by an error (e.g. an allocation failure) or by execution of a stop-stmt,

error-stop-stmt, or end-program-stmt, entities existing immediately prior to termination are not finalized. NOTE 1 A nonpointer, nonallocatable object that has the SAVE attribute is never finalized as a direct consequence of the execution of a RETURN or END statement.

4

7.5.7

Type extension

5

7.5.7.1

Extensible, extended, and abstract types

6 7

1 A derived type, other than the type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, that

8 9

2 A type with the EXTENDS attribute is an extended type; its parent type is the type named in the EXTENDS

does not have the BIND attribute or the SEQUENCE attribute is an extensible type. type-attr-spec. NOTE 1 The name of the parent type might be a local name introduced via renaming in a USE statement.

10 11

3 An extensible type that does not have the EXTENDS attribute is an extension type of itself only. An extended

12

4 An abstract type is a type that has the ABSTRACT attribute.

type is an extension of itself and of all types for which its parent type is an extension.

NOTE 2 The DEFERRED attribute (7.5.5) defers the implementation of a type-bound procedure to extensions of the type; it can appear only in an abstract type. The dynamic type of an object cannot be abstract; therefore, a deferred type-bound procedure cannot be invoked. An extension of an abstract type need not be abstract if it has no deferred type-bound procedures. A short example of an abstract type is: TYPE, ABSTRACT :: FILE_HANDLE CONTAINS PROCEDURE(OPEN_FILE), DEFERRED, PASS(HANDLE) :: OPEN ... END TYPE For a more elaborate example see C.3.4. 13 14 15 16 17

7.5.7.2

Inheritance

1 An extended type includes all of the type parameters, all of the components, and the nonoverridden (7.5.7.3)

type-bound procedures of its parent type. These are inherited by the extended type from the parent type. They retain all of the attributes that they had in the parent type. Additional type parameters, components, and procedure bindings may be declared in the derived-type definition of the extended type. NOTE 1 Inaccessible components and bindings of the parent type are also inherited, but they remain inaccessible in the extended type. Inaccessible entities occur if the type being extended is accessed via use association and has a private entity. NOTE 2 An extensible derived type is not required to have any components, bindings, or parameters; an extended type is not required to have more components, bindings, or parameters than its parent type.

ISO/IEC JTC 1/SC 22/WG5/N2184

83

J3/21-007r1

1 2 3 4 5 6 7 8

WD 1539-1

2021-05-21

2 An extended type has a scalar, nonpointer, nonallocatable, parent component with the type and type parameters

of the parent type. The name of this component is the parent type name. If the extended type is defined in a module, the parent component has the accessibility of the parent type in the module in which the parent type was defined. Components of the parent component are inheritance associated (19.5.4) with the corresponding components inherited from the parent type. An ancestor component of a type is the parent component of the type or an ancestor component of the parent component. 3 If a generic binding specified in a type definition has the same generic-spec as an inherited binding, it extends

the generic interface and shall satisfy the requirements specified in 15.4.3.4.5. NOTE 3 A component or type parameter declared in an extended type cannot have the same name as any accessible component or type parameter of its parent type. NOTE 4 For example: TYPE POINT REAL :: X, Y END TYPE POINT

! A base type

TYPE, EXTENDS(POINT) :: COLOR_POINT ! An extension of TYPE(POINT) ! Components X and Y, and component name POINT, inherited from parent INTEGER :: COLOR END TYPE COLOR_POINT

9

7.5.7.3

Type-bound procedure overriding

10 11 12

1 If a specific type-bound procedure specified in a type definition has the same binding name as an accessible

13

2 The overriding and overridden type-bound procedures shall satisfy the following conditions.

14 15 16 17 18 19 20 21 22 23

24 25

type-bound procedure from the parent type then the binding specified in the type definition overrides the one from the parent type.

• Either both shall have a passed-object dummy argument or neither shall. • If the overridden type-bound procedure is pure then the overriding one shall also be pure. • If the overridden type-bound procedure is simple then the overriding one shall also be simple. • Either both shall be elemental or neither shall. • They shall have the same number of dummy arguments. • Passed-object dummy arguments, if any, shall correspond by name and position. • Dummy arguments that correspond by position shall have the same names and characteristics, except for the type of the passed-object dummy arguments. • Either both shall be subroutines or both shall be functions having the same result characteristics (15.3.3). • If the overridden type-bound procedure is PUBLIC then the overriding one shall not be PRIVATE. 3 A binding of a type and a binding of an extension of that type correspond if the latter binding is the same binding

as the former, overrides a corresponding binding, or is an inherited corresponding binding. NOTE 1 The following is an example of procedure overriding, expanding on the example in 7.5.5, NOTE 3. TYPE, EXTENDS (POINT) :: POINT_3D REAL :: Z CONTAINS PROCEDURE, PASS :: LENGTH => POINT_3D_LENGTH END TYPE POINT_3D

84

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) ... and in the module-subprogram-part of the same module: REAL FUNCTION POINT_3D_LENGTH ( A, B ) CLASS (POINT_3D), INTENT (IN) :: A CLASS (POINT), INTENT (IN) :: B SELECT TYPE(B) CLASS IS(POINT_3D) POINT_3D_LENGTH = SQRT( (A%X-B%X)**2 + (A%Y-B%Y)**2 + (A%Z-B%Z)**2 ) RETURN END SELECT PRINT *, ’In POINT_3D_LENGTH, dynamic type of argument is incorrect.’ STOP END FUNCTION POINT_3D_LENGTH

1 2 3 4 5 6

7 8 9 10

7.5.8

Derived-type values

1 The component value of

• a pointer component is its pointer association, • an allocatable component is its allocation status and, if it is allocated, its dynamic type and type parameters, bounds and value, and • a nonpointer nonallocatable component is its value. 2 The set of values of a particular derived type consists of all possible sequences of the component values of its

components.

7.5.9

Derived-type specifier

1 A derived-type specifier is used in several contexts to specify a particular derived type and type parameters.

11

R754

derived-type-spec

is

type-name [ ( type-param-spec-list ) ]

12

R755

type-param-spec

is

[ keyword = ] type-param-value

13

C795

(R754) type-name shall be the name of an accessible derived type.

14

C796

(R754) type-param-spec-list shall appear only if the type is parameterized.

15 16 17

C797

(R754) There shall be at most one type-param-spec corresponding to each parameter of the type. If a type parameter does not have a default value, there shall be a type-param-spec corresponding to that type parameter.

18 19

C798

(R755) The keyword= shall not be omitted from a type-param-spec unless the keyword= has been omitted from each preceding type-param-spec in the type-param-spec-list.

20

C799

(R755) Each keyword shall be the name of a parameter of the type.

21 22

C7100 (R755) An asterisk shall not be used as a type-param-value in a type-param-spec except in the declaration of a dummy argument or associate name or in the allocation of a dummy argument.

23 24 25 26

2 Type parameter values that do not have type parameter keywords specified correspond to type parameters in type

parameter order (7.5.3.2). If a type parameter keyword appears, the value corresponds to the type parameter named by the keyword. If necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value of the same kind as the type parameter.

ISO/IEC JTC 1/SC 22/WG5/N2184

85

J3/21-007r1

1 2 3 4 5

WD 1539-1

2021-05-21

3 The value of a type parameter for which no type-param-value has been specified is its default value.

7.5.10

Construction of derived-type values

1 A derived-type definition implicitly defines a corresponding structure constructor that allows construction of

scalar values of that derived type. The type and type parameters of a constructed value are specified by a derived type specifier.

6

R756

structure-constructor

is

derived-type-spec ( [ component-spec-list ] )

7

R757

component-spec

is

[ keyword = ] component-data-source

8 9 10

R758

component-data-source

is expr or data-target or proc-target

11

C7101 (R756) The derived-type-spec shall not specify an abstract type (7.5.7).

12

C7102 (R756) At most one component-spec shall be provided for a component.

13 14

C7103 (R756) If a component-spec is provided for an ancestor component, a component-spec shall not be provided for any component that is inheritance associated with a subcomponent of that ancestor component.

15 16 17

C7104 (R756) A component-spec shall be provided for a nonallocatable component unless it has default initialization or is inheritance associated with a subcomponent of another component for which a component-spec is provided.

18 19

C7105 (R757) The keyword= shall not be omitted from a component-spec unless the keyword= has been omitted from each preceding component-spec in the constructor.

20

C7106 (R757) Each keyword shall be the name of a component of the type.

21 22

C7107 (R756) The type name and all components of the type for which a component-spec appears shall be accessible in the scoping unit containing the structure constructor.

23 24 25

C7108 (R756) If derived-type-spec is a type name that is the same as a generic name, the component-spec-list shall not be a valid actual-arg-spec-list for a function reference that is resolvable as a generic reference to that name (15.5.5.2).

26 27

C7109 (R758) A data-target shall correspond to a data pointer component; a proc-target shall correspond to a procedure pointer component.

28

C7110 (R758) A data-target shall have the same rank as its corresponding component. NOTE 1 The form ’name(...)’ is interpreted as a generic function-reference if possible; it is interpreted as a structureconstructor only if it cannot be interpreted as a generic function-reference.

29 30 31 32 33 34 35 36 37

2 In the absence of a component keyword, each component-data-source is assigned to the corresponding component

in component order (7.5.4.7). If a component keyword appears, the expr is assigned to the component named by the keyword. For a nonpointer component, the declared type and type parameters of the component and expr shall conform in the same way as for a variable and expr in an intrinsic assignment statement (10.2.1.2). If necessary, each value of intrinsic type is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type and type parameters with the corresponding component of the derived type. For a nonpointer nonallocatable component, the shape of the expression shall conform with the shape of the component. 3 If a component with default initialization has no corresponding component-data-source, then the default initial-

ization is applied to that component. If an allocatable component has no corresponding component-data-source,

86

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

then that component has an allocation status of unallocated. NOTE 2 Because no parent components appear in the defined component ordering, a value for a parent component can be specified only with a component keyword. Examples of equivalent values using types defined in 7.5.7.2, NOTE 4: ! Create values with components x = 1.0, y = 2.0, color = 3. TYPE(POINT) :: PV = POINT(1.0, 2.0) ! Assume components of TYPE(POINT) ! are accessible here. ... COLOR_POINT( point=point(1,2), color=3) ! Value for parent component COLOR_POINT( point=PV, color=3) ! Available even if TYPE(point) ! has private components COLOR_POINT( 1, 2, 3) ! All components of TYPE(point) ! need to be accessible.

2

4 A structure constructor shall not appear before the referenced type is defined.

3

5 For a pointer component, the corresponding component-data-source shall be an allowable data-target or proc-

4 5 6

target for such a pointer in a pointer assignment statement (10.2.2). If the component data source is a pointer, the association of the component is that of the pointer; otherwise, the component is pointer associated with the component data source. NOTE 3 For example, if the variable TEXT were declared (8.2) to be CHARACTER, DIMENSION (1:400), TARGET :: TEXT and BIBLIO were declared using the derived-type definition REFERENCE in 7.5.4.4, NOTE 1 TYPE (REFERENCE) :: BIBLIO the statement BIBLIO = REFERENCE (1, 1987, 1, "This is the title of the referenced & &paper", SYNOPSIS=TEXT) is valid and associates the pointer component SYNOPSIS of the object BIBLIO with the target object TEXT. The keyword SYNOPSIS is required because the fifth component of the type REFERENCE is a procedure pointer component, not a data pointer component of type character. It is not necessary to specify a proc-target for the procedure pointer component because it has default initialization.

7 8 9 10

6 If a component of a derived type is allocatable, the corresponding constructor expression shall be a reference

11 12 13 14 15

7 If the component is allocatable and the expression is an allocatable entity, the corresponding component of the

16

8 If the component is allocatable and the expression is not an allocatable entity, the component has an allocation

17 18 19

status of allocated and the same bounds as the expression; if a length parameter of the component is deferred, its value is the same as the corresponding parameter of the expression. If the component is polymorphic, it has the same dynamic type and value; otherwise, it has the value converted, if necessary, to the declared type of the

to the intrinsic function NULL with no arguments, an allocatable entity of the same rank, or shall evaluate to an entity of the same rank. If the expression is a reference to the intrinsic function NULL, the corresponding component of the constructor has a status of unallocated. constructor has the same allocation status as that allocatable entity. If it is allocated, it has the same bounds; if a length parameter of the component is deferred, its value is the same as the corresponding parameter of the expression. If the component is polymorphic, it has the same dynamic type and value; otherwise, it has the value converted, if necessary, to the declared type of the component.

ISO/IEC JTC 1/SC 22/WG5/N2184

87

J3/21-007r1

1

WD 1539-1

2021-05-21

component. NOTE 4 This example shows a derived-type constant expression using the derived type defined in 7.5.2.1, NOTE 1: PERSON (21, ’JOHN SMITH’) This could also be written as PERSON (NAME = ’JOHN SMITH’, AGE = 21)

NOTE 5 An example constructor using the derived type GENERAL_POINT defined in 7.5.3.1, NOTE 1 is general_point(dim=3) ( [ 1., 2., 3. ] )

2 3 4

7.5.11

Derived-type operations and assignment

1 Intrinsic assignment of derived-type entities is described in 10.2.1. This document does not specify any intrinsic

5 6

operations on derived-type entities. Any operation on derived-type entities or defined assignment (10.2.1.4) for derived-type entities shall be defined explicitly by a function or a subroutine, and a generic interface (7.5.5, 15.4.3.2).

7

7.6

Other user-defined types

8

7.6.1

Interoperable enumerations and enum types

9 10 11 12

1 An interoperable enumeration is a set of interoperable enumerators, optionally together with an interoperable

enum type. An enum-def defines an interoperable enumeration. An interoperable enumerator is a named integer constant; all the enumerators defined by a particular enum-def have the same kind. An interoperable enum type is a user-defined type that is not a derived type; it has no type parameter.

13 14 15 16

R759

enum-def

is

enum-def-stmt enumerator-def-stmt [ enumerator-def-stmt ] ... end-enum-stmt

17

R760

enum-def-stmt

is

ENUM, BIND(C) [ :: enum-type-name ]

18

R761

enumerator-def-stmt

is

ENUMERATOR [ :: ] enumerator-list

19

R762

enumerator

is

named-constant [ = scalar-int-constant-expr ]

20

R763

end-enum-stmt

is

END ENUM

21

C7111 (R761) If = appears in an enumerator, a double-colon separator shall appear before the enumerator-list.

22

R764

23

C7112 An enum-type-name in an enum-type-spec shall be the name of a previously defined enum type.

enum-type-spec

is

enum-type-name

24

2 The kind type parameter of each enumerator defined by an enum-def is the kind that is interoperable (18.3.1)

25 26 27

with the corresponding C enumeration type. The corresponding C enumeration type is the type that would be declared by a C enumeration specifier (ISO/IEC 9899:2011, 6.7.2.2) that specified C enumeration constants with the same values as those specified by the enum-def , in the same order as specified by the enum-def .

28

3 If enum-type-name appears in an enum-def , the enum-def defines the enum type with that name. An enum type

88

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

is an interoperable type. 4 The companion processor (5.5.7) shall be one that uses the same representation for the types declared by all C

enumeration specifiers that specify the same values in the same order. NOTE 1 If a companion processor uses an unsigned type to represent a given enumeration type, the Fortran processor will use the signed integer type of the same width for the enumeration, even though some of the values of the C enumerators might not be representable in this signed integer type. The types of any such enumerators will be interoperable with the type declared in the C enumeration. NOTE 2 ISO/IEC 9899:2011 guarantees the enumeration constants fit in a C int (ISO/IEC 9899:2011, 6.7.2.2). Therefore, the Fortran processor can evaluate all enumerator values using the integer type with kind parameter C_INT, and then determine the kind parameter of the integer type that is interoperable with the corresponding C enumerated type. NOTE 3 ISO/IEC 9899:2011 specifies that two enumeration types are compatible only if they specify enumeration constants with the same names and same values in the same order. This document further requires that a C processor that is to be a companion processor of a Fortran processor use the same representation for two enumeration types if they both specify enumeration constants with the same values in the same order, even if the names are different.

4 5

5 An enumerator is treated as if it were explicitly declared with the PARAMETER attribute. The enumerator is

defined in accordance with the rules of intrinsic assignment (10.2) with the value determined as follows.

6 7

(1)

8 9

(2)

10 11 12

(3)

If scalar-int-constant-expr is specified, the value of the enumerator is the result of scalar-int-constantexpr. If scalar-int-constant-expr is not specified and the enumerator is the first enumerator in enum-def , the enumerator has the value 0. If scalar-int-constant-expr is not specified and the enumerator is not the first enumerator in enumdef , its value is the result of adding 1 to the value of the enumerator that immediately precedes it in the enum-def .

R765

14

C7113 The expr in an enum-constructor shall be of type integer or be a boz-literal-constant.

15 16

enum-constructor

is

13

enum-type-spec ( expr )

6 An enum constructor produces a scalar value of the specified type, with the specified internal representation. The

value of expr shall be representable in objects of that type. NOTE 4 Example of an interoperable enumeration definition: ENUM, BIND(C) ENUMERATOR :: RED = 4, BLUE = 9 ENUMERATOR YELLOW END ENUM The kind type parameter for this enumeration is processor dependent, but the processor is required to select a kind sufficient to represent the values 4, 9, and 10, which are the values of its enumerators. The following declaration might be equivalent to the above enumeration definition. INTEGER (SELECTED_INT_KIND (2)), PARAMETER :: RED = 4, BLUE = 9, YELLOW = 10 An entity of the same kind type parameter value can be declared using the intrinsic function KIND with one of the enumerators as its argument, for example

ISO/IEC JTC 1/SC 22/WG5/N2184

89

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 4 (cont.) INTEGER (KIND (RED)) :: X

NOTE 5 There is no difference in the effect of declaring the enumerators in multiple ENUMERATOR statements or in a single ENUMERATOR statement. The order in which the enumerators in an enumeration definition are declared is significant, but the number of ENUMERATOR statements is not. NOTE 6 Here is an example of a module that defines two interoperable enum types. Module enum_mod Enum,Bind(C) :: myenum Enumerator :: one=1, two, three End Enum Enum,Bind(C) :: flags Enumerator :: f1 = 1, f2 = 2, f3 = 4 End Enum Contains Subroutine sub(a) Bind(C) Type(myenum),Value :: a Print *,a ! Prints the integer value, as if it were Print *,Int(a). End Subroutine End Module Here is a simple program that uses that module and the enum constructor. Program example Use enum_mod Type(myenum) :: x = one ! Assign enumerator to enum-type var. Type(myenum) :: y = myenum(12345) ! Using the constructor. Type(myenum) :: x2 = myenum(two) ! Constructor not needed but valid. Call sub(x) Call sub(three) Call sub(myenum(-Huge(one))) End Program Here is an example of invalid usage. Program invalid Use enum_mod Type(myenum) :: z = 12345 Call sub(999) Call sub(f1) End Program 1

7.6.2

! Integer expr with no enumerator. ! Not type-compatible (constructor needed). ! Wrong enum type.

Enumeration types

2

1 An enumeration type is a user-defined type with no type parameter. It is not a derived type and is not inter-

3 4

operable. An enumeration type definition defines the name of the type and lists all the possible values of the type.

90

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

R766

enumeration-type-def

is

enumeration-type-stmt enumeration-enumerator-stmt [ enumeration-enumerator-stmt ]... end-enumeration-type-stmt

5

R767

enumeration-type-stmt

is

ENUMERATION TYPE [ [ , access-spec ] :: ] enumeration-type-name

6

C7114 An access-spec on an enumeration-type-stmt shall only appear in the specification part of a module.

7

R768

enumeration-enumerator-stmt is

8

R769

end-enumeration-type-stmt is

9 10

C7115 If enumeration-type-name appears on an END ENUMERATION TYPE statement, it shall be the same as on the ENUMERATION TYPE statement.

11

2 The access-spec on an ENUMERATION TYPE statement specifies the accessibility of the enumeration-type-

12 13

name and the default accessibility of its enumerators. The accessibility of an enumerator may be confirmed or overridden by an access-stmt.

14 15

3 Each enumerator in the definition is a named constant of the enumeration type. The order of the enumerator

ENUMERATOR [ :: ] enumerator-name-list END ENUMERATION TYPE [ enumeration-type-name ]

names in the definition defines the ordinal position of each enumerator. R770

17

C7116 The enumeration-type-name in an enumeration-type-spec shall be the name of a previously defined enumeration type.

18 19 20 21 22 23 24

enumeration-type-spec

is

16

enumeration-type-name

4 An enumeration type specifier specifiers the type. Two data entities of enumeration type have the same type if

they are declared with reference to the same enumeration type definition. R771

enumeration-constructor

is

enumeration-type-spec ( int-expr )

5 An enumeration constructor returns the value of the enumeration type whose ordinal position is the value of the

int-expr. The int-expr shall have a value that is positive and less than or equal to the number of enumerators in the enumeration type’s definition. NOTE 1 Here is an example of a module defining two enumeration types. Module enumeration_mod Enumeration Type :: v_value Enumerator :: v_one, v_two, v_three Enumerator v_four End Enumeration Type Enumeration Type :: w_value Enumerator :: w1, w2, w3, w4, w5, wendsentinel End Enumeration Type Contains Subroutine sub(a) Type(v_value),Intent(In) :: a Print 1,a ! Acts similarly to Print *,Int(a). 1 Format(’A has ordinal value ’,I0) End Subroutine Subroutine wcheck(w) Type(w_value),Intent(In) :: w Select Case(w) Case(w1)

ISO/IEC JTC 1/SC 22/WG5/N2184

91

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) Print *,’w 1 selected’ Case (w2:w4) Print *,’One of w2...w4 selected’ Case (wendsentinel) Stop ’Invalid w selected’ Case Default Stop ’Unrecognized w selected’ End Select End Subroutine End Module Here is an example of a program using that module. Program example Use enumeration_mod Type(v_value) :: x = v_one Type(v_value) :: y = v_value(2) ! Explicit constructor producing v_two. Type(v_value) :: z,nz ! Initially undefined. Call sub(x) Call sub(v_three) z = v_value(1) ! First value. Do If (z==Huge(x)) Write (*,’(A)’,Advance=’No’) ’ Huge:’ Call sub(z) nz = Next(z) If (z==nz) Exit z = nz End Do End Program Here is an example showing some invalid usages of enumerations. Program invalid Use enumeration_mod Type(v_value) :: a, b a = 1 ! INVALID - wrong type (INTEGER). b = w1 ! INVALID - wrong enumeration type. Print *,a ! INVALID - list-directed i/o not available. End Program An enumeration type can be used to declare components, for example: Module example2 Use enumeration_mod Type vw Type(v_value) v Type(w_value) w End Type Contains Subroutine showme(ka) Type(vw),Intent(In) :: ka Print 1,ka 1 Format(1X,’v ordinal is ’,I0,’, w ordinal is ’,I0) End Subroutine

92

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) End Module

1 2 3

7.7

Binary, octal, and hexadecimal literal constants

1 A binary, octal, or hexadecimal constant (boz-literal-constant) is a sequence of digits that represents an ordered

sequence of bits. Such a constant has no type.

4 5 6

R772

boz-literal-constant

is binary-constant or octal-constant or hex-constant

7 8

R773

binary-constant

is B ’ digit [ digit ] ... ’ or B " digit [ digit ] ... "

9

C7117 (R773) digit shall have one of the values 0 or 1.

10 11

R774

12

C7118 (R774) digit shall have one of the values 0 through 7.

13 14

R775

hex-constant

is Z ’ hex-digit [ hex-digit ] ... ’ or Z " hex-digit [ hex-digit ] ... "

15 16 17 18

R776

hex-digit

is or or or or or or

octal-constant

19 20 21 22 23 24 25 26 27 28 29 30 31

is O ’ digit [ digit ] ... ’ or O " digit [ digit ] ... "

digit A B C D E F

2 The hex-digits A through F represent the numbers ten through fifteen, respectively; they may be represented

by their lower-case equivalents. Each digit of a boz-literal-constant represents a sequence of bits, according to its numerical interpretation, using the model of 16.3, with z equal to one for binary constants, three for octal constants or four for hexadecimal constants. A boz-literal-constant represents a sequence of bits that consists of the concatenation of the sequences of bits represented by its digits, in the order the digits are specified. The positions of bits in the sequence are numbered from right to left, with the position of the rightmost bit being zero. The length of a sequence of bits is the number of bits in the sequence. The processor shall allow the position of the leftmost nonzero bit to be at least z − 1, where z is the maximum value that could result from invoking the intrinsic function STORAGE_SIZE (16.9.200) with an argument that is a real or integer scalar of any kind supported by the processor.

36

C7119 (R772) A boz-literal-constant shall appear only as a data-stmt-constant in a DATA statement, as the initialization for a named constant or variable of type integer or real, as the expr in an intrinsic assignment whose variable is of type integer or real, as an ac-value in an array constructor with a type-spec that specifies type integer or real, as an output-item in an output statement, or where explicitly allowed in 16.9 as an actual argument of an intrinsic procedure.

37

7.8

32 33 34 35

38 39

Construction of array values

1 An array constructor constructs a rank-one array value from a sequence of scalar values, array values, and implied

DO loops.

ISO/IEC JTC 1/SC 22/WG5/N2184

93

J3/21-007r1

WD 1539-1

2021-05-21

1 2

R777

array-constructor

is (/ ac-spec /) or lbracket ac-spec rbracket

3 4

R778

ac-spec

is type-spec :: or [type-spec ::] ac-value-list

5

R779

lbracket

is

[

6

R780

rbracket

is

]

7 8

R781

ac-value

is expr or ac-implied-do

9

R782

ac-implied-do

is

( ac-value-list , ac-implied-do-control )

10 11

R783

ac-implied-do-control

is

[ integer-type-spec :: ] ac-do-variable = scalar-int-expr , scalar-int-expr [ , scalar-int-expr ]

12

R784

ac-do-variable

is

do-variable

13 14

C7120 (R778) If type-spec is omitted, each ac-value expression in the array-constructor shall have the same declared type and kind type parameters.

15 16 17

C7121 (R778) If type-spec specifies an intrinsic type or enum type, each ac-value expression in the arrayconstructor shall be of a type that is in type conformance with a variable of type type-spec as specified in Table 10.8, or be a boz-literal-constant.

18 19 20

C7122 (R778) If type-spec specifies a derived type, the declared type of each ac-value expression in the arrayconstructor shall be that derived type and shall have the same kind type parameter values as specified by type-spec.

21

C7123 (R778) If type-spec specifies an enumeration type, each ac-value shall be of that type.

22

C7124 (R781) An ac-value shall not be unlimited polymorphic.

23

C7125 (R781) The declared type of an ac-value shall not be abstract.

24

C7126 If an ac-value is a boz-literal-constant, type-spec shall appear and shall specify type integer or real.

25 26

C7127 If an ac-value is a boz-literal-constant and type-spec specifies type real, the boz-literal-constant shall be a valid internal representation for the specified kind of real.

27 28

C7128 (R782) The ac-do-variable of an ac-implied-do that is in another ac-implied-do shall not appear as the ac-do-variable of the containing ac-implied-do.

29

2 If type-spec is omitted, corresponding length type parameters of the declared type of each ac-value expression

30 31

shall have the same value; in this case, the declared type and type parameters of the array constructor are those of the ac-value expressions.

32 33 34 35

3 If type-spec appears, it specifies the declared type and type parameters of the array constructor. Each ac-value

36

4 The dynamic type of an array constructor is the same as its declared type.

37 38

5 The character length of an ac-value in an ac-implied-do whose iteration count is zero shall not depend on the

39 40

6 If an ac-value is a scalar expression, its value specifies an element of the array constructor. If an ac-value is

expression in the array-constructor shall be compatible with intrinsic assignment to a variable of this type and type parameters. Each value is converted to the type and type parameters of the array-constructor in accordance with the rules of intrinsic assignment (10.2.1.3).

value of the ac-do-variable and shall not depend on the value of an expression that is not a constant expression. an array expression, the values of the elements of the expression, in array element order (9.5.3.3), specify the

94

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

corresponding sequence of elements of the array constructor. If an ac-value is an ac-implied-do, it is expanded to form a sequence of elements under the control of the ac-do-variable, as in the DO construct (11.1.7.4).

3 4

7 For an ac-implied-do, the loop initialization and execution is the same as for a DO construct. The scope and

5

8 An empty sequence forms a zero-sized array.

attributes of an ac-do-variable are described in 19.4.

NOTE 1 A one-dimensional array can be reshaped into any allowable array shape using the intrinsic function RESHAPE (16.9.175). An example is: X = (/ 3.2, 4.01, 6.5 /) Y = RESHAPE (SOURCE = [ 2.0, [ 4.5, 4.5 ], X ], SHAPE = [ 3, 2 ]) This results in Y having the 3 × 2 array of values: 2.0 4.5 4.5

3.2 4.01 6.5

NOTE 2 Examples of array constructors containing an implied DO are: (/ (I, I = 1, 1075) /) and [ 3.6, (3.6 / I, I = 1, N) ]

NOTE 3 Using the type definition for PERSON in 7.5.2.1, NOTE 1, an example of the construction of a derived-type array value is: [ PERSON (40, ’SMITH’), PERSON (20, ’JONES’) ] NOTE 4 Using the type definition for LINE in 7.5.4.2, NOTE 1, an example of the construction of a derived-type scalar value with a rank-two array component is: LINE (RESHAPE ( [ 0.0, 0.0, 1.0, 2.0 ], [ 2, 2 ] ), 0.1, 1) The intrinsic function RESHAPE is used to construct a value that represents a solid line from (0, 0) to (1, 2) of width 0.1 centimeters. NOTE 5 Examples of zero-size array constructors are: [ INTEGER :: ] [ ( I, I = 1, 0) ] NOTE 6 An example of an array constructor that specifies a length type parameter: [ CHARACTER(LEN=7) :: ’Takata’, ’Tanaka’, ’Hayashi’ ]

ISO/IEC JTC 1/SC 22/WG5/N2184

95

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 6 (cont.) In this constructor, without the type specification, it would have been necessary to specify all of the constants with the same character length.

96

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

8 Attribute declarations and specifications

2

8.1

3 4 5 6 7

J3/21-007r1

Attributes of procedures and data objects

1 Every data object has a type and rank and can have type parameters and other properties that determine the

uses of the object. Collectively, these properties are the attributes of the object. The declared type of a named data object is either specified explicitly in a type declaration statement or determined implicitly by the first letter of its name (8.7). The attributes listed in 8.5 can be specified in a type declaration statement or individually in separate specification statements.

8 9

2 A function has a type and rank and can have type parameters and other attributes that determine the uses of

10 11

3 A subroutine does not have a type, rank, or type parameters, but can have other attributes that determine the

the function. The type, rank, and type parameters are the same as those of the function result. uses of the subroutine.

12

8.2

Type declaration statement

13

R801

type-declaration-stmt

14 15 16

is

declaration-type-spec [ [ , attr-spec ] ... :: ] entity-decl-list

1 The type declaration statement specifies the declared type of the entities in the entity declaration list. The type

and type parameters are those specified by declaration-type-spec, except that the character length type parameter can be overridden for an entity by the appearance of * char-length in its entity-decl. is or or or or or or or or or or or or or or or or or or

R802

attr-spec

37

C801

(R801) The same attr-spec shall not appear more than once in a given type-declaration-stmt.

38 39

C802

(R801) If a language-binding-spec with a NAME= specifier appears, the entity-decl-list shall consist of a single entity-decl.

40

C803

(R801) If a language-binding-spec is specified, the entity-decl-list shall not contain any procedure names.

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

access-spec ALLOCATABLE ASYNCHRONOUS CODIMENSION lbracket coarray-spec rbracket CONTIGUOUS DIMENSION ( array-spec ) EXTERNAL INTENT ( intent-spec ) INTRINSIC language-binding-spec OPTIONAL PARAMETER POINTER PROTECTED rank-clause SAVE TARGET VALUE VOLATILE

ISO/IEC JTC 1/SC 22/WG5/N2184

97

J3/21-007r1

1 2 3 4

WD 1539-1

2021-05-21

2 The type declaration statement also specifies the attributes whose keywords appear in the attr-spec, except that

the DIMENSION attribute can be specified or overridden for an entity by the appearance of array-spec in its entity-decl, and the CODIMENSION attribute can be specified or overridden for an entity by the appearance of coarray-spec in its entity-decl. is

5 6 7 8

R803

entity-decl

9

C804

(R803) If the entity is not of type character, * char-length shall not appear.

10

C805

A type-param-value in a char-length in an entity-decl shall be a colon, asterisk, or specification expression.

11

C806

(R801) If initialization appears, a double-colon separator shall appear before the entity-decl-list.

12

C807

(R801) If the PARAMETER keyword appears, initialization shall appear in each entity-decl.

13 14 15

C808

(R803) An initialization shall not appear if object-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable variable, or an automatic data object.

16 17

C809

(R803) The function-name shall be the name of an external function, an intrinsic function, a dummy function, a procedure pointer, or a statement function.

18

R804

object-name

19

C810

(R804) The object-name shall be the name of a data object.

20 21 22

R805

initialization

is = constant-expr or => null-init or => initial-data-target

23

R806

null-init

is

24 25

C811

(R803) If => appears in initialization, the entity shall have the POINTER attribute. If = appears in initialization, the entity shall not have the POINTER attribute.

26 27

C812

(R803) If initial-data-target appears, object-name shall be data-pointer-initialization compatible with it (7.5.4.6).

28

C813

(R806) The function-reference shall be a reference to the intrinsic function NULL with no arguments.

29 30 31 32 33 34 35 36

object-name [ ( array-spec ) ] [ lbracket coarray-spec rbracket ] [ * char-length ] [ initialization ] or function-name [ * char-length ]

is

name

function-reference

3 A name that identifies a specific intrinsic function has a type as specified in 16.8. An explicit type declaration statement is not required; however, it is permitted.

Specifying a type for a generic intrinsic function name in a type declaration

statement has no effect. 4 If initialization appears for a nonpointer entity,

• its type and type parameters shall conform as specified for intrinsic assignment (10.2.1.2); • if the entity has implied shape, the rank of initialization shall be the same as the rank of the entity; • if the entity does not have implied shape, initialization shall either be scalar or have the same shape as the entity. NOTE 1 Examples of type declaration statements: REAL A (10) LOGICAL, DIMENSION (5, 5) :: MASK1, MASK2 COMPLEX :: CUBE_ROOT = (-0.5, 0.866)

98

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) INTEGER, PARAMETER :: SHORT = SELECTED_INT_KIND (4) INTEGER (SHORT) K ! Range at least -9999 to 9999. TYPEOF (K) K_TMP ! Also has range at least -9999 to 9999. REAL (KIND (0.0D0)) B1 REAL (KIND = 2) B2 COMPLEX (KIND = KIND (0.0D0)) :: C CHARACTER (LEN = 10, KIND = 2) TEXT2 CHARACTER CHAR, STRING *20 TYPE (PERSON) :: CHAIRMAN TYPE(NODE), POINTER :: HEAD => NULL ( ) TYPE (humongous_matrix (k=8, d=1000)) :: MAT CLASSOF (MAT), POINTER :: MAT_REF ! Same declared type and type parameters as MAT. (The last line above uses a type definition from 7.5.3.1, NOTE 1.)

1 2 3 4 5 6 7 8 9

10 11 12 13 14 15 16 17 18

8.3

Automatic data objects

1 An automatic data object is a nondummy data object with a type parameter or array bound that depends on

the value of a specification-expr that is not a constant expression. C814

An automatic data object shall not have the SAVE attribute.

2 If a type parameter in a declaration-type-spec or in a char-length in an entity-decl for a local variable of a

subprogram or BLOCK construct is defined by an expression that is not a constant expression, the type parameter value is established on entry to a procedure defined by the subprogram, or on execution of the BLOCK statement, and is not affected by any redefinition or undefinition of the variables in the expression during execution of the procedure or BLOCK construct.

8.4

Initialization

1 The appearance of initialization in an entity-decl for an entity without the PARAMETER attribute specifies that

the entity is a variable with explicit initialization. Explicit initialization alternatively may be specified in a DATA statement unless the variable is of a derived type for which default initialization is specified. If initialization is = constant-expr, the variable is initially defined with the value specified by the constant-expr; if necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type, type parameters, and shape with the variable. A variable, or part of a variable, shall not be explicitly initialized more than once in a program. If the variable is an array, it shall have its shape specified in either the type declaration statement or a previous attribute specification statement in the same scoping unit.

19 20

2 If null-init appears, the initial association status of the object is disassociated. If initial-data-target appears, the

21 22

3 Explicit initialization of a variable that is not in a common block implies the SAVE attribute, which may be confirmed

object is initially associated with the target. by explicit specification.

23

8.5

Attributes

24

8.5.1

Attribute specification

25 26 27

1 An attribute may be explicitly specified by an attr-spec in a type declaration statement or by an attribute

specification statement (8.6). The following constraints apply to attributes. C815

An entity shall not be explicitly given any attribute more than once in a scoping unit.

ISO/IEC JTC 1/SC 22/WG5/N2184

99

J3/21-007r1

WD 1539-1

2021-05-21

1

C816

An array-spec for a nonallocatable nonpointer function result shall be an explicit-shape-spec-list.

2

8.5.2

Accessibility attribute

3

1 The accessibility attribute specifies the accessibility of an entity via a particular identifier.

is PUBLIC or PRIVATE

4 5

R807

access-spec

6

C817

An access-spec shall appear only in the specification-part of a module.

7 8 9

2 An access-spec in a type declaration statement specifies the accessibility of the names of all the entities declared

10 11 12

3 An identifier that is specified in a module or is accessible in a module by use association has either the PUB-

13 14 15

4 The default accessibility attribute for a module is PUBLIC unless it has been changed by a PRIVATE statement.

by that statement. An access-spec in a derived-type-stmt specifies the accessibility of the derived type name. Accessibility can also be specified by an access-stmt. LIC attribute or PRIVATE attribute. An identifier whose accessibility is not explicitly specified has default accessibility (8.6.1). Only an identifier that has the PUBLIC attribute in that module is available to be accessed from that module by use association. NOTE 1 An identifier can only be accessed by use association if it has the PUBLIC attribute in the module from which it is accessed. It can nonetheless have the PRIVATE attribute in a module in which it is accessed by use association, and therefore not be available by use association from that module. NOTE 2 An example of an accessibility specification is: REAL, PRIVATE :: X, Y, Z

16 17

8.5.3

ALLOCATABLE attribute

1 A variable with the ALLOCATABLE attribute is a variable for which space is allocated during execution.

NOTE 1 Only variables and components can have the ALLOCATABLE attribute. The result of referencing a function whose result variable has the ALLOCATABLE attribute is a value that does not itself have the ALLOCATABLE attribute. 18

8.5.4

ASYNCHRONOUS attribute

19 20

1 An entity with the ASYNCHRONOUS attribute is a variable, and may be subject to asynchronous input/output

21

2 The base object of a variable shall have the ASYNCHRONOUS attribute in a scoping unit if

22 23 24 25

26 27

or asynchronous communication.

• the variable is a dummy argument or appears in an executable statement or specification expression in that scoping unit, and • any statement of the scoping unit is executed while the variable is a pending input/output storage sequence affector (12.6.2.5) or a pending communication affector (18.10.4). 3 Use of a variable in an asynchronous data transfer statement can imply the ASYNCHRONOUS attribute; see

12.6.2.5.

100

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6

WD 1539-1

J3/21-007r1

4 An object with the ASYNCHRONOUS attribute may be associated with an object that does not have the

ASYNCHRONOUS attribute, including by use (14.2.2) or host association (19.5.1.4). If an object that is not a local variable of a BLOCK construct is specified to have the ASYNCHRONOUS attribute in the specificationpart of the construct, the object has the attribute within the construct even if it does not have the attribute outside the construct. If an object has the ASYNCHRONOUS attribute, then all of its subobjects also have the ASYNCHRONOUS attribute. NOTE 1 The ASYNCHRONOUS attribute specifies the variables that might be associated with a pending input/output storage sequence (the actual memory locations on which asynchronous input/output is being performed) while the scoping unit is in execution. This information could be used by the compiler to disable certain code motion optimizations.

7 8 9

8.5.5

BIND attribute for data entities

1 The BIND attribute for a variable or common block specifies that it is capable of interoperating with a C variable

whose name has external linkage (18.9). is

10

R808

language-binding-spec

11

C818

An entity with the BIND attribute shall be a common block, variable, type, or procedure.

12

C819

A variable with the BIND attribute shall be declared in the specification part of a module.

13

C820

A variable with the BIND attribute shall be interoperable (18.3).

14

C821

Each variable of a common block with the BIND attribute shall be interoperable.

15 16

BIND (C [ , NAME = scalar-default-char-constant-expr ])

2 If the value of the scalar-default-char-constant-expr after discarding leading and trailing blanks has nonzero

length, it shall be valid as an identifier on the companion processor. NOTE 1 ISO/IEC 9899:2011 provides a facility for creating C identifiers whose characters are not restricted to the C basic character set. Such a C identifier is referred to as a universal character name (ISO/IEC 9899:2011, 6.4.3). The name of such a C identifier might include characters that are not part of the representation method used by the processor for default character. If so, the C entity cannot be referenced from Fortran.

17

3 The BIND attribute for a common block implies the SAVE attribute, which may be confirmed by explicit specification.

18

8.5.6

CODIMENSION attribute

19

8.5.6.1

General

20

1 The CODIMENSION attribute specifies that an entity is a coarray. The coarray-spec specifies its corank or

21

corank and cobounds.

22 23

R809

coarray-spec

24

C822

The sum of the rank and corank of an entity shall not exceed fifteen.

25

C823

A coarray shall be a component or a variable that is not a function result.

26

C824

A coarray shall not be of type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING (18.3.2), or of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV (16.10.2.34).

C825

An entity whose type has a coarray ultimate component shall not be a pointer, shall not be a coarray, and shall not be a function result.

27 28 29

is deferred-coshape-spec-list or explicit-coshape-spec

ISO/IEC JTC 1/SC 22/WG5/N2184

101

J3/21-007r1

1 2

C826

WD 1539-1

2021-05-21

A coarray or an object with a coarray ultimate component shall be an associate name, a dummy argument, or have the ALLOCATABLE or SAVE attribute.

NOTE 1 A coarray is permitted to be of a derived type with pointer or allocatable components. The target of such a pointer component is always on the same image as the pointer. NOTE 2 This requirement for the SAVE attribute has the effect that automatic coarrays are not permitted; for example, the coarray WORK in the following code fragment is not valid. SUBROUTINE SOLVE3(N,A,B) INTEGER :: N REAL :: A(N)[*], B(N) REAL :: WORK(N)[*] ! Not permitted If this were permitted, it would require an implicit synchronization on entry to the procedure. Explicit-shape coarrays that are declared in a subprogram and are not dummy arguments are required to have the SAVE attribute because otherwise they might be implemented as if they were automatic coarrays. NOTE 3 Examples of CODIMENSION attribute specifications are: REAL W(100,100)[0:2,*] ! Explicit-shape coarray REAL, CODIMENSION[*] :: X ! Scalar coarray REAL, CODIMENSION[3,*] :: Y(:) ! Assumed-shape coarray REAL, CODIMENSION[:],ALLOCATABLE :: Z(:,:) ! Allocatable coarray 3 4 5

8.5.6.2

Allocatable coarray

1 A coarray with the ALLOCATABLE attribute has a specified corank, but its cobounds are determined by

allocation or argument association. is

6

R810

deferred-coshape-spec

7

C827

A coarray with the ALLOCATABLE attribute shall have a coarray-spec that is a deferred-coshape-speclist.

8

:

9

2 The corank of an allocatable coarray is equal to the number of colons in its deferred-coshape-spec-list.

10 11

3 The cobounds of an unallocated allocatable coarray are undefined. No part of such a coarray shall be referenced

12

4 The cobounds of an allocated allocatable coarray are those specified when the coarray is allocated.

13

5 The cobounds of an allocatable coarray are unaffected by any subsequent redefinition or undefinition of the

or defined; however, the coarray may appear as an argument to an intrinsic inquiry function as specified in 16.1.

14

variables on which the cobounds’ expressions depend.

15

8.5.6.3

16 17

Explicit-coshape coarray

1 An explicit-coshape coarray is a named coarray that has its corank and cobounds declared by an explicit-coshape-

spec. is

18 19

R811

explicit-coshape-spec

20

C828

A nonallocatable coarray shall have a coarray-spec that is an explicit-coshape-spec.

102

[ [ lower-cobound : ] upper-cobound, ]... [ lower-cobound : ] *

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

2 The corank is equal to one plus the number of upper-cobounds.

2

R812

lower-cobound

is

specification-expr

3

R813

upper-cobound

is

specification-expr

4 5

C829

(R811) A lower-cobound or upper-cobound that is not a constant expression shall appear only in a subprogram, BLOCK construct, or interface body.

6 7 8 9 10

3 If an explicit-coshape coarray is a local variable of a subprogram or BLOCK construct and has cobounds that are

11

4 The values of each lower-cobound and upper-cobound determine the cobounds of the coarray along a particular

12 13 14

codimension. The cosubscript range of the coarray in that codimension is the set of integer values between and including the lower and upper cobounds. If the lower cobound is omitted, the default value is 1. The upper cobound shall not be less than the lower cobound.

15

8.5.7

CONTIGUOUS attribute

16 17

C830

An entity with the CONTIGUOUS attribute shall be an array pointer, an assumed-shape array, or an assumed-rank dummy data object.

not constant expressions, the cobounds are determined on entry to a procedure defined by the subprogram, or on execution of the BLOCK statement, by evaluating the cobounds expressions. The cobounds of such a coarray are unaffected by the redefinition or undefinition of any variable during execution of the procedure or BLOCK construct.

18 19

1 The CONTIGUOUS attribute specifies that an assumed-shape array is contiguous, that an array pointer can

20

2 An object is contiguous if it is

21 22 23 24 25 26 27 28 29 30 31

only be pointer associated with a contiguous target, or that an assumed-rank dummy data object is contiguous.

(1) (2) (3) (4) (5) (6) (7)

an object with the CONTIGUOUS attribute, a nonpointer whole array that is not assumed-shape, an assumed-shape array that is argument associated with an array that is contiguous, an assumed-rank dummy data object whose effective argument is contiguous, an array allocated by an ALLOCATE statement, a pointer associated with a contiguous target, or a nonzero-sized array section (9.5.3) provided that (a) (b) (c)

32 33 34

(d)

35 36

(e)

37

(f) (g)

38 39 40 41 42 43 44

its base object is contiguous, it does not have a vector subscript, the array element ordering of the elements of the section is the same as the array element ordering of those elements of the base object, in the array element ordering of the base object, every element of the base object that is not an element of the section either precedes every element of the section or follows every element of the section, if the array is of type character and a substring-range appears, the substring-range specifies all of the characters of the parent-string (9.4.1), only its final part-ref has nonzero rank, and it is not the real or imaginary part (9.4.4) of an array of type complex.

3 An object is not contiguous if it is an array subobject, and

• the object has two or more elements, • the elements of the object in array element order are not consecutive in the elements of the base object, • the object is not of type character with length zero, and • the object is not of a derived type that has no ultimate components other than zero-sized arrays and characters with length zero.

ISO/IEC JTC 1/SC 22/WG5/N2184

103

J3/21-007r1

1

WD 1539-1

2021-05-21

4 It is processor dependent whether any other object is contiguous.

NOTE 1 If a derived type has only one component that is not zero-sized, it is processor dependent whether a structure component of a contiguous array of that type is contiguous. That is, the derived type might contain padding on some processors. NOTE 2 The CONTIGUOUS attribute makes it easier for a processor to enable optimizations that depend on the memory layout of the object occupying a contiguous block of memory. Examples of CONTIGUOUS attribute specifications are: REAL, POINTER, CONTIGUOUS :: SPTR(:) REAL, CONTIGUOUS, DIMENSION(:,:) :: D NOTE 3 If an assumed-shape or assumed-rank dummy argument has the CONTIGUOUS attribute, there is no requirement for the actual argument to be contiguous. This is the same as for dummy arguments that have explicit shape or assumed size. The dummy argument will be contiguous even when the actual argument is not. 2

8.5.8

DIMENSION attribute

3

8.5.8.1

General

4 5

1 The DIMENSION attribute specifies that an entity is scalar, assumed-rank, or an array. An assumed-rank

6

dummy data object has the rank, shape, and size of its effective argument; otherwise, the rank or rank and shape is specified by its RANK clause or its array-spec.

7

R814

dimension-spec

is

DIMENSION ( array-spec )

8 9 10 11

R815

array-spec

is or or or or or or or or

explicit-shape-spec-list explicit-shape-bounds-spec assumed-shape-spec-list assumed-shape-bounds-spec deferred-shape-spec-list assumed-size-spec implied-shape-spec implied-shape-or-assumed-size-spec assumed-rank-spec

12 13 14 15 16

NOTE 1 The maximum rank of an entity is fifteen minus the corank. NOTE 2 Examples of DIMENSION attribute specifications are: SUBROUTINE EX (N, A, B) REAL, DIMENSION (N, 10) :: W ! Automatic explicit-shape array REAL, DIMENSION (SHAPE (W)) :: X ! Array with the same shape as W REAL, DIMENSION ([1, 2, 3] :: 10) :: Y ! Same as DIMENSION (1:10, 2:10, 3:10) REAL, DIMENSION (LBARRAY:UBARRAY) :: Z ! Upper/lower bounds provided by arrays REAL :: ZZ (LBARRAY+2:UBARRAY+2) ! Upper/lower bounds provided by arrays REAL A (:), B (0:) ! Assumed-shape arrays REAL C (LBARRAY:) ! Specified lower bounds, assumed shape

104

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) REAL, POINTER :: D (:, :) ! Array pointer REAL, DIMENSION (:), POINTER :: P ! Array pointer REAL, ALLOCATABLE, DIMENSION (:) :: E ! Allocatable array REAL, PARAMETER :: V(0:*) = [0.1, 1.1] ! Implied-shape array 1

8.5.8.2

Explicit-shape array

2

R816

explicit-shape-spec

is

[ lower-bound : ] upper-bound

3

R817

lower-bound

is

specification-expr

4

R818

upper-bound

is

specification-expr

5 6

R819

explicit-shape-bounds-spec

is [ explicit-bounds-expr : ] explicit-bounds-expr or lower-bound : explicit-bounds-expr or explicit-bounds-expr : upper-bound

8

R820

explicit-bounds-expr

is

9 10

C831

An explicit-shape-spec or explicit-shape-bounds-spec whose bounds are not constant expressions shall appear only in a subprogram, derived type definition, BLOCK construct, or interface body.

11

C832

If an explicit-shape-bounds-spec has two explicit-bounds-exprs, they shall have the same size.

12 13

C833

An explicit-bounds-expr shall be a restricted expression that is a rank one integer array with constant size.

7

int-expr

14 15 16

1 The rank of an entity declared with an explicit-shape-spec-list is equal to the number of explicit-shape-specs; the

17 18

2 The values of each lower-bound and upper-bound in an explicit-shape-spec determine the bounds along a particular

rank of an entity declared with an explicit-shape-bounds-spec is equal to the size of one of the explicit-bounds-exprs. If the rank of such an entity is nonzero, the entity is an explicit-shape array; otherwise, it is scalar. dimension and hence the extent in that dimension. If lower-bound is omitted, the lower bound is equal to one.

19

3 An explicit-bounds-expr that appears immediately before a colon specifies the lower bounds; otherwise, it specifies

20 21 22

the upper bounds. The first element specifies the bound for the first dimension, and so on. A lower-bound or upper-bound in an explicit-shape-bounds-spec specifies the bound for every dimension of the entity. If no lower bound is specified in an explicit-shape-bounds-spec, all the lower bounds are equal to one.

23 24 25

4 The value of a lower bound or an upper bound may be positive, negative, or zero. The subscript range of the

26 27 28 29 30

array in that dimension is the set of integer values between and including the lower and upper bounds, provided the upper bound is not less than the lower bound. If the upper bound is less than the lower bound, the range is empty, the extent in that dimension is zero, and the array is of zero size. 5 An explicit-shape array that is a named local variable of a subprogram or BLOCK construct may have bounds

31

that are not constant expressions. The bounds, and hence shape, are determined on entry to a procedure defined by the subprogram, or on execution of the BLOCK statement, by evaluating the bounds’ expressions. The bounds of such an array are unaffected by the redefinition or undefinition of any variable during execution of the procedure or BLOCK construct.

32

8.5.8.3

33 34 35

Assumed-shape array

1 An assumed-shape array is a nonallocatable nonpointer dummy argument array that takes its shape from its

effective argument. R821

assumed-shape-spec

is

[ lower-bound ] :

ISO/IEC JTC 1/SC 22/WG5/N2184

105

J3/21-007r1

1

R822

WD 1539-1

assumed-shape-bounds-spec is

2021-05-21

explicit-bounds-expr :

2 3 4

2 If the rank is not specified by a rank-clause, it is equal to the number of colons in the assumed-shape-spec-list,

5 6

3 If explicit-bounds-expr appears it specifies the lower bounds for every dimension; otherwise, if lower-bound appears

7 8 9

4 The extent of a dimension of an assumed-shape array dummy argument is the extent of the corresponding

10 11 12

or the size of the explicit-bounds-expr in the assumed-shape-bounds-spec. If the rank is nonzero, the entity is an assumed-shape array; otherwise, it is scalar. it specifies the lower bound for that dimension; otherwise the lower bound is equal to one. dimension of its effective argument. If the lower bound value is d and the extent of the corresponding dimension of its effective argument is s, then the value of the upper bound is s + d − 1. 8.5.8.4

Deferred-shape array

1 A deferred-shape array is an allocatable array or an array pointer. (An allocatable array has the ALLOCATABLE

attribute; an array pointer has the POINTER attribute.) is

13

R823

deferred-shape-spec

:

14 15

C834

An array with the POINTER or ALLOCATABLE attribute shall be declared with a rank-clause or have an array-spec that is a deferred-shape-spec-list.

16

2 If the rank is not specified by a rank-clause, it is equal to the number of colons in the deferred-shape-spec-list.

17 18 19

3 The size, bounds, and shape of an unallocated allocatable array or a disassociated array pointer are undefined.

20 21

4 The bounds of each dimension of an allocated allocatable array are those specified when the array is allocated

22

5 The bounds of each dimension of an associated array pointer, and hence its shape, may be specified

No part of such an array shall be referenced or defined; however, the array may appear as an argument to an intrinsic inquiry function as specified in 16.1. or, if it is a dummy argument, when it is argument associated with an allocated effective argument.

25 26

• in an ALLOCATE statement (9.7.1) when the target is allocated, • by pointer assignment (10.2.2), or • if it is a dummy argument, by argument association with a nonpointer actual argument or an associated pointer effective argument.

27

6 The bounds of an array pointer or allocatable array are unaffected by any subsequent redefinition or undefinition

23 24

28

of variables on which the bounds’ expressions depend.

29

8.5.8.5

30 31 32

Assumed-size array

1 An assumed-size array is a dummy argument array whose size is assumed from that of its effective argument, or

33 34

the associate name of a RANK ( * ) block in a SELECT RANK construct. The rank and extents may differ for the effective and dummy arguments; only the size of the effective argument is assumed by the dummy argument. A dummy argument is declared to be an assumed-size array by an assumed-size-spec or an implied-shape-orassumed-size-spec.

35

R824

assumed-implied-spec

is

[ lower-bound : ] *

36

R825

assumed-size-spec

is

explicit-shape-spec-list, assumed-implied-spec

37

C835

An object whose array bounds are specified by an assumed-size-spec shall be a dummy data object.

38

C836

An assumed-size array with the INTENT (OUT) attribute shall not be polymorphic, finalizable, of a type with an allocatable ultimate component, or of a type for which default initialization is specified.

39

106

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

is

J3/21-007r1

1

R826

implied-shape-or-assumed-size-spec

2 3

C837

An object whose array bounds are specified by an implied-shape-or-assumed-size-spec shall be a dummy data object or a named constant.

4 5 6 7 8 9 10 11 12 13 14 15 16

assumed-implied-spec

2 The size of an assumed-size array is determined as follows.

• If the effective argument associated with the assumed-size dummy array is an array of any type other than default character, the size is that of the effective argument. • If the actual argument corresponding to the assumed-size dummy array is an array element of any type other than default character with a subscript order value of r (9.5.3.3) in an array of size x, the size of the dummy array is x − r + 1. • If the actual argument is a default character array, default character array element, or a default character array element substring (9.4.1), and if it begins at character storage unit t of an array with c character storage units, the size of the dummy array is MAX (INT ((c − t + 1)/e), 0), where e is the length of an element in the dummy character array. • If the actual argument is a default character scalar that is not an array element or array element substring designator, the size of the dummy array is MAX (INT (l/e), 0), where e is the length of an element in the dummy character array and l is the length of the actual argument.

17

3 The rank is equal to one plus the number of explicit-shape-specs.

18 19

4 An assumed-size array has no upper bound in its last dimension and therefore has no extent in its last dimension

20 21 22

5 If a list of explicit-shape-specs appears, it specifies the bounds of the first rank−1 dimensions. If lower-bound

23

6 If an assumed-size array has bounds that are not constant expressions, the bounds are determined on entry to

24 25

the procedure. The bounds of such an array are unaffected by the redefinition or undefinition of any variable during execution of the procedure.

26

8.5.8.6

27 28 29

and no shape. An assumed-size array shall not appear in a context that requires its shape. appears it specifies the lower bound of the last dimension; otherwise that lower bound is 1. An assumed-size array can be subscripted or sectioned (9.5.3).

Implied-shape array

1 An implied-shape array is a named constant that takes its shape from the constant-expr in its declaration. A

named constant is declared to be an implied-shape array with an array-spec that is an implied-shape-or-assumedsize-spec or an implied-shape-spec. is

30

R827

implied-shape-spec

assumed-implied-spec, assumed-implied-spec-list

31

C838

An implied-shape array shall be a named constant.

32

2 The rank of an implied-shape array is the number of assumed-implied-specs in its array-spec.

33 34 35

3 The extent of each dimension of an implied-shape array is the same as the extent of the corresponding dimension

36 37 38 39 40 41

of the constant-expr. The lower bound of each dimension is lower-bound, if it appears, and 1 otherwise; the upper bound is one less than the sum of the lower bound and the extent. 8.5.8.7

Assumed-rank entity

1 An assumed-rank entity is a dummy data object whose rank is assumed from its effective argument, or the

associate name of a RANK DEFAULT block in a SELECT RANK construct; this rank can be zero. The bounds and shape of an assumed-rank entity with the ALLOCATABLE or POINTER attribute are determined as specified in 8.5.8.4. An assumed-rank entity is declared with an array-spec that is an assumed-rank-spec. R828

assumed-rank-spec

is

..

ISO/IEC JTC 1/SC 22/WG5/N2184

107

J3/21-007r1

WD 1539-1

2021-05-21

1 2

C839

An assumed-rank entity shall be an associate name or a dummy data object that does not have the CODIMENSION or VALUE attribute.

3 4

C840

An assumed-rank variable name shall not appear in a designator or expression except as an actual argument that corresponds to a dummy argument that is assumed-rank, the argument of the function C_LOC or C_SIZEOF from the intrinsic module ISO_C_BINDING (18.2), the first dummy argument of an intrinsic inquiry function, or the selector of a SELECT RANK statement.

7 8 9 10

C841

If an assumed-size or nonallocatable nonpointer assumed-rank array is an actual argument that corresponds to a dummy argument that is an INTENT (OUT) assumed-rank array, it shall not be polymorphic, finalizable, of a type with an allocatable ultimate component, or of a type for which default initialization is specified.

11

8.5.9

EXTERNAL attribute

5 6

12 13

1 The EXTERNAL attribute specifies that an entity is an external procedure, dummy procedure, procedure pointer, or block data program unit.

14

C842

An entity shall not have both the EXTERNAL attribute and the INTRINSIC attribute.

15 16

C843

In an external subprogram, the EXTERNAL attribute shall not be specified for a procedure defined by the subprogram.

17 18

C844

In an interface body, the EXTERNAL attribute shall not be specified for the procedure declared by the interface body.

19 20

2 If an external procedure or dummy procedure is used as an actual argument or is the target of a procedure pointer

assignment, it shall be declared to have the EXTERNAL attribute. NOTE 1 The EXTERNAL attribute can be specified in a type declaration statement, by an interface body (15.4.3.2), by an EXTERNAL statement (15.4.3.5), or by a procedure declaration statement (15.4.3.6).

21 22 23 24 25

8.5.10

INTENT attribute

1 The INTENT attribute specifies the intended use of a dummy argument. An INTENT (IN) dummy argument

is suitable for receiving data from the invoking scoping unit, an INTENT (OUT) dummy argument is suitable for returning data to the invoking scoping unit, and an INTENT (INOUT) dummy argument is suitable for use both to receive data from and to return data to the invoking scoping unit. is IN or OUT or INOUT

26 27 28

R829

intent-spec

29

C845

An entity with the INTENT attribute shall be a dummy data object or a dummy procedure pointer.

30 31

C846

(R829) A nonpointer object with the INTENT (IN) attribute shall not appear in a variable definition context (19.6.7).

32

C847

A pointer with the INTENT (IN) attribute shall not appear in a pointer association context (19.6.8).

33 34

C848

An INTENT (OUT) dummy argument of a nonintrinsic procedure shall not be an allocatable coarray or have a subobject that is an allocatable coarray.

35

C849

An entity with the INTENT (OUT) attribute shall not be of, or have a subcomponent of, type EVENT_TYPE (16.10.2.10), LOCK_TYPE (16.10.2.19), or NOTIFY_TYPE (16.10.2.22) from the intrinsic module ISO_FORTRAN_ENV.

36 37

108

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

WD 1539-1

J3/21-007r1

2 The INTENT (IN) attribute for a nonpointer dummy argument specifies that it shall neither be defined nor

become undefined during the invocation and execution of the procedure. The INTENT (IN) attribute for a pointer dummy argument specifies that during the invocation and execution of the procedure its association shall not be changed except that it may become undefined if the target is deallocated other than through the pointer (19.5.2.5). 3 The INTENT (OUT) attribute for a nonpointer dummy argument specifies that the dummy argument becomes

undefined on invocation of the procedure, except for any subcomponents that are default-initialized (7.5.4.6). Any actual argument that corresponds to such a dummy argument shall be definable. The INTENT (OUT) attribute for a pointer dummy argument specifies that on invocation of the procedure the pointer association status of the dummy argument becomes undefined. Any actual argument that corresponds to such a pointer dummy shall be a pointer variable or a procedure pointer that is not the result of a function reference. Any undefinition or definition implied by association of an actual argument with an INTENT (OUT) dummy argument shall not affect any other entity within the statement that invokes the procedure. 4 The INTENT (INOUT) attribute for a nonpointer dummy argument specifies that any actual argument that

corresponds to the dummy argument shall be definable. The INTENT (INOUT) attribute for a pointer dummy argument specifies that any actual argument that corresponds to the dummy argument shall be a pointer variable or a procedure pointer that is not the result of a function reference. NOTE 1 The INTENT attribute for an allocatable dummy argument applies to both the allocation status and the definition status. An actual argument that corresponds to an INTENT (OUT) allocatable dummy argument is deallocated on procedure invocation (9.7.3.2). To avoid this deallocation for coarrays, INTENT (OUT) is not allowed for a dummy argument that is an allocatable coarray or has a subobject that is an allocatable coarray.

18 19

5 If no INTENT attribute is specified for a dummy argument, its use is subject to the limitations of its effective

20

6 If a nonpointer object has an INTENT attribute, then all of its subobjects have the same INTENT attribute.

argument (15.5.2).

NOTE 2 An example of INTENT specification is: SUBROUTINE MOVE (FROM, TO) TYPE (PERSON), INTENT (IN) :: FROM TYPE (PERSON), INTENT (OUT) :: TO NOTE 3 If a dummy argument is a nonpointer derived-type object with a pointer component, then the pointer as a pointer is a subobject of the dummy argument, but the target of the pointer is not. Therefore, the restrictions on subobjects of the dummy argument apply to the pointer in contexts where it is used as a pointer, but not in contexts where it is dereferenced to indicate its target. For example, if X is a nonpointer dummy argument of derived type with an integer pointer component P, and X is INTENT (IN), then the statement X%P => NEW_TARGET is prohibited, but X%P = 0 is allowed (provided that X%P is associated with a definable target). Similarly, the INTENT restrictions on pointer dummy arguments apply only to the association of the dummy argument; they do not restrict the operations allowed on its target.

ISO/IEC JTC 1/SC 22/WG5/N2184

109

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 4 Argument intent specifications serve several purposes in addition to documenting the intended use of dummy arguments. A processor can check whether an INTENT (IN) dummy argument is used in a way that could redefine it. A slightly more sophisticated processor could check to see whether an INTENT (OUT) dummy argument could possibly be referenced before it is defined. If the procedure’s interface is explicit, the processor can also verify that actual arguments corresponding to INTENT (OUT) or INTENT (INOUT) dummy arguments are definable. A more sophisticated processor could use this information to optimize the translation of the referencing scoping unit by taking advantage of the fact that actual arguments corresponding to INTENT (IN) dummy arguments will not be changed and that any prior value of an actual argument corresponding to an INTENT (OUT) dummy argument will not be referenced and could thus be discarded. INTENT (OUT) means that the value of the argument after invoking the procedure is entirely the result of executing that procedure. If an argument might not be redefined and it is desired to have the argument retain its value in that case, INTENT (OUT) cannot be used because it would cause the argument to become undefined; however, INTENT (INOUT) can be used, even if there is no explicit reference to the value of the dummy argument. INTENT (INOUT) is not equivalent to omitting the INTENT attribute. The actual argument corresponding to an INTENT (INOUT) dummy argument is always required to be definable, while an actual argument corresponding to a dummy argument without an INTENT attribute need be definable only if the dummy argument is actually redefined. 1

8.5.11

INTRINSIC attribute

2 3

1 The INTRINSIC attribute specifies that the entity is an intrinsic procedure. The procedure name may be a

4

2 If the specific name of an intrinsic procedure (16.8) is used as an actual argument, the name shall be explicitly specified to have the

5 6

INTRINSIC attribute. Note that a specific intrinsic procedure listed in Table 16.3 is not permitted to be used as an actual argument (C1534).

7 8 9 10

C850

11

8.5.12

12

generic name (16.7), a specific name (16.8), or both.

If the generic name of an intrinsic procedure is explicitly declared to have the INTRINSIC attribute, and it is also the generic name of one or more generic interfaces (15.4.3.2) accessible in the same scoping unit, the procedures in the interfaces and the generic intrinsic procedure shall all be functions or all be subroutines.

OPTIONAL attribute

1 The OPTIONAL attribute specifies that the dummy argument need not have an effective argument in a reference

13

to the procedure (15.5.2.12).

14

C851

An entity with the OPTIONAL attribute shall be a dummy argument.

NOTE 1 The intrinsic function PRESENT (16.9.163) can be used to determine whether an optional dummy argument has an associated effective argument. 15 16 17

8.5.13

PARAMETER attribute

1 The PARAMETER attribute specifies that an entity is a named constant. The entity has the value specified by

its constant-expr, converted, if necessary, to the type, type parameters and shape of the entity.

18

C852

An entity with the PARAMETER attribute shall not be a variable, a coarray, or a procedure.

19

C853

An expression that specifies a length type parameter or array bound of a named constant shall be a

110

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

J3/21-007r1

constant expression.

1 2 3

WD 1539-1

2 A named constant shall not be referenced unless it has been defined previously; it may be defined previously in

the same statement. NOTE 1 Examples of declarations with a PARAMETER attribute are: REAL, PARAMETER :: ONE = 1.0, Y = 4.1 / 3.0 INTEGER, DIMENSION (3), PARAMETER :: ORDER = (/ 1, 2, 3 /) TYPE(NODE), PARAMETER :: DEFAULT = NODE(0, NULL ( ))

4 5

8.5.14

POINTER attribute

1 Entities with the POINTER attribute can be associated with different data objects or procedures during execution

6

of a program. A pointer is either a data pointer or a procedure pointer.

7 8

C854

An entity with the POINTER attribute shall not have the ALLOCATABLE, INTRINSIC, or TARGET attribute, and shall not be a coarray.

9

C855

A named procedure with the POINTER attribute shall have the EXTERNAL attribute.

10 11

2 A data pointer shall not be referenced unless it is pointer associated with a target object that is defined. A data

12 13

3 If a data pointer is associated, the values of its deferred type parameters are the same as the values of the

14

4 A procedure pointer shall not be referenced unless it is pointer associated with a target procedure.

pointer shall not be defined unless it is pointer associated with a target object that is definable. corresponding type parameters of its target.

NOTE 1 Examples of POINTER attribute specifications are: TYPE (NODE), POINTER :: CURRENT, TAIL REAL, DIMENSION (:, :), POINTER :: IN, OUT, SWAP 15 16

8.5.15

PROTECTED attribute

1 The PROTECTED attribute imposes limitations on the usage of module entities.

17

C856

The PROTECTED attribute shall be specified only in the specification part of a module.

18

C857

An entity with the PROTECTED attribute shall be a procedure pointer or variable.

19

C858

An entity with the PROTECTED attribute shall not be in a common block.

20 21

C859

A nonpointer object that has the PROTECTED attribute and is accessed by use association shall not appear in a variable definition context (19.6.7) or as a data-target or initial-data-target.

22 23

C860

A pointer that has the PROTECTED attribute and is accessed by use association shall not appear in a pointer association context (19.6.8).

24 25

2 Other than within the module in which an entity is given the PROTECTED attribute, or within any of its

26

• if it is a nonpointer object, it is not definable, and • if it is a pointer, its association status shall not be changed except that it may become undefined if its target is deallocated other than through the pointer (19.5.2.5), or if its target becomes undefined by completing execution of a BLOCK construct or by execution of a RETURN or END statement.

27 28 29

descendants,

ISO/IEC JTC 1/SC 22/WG5/N2184

111

J3/21-007r1

1

WD 1539-1

2021-05-21

3 If an object has the PROTECTED attribute, all of its subobjects have the PROTECTED attribute.

NOTE 1 An example of the PROTECTED attribute: MODULE temperature REAL, PROTECTED :: temp_c, temp_f CONTAINS SUBROUTINE set_temperature_c(c) REAL, INTENT(IN) :: c temp_c = c temp_f = temp_c*(9.0/5.0) + 32 END SUBROUTINE END MODULE The PROTECTED attribute ensures that the variables temp_c and temp_f cannot be modified other than via the set_temperature_c procedure, thus keeping them consistent with each other. 2 3 4 5 6

8.5.16

SAVE attribute

1 The SAVE attribute specifies that a local variable of a program unit or subprogram retains its association status,

allocation status, definition status, and value after execution of a RETURN or END statement unless it is a pointer and its target becomes undefined (19.5.2.5(6)). If it is a local variable of a subprogram it is shared by all instances (15.6.2.4) of the subprogram.

7 8 9 10

2 The SAVE attribute specifies that a local variable of a BLOCK construct retains its association status, allocation

11

3 Giving a common block the SAVE attribute confers the attribute on all entities in the common block.

status, definition status, and value after termination of the construct unless it is a pointer and its target becomes undefined (19.5.2.5(7)). If the BLOCK construct is within a subprogram the variable is shared by all instances (15.6.2.4) of the subprogram.

12

C861

An entity with the SAVE attribute shall be a common block, variable, or procedure pointer.

13 14

C862

The SAVE attribute shall not be specified for a dummy argument, a function result, an automatic data object, or an object that is in a common block.

15 16 17

4 A variable, common block, or procedure pointer declared in the scoping unit of a main program, module, or

submodule implicitly has the SAVE attribute, which may be confirmed by explicit specification. If a common block has the SAVE attribute in any other kind of scoping unit, it shall have the SAVE attribute in every scoping unit that is not of a

18

main program, module, or submodule.

19

8.5.17

20

RANK clause

1 The RANK clause specifies the DIMENSION attribute.

is

21

R830

rank-clause

RANK ( scalar-int-constant-expr )

22 23

C863

The scalar-int-constant-expr in a rank-clause shall be nonnegative with a value less than or equal to the maximum array rank supported by the processor.

24 25

C864

An entity declared with a rank-clause shall be a dummy data object or have the ALLOCATABLE or POINTER attribute.

26

2 An entity declared with a RANK clause has the specified rank. If the rank is zero the entity is scalar; otherwise,

27 28

if it has the ALLOCATABLE or POINTER attribute, it specifies that it is a deferred-shape array; otherwise, it specifies that it is an assumed-shape array with all the lower bounds equal to one.

112

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 Examples of RANK specifications are: INTEGER :: X0(10,10,10) LOGICAL, RANK(RANK(X0)), ALLOCATABLE :: X1 ! Rank 3, deferred shape COMPLEX, RANK(2), POINTER :: X2 ! Rank 2, deferred-shape LOGICAL, RANK(RANK(X0) :: X3 ! Rank 3, assumed-shape (dummy) REAL, RANK(0) :: X4 ! Scalar dummy

1 2 3

8.5.18

TARGET attribute

1 The TARGET attribute specifies that a data object may have a pointer associated with it (10.2.2). An object

without the TARGET attribute shall not have a pointer associated with it.

4

C865

An entity with the TARGET attribute shall be a variable.

5

C866

An entity with the TARGET attribute shall not have the POINTER attribute.

6

2 If an object has the TARGET attribute, then all of its nonpointer subobjects also have the TARGET attribute.

NOTE 1 In addition to variables explicitly declared to have the TARGET attribute, the objects created by allocation of pointers (9.7.1.4) have the TARGET attribute. NOTE 2 Examples of TARGET attribute specifications are: TYPE (NODE), TARGET :: HEAD REAL, DIMENSION (1000, 1000), TARGET :: A, B NOTE 3 Every object designator that starts from an object with the TARGET attribute will have either the TARGET or POINTER attribute. If pointers are involved, the designator might not necessarily be a subobject of the original object, but because a pointer can point only to an entity with the TARGET attribute, there is no way to end up at a nonpointer that does not have the TARGET attribute. 7 8

8.5.19

VALUE attribute

1 The VALUE attribute specifies a type of argument association (15.5.2.4) for a dummy argument.

C867

An entity with the VALUE attribute shall be a dummy data object. It shall not be an assumed-size array, a coarray, or a variable with a coarray ultimate component.

11 12

C868

An entity with the VALUE attribute shall not have the ALLOCATABLE, INTENT (INOUT), INTENT (OUT), POINTER, or VOLATILE attributes.

13 14

C869

A dummy argument of a procedure with the BIND attribute shall not have both the OPTIONAL and VALUE attributes.

15

8.5.20

9 10

16 17 18 19 20

VOLATILE attribute

1 The VOLATILE attribute specifies that an object may be referenced, defined, or become undefined, by means

not specified by the program. A pointer with the VOLATILE attribute may additionally have its association status, dynamic type and type parameters, and array bounds changed by means not specified by the program. An allocatable object with the VOLATILE attribute may additionally have its allocation status, dynamic type and type parameters, and array bounds changed by means not specified by the program.

ISO/IEC JTC 1/SC 22/WG5/N2184

113

J3/21-007r1

WD 1539-1

2021-05-21

1 2

C870

An entity with the VOLATILE attribute shall be a variable that is not an INTENT (IN) dummy argument.

3 4

C871

The VOLATILE attribute shall not be specified for a coarray, or a variable with a coarray ultimate component, that is accessed by use (14.2.2) or host (19.5.1.4) association.

5 6

C872

Within a BLOCK construct (11.1.4), the VOLATILE attribute shall not be specified for a coarray, or a variable with a coarray ultimate component, that is not a construct entity (19.4) of that construct.

7 8 9 10 11 12 13 14 15 16 17

2 A noncoarray object that has the VOLATILE attribute may be associated with an object that does not have

the VOLATILE attribute, including by use (14.2.2) or host association (19.5.1.4). If an object that is not a local variable of a BLOCK construct is specified to have the VOLATILE attribute in the specification-part of the construct, the object has the attribute within the construct even if it does not have the attribute outside the construct. The relationship between coarrays, the VOLATILE attribute, and argument association is described in 15.5.2.8. The relationship between between coarrays, the VOLATILE attribute, and pointer association is described in 10.2.2.3. 3 A pointer should have the VOLATILE attribute if its target has the VOLATILE attribute. If, by means not

specified by the program, the target is referenced, defined, or becomes undefined, the pointer shall have the VOLATILE attribute. All members of an EQUIVALENCE group should have the VOLATILE attribute if any member has the VOLATILE attribute.

18

4 If an object has the VOLATILE attribute, then all of its subobjects also have the VOLATILE attribute.

19 20 21

5 The Fortran processor should use the most recent definition of a volatile object each time its value is required.

When a volatile object is defined by means of Fortran, it should make that definition available to the non-Fortran parts of the program as soon as possible.

22

8.6

Attribute specification statements

23

8.6.1

Accessibility statement

24

R831

access-stmt

is

25 26

R832

access-id

is access-name or generic-spec

27 28

C873

(R831) An access-stmt shall appear only in the specification-part of a module. Only one accessibility statement with an omitted access-id-list is permitted in the specification-part of a module.

29 30

C874

(R832) Each access-name shall be the name of a module, variable, procedure, derived type, named constant, or namelist group.

31 32

C875

A module whose name appears in an access-stmt shall be referenced by a USE statement in the scoping unit that contains the access-stmt.

33

C876

The name of a module shall appear at most once in all of the access-stmts in a module.

34 35 36 37 38 39 40 41 42 43

access-spec [ [ :: ] access-id-list ]

1 An access-stmt with an access-id-list specifies the accessibility attribute, PUBLIC or PRIVATE, of each access-id

in the list that is not a module name. An access-stmt without an access-id list specifies the default accessibility of the identifiers of entities declared in the module, and of entities accessed from a module whose name does not appear in any access-stmt in the module. If an identifier is accessed from another module and also declared locally, it has the default accessibility of a locally declared identifier. The statement PUBLIC specifies a default of public accessibility. The statement PRIVATE specifies a default of private accessibility. If no such statement appears in a module, the default is public accessibility.

114

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

WD 1539-1

J3/21-007r1

2 If an identifier is accessed by use association and not declared in the module, and the name of every module

from which it is accessed appears in an access-stmt in the scoping unit, its default accessibility is PRIVATE if the access-spec in every such access-stmt is PRIVATE, or PUBLIC if the access-spec in any such access-stmt is PUBLIC. NOTE 1 Examples of accessibility statements are: MODULE EX PRIVATE PUBLIC :: A, B, C, ASSIGNMENT (=), OPERATOR (+) NOTE 2 The following is an example of using an accessibility statement on a module name. MODULE m2 USE m1 ! We want to use the types and procedures in m1, but we only want to ! re-export m_type from m1, and export our own procedures. PRIVATE m1 PUBLIC m_type . . . definitions for our own entities and module procedures. END MODULE

5

8.6.2

ALLOCATABLE statement

6

R833

allocatable-stmt

is

ALLOCATABLE [ :: ] allocatable-decl-list

7 8

R834

allocatable-decl

is

object-name [ ( array-spec ) ] [ lbracket coarray-spec rbracket ]

9

1 The ALLOCATABLE statement specifies the ALLOCATABLE attribute (8.5.3) for a list of objects.

NOTE 1 An example of an ALLOCATABLE statement is: REAL A, B (:), SCALAR ALLOCATABLE :: A (:, :), B, SCALAR

10

8.6.3

ASYNCHRONOUS statement

11

R835

asynchronous-stmt

12

is

ASYNCHRONOUS [ :: ] object-name-list

1 The ASYNCHRONOUS statement specifies the ASYNCHRONOUS attribute (8.5.4) for a list of objects.

13

8.6.4

BIND statement

14

R836

bind-stmt

is

language-binding-spec [ :: ] bind-entity-list

15 16

R837

bind-entity

is

entity-name

or

/ common-block-name /

17

C877

18 19

(R836) If the language-binding-spec has a NAME= specifier, the bind-entity-list shall consist of a single bind-entity.

1 The BIND statement specifies the BIND attribute for a list of variables and common blocks.

ISO/IEC JTC 1/SC 22/WG5/N2184

115

J3/21-007r1

WD 1539-1

1

8.6.5

CODIMENSION statement

2

R838

codimension-stmt

is

CODIMENSION [ :: ] codimension-decl-list

3

R839

codimension-decl

is

coarray-name lbracket coarray-spec rbracket

4

2021-05-21

1 The CODIMENSION statement specifies the CODIMENSION attribute (8.5.6) for a list of objects.

NOTE 1 An example of a CODIMENSION statement is: CODIMENSION a[*], b[3,*], c[:]

5

8.6.6

CONTIGUOUS statement

6

R840

contiguous-stmt

7

is

CONTIGUOUS [ :: ] object-name-list

1 The CONTIGUOUS statement specifies the CONTIGUOUS attribute (8.5.7) for a list of objects.

8

8.6.7

DATA statement

9

R841

data-stmt

is

DATA data-stmt-set [ [ , ] data-stmt-set ] ...

10

1 The DATA statement specifies explicit initialization (8.4).

11

2 If a nonpointer variable has default initialization, it shall not appear in a data-stmt-object-list.

12 13

3 A variable that appears in a DATA statement and has not been typed previously shall not appear in a sub-

14 15 16 17

sequent type declaration unless that declaration confirms the implicit typing. An array name, array section, or array element that appears in a DATA statement shall have had its array properties established by a previous specification statement. 4 Except for variables in named common blocks, a named variable has the SAVE attribute if any part of it is initialized

in a DATA statement, and this may be confirmed by explicit specification.

18

R842

data-stmt-set

is

19

R843

data-stmt-object

is variable or data-implied-do

21 22 23 24

R844

data-implied-do

is

25 26

R845

data-i-do-object

is array-element or scalar-structure-component or data-implied-do

28

R846

data-i-do-variable

is

29

C878

A data-stmt-object or data-i-do-object shall not be a coindexed variable.

30 31

C879

(R843) A data-stmt-object that is a variable shall be a designator. Each subscript, section subscript, substring starting point, and substring ending point in the variable shall be a constant expression.

32

C880

(R843) A variable whose designator appears as a data-stmt-object or a data-i-do-object shall not be a dummy argument, accessed by use or host association, in a named common block unless the DATA statement is in a block data program unit, in blank common, a function name, a function result name, an automatic data object, or an allocatable variable.

20

27

33 34 35

116

data-stmt-object-list / data-stmt-value-list /

( data-i-do-object-list , [ integer-type-spec :: ] data-i-do-variable = scalar-int-constant-expr , scalar-int-constant-expr [ , scalar-int-constant-expr ] )

do-variable

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

C881

(R843) A data-i-do-object or a variable that appears as a data-stmt-object shall not be an object designator in which a pointer appears other than as the entire rightmost part-ref .

3

C882

(R845) The array-element shall be a variable.

4

C883

(R845) The scalar-structure-component shall be a variable.

5

C884

(R845) The scalar-structure-component shall contain at least one part-ref that contains a subscript-list.

6 7 8

C885

(R845) In an array-element or scalar-structure-component that is a data-i-do-object, any subscript shall be a constant expression, and any primary within that subscript that is a data-i-do-variable shall be a DO variable of this data-implied-do or of a containing data-implied-do.

9

R847

data-stmt-value

is

10 11

R848

data-stmt-repeat

is scalar-int-constant or scalar-int-constant-subobject

12 13

C886

(R848) The data-stmt-repeat shall be positive or zero. If the data-stmt-repeat is a named constant, it shall have been defined previously.

14 15 16 17

R849

data-stmt-constant

23 24

C887

(R849) If a DATA statement constant value is a named constant or a structure constructor, the named constant or derived type shall have been defined previously.

25 26

C888

(R849) If a data-stmt-constant is a structure-constructor, enum-constructor, or enumeration-constructor, it shall be a constant expression.

27

R850

int-constant-subobject

28

C889

(R850) int-constant-subobject shall be of type integer.

29

R851

constant-subobject

30

C890

(R851) constant-subobject shall be a subobject of a constant.

31

C891

(R851) Any subscript, substring starting point, or substring ending point shall be a constant expression.

18 19 20 21 22

32 33 34 35 36 37 38 39 40

is or or or or or or or or

is

is

[ data-stmt-repeat * ] data-stmt-constant

scalar-constant scalar-constant-subobject signed-int-literal-constant signed-real-literal-constant null-init initial-data-target structure-constructor enum-constructor enumeration-constructor

constant-subobject

designator

5 The data-stmt-object-list is expanded to form a sequence of pointers and scalar variables, referred to as “sequence

of variables” in subsequent text. A nonpointer array whose unqualified name appears as a data-stmt-object or data-i-do-object is equivalent to a complete sequence of its array elements in array element order (9.5.3.3). An array section is equivalent to the sequence of its array elements in array element order. A data-implied-do is expanded to form a sequence of array elements and structure components, under the control of the data-i-dovariable, as in the DO construct (11.1.7.4). The scope and attributes of a data-i-do-variable are described in 19.4. 6 The data-stmt-value-list is expanded to form a sequence of data-stmt-constants. A data-stmt-repeat indicates the

41

number of times the following data-stmt-constant is to be included in the sequence; omission of a data-stmt-repeat has the effect of a repeat factor of 1.

42

7 A zero-sized array or a data-implied-do with an iteration count of zero contributes no variables to the expanded

ISO/IEC JTC 1/SC 22/WG5/N2184

117

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

sequence of variables, but a zero-length scalar character variable does contribute a variable to the expanded sequence. A data-stmt-constant with a repeat factor of zero contributes no data-stmt-constants to the expanded sequence of scalar data-stmt-constants.

4

8 The expanded sequences of variables and data-stmt-constants are in one-to-one correspondence. Each data-stmt-

5 6

constant specifies the initial value, initial data target, or null-init for the corresponding variable. The lengths of the two expanded sequences shall be the same.

7 8 9 10

9 A data-stmt-constant shall be null-init or initial-data-target if and only if the corresponding data-stmt-object has

11

the POINTER attribute. If data-stmt-constant is null-init, the initial association status of the corresponding data statement object is disassociated. If data-stmt-constant is initial-data-target the corresponding data statement object shall be data-pointer-initialization compatible (7.5.4.6) with the initial data target; the data statement object is initially associated with the target.

12 13 14 15

10 A data-stmt-constant other than boz-literal-constant, null-init, or initial-data-target shall be compatible with its

16

11 If a data-stmt-constant is a boz-literal-constant, the corresponding variable shall be of type integer. The boz-

17 18

literal-constant is treated as if it were converted by the intrinsic function INT (16.9.110) to type integer with the kind type parameter of the variable.

corresponding variable according to the rules of intrinsic assignment (10.2.1.2). The variable is initially defined with the value specified by the data-stmt-constant; if necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type, type parameters, and shape with the variable.

NOTE 1 Examples of DATA statements are: CHARACTER (LEN = 10) NAME INTEGER, DIMENSION (0:9) :: MILES REAL, DIMENSION (100, 100) :: SKEW TYPE (NODE), POINTER :: HEAD_OF_LIST TYPE (PERSON) MYNAME, YOURNAME DATA NAME / ’JOHN DOE’ /, MILES / 10 * 0 / DATA ((SKEW (K, J), J = 1, K), K = 1, 100) / 5050 * 0.0 / DATA ((SKEW (K, J), J = K + 1, 100), K = 1, 99) / 4950 * 1.0 / DATA HEAD_OF_LIST / NULL() / DATA MYNAME / PERSON (21, ’JOHN SMITH’) / DATA YOURNAME % AGE, YOURNAME % NAME / 35, ’FRED BROWN’ / The character variable NAME is initialized with the value JOHN DOE with padding on the right because the length of the constant is less than the length of the variable. All ten elements of the integer array MILES are initialized to zero. The two-dimensional array SKEW is initialized so that the lower triangle of SKEW is zero and the strict upper triangle is one. The structures MYNAME and YOURNAME are declared using the derived type PERSON from 7.5.2.1, NOTE 1. The pointer HEAD_OF_LIST is declared using the derived type NODE from 7.5.4.6, NOTE 4; it is initially disassociated. MYNAME is initialized by a structure constructor. YOURNAME is initialized by supplying a separate value for each component. 19

8.6.8

DIMENSION statement

20 21

R852

dimension-stmt

22

is

DIMENSION [ :: ] array-name ( array-spec ) [ , array-name ( array-spec ) ] ...

1 The DIMENSION statement specifies the DIMENSION attribute (8.5.8) for a list of objects.

NOTE 1 An example of a DIMENSION statement is: DIMENSION A (10), B (10, 70), C (:)

118

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

8.6.9

INTENT statement

2

R853

intent-stmt

3

is

J3/21-007r1

INTENT ( intent-spec ) [ :: ] dummy-arg-name-list

1 The INTENT statement specifies the INTENT attribute (8.5.10) for the dummy arguments in the list.

NOTE 1 An example of an INTENT statement is: SUBROUTINE EX (A, B) INTENT (INOUT) :: A, B

4

8.6.10

5

R854

6

OPTIONAL statement optional-stmt

is

OPTIONAL [ :: ] dummy-arg-name-list

1 The OPTIONAL statement specifies the OPTIONAL attribute (8.5.12) for the dummy arguments in the list.

NOTE 1 An example of an OPTIONAL statement is: SUBROUTINE EX (A, B) OPTIONAL :: B 7 8 9

8.6.11

PARAMETER statement

1 The PARAMETER statement specifies the PARAMETER attribute (8.5.13) and the values for the named con-

stants in the list.

10

R855

parameter-stmt

is

PARAMETER ( named-constant-def-list )

11

R856

named-constant-def

is

named-constant = constant-expr

12 13 14 15

2 If a named constant is defined by a PARAMETER statement, it shall not be subsequently declared to have a

16 17

3 The constant expression that corresponds to a named constant shall have type and type parameters that conform

18 19 20 21 22

type or type parameter value that differs from the type and type parameters it would have if declared implicitly (8.7). A named array constant defined by a PARAMETER statement shall have its rank specified in a prior specification statement. with the named constant as specified for intrinsic assignment (10.2.1.2). If the named constant has implied shape, the expression shall have the same rank as the named constant; otherwise, the expression shall either be scalar or have the same shape as the named constant. 4 The value of each named constant is that specified by the corresponding constant expression; if necessary, the

value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type, type parameters, and shape with the named constant. NOTE 1 An example of a PARAMETER statement is: PARAMETER (MODULUS = MOD (28, 3), NUMBER_OF_SENATORS = 100)

23

8.6.12

POINTER statement

24

R857

pointer-stmt

is

25 26

R858

pointer-decl

is object-name [ ( deferred-shape-spec-list ) ] or proc-entity-name

POINTER [ :: ] pointer-decl-list

ISO/IEC JTC 1/SC 22/WG5/N2184

119

J3/21-007r1

1 2

C892

WD 1539-1

2021-05-21

A proc-entity-name shall have the EXTERNAL attribute.

1 The POINTER statement specifies the POINTER attribute (8.5.14) for a list of entities.

NOTE 1 An example of a POINTER statement is: TYPE (NODE) :: CURRENT POINTER :: CURRENT, A (:, :)

3

8.6.13

4

R859

5

PROTECTED statement is

protected-stmt

PROTECTED [ :: ] entity-name-list

1 The PROTECTED statement specifies the PROTECTED attribute (8.5.15) for a list of entities.

6

8.6.14

7

R860

save-stmt

is

8 9 10

R861

saved-entity

is object-name or proc-pointer-name

11

R862

proc-pointer-name

12 13

C893

(R860) If a SAVE statement with an omitted saved entity list appears in a scoping unit, no other appearance of the SAVE attr-spec or SAVE statement is permitted in that scoping unit.

14

C894

A proc-pointer-name shall be the name of a procedure pointer.

15 16 17

SAVE statement SAVE [ [ :: ] saved-entity-list ]

or

/ common-block-name /

is

name

1 A SAVE statement with a saved entity list specifies the SAVE attribute (8.5.16) for a list of entities. A SAVE

statement without a saved entity list is treated as though it contained the names of all allowed items in the same scoping unit. NOTE 1 An example of a SAVE statement is: SAVE A, B, C, / BLOCKA /, D

18

8.6.15

19

R863

target-stmt

is

TARGET [ :: ] target-decl-list

20 21

R864

target-decl

is

object-name [ ( array-spec ) ] [ lbracket coarray-spec rbracket ]

22

TARGET statement

1 The TARGET statement specifies the TARGET attribute (8.5.18) for a list of objects.

NOTE 1 An example of a TARGET statement is: TARGET :: A (1000, 1000), B

23

8.6.16

24

R865

25

VALUE statement value-stmt

is

VALUE [ :: ] dummy-arg-name-list

1 The VALUE statement specifies the VALUE attribute (8.5.19) for a list of dummy arguments.

120

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

8.6.17

2

R866

3

4 5 6 7 8

WD 1539-1

J3/21-007r1

VOLATILE statement volatile-stmt

is

VOLATILE [ :: ] object-name-list

1 The VOLATILE statement specifies the VOLATILE attribute (8.5.20) for a list of objects.

8.7

IMPLICIT statement

1 In a scoping unit, an IMPLICIT statement specifies a type, and possibly type parameters, for all implicitly

typed data entities whose names begin with one of the letters specified in the statement. An IMPLICIT NONE statement can indicate that no implicit typing rules are to apply in a particular scoping unit, or that external and dummy procedures need to be explicitly given the EXTERNAL attribute. R867

implicit-stmt

is IMPLICIT implicit-spec-list or IMPLICIT NONE [ ( [ implicit-none-spec-list ] ) ]

11

R868

implicit-spec

is

declaration-type-spec ( letter-spec-list )

12

R869

letter-spec

is

letter [ – letter ]

13 14

R870

implicit-none-spec

is EXTERNAL or TYPE

15

C895

(R867) If an IMPLICIT NONE statement appears in a scoping unit, it shall precede any PARAMETER statements that appear in the scoping unit. No more than one IMPLICIT NONE statement shall appear in a scoping unit.

18

C896

The same implicit-none-spec shall not appear more than once in a given implicit-stmt.

19 20

C897

If an IMPLICIT NONE statement in a scoping unit has an implicit-none-spec of TYPE or has no implicitnone-spec-list, there shall be no other IMPLICIT statements in the scoping unit.

21

C898

(R869) If the minus and second letter appear, the second letter shall follow the first letter alphabetically.

22 23 24

C899

If IMPLICIT NONE with an implicit-none-spec of EXTERNAL appears within a scoping unit, the name of an external or dummy procedure in that scoping unit or in a contained subprogram or BLOCK construct shall have an explicit interface or be explicitly declared to have the EXTERNAL attribute.

9 10

16 17

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

2 A letter-spec consisting of two letters separated by a minus is equivalent to writing a list containing all of the letters

in alphabetical order in the alphabetic sequence from the first letter through the second letter. For example, A–C is equivalent to A, B, C. The same letter shall not appear as a single letter, or be included in a range of letters, more than once in all of the IMPLICIT statements in a scoping unit. 3 In each scoping unit, there is a mapping, which may be null, between each of the letters A, B, ..., Z and a

type (and type parameters). An IMPLICIT statement specifies the mapping for the letters in its letter-speclist. IMPLICIT NONE with an implicit-none-spec of TYPE or with no implicit-none-spec-list specifies the null mapping for all the letters. If a mapping is not specified for a letter, the default for a program unit or an interface body is default integer if the letter is I, J, ..., or N and default real otherwise, and the default for a BLOCK construct, internal subprogram, or module subprogram is the mapping in the host scoping unit. 4 Any data entity that is not explicitly declared by a type declaration statement, is not an intrinsic function, is

not a component, and is not accessed by use or host association is declared implicitly to be of the type (and type parameters) mapped from the first letter of its name, provided the mapping is not null. The mapping for the first letter of the data entity shall either have been established by a prior IMPLICIT statement or be the default mapping for the letter. An explicit type specification in a FUNCTION statement overrides an IMPLICIT statement for the result of that function.

ISO/IEC JTC 1/SC 22/WG5/N2184

121

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 The following are examples of the use of IMPLICIT statements: MODULE EXAMPLE_MODULE IMPLICIT NONE ... INTERFACE FUNCTION FUN (I) ! Not all data entities need to INTEGER FUN ! be declared explicitly END FUNCTION FUN END INTERFACE CONTAINS FUNCTION JFUN (J) ! All data entities need to INTEGER JFUN, J ! be declared explicitly. ... END FUNCTION JFUN END MODULE EXAMPLE_MODULE SUBROUTINE SUB IMPLICIT COMPLEX (C) C = (3.0, 2.0) ! C is implicitly declared COMPLEX ... CONTAINS SUBROUTINE SUB1 IMPLICIT INTEGER (A, C) C = (0.0, 0.0) ! C is host associated and of ! type complex Z = 1.0 ! Z is implicitly declared REAL A = 2 ! A is implicitly declared INTEGER CC = 1 ! CC is implicitly declared INTEGER ... END SUBROUTINE SUB1 SUBROUTINE SUB2 Z = 2.0 ! Z is implicitly declared REAL and ! is different from the variable of ! the same name in SUB1 ... END SUBROUTINE SUB2 SUBROUTINE SUB3 USE EXAMPLE_MODULE ! Accesses integer function FUN ! by use association Q = FUN (K) ! Q is implicitly declared REAL and ... ! K is implicitly declared INTEGER END SUBROUTINE SUB3 END SUBROUTINE SUB NOTE 2 The following is an example of a mapping to a derived type that is inaccessible in the local scope: PROGRAM MAIN IMPLICIT TYPE(BLOB) (A) TYPE BLOB INTEGER :: I END TYPE BLOB TYPE(BLOB) :: B CALL STEVE CONTAINS

122

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) SUBROUTINE STEVE INTEGER :: BLOB ... AA = B ... END SUBROUTINE STEVE END PROGRAM MAIN In the subroutine STEVE, it is not possible to explicitly declare a variable to be of type BLOB because BLOB has been given a different meaning, but implicit mapping for the letter A still maps to type BLOB, so AA is of type BLOB. NOTE 3 Implicit typing is not affected by BLOCK constructs. For example, in SUBROUTINE S(N) ... IF (N>0) THEN BLOCK NSQP = CEILING (SQRT (DBLE (N))) END BLOCK END IF ... IF (N>0) THEN BLOCK PRINT *,NSQP END BLOCK END IF END SUBROUTINE even if the only two appearances of NSQP are within the BLOCK constructs, the scope of NSQP is the whole subroutine S. NOTE 4 In the subprogram SUBROUTINE EXAMPLE (X, Y) IMPLICIT NONE (EXTERNAL) REAL, EXTERNAL :: G REAL :: X, Y X = F (Y) X = G (Y) END SUBROUTINE

! Invalid: F lacks the EXTERNAL attribute. ! Valid: G has the EXTERNAL attribute.

the referenced function F needs to have the EXTERNAL attribute (8.5.9).

1 2 3 4 5 6 7

8.8

IMPORT statement

R871

import-stmt

is or or or

IMPORT [[ :: ] import-name-list ] IMPORT, ONLY : import-name-list IMPORT, NONE IMPORT, ALL

C8100 (R871) An IMPORT statement shall not appear in the scoping unit of a main-program, externalsubprogram, module, or block-data .

ISO/IEC JTC 1/SC 22/WG5/N2184

123

J3/21-007r1

WD 1539-1

2021-05-21

1

C8101 (R871) Each import-name shall be the name of an entity in the host scoping unit.

2 3

C8102 If any IMPORT statement in a scoping unit has an ONLY specifier, all IMPORT statements in that scoping unit shall have an ONLY specifier.

4

C8103 IMPORT, NONE shall not appear in the scoping unit of a submodule.

5 6

C8104 If an IMPORT, NONE or IMPORT, ALL statement appears in a scoping unit, no other IMPORT statement shall appear in that scoping unit.

7 8

C8105 Within an interface body, an entity that is accessed by host association shall be accessible by host or use association within the host scoping unit, or explicitly declared prior to the interface body.

9 10 11

C8106 An entity whose name appears as an import-name or which is made accessible by an IMPORT, ALL statement shall not appear in any context described in 19.5.1.4 that would cause the host entity of that name to be inaccessible.

12 13 14 15 16

1 If the ONLY specifier appears on an IMPORT statement in a scoping unit other than a BLOCK construct,

17

2 An IMPORT, NONE statement in a scoping unit specifies that no entities in the host scoping unit are accessible

18 19 20

by host association in that scoping unit. This is the default for an interface body that is not a module procedure interface body. An IMPORT, NONE statement in a BLOCK construct specifies that the identifiers of local and construct entities in the host scoping unit are inaccessible in the BLOCK construct.

21 22

3 An IMPORT, ALL statement in a scoping unit specifies that all entities from the host scoping unit are accessible

23

4 If an IMPORT statement with no specifier and no import-name-list appears in a scoping unit, every entity in

24 25 26

the host scoping unit is accessible unless its name appears in a context described in 19.5.1.4 that causes it to be inaccessible. This is the default for a derived-type definition, internal subprogram, module procedure interface body, module subprogram, or submodule.

27 28

5 If an IMPORT statement with an import-name-list appears in a scoping unit other than a BLOCK construct,

an entity is only accessible by host association if its name appears as an import-name in that scoping unit. If a BLOCK construct contains one or more IMPORT statements with ONLY specifiers, identifiers of local and construct entities in the host scoping unit that are not in the import-name-list of at least one of the IMPORT statements are inaccessible in the BLOCK construct.

in that scoping unit.

each entity named in the list is accessible. NOTE 1 The IMPORT, NONE statement can be used to prevent accidental host association: SUBROUTINE s(x,n) IMPLICIT NONE IMPORT, NONE ... DO i=1,n ! Forces I to be locally declared. NOTE 2 The IMPORT, ALL statement can be used to prevent accidental “shadowing” of host entities: SUBROUTINE outer REAL x ... CONTAINS SUBROUTINE inner IMPORT, ALL ...

124

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) x = x + 1 ! There is a host X, so this must be the host X. NOTE 3 The IMPORT, ONLY statement can be used to document deliberate access via host association whilst blocking accidental access: SUBROUTINE sub IMPORT,ONLY : x, y ... x = y + z ! Only X and Y are imported, so Z is local. NOTE 4 The program PROGRAM MAIN BLOCK IMPORT, NONE !IMPORT, ONLY: X X = 1.0 END BLOCK END is not conformant. The variable X is implicitly declared in the scoping unit of the main program. The statement IMPORT, NONE makes X inaccessible in the BLOCK construct. If the IMPORT, NONE statement is replaced with the IMPORT statement in the comment, the program is conformant. NOTE 5 The IMPORT statement can be used to allow module procedures to have dummy arguments that are procedures with assumed-shape arguments of an opaque type. For example: MODULE M TYPE T PRIVATE ! T is an opaque type ... END TYPE CONTAINS SUBROUTINE PROCESS(X,Y,RESULT,MONITOR) TYPE(T),INTENT(IN) :: X(:,:),Y(:,:) TYPE(T),INTENT(OUT) :: RESULT(:,:) INTERFACE SUBROUTINE MONITOR(ITERATION_NUMBER,CURRENT_ESTIMATE) IMPORT T INTEGER,INTENT(IN) :: ITERATION_NUMBER TYPE(T),INTENT(IN) :: CURRENT_ESTIMATE(:,:) END SUBROUTINE END INTERFACE ... END SUBROUTINE END MODULE The MONITOR dummy procedure requires an explicit interface because it has an assumed-shape array argument, but TYPE(T) would not be available inside the interface body without the IMPORT statement.

ISO/IEC JTC 1/SC 22/WG5/N2184

125

J3/21-007r1

1 2 3 4 5

8.9

WD 1539-1

2021-05-21

NAMELIST statement

1 A NAMELIST statement specifies a group of named data objects, which can be referred to by a single name for

the purpose of data transfer (12.6, 13.11). R872

namelist-stmt

is

6 7

NAMELIST / namelist-group-name / namelist-group-object-list [ [ , ] / namelist-group-name / namelist-group-object-list ] . . .

8

C8107 (R872) The namelist-group-name shall not be a name accessed by use association.

9

R873

10

C8108 (R873) A namelist-group-object shall not be an assumed-size array.

11

C8109 A namelist-group-object shall not be of enumeration type, or have a direct component that is of enumeration type.

12

namelist-group-object

is

variable-name

13 14 15

2 The order in which the values appear on output is the same as the order of the namelist-group-objects in the

16 17

3 Any namelist-group-name may occur more than once in the NAMELIST statements in a scoping unit. The

18

namelist group object list; if a variable appears more than once as a namelist-group-object for the same namelist group, its value appears once for each occurrence. namelist-group-object-list following each successive appearance of the same namelist-group-name in a scoping unit is treated as a continuation of the list for that namelist-group-name.

19

4 A namelist group object may be a member of more than one namelist group.

20 21 22 23

5 A namelist group object shall either be accessed by use or host association or shall have its declared type, kind

24

type parameters of the declared type, and rank specified by previous specification statements or the procedure heading in the same scoping unit or by the implicit typing rules in effect for the scoping unit. If a namelist group object is typed by the implicit typing rules, its appearance in any subsequent type declaration statement shall confirm the implied type and type parameters. NOTE 1 An example of a NAMELIST statement is: NAMELIST /NLIST/ A, B, C

25

8.10

Storage association of data objects

26

8.10.1

EQUIVALENCE statement

27

8.10.1.1

General

28 29

1 An EQUIVALENCE statement is used to specify the sharing of storage units by two or more objects in a scoping unit. This causes

30 31 32

2 If the equivalenced objects have differing type or type parameters, the EQUIVALENCE statement does not cause type conversion or

storage association (19.5.3) of the objects that share the storage units.

imply mathematical equivalence. If a scalar and an array are equivalenced, the scalar does not have array properties and the array does not have the properties of a scalar.

33

R874

equivalence-stmt

is

EQUIVALENCE equivalence-set-list

34

R875

equivalence-set

is

( equivalence-object , equivalence-object-list )

35 36 37

R876

equivalence-object

is or or

variable-name array-element substring

126

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

C8110

(R876) An equivalence-object shall not be a designator with a base object that is a dummy argument, a function result, a pointer, an allocatable variable, a derived-type object that has an allocatable or pointer ultimate component, an object of a nonsequence derived type, an automatic data object, a coarray, a variable with the BIND attribute, a variable in a common block that has the BIND attribute, or a named constant.

5

C8111

(R876) An equivalence-object shall not be a designator that has more than one part-ref .

6

C8112

(R876) An equivalence-object shall not have the TARGET attribute.

7 8

C8113

(R876) Each subscript or substring range expression in an equivalence-object shall be an integer constant expression (10.1.12).

9 10

C8114

(R875) If an equivalence-object is default integer, default real, double precision real, default complex, default logical, or of numeric sequence type, all of the objects in the equivalence set shall be of these types and kinds.

11 12

C8115

(R875) If an equivalence-object is default character or of character sequence type, all of the objects in the equivalence set shall be of these types and kinds.

13 14

C8116

(R875) If an equivalence-object is of a sequence type that is not a numeric sequence or character sequence type, all of the objects in the equivalence set shall be of that type.

15 16 17

C8117

(R875) If an equivalence-object is of an intrinsic type but is not default integer, default real, double precision real, default complex, default logical, or default character, all of the objects in the equivalence set shall be of the same type with the same kind type parameter value.

18 19

C8118

(R876) If an equivalence-object has the PROTECTED attribute, all of the objects in the equivalence set shall have the PROTECTED attribute.

20

C8119

(R876) The name of an equivalence-object shall not be a name made accessible by use association.

21

C8120

(R876) A substring shall not have length zero.

NOTE 1 The EQUIVALENCE statement allows the equivalencing of sequence structures and the equivalencing of objects of intrinsic type with nondefault type parameters, but there are strict rules regarding the appearance of these objects in an EQUIVALENCE statement. In addition to the above constraints, further rules on the interaction of EQUIVALENCE statements and default initialization are given in 19.5.3.4.

22

8.10.1.2

Equivalence association

23 24 25 26 27

1 An EQUIVALENCE statement specifies that the storage sequences (19.5.3.2) of the data objects specified in an equivalence-set are

28 29

2 If any data object in an equivalence-set has the SAVE attribute, all other objects in the equivalence-set have the SAVE attribute;

30

storage associated. All of the nonzero-sized sequences in the equivalence-set, if any, have the same first storage unit, and all of the zero-sized sequences in the equivalence-set, if any, are storage associated with one another and with the first storage unit of any nonzero-sized sequences. This causes the storage association of the data objects in the equivalence-set and can cause storage association of other data objects. this may be confirmed by explicit specification.

8.10.1.3

Equivalence of default character objects

31 32

1 A default character data object shall not be equivalenced to an object that is not default character and not of a character sequence

33 34 35 36 37

2 An EQUIVALENCE statement specifies that the storage sequences of all the default character data objects specified in an equivalence-

type. The lengths of equivalenced default character objects need not be the same.

set are storage associated. All of the nonzero-sized sequences in the equivalence-set, if any, have the same first character storage unit, and all of the zero-sized sequences in the equivalence-set, if any, are storage associated with one another and with the first character storage unit of any nonzero-sized sequences. This causes the storage association of the data objects in the equivalence-set and can cause storage association of other data objects. NOTE 1 For example, using the declarations: CHARACTER (LEN = 4) :: A, B CHARACTER (LEN = 3) :: C (2) EQUIVALENCE (A, C (1)), (B, C (2)) the association of A, B, and C can be illustrated graphically as:

ISO/IEC JTC 1/SC 22/WG5/N2184

127

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.)

1 2 3 4

8.10.1.4

1 |---

2 --- A

3 ---

|---

C(1)

---|

4 ---| |--|---

5

6

7

--- B C(2)

-----|

---|

Array names and array element designators

1 For a nonzero-sized array, the use of the array name unqualified by a subscript list as an equivalence-object has the same effect as using an array element designator that identifies the first element of the array.

8.10.1.5

Restrictions on EQUIVALENCE statements

5

1 An EQUIVALENCE statement shall not specify that the same storage unit is to occur more than once in a storage sequence.

6

2 An EQUIVALENCE statement shall not specify that consecutive storage units are to be nonconsecutive.

7

8.10.2

COMMON statement

8

8.10.2.1

General

9 10

1 The COMMON statement specifies blocks of physical storage, called common blocks, that can be accessed by any of the scoping

11

2 A common block that does not have a name is called blank common.

units in a program. Thus, the COMMON statement provides a global data facility based on storage association (19.5.3).

12 13 14 15

R877

common-stmt

is

COMMON [ / [ common-block-name ] / ] common-block-object-list [ [ , ] / [ common-block-name ] / common-block-object-list ] ...

16

R878

common-block-object

is

variable-name [ ( array-spec ) ]

17

C8121

(R878) An array-spec in a common-block-object shall be an explicit-shape-spec-list.

18

C8122

(R878) Only one appearance of a given variable-name is permitted in all common-block-object-lists within a scoping unit.

19 20 21

C8123

(R878) A common-block-object shall not be a dummy argument, a function result, an allocatable variable, a derived-type object with an ultimate component that is allocatable, a procedure pointer, an automatic data object, a variable with the BIND attribute, an unlimited polymorphic pointer, or a coarray.

22 23

C8124

(R878) If a common-block-object is of a derived type, the type shall have the BIND attribute or the SEQUENCE attribute and it shall have no default initialization.

24

C8125

(R878) A variable-name shall not be a name made accessible by use association.

25 26 27 28 29

3 In each COMMON statement, the data objects whose names appear in a common block object list following a common block name

30 31 32 33

4 Any common block name or an omitted common block name for blank common may occur more than once in one or more COMMON

34

5 The form variable-name (array-spec) specifies the DIMENSION attribute for that variable.

35 36

6 If derived-type objects of numeric sequence type or character sequence type (7.5.2.3) appear in common, it is as if the individual

37 38

are declared to be in that common block. If the first common block name is omitted, all data objects whose names appear in the first common block object list are specified to be in blank common. Alternatively, the appearance of two slashes with no common block name between them declares the data objects whose names appear in the common block object list that follows to be in blank common. statements in a scoping unit. The common block list following each successive appearance of the same common block name in a scoping unit is treated as a continuation of the list for that common block name. Similarly, each blank common block object list in a scoping unit is treated as a continuation of blank common.

components were enumerated directly in the common list.

8.10.2.2

Common block storage sequence

1 For each common block in a scoping unit, a common block storage sequence is formed as follows:

128

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

(1)

1 2 3 4 5 6 7 8 9 10 11 12

(2)

WD 1539-1

J3/21-007r1

A storage sequence is formed consisting of the sequence of storage units in the storage sequences (19.5.3.2) of all data objects in the common block object lists for the common block. The order of the storage sequences is the same as the order of the appearance of the common block object lists in the scoping unit. The storage sequence formed in (1) is extended to include all storage units of any storage sequence associated with it by equivalence association. The sequence shall be extended only by adding storage units beyond the last storage unit. Data objects associated with an entity in a common block are considered to be in that common block.

2 Only COMMON statements and EQUIVALENCE statements appearing in the scoping unit contribute to common block storage sequences formed in that scoping unit.

8.10.2.3

Size of a common block

1 The size of a common block is the size of its common block storage sequence, including any extensions of the sequence resulting from equivalence association.

8.10.2.4

Common association

13 14 15 16 17 18

1 Within a program, the common block storage sequences of all nonzero-sized common blocks with the same name have the same first

19 20

2 A nonpointer object that is default integer, default real, double precision real, default complex, default logical, or of numeric sequence

21 22

3 A nonpointer object that is default character or of character sequence type shall be associated only with nonpointer objects of these

23 24

4 A nonpointer object of a derived type that is not a numeric sequence or character sequence type shall be associated only with

25 26

5 A nonpointer object of intrinsic type but which is not default integer, default real, double precision real, default complex, default

27 28

6 A data pointer shall be storage associated only with data pointers of the same type and rank. Data pointers that are storage

29 30

7 An object with the TARGET attribute shall be storage associated only with another object that has the TARGET attribute and the

storage unit, and the common block storage sequences of all zero-sized common blocks with the same name are storage associated with one another. Within a program, the common block storage sequences of all nonzero-sized blank common blocks have the same first storage unit and the storage sequences of all zero-sized blank common blocks are associated with one another and with the first storage unit of any nonzero-sized blank common blocks. This results in the association of objects in different scoping units. Use or host association can cause these associated objects to be accessible in the same scoping unit. type shall be associated only with nonpointer objects of these types and kinds. types and kinds.

nonpointer objects of the same type.

logical, or default character shall be associated only with nonpointer objects of the same type and type parameters.

associated shall have deferred the same type parameters; corresponding nondeferred type parameters shall have the same value. same type and type parameters. NOTE 1

A common block is permitted to contain sequences of different storage units, provided each scoping unit that accesses the common block specifies an identical sequence of storage units for the common block. For example, this allows a single common block to contain both numeric and character storage units. Association in different scoping units between objects of default type, objects of double precision real type, and sequence structures is permitted according to the rules for equivalence objects (8.10.1).

31 32 33 34 35 36 37 38 39 40

8.10.2.5

Differences between named common and blank common

1 A blank common block has the same properties as a named common block, except for the following. • Execution of a RETURN or END statement might cause data objects in a named common block to become undefined unless the common block has the SAVE attribute, but never causes nonpointer data objects in blank common to become undefined (19.6.6). • Named common blocks of the same name shall be of the same size in all scoping units of a program in which they appear, but blank common blocks may be of different sizes. • A data object in a named common block may be initially defined by means of a DATA statement or type declaration statement in a block data program unit (14.3), but objects in blank common shall not be initially defined.

8.10.3

Restrictions on common and equivalence

41

1 An EQUIVALENCE statement shall not cause the storage sequences of two different common blocks to be associated.

42 43

2 Equivalence association shall not cause a derived-type object with default initialization to be associated with an object in a common block.

ISO/IEC JTC 1/SC 22/WG5/N2184

129

J3/21-007r1

1 2

WD 1539-1

2021-05-21

3 Equivalence association shall not cause a common block storage sequence to be extended by adding storage units preceding the first storage unit of the first object specified in a COMMON statement for the common block.

130

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

9 Use of data objects

2

9.1

Designator

R901

designator

3 4 5 6 7 8 9 10

is or or or or or or

object-name array-element array-section coindexed-named-object complex-part-designator structure-component substring

1 The appearance of a data object designator in a context that requires its value is termed a reference.

9.2

Variable

12 13

R902

variable

14

C901

(R902) designator shall not be a constant or a subobject of a constant.

15

C902

(R902) function-reference shall have a data pointer result.

11

16 17 18 19 20

J3/21-007r1

is designator or function-reference

1 A variable is either the data object denoted by designator or the target of the pointer resulting from the evaluation

of function-reference; this pointer shall be associated. 2 A reference is permitted only if the variable is defined. A reference to a data pointer is permitted only if the

pointer is associated with a target object that is defined. A variable becomes defined with a value when events described in 19.6.5 occur. is

21

R903

variable-name

22

C903

(R903) variable-name shall be the name of a variable.

23

R904

logical-variable

24

C904

(R904) logical-variable shall be of type logical.

25

R905

char-variable

26

C905

(R905) char-variable shall be of type character.

27

R906

default-char-variable

28

C906

(R906) default-char-variable shall be default character.

29

R907

int-variable

30

C907

(R907) int-variable shall be of type integer.

is

is

is

is

name

variable

variable

variable

variable

NOTE 1 For example, given the declarations: CHARACTER (10) A, B (10) TYPE (PERSON) P ! See 7.5.2.1, NOTE 1

ISO/IEC JTC 1/SC 22/WG5/N2184

131

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) then A, B, B (1), B (1:5), P % AGE, and A (1:1) are all variables.

1

9.3

Constants

2

1 A constant (6.2.3) is a literal constant or a named constant. A literal constant is a scalar denoted by a syntactic

3 4 5

form, which indicates its type, type parameters, and value. A named constant is a constant that has a name; the name has the PARAMETER attribute (8.5.13, 8.6.11). A reference to a constant is always permitted; redefinition of a constant is never permitted.

6

9.4

Scalars

7

9.4.1

Substrings

8

1 A substring is a contiguous portion of a character string (7.4.4).

9

R908

substring

is

parent-string ( substring-range )

10 11 12 13 14

R909

parent-string

is or or or or

scalar-variable-name array-element coindexed-named-object scalar-structure-component scalar-constant

15

R910

substring-range

is

[ scalar-int-expr ] : [ scalar-int-expr ]

16

C908

(R909) parent-string shall be of type character.

17 18 19

2 The value of the first scalar-int-expr in substring-range is the starting point of the substring and the value of

20 21

3 Let the characters in the parent string be numbered 1, 2, 3, ..., n, where n is the length of the parent string.

22 23 24 25

the second one is the ending point of the substring. The length of a substring is the number of characters in the substring and is MAX (l − f + 1, 0), where f and l are the starting and ending points, respectively. Then the characters in the substring are those from the parent string from the starting point and proceeding in sequence up to and including the ending point. If the starting point is greater than the ending point, the substring has length zero; otherwise, both the starting point and the ending point shall be within the range 1, 2, ..., n. If the starting point is not specified, the default value is 1. If the ending point is not specified, the default value is n. NOTE 1 Examples of character substrings are: B(1)(1:5) P%NAME(1:1) ID(4:9) ’0123456789’(N:N)

26 27 28

9.4.2

array element as parent string structure component as parent string scalar variable name as parent string character constant as parent string

Structure components

1 A structure component is part of an object of derived type; it can be referenced by an object designator. A

structure component may be a scalar or an array.

29

R911

data-ref

is

part-ref [ % part-ref ] ...

30

R912

part-ref

is

part-name [ ( section-subscript-list ) ] [ image-selector ]

132

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

C909

(R911) Each part-name except the rightmost shall be of derived type.

2 3

C910

(R911) Each part-name except the leftmost shall be the name of a component of the declared type of the preceding part-name.

4

C911

(R911) If the rightmost part-name is of abstract type, data-ref shall be polymorphic.

5

C912

(R911) The leftmost part-name shall be the name of a data object.

6 7

C913

(R912) If a section-subscript-list appears, the sum of the rank of part-ref , the sizes of the arrays in each multiple subscript, and the number of subscripts, shall equal the rank of part-name.

8

C914

(R912) If image-selector appears, the number of cosubscripts shall be equal to the corank of part-name.

9 10 11

C915

A data-ref shall not be of type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING (18.2), or of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV (16.10.2), if one of its part-ref s has an image-selector.

12

C916

(R912) If image-selector appears and part-name is an array, section-subscript-list shall appear.

13 14 15

C917

(R911) Except as an actual argument to an intrinsic inquiry function or as the designator in a type parameter inquiry, a data-ref shall not be a coindexed object that has a polymorphic allocatable potential subobject component.

16 17

C918

Except as an actual argument to an intrinsic inquiry function or as the designator in a type parameter inquiry, if the rightmost part-ref is polymorphic, no other part-ref shall be coindexed.

18 19 20 21 22 23 24

2 The rank of a part-ref of the form part-name is the rank of part-name. The rank of a part-ref that has a section

subscript list is the sum of the number of subscript triplets, the number of vector subscripts, and the sizes of one of the arrays in each multiple section subscript. C919

(R911) There shall not be more than one part-ref with nonzero rank. A part-name to the right of a part-ref with nonzero rank shall not have the ALLOCATABLE or POINTER attribute.

3 The rank of a data-ref is the rank of the part-ref with nonzero rank, if any; otherwise, the rank is zero. The base

object of a data-ref is the data object whose name is the leftmost part name.

25

4 The type and type parameters, if any, of a data-ref are those of the rightmost part name.

26 27 28

5 A data-ref with more than one part-ref is a subobject of its base object if none of the part-names, except for

possibly the rightmost, is a pointer. If the rightmost part-name is the only pointer, then the data-ref is a subobject of its base object in contexts that pertain to its pointer association status but not in any other contexts. NOTE 1 If X is an object of derived type with a pointer component P, then the pointer X%P is a subobject of X when considered as a pointer – that is in contexts where it is not dereferenced. However the target of X%P is not a subobject of X. Thus, in contexts where X%P is dereferenced to refer to the target, it is not a subobject of X. is

29

R913

structure-component

30 31

C920

(R913) There shall be more than one part-ref and the rightmost part-ref shall not have a section-subscriptlist.

32 33

data-ref

6 A structure component shall be neither referenced nor defined before the declaration of the base object. A

structure component is a pointer only if the rightmost part name has the POINTER attribute.

ISO/IEC JTC 1/SC 22/WG5/N2184

133

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 Examples of structure components are: SCALAR_PARENT%SCALAR_FIELD ARRAY_PARENT(J)%SCALAR_FIELD ARRAY_PARENT(1:N)%SCALAR_FIELD

scalar component of scalar parent component of array element parent component of array section parent

For a more elaborate example see C.5.1. NOTE 3 The syntax rules are structured such that a data-ref that ends in a component name without a following subscript list is a structure component, even when other component names in the data-ref are followed by a subscript list. A data-ref that ends in a component name with a following subscript list is either an array element or an array section. A data-ref of nonzero rank that ends with a substring-range is an array section. A data-ref of zero rank that ends with a substring-range is a substring. 1 2

9.4.3

Coindexed named objects

1 A coindexed-named-object is a named scalar coarray variable followed by an image selector.

is

3

R914

coindexed-named-object

4 5

C921

(R914) The data-ref shall contain exactly one part-ref . The part-ref shall contain an image-selector. The part-name shall be the name of a scalar coarray.

6

9.4.4

Complex parts

7 8

R915

complex-part-designator

9

C922

(R915) The designator shall be of complex type.

10 11 12

data-ref

is designator % RE or designator % IM

1 If complex-part-designator is designator%RE it designates the real part of designator. If it is designator%IM

it designates the imaginary part of designator. The type of a complex-part-designator is real, and its kind and shape are those of the designator, which can be an array or scalar. NOTE 1 The following are examples of complex part designators: Same value as REAL (impedance). Same value as AIMAG (fft). Sets the imaginary part of X to zero.

impedance%re fft%im x%im = 0.0

13 14 15

9.4.5

Type parameter inquiry

1 A type parameter inquiry is used to inquire about a type parameter of a data object. It applies to both intrinsic

and derived types. is

16

R916

type-param-inquiry

17 18

C923

(R916) The type-param-name shall be the name of a type parameter of the declared type of the object designated by the designator.

19 20

designator % type-param-name

2 A deferred type parameter of a pointer that is not associated or of an unallocated allocatable variable shall not

be inquired about.

134

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 A type-param-inquiry has a syntax like that of a structure component reference, but it does not have the same semantics. It is not a variable and thus can never be assigned to. It can be used only as a primary in an expression. It is scalar even if designator is an array. The intrinsic type parameters can also be inquired about by using the intrinsic functions KIND and LEN. NOTE 2 The following are examples of type parameter inquiries: A is real. Same value as KIND (a). S is character. Same value as LEN (s). Inquiry about an array element. P is of the derived type general_point.

a%kind s%len b(10)%kind p%dim

See 7.5.3.1, NOTE 1 for the definition of the general_point type used in the last example above.

1

9.5

Arrays

2

9.5.1

Order of reference

3 4 5

1 No order of reference to the elements of an array is indicated by the appearance of the array designator, except

where array element ordering (9.5.3.3) is specified.

9.5.2

Whole arrays

6 7

1 A whole array is a named array or a structure component whose final part-ref is an array component name; no

8 9 10

2 The appearance of a whole array variable in an executable construct specifies all the elements of the array (5.4.6).

subscript list is appended.

11 12

The appearance of a whole array designator in a nonexecutable statement specifies the entire array except for the appearance of a whole array designator in an equivalence set (8.10.1.4). An assumed-size array (8.5.8.5) is permitted to appear as a whole array in an executable construct or specification expression only as an actual argument in a procedure reference that does not require the shape.

13

9.5.3

Array elements and array sections

14

9.5.3.1

Syntax

15

R917

array-element

16

C924

(R917) Every part-ref shall have rank zero and the last part-ref shall contain a subscript-list.

17

R918

array-section

19 20 21

C925

(R918) Exactly one part-ref shall have nonzero rank, and either the final part-ref shall have a sectionsubscript-list with nonzero rank, another part-ref shall have nonzero rank, or the complex-part-designator shall be an array.

22

C926

(R918) If a substring-range appears, data-ref shall be of type character.

23

R919

subscript

is

scalar-int-expr

24

R920

multiple-subscript

is

@ int-expr

18

is

data-ref

is data-ref [ ( substring-range ) ] or complex-part-designator

ISO/IEC JTC 1/SC 22/WG5/N2184

135

J3/21-007r1

WD 1539-1

2021-05-21

1

C927

The int-expr in a multiple-subscript shall be an array of rank one.

2 3 4

R921

section-subscript

is or or or or

subscript multiple-subscript subscript-triplet multiple-subscript-triplet vector-subscript

7

R922

subscript-triplet

is

[ subscript ] : [ subscript ] [ : stride ]

8

R923

multiple-subscript-triplet

is

@ [ int-expr ] : [ int-expr ] [ : int-expr ]

9 10

C928

A multiple-subscript-triplet shall have at least one int-expr that is an array of rank one. The int-exprs in a multiple-subscript-triplet shall be conformable.

11

R924

stride

is

scalar-int-expr

12

R925

vector-subscript

is

int-expr

13

C929

(R925) A vector-subscript shall be an integer array expression of rank one.

14 15

C930

(R922) The second subscript shall not be omitted from a subscript-triplet in the last dimension of an assumed-size array.

16 17

C931

If a multiple-subscript-triplet is the last section-subscript in the section-subscript-list of an assumed-size array, the second int-expr shall appear.

5 6

18 19

1 An array element is a scalar. An array section is an array. If a substring-range appears in an array-section, each

20

2 The value of a subscript in an array element shall be within the bounds for its dimension.

element is the designated substring of the corresponding element of the array section.

NOTE 1 For example, with the declarations: REAL A (10, 10) CHARACTER (LEN = 10) B (5, 5, 5) A (1, 2) is an array element, A (1:N:2, M) is a rank-one array section, and B (:, :, :) (2:3) is an array of shape (5, 5, 5) whose elements are substrings of length 2 of the corresponding elements of B. NOTE 2 Unless otherwise specified, an array element or array section does not have an attribute of the whole array. In particular, an array element or an array section does not have the POINTER or ALLOCATABLE attribute. NOTE 3 Examples of array elements and array sections are: ARRAY_A(1:N:2)%ARRAY_B(I, J)%STRING(K)(:) SCALAR_PARENT%ARRAY_FIELD(J) SCALAR_PARENT%ARRAY_FIELD(1:N) SCALAR_PARENT%ARRAY_FIELD(1:N)%SCALAR_FIELD 21 22 23 24

9.5.3.2

array section array element array section array section

Sequences of subscripts and subscript triplets

1 A multiple-subscript specifies a sequence of subscripts, the number of which is equal to the size of multiple-

subscript. The effect is as if the array elements were specified individually as subscripts of consecutive dimensions (not preceded by @).

136

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

2 In a multiple-subscript-triplet, if the first int-expr does not appear, the effect is as if it were a rank-one array whose

5 6 7 8 9

3 A multiple-subscript-triplet specifies a sequence of subscript triplets, the number of which is equal to the size of

element values are the lower bounds of the corresponding dimensions. If the second int-expr does not appear, the effect is as if it were a rank-one array whose element values are the upper bounds of the corresponding dimensions. If the third int-expr does not appear, the effect is as if it appeared with the value one. one of its array int-exprs. If any int-expr is a scalar, the effect is as if it were broadcast to the shape of one that is an array. An element of the first array acts as if it were the first subscript in a subscript triplet; the corresponding element of the second array acts as if it were the second subscript; the corresponding element of the third array acts as if it were the stride. NOTE 1 Examples of references to parts of arrays using one-dimensional arrays to specify sequences of subscripts or sequences of subscript triplets, assuming V1, V2, and V3 are rank-one arrays, are: A(@[3,5]) ! Array element, equivalent to A(3, 5) A(6, @[3,5], 1) ! Array element, equivalent to A(6, 3, 5, 1) A(@[1,2]:[3,4]) ! Array section, equivalent to A(1:3, 2:4) A(@:[4,6]:2, :, 1) ! Array section with stride, equivalent to A(:4:2, :6:2, :, 1) A(@V1, :, @V2) ! Rank-one array section, the rank of A being ! SIZE (V1) + 1 + SIZE (V2). B(@V1, :, @V2:) ! Rank 1 + SIZE (V2) array section, the rank of B being ! SIZE (V1) + 1 + SIZE (V2). C(@V1, :, @::V3) ! Rank 1 + SIZE (V3) array section, the rank of C being ! SIZE (V1) + 1 + SIZE (V3).

10 11 12 13

9.5.3.3

Array element order

1 The elements of an array form a sequence known as the array element order. The position of an array element

in this sequence is determined by the subscript order value of the subscript list designating the element. The subscript order value is computed from the formulas in Table 9.1.

.. .

Table 9.1: Subscript order value Subscript bounds Subscript list Subscript order value j1 :k1 s1 1 + (s1 − j1 ) 1 + (s1 − j1 ) j1 :k1 ,j2 :k2 s1 , s2 +(s2 − j2 ) × d1 1 + (s1 − j1 ) j1 :k1 , j2 :k2 , j3 :k3 s1 , s2 , s3 +(s2 − j2 ) × d1 +(s3 − j3 ) × d2 × d1 .. .. .. . . .

15

j1 :k1 , . . . , j15 :k15

Rank 1 2 3

NOTE 1 NOTE 2

14

9.5.3.4

15

9.5.3.4.1

16 17

s1 , . . . , s15

1 + (s1 − j1 ) +(s2 − j2 ) × d1 +... +(s15 −j15 )×d14 ×. . .×d1

di = max (ki − ji + 1, 0) is the size of the ith dimension. If the size of the array is nonzero, ji ≤ si ≤ ki for all i = 1, 2, . . . , 15.

Array sections Section subscript lists

1 In an array-section having a section-subscript-list, each subscript triplet and vector-subscript in the section

subscript list indicates a sequence of subscripts, which may be empty. Each subscript in such a sequence shall

ISO/IEC JTC 1/SC 22/WG5/N2184

137

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

be within the bounds for its dimension unless the sequence is empty. The array section is the set of elements from the array determined by all possible subscript lists obtainable from the single subscripts or sequences of subscripts specified by each section subscript.

4

2 In an array-section with no section-subscript-list, the rank and shape of the array is the rank and shape of the

5 6 7 8 9

part-ref with nonzero rank; otherwise, the rank of the array section is the number of subscript triplets and vector subscripts in the section subscript list. The shape is the rank-one array whose ith element is the number of integer values in the sequence indicated by the ith subscript triplet or vector subscript. If any of these sequences is empty, the array section has size zero. The subscript order of the elements of an array section is that of the array data object that the array section represents.

10

9.5.3.4.2

Subscript triplet

11

1 A subscript triplet designates a regular sequence of subscripts consisting of zero or more subscript values. The

12 13 14 15

stride in the subscript triplet specifies the increment between the subscript values. The subscripts and stride of a subscript triplet are optional. An omitted first subscript in a subscript triplet is equivalent to a subscript whose value is the lower bound for the array and an omitted second subscript is equivalent to the upper bound. An omitted stride is equivalent to a stride of 1.

16

2 The stride shall not be zero.

17

3 When the stride is positive, the subscripts specified by a triplet form a regularly spaced sequence of integers

18 19

beginning with the first subscript and proceeding in increments of the stride to the largest such integer not greater than the second subscript; the sequence is empty if the first subscript is greater than the second. NOTE 1 For example, suppose an array is declared as A (5, 4, 3). The section A (3 : 5, 2, 1 : 2) is the array of shape (3, 2): A (3, 2, 1) A (4, 2, 1) A (5, 2, 1)

20 21 22

A (3, 2, 2) A (4, 2, 2) A (5, 2, 2)

4 When the stride is negative, the sequence begins with the first subscript and proceeds in increments of the stride

down to the smallest such integer equal to or greater than the second subscript; the sequence is empty if the second subscript is greater than the first. NOTE 2 For example, if an array is declared B (10), the section B (9 : 1 : −2) is the array of shape (5) whose elements are B (9), B (7), B (5), B (3), and B (1), in that order. NOTE 3 A subscript in a subscript triplet need not be within the declared bounds for that dimension if all values used in selecting the array elements are within the declared bounds. For example, if an array is declared as B (10), the array section B (3 : 11 : 7) is the array of shape (2) consisting of the elements B (3) and B (10), in that order.

23 24 25

9.5.3.4.3

Vector subscript

1 A vector subscript designates a sequence of subscripts corresponding to the values of the elements of the expression.

Each element of the expression shall be defined.

26

2 An array section with a vector subscript shall not be finalized by a nonelemental final subroutine.

27

3 If a vector subscript has two or more elements with the same value, an array section with that vector subscript

138

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

is not definable and shall not be defined or become undefined. NOTE 1 For example, suppose Z is a two-dimensional array of shape [5, 7] and U and V are one-dimensional arrays of shape (3) and (4), respectively. Assume the values of U and V are: U = [ 1, 3, 2 ] V = [ 2, 1, 1, 3 ] Then Z (3, V) consists of elements from the third row of Z in the order: Z (3, 2)

Z (3, 1)

Z (3, 1)

Z (3, 3)

Z (U, 2) consists of the column elements: Z (1, 2)

Z (3, 2)

Z (2, 2)

and Z (U, V) consists of the elements: Z (1, 2) Z (3, 2) Z (2, 2)

Z (1, 1) Z (3, 1) Z (2, 1)

Z (1, 1) Z (3, 1) Z (2, 1)

Z (1, 3) Z (3, 3) Z (2, 3)

Because Z (3, V) and Z (U, V) contain duplicate elements from Z, the sections Z (3, V) and Z (U, V) cannot be redefined as sections. 2 3 4 5 6

7 8 9 10 11 12 13 14 15 16 17 18 19

20 21

9.5.4

Simply contiguous array designators

1 A section-subscript-list specifies a simply contiguous section if and only if it does not have a vector subscript and

• all but the last subscript-triplet is a colon, • the last subscript-triplet does not have a stride, and • no subscript-triplet is preceded by a section-subscript that is a subscript. 2 An array designator is simply contiguous if and only if it is

• an object-name that has the CONTIGUOUS attribute, • an object-name that is not a pointer, not assumed-shape, and not assumed-rank, • a structure-component whose final part-name is an array and that either has the CONTIGUOUS attribute or is not a pointer, or • an array section – that is not a complex-part-designator, – that does not have a substring-range, – whose final part-ref has nonzero rank, – whose rightmost part-name has the CONTIGUOUS attribute or is neither assumed-shape nor a pointer, and – which either does not have a section-subscript-list, or has a section-subscript-list which specifies a simply contiguous section. 3 An array variable is simply contiguous if and only if it is a simply contiguous array designator or a reference to

a function that returns a pointer with the CONTIGUOUS attribute. NOTE 1 Array sections that are simply contiguous include column, plane, cube, and hypercube subobjects of a simply contiguous base object, for example: ARRAY1 (10:20, 3) X3D (:, i:j, 2)

Passes part of the third column of ARRAY1. Passes part of the second plane of X3D (or the whole plane if i==LBOUND (X3D, 2) and j==UBOUND (X3D, 2).

ISO/IEC JTC 1/SC 22/WG5/N2184

139

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) Passes the seventh hypercube of Y5D.

Y5D (:, :, :, :, 7)

All simply contiguous designators designate contiguous objects.

1 2

9.6

Image selectors

1 An image selector determines the image index for a coindexed object.

3

R926

image-selector

is

lbracket cosubscript-list [ , image-selector-spec-list ] rbracket

4

R927

cosubscript

is

scalar-int-expr

5

R928

image-selector-spec

is or or or

NOTIFY = notify-variable STAT = stat-variable TEAM = team-value TEAM_NUMBER = scalar-int-expr

9

C932

No specifier shall appear more than once in a given image-selector-spec-list.

10 11

C933

A NOTIFY= image-selector-spec shall appear only in the designator of the variable of an intrinsic assignment statement.

12

C934

TEAM and TEAM_NUMBER shall not both appear in the same image-selector-spec-list.

13

C935

A stat-variable in an image-selector shall not be a coindexed object.

6 7 8

14 15 16 17

2 The number of cosubscripts shall be equal to the corank of the object. The value of a cosubscript in an image

18 19 20 21 22 23

3 If a TEAM= specifier appears in an image-selector, the team of the image selector is specified by team-value,

24 25 26

selector shall be within the cobounds for its codimension. Taking account of the cobounds, the cosubscript list in an image selector determines the image index in the same way that a subscript list in an array element determines the subscript order value (9.5.3.3), taking account of the bounds. which shall identify the current or an ancestor team; the object shall be an established coarray in that team or an ancestor thereof. If a TEAM_NUMBER= specifier appears in an image-selector and the current team is not the initial team, the value of the scalar-int-expr shall be equal to the value of a team number for a sibling team of the current team and the team of the image selector is that team; the object shall be an established coarray in an ancestor of the current team, or an associating entity of the CHANGE TEAM construct. If a TEAM_NUMBER= specifier appears in an image-selector and the current team is the initial team, the value of scalar-int-expr shall be the team number for the initial team; the object shall be an established coarray in the initial team. Otherwise, the team of the image selector is the current team.

27 28 29

4 Execution of an assignment statement whose variable has a NOTIFY= specifier atomically increments the count

30 31

5 An image selector shall specify an image index value that is not greater than the number of images in the team

32 33 34 35

6 Execution of a statement containing an image-selector with a STAT= specifier causes the stat-variable to become

36 37 38

of the corresponding notify variable on the image specified by the image selector, and does not wait for that image to execute a corresponding NOTIFY WAIT statement. of the image selector, and identifies the image with that index in that team. defined. If the designator is part of an operand that is evaluated or is a variable that is being defined or partly defined, and the object designated is on a failed image, the stat-variable is defined with the value STAT_FAILED_IMAGE (16.10.2.28) in the intrinsic module ISO_FORTRAN_ENV; otherwise, it is defined with the value zero. 7 The denotation of a stat-variable in an image-selector shall not depend on the evaluation of any entity in the

same statement. The value of an expression shall not depend on the value of any stat-variable that appears in

140

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

the same statement. The value of a stat-variable in an image-selector shall not be affected by the execution of any part of the statement, other than by whether the image specified by the image-selector has failed. NOTE 1 For example, if there are 16 images and the coarray A is declared REAL :: A(10)[5,*] A(:)[1,4] is valid because it specifies image 16, but A(:)[2,4] is invalid because it specifies image 17.

3

9.7

Dynamic association

4

9.7.1

ALLOCATE statement

5

9.7.1.1

Form of the ALLOCATE statement

6

1 The ALLOCATE statement dynamically creates pointer targets and allocatable variables.

R929

allocate-stmt

is

ALLOCATE ( [ type-spec :: ] allocation-list [ , alloc-opt-list ] )

9 10 11 12

R930

alloc-opt

is or or or

ERRMSG = errmsg-variable MOLD = source-expr SOURCE = source-expr STAT = stat-variable

13

R931

errmsg-variable

is

scalar-default-char-variable

14

R932

source-expr

is

expr

15 16 17 18

R933

allocation

is

allocate-object [ ( allocate-shape-spec-list ) ] [ lbracket allocate-coarray-spec rbracket ] or ( [ lower-bounds-expr : ] upper-bounds-expr ) [ lbracket allocate-coarray-spec rbracket ]

19

R934

allocate-object

is variable-name or structure-component

21

R935

allocate-shape-spec

is

[ lower-bound-expr : ] upper-bound-expr

22

R936

lower-bound-expr

is

scalar-int-expr

23

R937

lower-bounds-expr

is

int-expr

24

R938

upper-bound-expr

is

scalar-int-expr

25

R939

upper-bounds-expr

is

int-expr

26

R940

allocate-coarray-spec

is

[ allocate-coshape-spec-list , ] [ lower-bound-expr : ] *

27

R941

allocate-coshape-spec

is

[ lower-bound-expr : ] upper-bound-expr

28

C936

(R934) Each allocate-object shall be a data pointer or an allocatable variable.

29 30

C937

(R929) If any allocate-object has a deferred type parameter, is unlimited polymorphic, or is of abstract type, either type-spec or source-expr shall appear.

31

C938

(R929) If type-spec appears, it shall specify a type with which each allocate-object is type compatible.

32

C939

(R929) A type-param-value in a type-spec shall be an asterisk if and only if each allocate-object is a dummy

7 8

20

ISO/IEC JTC 1/SC 22/WG5/N2184

141

J3/21-007r1

WD 1539-1

2021-05-21

argument for which the corresponding type parameter is assumed.

1 2 3

C940

(R929) If type-spec appears, the kind type parameter values of each allocate-object shall be the same as the corresponding type parameter values of the type-spec.

4

C941

(R929) If an allocate-object is a coarray, type-spec shall not specify type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, or type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.

7 8 9

C942

(R929) If an allocate-object is an array, either allocate-shape-spec-list or upper-bounds-expr shall appear in its allocation, or source-expr shall appear in the ALLOCATE statement and have the same rank as the allocate-object.

10

C943

(R933) If allocate-object is scalar, allocate-shape-spec-list shall not appear.

11

C944

(R933) An allocate-coarray-spec shall appear if and only if the allocate-object is a coarray.

12 13 14

C945

(R933) The number of allocate-shape-specs in an allocate-shape-spec-list shall be the same as the rank of the allocate-object. The number of allocate-coshape-specs in an allocate-coarray-spec shall be one less than the corank of the allocate-object.

15 16

C946

If upper-bounds-expr and lower-bounds-expr both appear in an allocation, at least one of them shall be a rank-one array of constant size equal to the rank of allocate-object. Otherwise, if upper-bounds-expr appears in an allocation, it shall be a rank-one array of constant size equal to the rank of allocate-object.

18

C947

(R930) No alloc-opt shall appear more than once in a given alloc-opt-list.

19

C948

(R929) At most one of source-expr and type-spec shall appear.

20 21

C949

(R929) Each allocate-object shall be type compatible (7.3.3) with source-expr. If SOURCE= appears, source-expr shall be a scalar or have the same rank as each allocate-object.

22

C950

(R929) If source-expr appears, the kind type parameters of each allocate-object shall have the same values as the corresponding type parameters of source-expr.

24 25 26

C951

(R929) The declared type of source-expr shall not be C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, or TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, if an allocateobject is a coarray.

27 28

C952

(R929) If SOURCE= appears, the declared type of source-expr shall not be EVENT_TYPE, LOCK_TYPE, or NOTIFY_TYPE from the intrinsic module ISO_FORTRAN_ENV, or have a potential subobject component of type EVENT_TYPE, LOCK_TYPE, or NOTIFY_TYPE.

30

C953

(R932) The declared type of source-expr shall not have a coarray ultimate component.

31

C954

(R934) An allocate-object shall not be a coindexed object.

5 6

17

23

29

NOTE 1 A pointer or allocatable component of a coarray can only be allocated by its own image. TYPE (SOMETHING), ALLOCATABLE :: T[:] ... ALLOCATE (T[*]) Allowed - implies synchronization. ALLOCATE (T%AAC (N)) Allowed - allocated by its own image. ALLOCATE (T[Q]%AAC (N)) Not allowed, because it is coindexed.

32 33 34

2 An allocate-object or a bound or type parameter of an allocate-object shall not depend on the value of stat-variable,

the value of errmsg-variable, or on the value, bounds, length type parameters, allocation status, or association status of any allocate-object in the same ALLOCATE statement.

142

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

3 source-expr shall not be allocated within the ALLOCATE statement in which it appears; nor shall it depend on

4

4 If an ALLOCATE statement has a SOURCE= specifier and an allocate-object that is a coarray, source-expr shall

5 6 7 8

not have a dynamic type of C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, or EVENT_TYPE, LOCK_TYPE, NOTIFY_TYPE, or TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, or have a subcomponent whose dynamic type is EVENT_TYPE, LOCK_TYPE, NOTIFY_TYPE, or TEAM_TYPE.

9 10

5 If type-spec is specified, each allocate-object is allocated with the specified dynamic type and type parameter

11 12 13 14 15

the value, bounds, deferred type parameters, allocation status, or association status of any allocate-object in that statement.

values; if source-expr is specified, each allocate-object is allocated with the dynamic type and type parameter values of source-expr; otherwise, each allocate-object is allocated with its dynamic type the same as its declared type. 6 If a type-param-value in a type-spec in an ALLOCATE statement is an asterisk, it denotes the current value of

that assumed type parameter. If it is an expression, subsequent redefinition or undefinition of any entity in the expression does not affect the type parameter value. NOTE 2 An example of an ALLOCATE statement is: ALLOCATE (X (N), B (-3 : M, 0:9), STAT = IERR_ALLOC)

16 17 18 19 20 21 22 23 24 25 26 27

9.7.1.2

Execution of an ALLOCATE statement

1 When an ALLOCATE statement is executed for an array for which allocate-shape-spec-list is specified, the values

of the lower bound and upper bound expressions determine the bounds of the array. Subsequent redefinition or undefinition of any entities in the bound expressions do not affect the array bounds. If the lower bound is omitted, the default value is one. If the upper bound is less than the lower bound, the extent in that dimension is zero and the array has zero size. 2 When an ALLOCATE statement is executed for an array for which upper-bounds-expr is specified, it determines

the upper bounds of the array. Subsequent redefinition or undefinition of an entity in a bounds expression does not affect the array bounds. If lower-bounds-expr appears, it determines the lower bounds; otherwise the default value is one. If lower-bounds-expr or upper-bounds-expr is scalar, the effect is as if it were broadcast to the shape of the other. If any element of upper-bounds-expr is less than the corresponding element of lower-bounds-expr, the extent in the corresponding dimension is zero and the array has zero size.

28 29 30 31

3 When an ALLOCATE statement is executed for a coarray, the values of the lower cobound and upper cobound

32 33 34 35 36

4 If an allocation specifies a coarray, its dynamic type and the values of corresponding type parameters shall be the

37

5 When an ALLOCATE statement is executed for which an allocate-object is a coarray, there is an implicit syn-

38 39 40 41 42 43

chronization of all active images in the current team. If the current team contains a stopped or failed image, an error condition occurs. If no other error condition occurs, execution on the active images of the segment (11.7.2) following the statement is delayed until all other active images in the current team have executed the same statement the same number of times in this team. The segments that executed before the ALLOCATE statement on an active image of this team precede the segments that execute after the ALLOCATE statement on another active image of this team. The coarray shall not become allocated on an image unless it is successfully

expressions determine the cobounds of the coarray. Subsequent redefinition or undefinition of any entities in the cobound expressions do not affect the cobounds. If the lower cobound is omitted, the default value is 1. The upper cobound shall not be less than the lower cobound. same on every active image in the current team. The values of corresponding bounds and corresponding cobounds shall be the same on those images. If the coarray is a dummy argument, its ultimate argument (15.5.2.3) shall be the same coarray on those images. If the coarray is an ultimate component of an array element, the element shall have the same position in array element order on those images.

ISO/IEC JTC 1/SC 22/WG5/N2184

143

J3/21-007r1

1

WD 1539-1

2021-05-21

allocated on all active images in this team. NOTE 1 When an image executes an ALLOCATE statement, communication is not necessarily involved apart from any required for synchronization. The image allocates its coarray and records how the corresponding coarrays on other images are to be addressed. The processor is not required to detect violations of the rule that the bounds are the same on all images of the current team, nor is it responsible for detecting or resolving deadlock problems (such as two images waiting on different ALLOCATE statements.).

2

6 If source-expr is a pointer, it shall be associated with a target. If source-expr is allocatable, it shall be allocated.

3 4

7 When an ALLOCATE statement is executed for an array with no allocate-shape-spec-list, the bounds of source-

5 6 7 8 9 10 11 12

expr determine the bounds of the array. Subsequent changes to the bounds of source-expr do not affect the array bounds. 8 If SOURCE= appears, source-expr shall be conformable with allocation. If an allocate-object is not polymorphic

and the source-expr is polymorphic with a dynamic type that differs from its declared type, the value provided for that allocate-object is the ancestor component of the source-expr that has the type of the allocate-object; otherwise the value provided is the value of the source-expr. On successful allocation, if allocate-object and source-expr have the same rank the value of allocate-object becomes the value provided, otherwise the value of each element of allocate-object becomes the value provided. The source-expr is evaluated exactly once for each execution of an ALLOCATE statement.

13

9 If MOLD= appears and source-expr is a variable, its value need not be defined.

14 15 16

10 If type-spec appears and the value of a length type parameter it specifies differs from the value of the corresponding

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

nondeferred type parameter specified in the declaration of any allocate-object, an error condition occurs. If the value of a nondeferred length type parameter of an allocate-object differs from the value of the corresponding type parameter of source-expr, an error condition occurs. 11 The set of error conditions for an ALLOCATE statement is processor dependent. If an error condition occurs

during execution of an ALLOCATE statement that does not contain the STAT= specifier, error termination is initiated. The STAT= specifier is described in 9.7.4. The ERRMSG= specifier is described in 9.7.5. 9.7.1.3

Allocation of allocatable variables

1 The allocation status of an allocatable entity is one of the following at any time.

• The status of an allocatable variable becomes “allocated” if it is allocated by an ALLOCATE statement, if it is allocated during assignment, or if it is given that status by the intrinsic subroutine MOVE_ALLOC (16.9.147). An allocatable variable with this status may be referenced, defined, or deallocated; allocating it causes an error condition in the ALLOCATE statement. The result of the intrinsic function ALLOCATED (16.9.13) is true for such a variable. • An allocatable variable has a status of “unallocated” if it is not allocated. The status of an allocatable variable becomes unallocated if it is deallocated (9.7.3) or if it is given that status by the intrinsic subroutine MOVE_ALLOC. An allocatable variable with this status shall not be referenced or defined. It shall not be supplied as an actual argument corresponding to a nonallocatable nonoptional dummy argument, except to certain intrinsic inquiry functions. It may be allocated with the ALLOCATE statement. Deallocating it causes an error condition in the DEALLOCATE statement. The result of the intrinsic function ALLOCATED (16.9.13) is false for such a variable.

35

2 At the beginning of execution of a program, allocatable variables are unallocated.

36 37 38

3 When the allocation status of an allocatable variable changes, the allocation status of any associated allocat-

able variable changes accordingly. Allocation of an allocatable variable establishes values for the deferred type parameters of all associated allocatable variables.

144

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

4 An unsaved allocatable local variable of a procedure has a status of unallocated at the beginning of each invocation

4

5 When an object of derived type is created by an ALLOCATE statement, any allocatable ultimate components

5 6

have an allocation status of unallocated unless the SOURCE= specifier appears and the corresponding component of the source-expr is allocated.

7 8 9

6 If the evaluation of a function would change the allocation status of a variable and if a reference to the function

10 11 12 13 14 15 16 17 18 19 20 21 22

of the procedure. An unsaved allocatable local variable of a construct has a status of unallocated at the beginning of each execution of the construct.

appears in an expression in which the value of the function is not needed to determine the value of the expression, the allocation status of the variable after evaluation of the expression is processor dependent. 9.7.1.4

Allocation of pointer targets

1 Allocation of a pointer creates an object that implicitly has the TARGET attribute. Following successful execution

of an ALLOCATE statement for a pointer, the pointer is associated with the target and can be used to reference or define the target. Additional pointers can become associated with the pointer target or a part of the pointer target by pointer assignment. It is not an error to allocate a pointer that is already associated with a target. In this case, a new pointer target is created as required by the attributes of the pointer and any array bounds, type, and type parameters specified by the ALLOCATE statement. The pointer is then associated with this new target. Any previous association of the pointer with a target is broken. If the previous target had been created by allocation, it becomes inaccessible unless other pointers are associated with it. The intrinsic function ASSOCIATED (16.9.20) can be used to determine whether a pointer that does not have undefined association status is associated. 2 At the beginning of execution of a function whose result is a pointer, the association status of the result pointer

23

is undefined. Before such a function returns, it shall either associate a target with this pointer or cause the association status of this pointer to become disassociated.

24

9.7.2

NULLIFY statement

25

R942

nullify-stmt

is

26 27 28

R943

pointer-object

is variable-name or structure-component or proc-pointer-name

29

C955

(R943) Each pointer-object shall have the POINTER attribute.

30 31 32

NULLIFY ( pointer-object-list )

1 A pointer-object shall not depend on the value, bounds, or association status of another pointer-object in the

same NULLIFY statement. 2 Execution of a NULLIFY statement causes each pointer-object to become disassociated.

NOTE 1 When a NULLIFY statement is applied to a polymorphic pointer (7.3.2.3), its dynamic type becomes the same as its declared type. 33

9.7.3

DEALLOCATE statement

34

9.7.3.1

Form of the DEALLOCATE statement

35 36 37

1 The DEALLOCATE statement causes allocatable variables to be deallocated; it causes pointer targets to be

deallocated and the pointers to be disassociated. R944

deallocate-stmt

is

DEALLOCATE ( allocate-object-list [ , dealloc-opt-list ] )

ISO/IEC JTC 1/SC 22/WG5/N2184

145

J3/21-007r1

WD 1539-1

2021-05-21

is STAT = stat-variable or ERRMSG = errmsg-variable

1 2

R945

dealloc-opt

3

C956

(R945) No dealloc-opt shall appear more than once in a given dealloc-opt-list.

4

2 An allocate-object shall not depend on the value, bounds, allocation status, or association status of another

5 6

allocate-object in the same DEALLOCATE statement; it also shall not depend on the value of the stat-variable or errmsg-variable in the same DEALLOCATE statement.

7 8 9

3 The set of error conditions for a DEALLOCATE statement is processor dependent. If an error condition occurs

10

4 When more than one allocated object is deallocated by execution of a DEALLOCATE statement, the order of

11

during execution of a DEALLOCATE statement that does not contain the STAT= specifier, error termination is initiated. The STAT= specifier is described in 9.7.4. The ERRMSG= specifier is described in 9.7.5. deallocation is processor dependent. NOTE 1 An example of a DEALLOCATE statement is: DEALLOCATE (X, B)

12 13 14 15 16

9.7.3.2

Deallocation of allocatable variables

1 Deallocating an unallocated allocatable variable causes an error condition in the DEALLOCATE statement.

Deallocating an allocatable variable with the TARGET attribute causes the pointer association status of any pointer associated with it to become undefined. An allocatable variable shall not be deallocated if it or any subobject of it is argument associated with a dummy argument or construct associated with an associate name.

17 18 19

2 When the execution of a procedure is terminated by execution of a RETURN or END statement, an unsaved

20

3 When a BLOCK construct terminates, any unsaved allocated allocatable local variable of the construct is deal-

21

allocatable local variable of the procedure retains its allocation and definition status if it is a function result or a subobject thereof; otherwise, if it is allocated it will be deallocated. located.

22 23 24

4 If an executable construct references a function whose result is allocatable or has an allocatable subobject, and

25 26

5 If a function whose result is allocatable or has an allocatable subobject is referenced in the specification part of a

27 28 29 30 31

the function reference is executed, an allocatable result and any allocated allocatable subobject of the result is deallocated after execution of the innermost executable construct containing the reference. scoping unit, and the function reference is executed, an allocatable result and any allocated allocatable subobject of the result is deallocated before execution of the executable constructs of the scoping unit. 6 When a procedure is invoked, any allocated allocatable object that is an actual argument corresponding to an

32 33 34 35 36

INTENT (OUT) allocatable dummy argument is deallocated; any allocated allocatable object that is a subobject of an actual argument corresponding to an INTENT (OUT) dummy argument is deallocated. If a Fortran procedure that has an INTENT (OUT) allocatable dummy argument is invoked by a C function and the corresponding argument in the C function call is a C descriptor that describes an allocated allocatable variable, the variable is deallocated on entry to the Fortran procedure. If a C function is invoked from a Fortran procedure via an interface with an INTENT (OUT) allocatable dummy argument and the corresponding actual argument in the reference to the C function is an allocated allocatable variable, the variable is deallocated on invocation (before execution of the C function begins).

37

7 When an intrinsic assignment statement (10.2.1.3) is executed, any noncoarray allocated allocatable subobject of

38 39 40 41

the variable is deallocated before the assignment takes place. 8 When a variable of derived type is deallocated, any allocated allocatable subobject is deallocated. If an error

condition occurs during deallocation, it is processor dependent whether an allocated allocatable subobject is deallocated.

146

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

9 If an allocatable component is a subobject of a finalizable object, any final subroutine for that object is executed

3 4

10 When a statement that deallocates a coarray is executed, there is an implicit synchronization of all active images

before the component is automatically deallocated.

5 6 7 8 9

in the current team. If the current team contains a stopped or failed image, an error condition occurs. If no other error condition occurs, execution on the active images of the segment (11.7.2) following the statement is delayed until all other active images in the current team have executed the same statement the same number of times in this team. The segments that executed before the statement on an active image of this team precede the segments that execute after the statement on another active image of this team. A coarray shall not become deallocated on an image unless it is successfully deallocated on all active images in this team.

10

11 If an allocate-object is a coarray dummy argument, its ultimate argument (15.5.2.3) shall be the same coarray on

11 12

those images. 12 The effect of automatic deallocation is the same as that of a DEALLOCATE statement without a dealloc-opt-list.

NOTE 1 In the following example: SUBROUTINE PROCESS REAL, ALLOCATABLE :: TEMP (:) REAL, ALLOCATABLE, SAVE :: X (:) ... END SUBROUTINE PROCESS on return from subroutine PROCESS, the allocation status of X is preserved because X has the SAVE attribute. TEMP does not have the SAVE attribute, so it will be deallocated if it was allocated. On the next invocation of PROCESS, TEMP will have an allocation status of unallocated. NOTE 2 For example, executing a RETURN, END, or END BLOCK statement, or deallocating an object that has an allocatable subobject, can cause deallocation of a coarray, and thus an implicit synchronization of all active images in the current team. 13

9.7.3.3

Deallocation of pointer targets

14

1 If a pointer appears in a DEALLOCATE statement, its association status shall be defined. Deallocating a pointer

15 16 17 18

that is disassociated or whose target was not created by an ALLOCATE statement causes an error condition in the DEALLOCATE statement. If a pointer is associated with an allocatable entity, the pointer shall not be deallocated. A pointer shall not be deallocated if its target or any subobject thereof is argument associated with a dummy argument or construct associated with an associate name.

19 20

2 If a pointer appears in a DEALLOCATE statement, it shall be associated with the whole of an object that was

21 22 23

created by allocation. The pointer shall have the same dynamic type and type parameters as the allocated object, and if the allocated object is an array the pointer shall be an array whose elements are the same as those of the allocated object in array element order. Deallocating a pointer target causes the pointer association status of any other pointer that is associated with the target or a portion of the target to become undefined.

24

9.7.4

STAT= specifier

25

R946

stat-variable

is

scalar-int-variable

26 27

1 A stat-variable should have a decimal exponent range of at least four; otherwise the processor-dependent error

28 29

2 This rest of this subclause applies where an alloc-opt or dealloc-opt that is a STAT= specifier appears in an

code might not be representable in the variable. ALLOCATE or DEALLOCATE statement.

ISO/IEC JTC 1/SC 22/WG5/N2184

147

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

3 The stat-variable shall not be allocated or deallocated within the ALLOCATE or DEALLOCATE statement

5 6

4 Successful execution of the ALLOCATE or DEALLOCATE statement causes the stat-variable to become defined

7 8 9 10

5 If an ALLOCATE or DEALLOCATE statement with a coarray allocate-object is executed when the current team

11 12 13 14 15 16 17 18 19 20 21 22

in which it appears; nor shall it depend on the value, bounds, deferred type parameters, allocation status, or association status of any allocate-object in that statement. The stat-variable shall not depend on the value of the errmsg-variable. with a value of zero. contains a stopped image, the stat-variable becomes defined with the value STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV (16.10.2). Otherwise, if an allocate-object is a coarray, the current team contains a failed image, and no other error condition occurs, the stat-variable becomes defined with value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV. If any other error condition occurs during execution of the ALLOCATE or DEALLOCATE statement, the stat-variable becomes defined with a processordependent positive integer value different from STAT_STOPPED_IMAGE and STAT_FAILED_IMAGE. 6 If stat-variable became defined with the value STAT_FAILED_IMAGE, each allocate-object is successfully al-

located or deallocated on all the active images of the current team. If any other error condition occurs, each allocate-object has a processor-dependent status: • each allocate-object that was successfully allocated shall have an allocation status of allocated or a pointer association status of associated; • each allocate-object that was successfully deallocated shall have an allocation status of unallocated or a pointer association status of disassociated; • each allocate-object that was not successfully allocated or deallocated shall retain its previous allocation status or pointer association status. NOTE 1 The status of objects that were not successfully allocated or deallocated can be individually checked with the intrinsic functions ALLOCATED or ASSOCIATED.

23

9.7.5

ERRMSG= specifier

24 25 26 27

1 The errmsg-variable shall not be an allocate-object of the ALLOCATE or DEALLOCATE statement in which

28 29 30

2 If an error condition occurs during execution of an ALLOCATE or DEALLOCATE statement with an ERRMSG=

it appears; nor shall it depend on the value, bounds, deferred type parameters, allocation status, or association status of any allocate-object in that statement. The errmsg-variable shall not depend on the value of the statvariable. specifier, the errmsg-variable is assigned an explanatory message, as if by intrinsic assignment. If no such condition occurs, the definition status and value of errmsg-variable are unchanged.

148

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

10 Expressions and assignment

2

10.1

Expressions

3

10.1.1

Expression semantics

4 5 6

J3/21-007r1

1 An expression represents either a data object reference or a computation, and its value is either a scalar or an

array. Evaluation of an expression produces a value, which has a type, type parameters (if appropriate), and a shape (10.1.9). The corank of an expression that is not a variable is zero.

7

10.1.2

Form of an expression

8

10.1.2.1

Overall expression syntax

9 10 11

1 An expression is formed from operands, operators, and parentheses. An operand is either a scalar or an array.

12 13

2 An expression is defined in terms of several categories: primary, level-1 expression, level-2 expression, level-3

14 15

3 These categories are related to the different operator precedence levels and, in general, are defined in terms of

An operation is either intrinsic (10.1.5) or defined (10.1.6). More complicated expressions can be formed using operands which are themselves expressions. expression, level-4 expression, and level-5 expression. other categories. The simplest form of each expression category is a primary.

16

10.1.2.2

Primary

17 18 19

R1001 primary

26

is or or or or or or or or or

27

C1001 (R1001) The type-param-name shall be the name of a type parameter.

28

C1002 (R1001) The designator shall not be a whole assumed-size array.

29

C1003 (R1001) The expr shall not be a function reference that returns a procedure pointer.

20 21 22 23 24 25

literal-constant designator array-constructor structure-constructor enum-constructor enumeration-constructor function-reference type-param-inquiry type-param-name ( expr )

NOTE 1 Examples of a primary are:

ISO/IEC JTC 1/SC 22/WG5/N2184

149

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) Example 1.0 ’ABCDEFGHIJKLMNOPQRSTUVWXYZ’ (I:I) [ 1.0, 2.0 ] PERSON (’Jones’, 12) F (X, Y) X%KIND KIND (S + T) 1 2 3

10.1.2.3

Syntactic class constant designator array-constructor structure-constructor function-reference type-param-inquiry type-param-name (expr)

Level-1 expressions

1 Defined unary operators have the highest operator precedence (Table 10.1). Level-1 expressions are primaries

optionally operated on by defined unary operators:

4

R1002 level-1-expr

is

[ defined-unary-op ] primary

5

R1003 defined-unary-op

is

. letter [ letter ] ... .

6

C1004 (R1003) A defined-unary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.

7

NOTE 1 Simple examples of a level-1 expression are: Syntactic class primary (R1001) level-1-expr (R1002)

Example A .INVERSE. B

A more complicated example of a level-1 expression is: .INVERSE. (A + B) 8 9 10

10.1.2.4

Level-2 expressions

1 Level-2 expressions are level-1 expressions optionally involving the numeric operators power-op, mult-op, and

add-op.

11

R1004 mult-operand

is

level-1-expr [ power-op mult-operand ]

12

R1005 add-operand

is

[ add-operand mult-op ] mult-operand

13

R1006 level-2-expr

is

[ [ level-2-expr ] add-op ] add-operand

14

R1007 power-op

is

**

15 16

R1008 mult-op

is * or /

17 18

R1009 add-op

is + or –

NOTE 1 Simple examples of a level-2 expression are:

150

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) Example A B ** C

Syntactic class level-1-expr mult-operand

D * E

add-operand

+1 F - I

level-2-expr level-2-expr

Remarks A is a primary. (R1002) B is a level-1-expr, ** is a power-op, and C is a mult-operand. (R1004) D is an add-operand, * is a mult-op, and E is a mult-operand. (R1005) + is an add-op and 1 is an add-operand. (R1006) F is a level-2-expr, – is an add-op, and I is an add-operand. (R1006)

A more complicated example of a level-2 expression is: - A + D * E + B ** C 1 2

10.1.2.5

Level-3 expressions

1 Level-3 expressions are level-2 expressions optionally involving the character operator concat-op.

3

R1010 level-3-expr

is

[ level-3-expr concat-op ] level-2-expr

4

R1011 concat-op

is

//

NOTE 1 Simple examples of a level-3 expression are: Example A B // C

Syntactic class level-2-expr (R1006) level-3-expr (R1010)

A more complicated example of a level-3 expression is: X // Y // ’ABCD’ 5 6

10.1.2.6

Level-4 expressions

1 Level-4 expressions are level-3 expressions optionally involving the relational operators rel-op.

7

R1012 level-4-expr

is

[ level-3-expr rel-op ] level-3-expr

8 9 10

R1013 rel-op

is or or or or or or or or or or or

.EQ. .NE. .LT. .LE. .GT. .GE. == /= < <= > >=

11 12 13 14 15 16 17 18 19

NOTE 1 Simple examples of a level-4 expression are:

ISO/IEC JTC 1/SC 22/WG5/N2184

151

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) Example A B == C D < E

Syntactic class level-3-expr (R1010) level-4-expr (R1012) level-4-expr (R1012)

A more complicated example of a level-4 expression is: (A + B) /= C 1 2 3

10.1.2.7

Level-5 expressions

1 Level-5 expressions are level-4 expressions optionally involving the logical operators not-op, and-op, or-op, and

equiv-op.

4

R1014 and-operand

is

[ not-op ] level-4-expr

5

R1015 or-operand

is

[ or-operand and-op ] and-operand

6

R1016 equiv-operand

is

[ equiv-operand or-op ] or-operand

7

R1017 level-5-expr

is

[ level-5-expr equiv-op ] equiv-operand

8

R1018 not-op

is

.NOT.

9

R1019 and-op

is

.AND.

10

R1020 or-op

is

.OR.

11 12

R1021 equiv-op

is .EQV. or .NEQV.

NOTE 1 Simple examples of a level-5 expression are: Example A .NOT. B C .AND. D E .OR. F G .EQV. H S .NEQV. T

Syntactic class level-4-expr (R1012) and-operand (R1014) or-operand (R1015) equiv-operand (R1016) level-5-expr (R1017) level-5-expr (R1017)

A more complicated example of a level-5 expression is: A .AND. B .EQV. .NOT. C 13 14 15

10.1.2.8

General form of an expression

1 Expressions are level-5 expressions optionally involving defined binary operators. Defined binary operators have

the lowest operator precedence (Table 10.1).

16

R1022 expr

is

[ expr defined-binary-op ] level-5-expr

17

R1023 defined-binary-op

is

. letter [ letter ] ... .

18

C1005 (R1023) A defined-binary-op shall not contain more than 63 letters and shall not be the same as any intrinsic-operator or logical-literal-constant.

19

152

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 Simple examples of an expression are: Example A B.UNION.C

Syntactic class level-5-expr (R1017) expr (R1022)

More complicated examples of an expression are: (B .INTERSECT. C) .UNION. (X - Y) A + B == C * D .INVERSE. (A + B) A + B .AND. C * D E // G == H (1:10)

1 2 3 4

10.1.3

Precedence of operators

1 There is a precedence among the intrinsic and extension operations corresponding to the form of expressions

specified in 10.1.2, which determines the order in which the operands are combined unless the order is changed by the use of parentheses. This precedence order is summarized in Table 10.1. Table 10.1: Categories of operations and relative precedence Category of operation Operators Precedence Extension Numeric Numeric Numeric Numeric Character Relational Logical Logical Logical Logical Extension

5

defined-unary-op ** *, / unary +, – binary +, – // .EQ., .NE., .LT., .LE., .GT., .GE., ==, /=, <, <=, >, >= .NOT. .AND. .OR. .EQV., .NEQV. defined-binary-op

Highest . . . . . . . . . . Lowest

2 The precedence of a defined operation is that of its operator.

NOTE 1 For example, in the expression -A ** 2 the exponentiation operator (**) has precedence over the negation operator (–); therefore, the operands of the exponentiation operator are combined to form an expression that is used as the operand of the negation operator. The interpretation of the above expression is the same as the interpretation of the expression - (A ** 2)

6 7 8

3 The general form of an expression (10.1.2) also establishes a precedence among operators in the same syntactic

class. This precedence determines the order in which the operands are to be combined in determining the interpretation of the expression unless the order is changed by the use of parentheses.

ISO/IEC JTC 1/SC 22/WG5/N2184

153

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 In interpreting a level-2-expr containing two or more binary operators + or –, each operand (add-operand) is combined from left to right. Similarly, the same left-to-right interpretation for a mult-operand in addoperand, as well as for other kinds of expressions, is a consequence of the general form. However, for interpreting a mult-operand expression when two or more exponentiation operators ** combine level-1-expr operands, each level-1-expr is combined from right to left. For example, the expressions 2.1 + 3.4 + 4.9 2.1 * 3.4 * 4.9 2.1 / 3.4 / 4.9 2 ** 3 ** 4 ’AB’ // ’CD’ // ’EF’ have the same interpretations as the expressions (2.1 + 3.4) + 4.9 (2.1 * 3.4) * 4.9 (2.1 / 3.4) / 4.9 2 ** (3 ** 4) (’AB’ // ’CD’) // ’EF’ As a consequence of the general form (10.1.2), only the first add-operand of a level-2-expr can be preceded by the identity (+) or negation (–) operator. These formation rules do not permit expressions containing two consecutive numeric operators, such as A ** –B or A + –B. However, expressions such as A ** (–B) and A + (–B) are permitted. The rules do allow a binary operator or an intrinsic unary operator to be followed by a defined unary operator, such as: A * .INVERSE. B - .INVERSE. (B) As another example, in the expression A .OR. B .AND. C the general form implies a higher precedence for the .AND. operator than for the .OR. operator; therefore, the interpretation of the above expression is the same as the interpretation of the expression A .OR. (B .AND. C) NOTE 3 An expression can contain more than one category of operator. The logical expression L .OR. A + B >= C where A, B, and C are of type real, and L is of type logical, contains a numeric operator, a relational operator, and a logical operator. This expression would be interpreted the same as the expression L .OR. ((A + B) >= C) NOTE 4 If • the operator ** is extended to type logical, • the operator .STARSTAR. is defined to duplicate the function of ** on type real, • .MINUS. is defined to duplicate the unary operator –, and • L1 and L2 are type logical and X and Y are type real, then in precedence: L1 ** L2 is higher than X * Y; X * Y is higher than X .STARSTAR. Y; and .MINUS. X is higher than –X.

154

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

10.1.4

WD 1539-1

J3/21-007r1

Evaluation of operations

2

1 An intrinsic operation requires the values of its operands.

3

2 Execution of a function reference in the logical expression in an IF statement (11.1.8.4), the mask expression in a

4 5 6

WHERE statement (10.2.3.1), or the concurrent-limits and concurrent-steps in a FORALL statement (10.2.4) is permitted to define variables in the subsidiary action-stmt, where-assignment-stmt, or forall-assignment-stmt respectively. Except in those cases: • the evaluation of a function reference shall neither affect nor be affected by the evaluation of any other entity within the statement; • if a function reference causes definition or undefinition of an actual argument of the function, that argument or any associated entities shall not appear elsewhere in the same statement.

7 8 9 10

NOTE 1 For example, the statements A (I) = F (I) Y = G (X) + X are prohibited if the reference to F defines or undefines I or the reference to G defines or undefines X. However, in the statements IF (F (X)) A = X WHERE (G (X)) B = X the reference to F and/or the reference to G can define X. 11 12

3 The appearance of an array constructor requires the evaluation of each scalar-int-expr of the ac-implied-do-control

13 14

4 When an elemental binary operation is applied to a scalar and an array or to two arrays of the same shape, the

in any ac-implied-do it contains. operation is performed element-by-element on corresponding array elements of the array operands. NOTE 2 For example, the array expression A + B produces an array of the same shape as A and B. The individual array elements of the result have the values of the first element of A added to the first element of B, the second element of A added to the second element of B, etc.

15

5 When an elemental unary operator operates on an array operand, the operation is performed element-by-element,

16 17

and the result is the same shape as the operand. If an elemental operation is intrinsically pure or is implemented by a pure elemental function (15.9), the element operations may be performed simultaneously or in any order.

18

10.1.5

Intrinsic operations

19

10.1.5.1

Intrinsic operation classification

20 21 22

1 An intrinsic operation is either a unary or binary operation. An intrinsic unary operation is an operation of

23

2 An intrinsic binary operation is an operation of the form x1 intrinsic-operator x2 where x1 and x2 are conformable

24 25 26

the form intrinsic-operator x2 where x2 is of an intrinsic type (7.4) listed in Table 10.2 for the unary intrinsic operator. and of the intrinsic or enumeration types listed in Table 10.2 for the binary intrinsic operator. 3 A numeric intrinsic operation is an intrinsic operation for which the intrinsic-operator is a numeric operator (+,

–, *, /, or **). A numeric intrinsic operator is the operator in a numeric intrinsic operation.

ISO/IEC JTC 1/SC 22/WG5/N2184

155

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

4 The character intrinsic operation is the intrinsic operation for which the intrinsic-operator is (//) and both

4

5 A logical intrinsic operation is an intrinsic operation for which the intrinsic-operator is .AND., .OR., .NOT.,

5 6

.EQV., or .NEQV. and both operands are of type logical. A logical intrinsic operator is the operator in a logical intrinsic operation.

7 8 9 10

6 A relational intrinsic operator is an intrinsic-operator that is .EQ., .NE., .GT., .GE., .LT., .LE., ==, /=, >,

11 12 13 14 15

operands are of type character with the same kind type parameter. The character intrinsic operator is the operator in a character intrinsic operation.

>=, <, or <=. A relational intrinsic operation is an intrinsic operation for which the intrinsic-operator is a relational intrinsic operator. A numeric relational intrinsic operation is a relational intrinsic operation for which both operands are of numeric type. A character relational intrinsic operation is a relational intrinsic operation for which both operands are of type character. An enumeration relational intrinsic operation is a relational intrinsic operation for which both operands are of the same enumeration type. The kind type parameters of the operands of a character relational intrinsic operation shall be the same. 7 The interpretations defined in 10.1.5 apply to both scalars and arrays; the interpretation for arrays is obtained

by applying the interpretation for scalars element by element. Table 10.2: Type of operands and results for intrinsic operators Intrinsic operator op

Type of x1

Unary +, –

Type of x2

Type of [x1 ] op x2

I, R, Z

I, R, Z

Binary +, –, *, /, **

I R Z

I, R, Z I, R, Z I, R, Z

I, R, Z R, R, Z Z, Z, Z

//

C

C

C

I R Z C E

I, R, Z I, R, Z I, R, Z C E

L, L, L L, L, L L, L, L L L

I R C E

I, R I, R C E

L, L L, L L L

L

L

L

L

.EQ., .NE., ==, /=

.GT., .GE., .LT., .LE. >, >=, <, <= .NOT. .AND., .OR., .EQV., .NEQV.

L

The symbols I, R, Z, C, and L stand for the types integer, real, complex, character, and logical, respectively. The symbol E stands for the same enumeration type for both operands. Where more than one type for x2 is given, the type of the result of the operation is given in the same relative position in the next column.

NOTE 1 For example, if X is of type real and J is of type integer, the expression X + J is of type real. 16

10.1.5.2

17

10.1.5.2.1

Numeric intrinsic operations Interpretation of numeric intrinsic operations

18

1 The two operands of numeric intrinsic binary operations may be of different numeric types or different kind

19

type parameters. Except for a value of type real or complex raised to an integer power, if the operands have

156

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

different types or kind type parameters, the effect is as if each operand that differs in type or kind type parameter from those of the result is converted to the type and kind type parameter of the result before the operation is performed. When a value of type real or complex is raised to an integer power, the integer operand need not be converted.

5 6

2 A numeric operation is used to express a numeric computation. Evaluation of a numeric operation produces a

7 8

3 The numeric operators and their interpretation in an expression are given in Table 10.3, where x1 denotes the

numeric value. The permitted data types for operands of the numeric intrinsic operations are specified in 10.1.5.1. operand to the left of the operator and x2 denotes the operand to the right of the operator. Table 10.3: Interpretation of the numeric intrinsic operators Operator Representing Use of operator Interpretation ** / * − − + +

Exponentiation Division Multiplication Subtraction Negation Addition Identity

x1 ** x2 x1 / x2 x1 * x2 x1 - x2 - x2 x1 + x2 + x2

Raise x1 to the power x2 Divide x1 by x2 Multiply x1 by x2 Subtract x2 from x1 Negate x2 Add x1 and x2 Same as x2

9

4 The interpretation of a division operation depends on the types of the operands (10.1.5.2.2).

10 11

5 If x1 and x2 are of type integer and x2 has a negative value, the interpretation of x1 ** x2 is the same as the

interpretation of 1/(x1 ** ABS (x2 )), which is subject to the rules of integer division (10.1.5.2.2). NOTE 1 For example, 2 ** (−3) has the value of 1/(2 ** 3), which is zero.

12

10.1.5.2.2

Integer division

13

1 One operand of type integer may be divided by another operand of type integer. Although the mathematical

14 15 16 17

quotient of two integers is not necessarily an integer, Table 10.2 specifies that an expression involving the division operator with two operands of type integer is interpreted as an expression of type integer. The result of such an operation is the integer closest to the mathematical quotient and between zero and the mathematical quotient inclusively. NOTE 1 For example, the expression (−8) / 3 has the value (−2).

18 19 20 21

10.1.5.2.3

Complex exponentiation

1 In the case of a complex value raised to a complex power, the value of the operation x1 ** x2 is the principal

value of xx1 2 .

10.1.5.2.4

Evaluation of numeric intrinsic operations

22 23

1 The execution of any numeric operation whose result is not defined by the arithmetic used by the processor is

24 25

2 Once the interpretation of a numeric intrinsic operation is established, the processor may evaluate any mathem-

26

3 Two expressions of a numeric type are mathematically equivalent if, for all possible values of their primaries, their

prohibited. Raising a negative real value to a real power is prohibited. atically equivalent expression, provided that the integrity of parentheses is not violated.

ISO/IEC JTC 1/SC 22/WG5/N2184

157

J3/21-007r1

1 2

WD 1539-1

2021-05-21

mathematical values are equal. However, mathematically equivalent expressions of numeric type can produce different computational results. NOTE 1 Any difference between the values of the expressions (1./3.)*3. and 1. is a computational difference, not a mathematical difference. The difference between the values of the expressions 5/2 and 5./2. is a mathematical difference, not a computational difference. The mathematical definition of integer division is given in 10.1.5.2.2. NOTE 2 The following are examples of expressions with allowable alternative forms that can be used by the processor in the evaluation of those expressions. A, B, and C represent arbitrary real or complex operands; I and J represent arbitrary integer operands; and X, Y, and Z represent arbitrary operands of numeric type. Allowable alternative form Y+X Y*X Y-X X + (Y + Z) X - (Y - Z) X * (A / Z) X * (Y - Z) A / (B * C) 0.2 * A

Expression X+Y X*Y -X + Y X+Y+Z X-Y+Z X*A/Z X*Y-X*Z A/B/C A / 5.0

The following are examples of expressions with forbidden alternative forms that cannot be used by a processor in the evaluation of those expressions. Forbidden alternative form 0.5 * I X * (I / J) I / (J * A) X + (Y + Z) X * (Y - Z) X*Y-X*Z

Expression I/2 X*I/J I/J/A (X + Y) + Z (X * Y) - (X * Z) X * (Y - Z)

NOTE 3 In addition to the parentheses required to establish the desired interpretation, parentheses can be included to restrict the alternative forms that can be used by the processor in the actual evaluation of the expression. This is useful for controlling the magnitude and accuracy of intermediate values developed during the evaluation of an expression. For example, in the expression A + (B - C) the parenthesized expression (B − C) is evaluated and then added to A. The inclusion of parentheses could change the mathematical value of an expression. For example, the two expressions A * I / J A * (I / J) could have different mathematical values if I and J are of type integer.

158

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 4 Each operand in a numeric intrinsic operation has a type that can depend on the order of evaluation used by the processor. For example, in the evaluation of the expression Z + R + I where Z, R, and I represent data objects of complex, real, and integer type, respectively, the type of the operand that is added to I could be either complex or real, depending on which pair of operands (Z and R, R and I, or Z and I) is added first. 1

10.1.5.3

2

10.1.5.3.1

Character intrinsic operation Interpretation of the character intrinsic operation

3 4

1 The character intrinsic operator // is used to concatenate two operands of type character with the same kind

5 6

2 The interpretation of the character intrinsic operator // when used to form an expression is given in Table 10.4,

type parameter. Evaluation of the character intrinsic operation produces a result of type character. where x1 denotes the operand to the left of the operator and x2 denotes the operand to the right of the operator. Table 10.4: Interpretation of the character intrinsic operator // Operator Representing Use of operator Interpretation //

Concatenation

x1 // x2

Concatenate x1 with x2

7

3 The result of the character intrinsic operation x1 // x2 is a character string whose value is the value of x1

8 9

concatenated on the right with the value of x2 and whose length is the sum of the lengths of x1 and x2 . Parentheses used to specify the order of evaluation have no effect on the value of a character expression. NOTE 1 For example, the value of the expression (’AB’ // ’CDE’) // ’F’ is the string ’ABCDEF’. The value of the expression ’AB’ // (’CDE’ // ’F’) is also the string ’ABCDEF’.

10 11 12

10.1.5.3.2

Evaluation of the character intrinsic operation

1 A processor is only required to evaluate as much of the character intrinsic operation as is required by the context

in which the expression appears. NOTE 1 For example, the statements CHARACTER (LEN = 2) C1, C2, C3, CF C1 = C2 // CF (C3) do not require the function CF to be evaluated, because only the value of C2 is needed to determine the value of C1 because C1 and C2 both have a length of 2.

13

10.1.5.4

14

10.1.5.4.1

Logical intrinsic operations Interpretation of logical intrinsic operations

15 16

1 A logical operation is used to express a logical computation. Evaluation of a logical operation produces a result

17 18

2 The logical operators and their interpretation when used to form an expression are given in Table 10.5, where x1

of type logical. The permitted types for operands of the logical intrinsic operations are specified in 10.1.5.1. denotes the operand to the left of the operator and x2 denotes the operand to the right of the operator.

ISO/IEC JTC 1/SC 22/WG5/N2184

159

J3/21-007r1

1

WD 1539-1

2021-05-21

Operator

Table 10.5: Interpretation of the logical intrinsic operators Representing Use of operator Interpretation

.NOT. .AND. .OR.

Logical negation Logical conjunction Logical inclusive disjunction

.NOT. x2 x1 .AND. x2 x1 .OR. x2

.EQV.

Logical equivalence

x1 .EQV. x2

.NEQV.

Logical nonequivalence

x1 .NEQV. x2

True if x2 is false True if x1 and x2 are both true True if x1 and/or x2 is true True if both x1 and x2 are true or both are false True if either x1 or x2 is true, but not both

3 The values of the logical intrinsic operations are shown in Table 10.6.

Table 10.6: The values of operations involving logical intrinsic operators x1 x2 .NOT. x2 x1 .AND. x2 x1 .OR. x2 x1 .EQV. x2 x1 .NEQV. x2 true true false false

2 3 4

10.1.5.4.2

true false true false

false true false true

true false false false

true true true false

true false false true

false true true false

Evaluation of logical intrinsic operations

1 Once the interpretation of a logical intrinsic operation is established, the processor may evaluate any other

expression that is logically equivalent, provided that the integrity of parentheses in any expression is not violated. NOTE 1 For example, for the variables L1, L2, and L3 of type logical, the processor could choose to evaluate the expression L1 .AND. L2 .AND. L3 as L1 .AND. (L2 .AND. L3)

5 6

2 Two expressions of type logical are logically equivalent if their values are equal for all possible values of their

primaries.

7

10.1.5.5

8

10.1.5.5.1

Relational intrinsic operations Interpretation of relational intrinsic operations

9 10 11

1 A relational intrinsic operation is used to compare values of two operands using the relational intrinsic operators

12 13

2 The operators <, <=, >, >=, ==, and /= always have the same interpretations as the operators .LT., .LE.,

.LT., .LE., .GT., .GE., .EQ., .NE., <, <=, >, >=, ==, and /=. The permitted types for operands of the relational intrinsic operators are specified in 10.1.5.1. .GT., .GE., .EQ., and .NE., respectively. NOTE 1 As shown in Table 10.2, a relational intrinsic operator cannot be used to compare the value of an expression of a numeric type with one of type character or logical. Also, two operands of type logical cannot be compared, a complex operand can be compared with another numeric operand only when the operator is .EQ., .NE., ==, or /=, and two character operands cannot be compared unless they have the same kind type parameter value.

160

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

3 Evaluation of a relational intrinsic operation produces a default logical result.

2 3

4 The interpretation of the relational intrinsic operators is given in Table 10.7, where x1 denotes the operand to

the left of the operator and x2 denotes the operand to the right of the operator. Table 10.7: Interpretation of the relational intrinsic operators Operator Representing Use of operator Interpretation .LT. < .LE. <= .GT. > .GE. >= .EQ. == .NE. /=

Less than Less than Less than or equal to Less than or equal to Greater than Greater than Greater than or equal to Greater than or equal to Equal to Equal to Not equal to Not equal to

x1 .LT. x2 x1 < x 2 x1 .LE. x2 x1 <= x2 x1 .GT. x2 x1 > x 2 x1 .GE. x2 x1 >= x2 x1 .EQ. x2 x1 == x2 x1 .NE. x2 x1 /= x2

x1 less than x2 x1 less than x2 x1 less than or equal to x2 x1 less than or equal to x2 x1 greater than x2 x1 greater than x2 x1 greater than or equal to x2 x1 greater than or equal to x2 x1 equal to x2 x1 equal to x2 x1 not equal to x2 x1 not equal to x2

4 5

5 A numeric relational intrinsic operation is interpreted as having the logical value true if and only if the values of

6

6 In the numeric relational operation

the operands satisfy the relation specified by the operator.

7 8 9

x1 rel-op x2 if the types or kind type parameters of x1 and x2 differ, their values are converted to the type and kind type parameter of the expression x1 + x2 before evaluation.

10 11

7 A character relational intrinsic operation is interpreted as having the logical value true if and only if the values

12 13 14 15

8 For a character relational intrinsic operation, the operands are compared one character at a time in order,

16 17 18 19

of the operands satisfy the relation specified by the operator. beginning with the first character of each character operand. If the operands are of unequal length, the shorter operand is treated as if it were extended on the right with blanks to the length of the longer operand. If both x1 and x2 are of zero length, x1 is equal to x2 ; if every character of x1 is the same as the character in the corresponding position in x2 , x1 is equal to x2 . Otherwise, at the first position where the character operands differ, the character operand x1 is considered to be less than x2 if the character value of x1 at this position precedes the value of x2 in the collating sequence (3.31); x1 is greater than x2 if the character value of x1 at this position follows the value of x2 in the collating sequence. NOTE 2 The collating sequence depends partially on the processor; however, the result of the use of the operators .EQ., .NE., ==, and /= does not depend on the collating sequence. For nondefault character kinds, the blank padding character is processor dependent.

20 21 22

9 An enumeration relational intrinsic operation is interpreted as having the logical value true if and only if the

ordinal values of the operands satisfy the relation specified by the operator. 10.1.5.5.2

Evaluation of relational intrinsic operations

23

1 Once the interpretation of a relational intrinsic operation is established, the processor may evaluate any other

24 25

expression that is relationally equivalent, provided that the integrity of parentheses in any expression is not violated.

ISO/IEC JTC 1/SC 22/WG5/N2184

161

J3/21-007r1

1 2

WD 1539-1

2021-05-21

2 Two relational intrinsic operations are relationally equivalent if their logical values are equal for all possible values

of their primaries. NOTE 1 Whether an operand of a relational intrinsic operation could be an IEEE NaN affects whether expressions are equivalent. For example, if x or y could be a NaN, the expressions .NOT. (x .LT. y)

and

x .GE. y

are not equivalent.

3

10.1.6

Defined operations

4

10.1.6.1

Definitions

5 6 7

1 A defined operation is either a unary operation or a binary operation. A unary defined operation is an operation

8

2 A function defines the unary operation op x2 if

that has the form defined-unary-op x2 or intrinsic-operator x2 and that is defined by a function and a generic interface (7.5.5, 15.4.3.4).

9 10

(1)

11

(2)

the function is specified with a FUNCTION (15.6.2.2) or ENTRY (15.6.2.6) statement that specifies one dummy argument d2 , either

12 13

(a)

14 15

(b) (3) (4) (5)

16 17 18

the type of d2 is compatible with the dynamic type of x2 , the type parameters, if any, of d2 match the corresponding type parameters of x2 , and either (a) (b)

19 20

a generic interface (15.4.3.2) provides the function with a generic-spec of OPERATOR (op), or there is a generic binding (7.5.5) in the declared type of x2 with a generic-spec of OPERATOR (op) and there is a corresponding binding to the function in the dynamic type of x2 ,

the rank of x2 matches that of d2 or the function is elemental and there is no other function that defines the operation.

21

3 If d2 is an array, the shape of x2 shall match the shape of d2 .

22 23

4 A binary defined operation is an operation that has the form x1 defined-binary-op x2 or x1 intrinsic-operator x2

24

5 A function defines the binary operation x1 op x2 if

and that is defined by a function and a generic interface.

25 26

(1)

27

(2)

the function is specified with a FUNCTION (15.6.2.2) or ENTRY (15.6.2.6) statement that specifies two dummy arguments, d1 and d2 , either

28 29

(a)

30

(b)

31 32

(3) (4)

33 34 35

(5)

36

the types of d1 and d2 are compatible with the dynamic types of x1 and x2 , respectively, the type parameters, if any, of d1 and d2 match the corresponding type parameters of x1 and x2 , respectively, and either (a)

37

162

a generic interface (15.4.3.2) provides the function with a generic-spec of OPERATOR (op), or there is a generic binding (7.5.5) in the declared type of x1 or x2 with a generic-spec of OPERATOR (op) and there is a corresponding binding to the function in the dynamic type of x1 or x2 , respectively,

the ranks of x1 and x2 match those of d1 and d2 , respectively, or

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

(b)

1 2 3

WD 1539-1

J3/21-007r1

the function is elemental, x1 and x2 are conformable, and there is no other function that defines the operation.

6 If d1 or d2 is an array, the shapes of x1 and x2 shall match the shapes of d1 and d2 , respectively.

NOTE 1 An intrinsic operator can be used as the operator in a defined operation. In such a case, the generic properties of the operator are extended. 4

10.1.6.2

Interpretation of a defined operation

5

1 The interpretation of a defined operation is provided by the function that defines the operation.

6 7

2 The operators <, <=, >, >=, ==, and /= always have the same interpretations as the operators .LT., .LE.,

8

.GT., .GE., .EQ., and .NE., respectively. 10.1.6.3

Evaluation of a defined operation

9 10

1 Once the interpretation of a defined operation is established, the processor may evaluate any other expression

11

2 Two expressions of derived type are equivalent if their values are equal for all possible values of their primaries.

12 13 14

that is equivalent, provided that the integrity of parentheses is not violated.

10.1.7

Evaluation of operands

1 It is not necessary for a processor to evaluate all of the operands of an expression, or to evaluate entirely each

operand, if the value of the expression can be determined otherwise. NOTE 1 This principle is most often applicable to logical expressions, zero-sized arrays, and zero-length strings, but it applies to all expressions. For example, in evaluating the expression X > Y .OR. L (Z) where X, Y, and Z are real and L is a function of type logical, the function reference L (Z) need not be evaluated if X is greater than Y. Similarly, in the array expression W (Z) + A where A is of size zero and W is a function, the function reference W (Z) need not be evaluated.

15

2 If a statement contains a function reference in a part of an expression that need not be evaluated, all entities that

16 17

would have become defined in the execution of that reference become undefined at the completion of evaluation of the expression containing the function reference. NOTE 2 In the examples in NOTE 1, if L or W defines its argument, evaluation of the expressions under the specified conditions causes Z to become undefined, no matter whether or not L(Z) or W(Z) is evaluated.

18

3 If a statement contains a function reference in a part of an expression that need not be evaluated, no invocation

19 20

of that function in that part of the expression shall execute an image control statement other than CRITICAL or END CRITICAL. NOTE 3 This restriction is intended to avoid inadvertent deadlock caused by optimization.

ISO/IEC JTC 1/SC 22/WG5/N2184

163

J3/21-007r1

1 2 3 4

10.1.8

WD 1539-1

2021-05-21

Integrity of parentheses

1 The rules for evaluation specified in 10.1.5 state certain conditions under which a processor can evaluate an expres-

sion that is different from the one specified by applying the rules given in 10.1.2 and the rules for interpretation specified in 10.1.5. However, any expression in parentheses shall be treated as a data entity. NOTE 1 For example, in evaluating the expression A + (B – C) where A, B, and C are of numeric types, the difference of B and C shall be evaluated before the addition operation is performed; the processor shall not evaluate the mathematically equivalent expression (A + B) – C.

5

10.1.9

Type, type parameters, and shape of an expression

6

10.1.9.1

General

7 8 9

1 The type, type parameters, and shape of an expression depend on the operators and on the types, type parameters,

10

2 If an expression is a polymorphic primary or defined operation, the type parameters and the declared and dynamic

11 12 13

types of the expression are the same as those of the primary or defined operation. Otherwise the type parameters and dynamic type of the expression are the same as its declared type and type parameters; they are referred to simply as the type and type parameters of the expression.

14

R1024 logical-expr

15

C1006 (R1024) logical-expr shall be of type logical.

16

R1025 default-char-expr

17

C1007 (R1025) default-char-expr shall be default character.

18

R1026 int-expr

19

C1008 (R1026) int-expr shall be of type integer.

20

R1027 numeric-expr

21

C1009 (R1027) numeric-expr shall be of type integer, real, or complex.

22

10.1.9.2

and shapes of the primaries used in the expression, and are determined recursively from the syntactic form of the expression. The type of an expression is one of the intrinsic types (7.4) or a derived type (7.5).

is

is

is

is

expr

expr

expr

expr

Type, type parameters, and shape of a primary

23

1 The type, type parameters, and shape of a primary are determined according to whether the primary is a

24 25 26 27 28

literal constant, designator, array constructor, structure constructor, enum constructor, enumeration constructor, function reference, type parameter inquiry, type parameter name, or parenthesized expression. If a primary is a literal constant, its type, type parameters, and shape are those of the literal constant. If it is a structure constructor, it is scalar and its type and type parameters are as described in 7.5.10. If it is an enum constructor, it is scalar and its type are as described in 7.6.1. If it is an enumeration constructor, it is scalar and its type are as described in 7.6.2. If it is an array constructor, its type, type parameters, and shape are as described in 7.8. If it is a designator or function reference, its type, type parameters, and shape are those of the designator (8.2, 8.5) or the function reference (15.5.3), respectively. If the function reference is generic (15.4.3.2, 16.7) then its type, type parameters, and shape are those of the specific function referenced, which is determined by the declared types, type parameters, and ranks of its actual arguments as specified in 15.5.5.2. If it is a type parameter inquiry or type parameter name, it is a scalar integer with the kind of the type parameter.

29 30 31 32 33 34 35

2 If a primary is a parenthesized expression, its type, type parameters, and shape are those of the expression.

36

3 The associated target object is referenced if a pointer appears as a primary in an intrinsic or defined operation, the

164

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8

WD 1539-1

J3/21-007r1

expr of a parenthesized primary, or the only primary on the right-hand side of an intrinsic assignment statement. The type, type parameters, and shape of the primary are those of the target. If the pointer is not associated with a target, it shall appear as a primary only as an actual argument in a reference to a procedure whose corresponding dummy argument is declared to be a pointer, as the target in a pointer assignment statement, or as explicitly permitted elsewhere in this document. 4 A disassociated array pointer or an unallocated allocatable array has no shape but does have rank. The type,

type parameters, and rank of the result of the intrinsic function NULL (16.9.155) depend on context. 10.1.9.3

Type, type parameters, and shape of the result of an operation

9 10

1 The type of the result of an intrinsic operation [x1 ] op x2 is specified by Table 10.2. The shape of the result of

11 12

2 The type, type parameters, and shape of the result of a defined operation [x1 ] op x2 are specified by the function

13 14

3 An expression of an intrinsic type has a kind type parameter. An expression of type character also has a character

15

4 The type parameters of the result of an intrinsic operation are as follows.

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

41

an intrinsic operation is the shape of x2 if op is unary or if x1 is scalar, and is the shape of x1 otherwise. defining the operation (10.1.6). length parameter.

• For an expression x1 // x2 where // is the character intrinsic operator and x1 and x2 are of type character, the character length parameter is the sum of the lengths of the operands and the kind type parameter is the kind type parameter of x1 , which shall be the same as the kind type parameter of x2 . • For an expression op x2 where op is an intrinsic unary operator and x2 is of type integer, real, complex, or logical, the kind type parameter of the expression is that of the operand. • For an expression x1 op x2 where op is a numeric intrinsic binary operator with one operand of type integer and the other of type real or complex, the kind type parameter of the expression is that of the real or complex operand. • For an expression x1 op x2 where op is a numeric intrinsic binary operator with both operands of the same type and kind type parameters, or with one real and one complex with the same kind type parameters, the kind type parameter of the expression is identical to that of each operand. In the case where both operands are integer with different kind type parameters, the kind type parameter of the expression is that of the operand with the greater decimal exponent range if the decimal exponent ranges are different; if the decimal exponent ranges are the same, the kind type parameter of the expression is processor dependent, but it is the same as that of one of the operands. In the case where both operands are any of type real or complex with different kind type parameters, the kind type parameter of the expression is that of the operand with the greater decimal precision if the decimal precisions are different; if the decimal precisions are the same, the kind type parameter of the expression is processor dependent, but it is the same as that of one of the operands. • For an expression x1 op x2 where op is a logical intrinsic binary operator with both operands of the same kind type parameter, the kind type parameter of the expression is identical to that of each operand. In the case where both operands are of type logical with different kind type parameters, the kind type parameter of the expression is processor dependent, but it is the same as that of one of the operands. • For an expression x1 op x2 where op is a relational intrinsic operator, the kind type parameter of the expression is default logical.

10.1.10

Conformability rules for elemental operations

42

1 An elemental operation is an intrinsic operation or a defined operation for which the function is elemental (15.9).

43 44 45

2 For all elemental binary operations, the two operands shall be conformable. In the case where one is a scalar and

the other an array, the scalar is treated as if it were an array of the same shape as the array operand with every element, if any, of the array equal to the value of the scalar.

ISO/IEC JTC 1/SC 22/WG5/N2184

165

J3/21-007r1

1 2 3

10.1.11

WD 1539-1

2021-05-21

Specification expression

1 A specification expression is an expression with limitations that make it suitable for use in specifications such as

4 5

length type parameters (C704) and array bounds (R817, R818). A specification-expr shall be a constant expression unless it is in an interface body (15.4.3.2), the specification part of a subprogram or BLOCK construct, a derived type definition, or the declaration-type-spec of a FUNCTION statement (15.6.2.2).

6

R1028 specification-expr

7

C1010 (R1028) The scalar-int-expr shall be a restricted expression.

8 9

and each primary is (1) (2)

11 12

(3) (4) (5)

13 14 15 16

(6) (7) (8) (9)

17 18 19 20

22 23 24 25 26

29 30 31 32 33 34 35 36 37 38 39

a constant or subobject of a constant, an object designator with a base object that is a dummy argument that has neither the OPTIONAL nor the INTENT (OUT) attribute, an object designator with a base object that is in a common block,

an object designator with a base object that is made accessible by use or host association, an array constructor where each element and each scalar-int-expr of each ac-implied-do-control is a restricted expression, a structure constructor where each component is a restricted expression, an enum constructor whose expr is a restricted expression, an enumeration constructor whose expr is a restricted expression, a specification inquiry where each designator or argument is (a) (b)

21

28

scalar-int-expr

2 A restricted expression is an expression in which each operation is intrinsic or defined by a specification function

10

27

is

a restricted expression or a variable that is not an optional dummy argument, and whose properties inquired about are not (i) dependent on the upper bound of the last dimension of an assumed-size array, (ii) deferred, or (iii) defined by an expression that is not a restricted expression,

(10) (11) (12) (13)

a specification inquiry that is a constant expression, a reference to the intrinsic function PRESENT, a reference to any other standard intrinsic function where each argument is a restricted expression, a reference to a transformational function from the intrinsic module IEEE_ARITHMETIC, IEEE_EXCEPTIONS, or ISO_C_BINDING, where each argument is a restricted expression, (14) a reference to a specification function where each argument is a restricted expression, (15) a type parameter of the derived type being defined, (16) an ac-do-variable within an array constructor where each scalar-int-expr of the corresponding acimplied-do-control is a restricted expression, or (17) a restricted expression enclosed in parentheses, where each subscript, section subscript, substring starting point, substring ending point, and type parameter value is a restricted expression. 3 A specification inquiry is a reference to

(1) (2) (3)

40 41 42 43

(4) (5)

44 45 46

166

an intrinsic inquiry function other than PRESENT, a type parameter inquiry (9.4.5), an inquiry function from the intrinsic modules IEEE_ARITHMETIC and IEEE_EXCEPTIONS (17.10), the function C_SIZEOF from the intrinsic module ISO_C_BINDING (18.2.3.8), or the COMPILER_VERSION or COMPILER_OPTIONS function from the intrinsic module ISO_FORTRAN_ENV (16.10.2.6, 16.10.2.7).

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

4 A function is a specification function if it is a pure function, is not a standard intrinsic function, is not an internal

3 4

5 Evaluation of a specification expression shall not directly or indirectly cause a procedure defined by the subpro-

function, is not a statement function, and does not have a dummy procedure argument. gram in which it appears to be invoked. NOTE 1 Specification functions are nonintrinsic functions that can be used in specification expressions to determine the attributes of data objects. The requirement that they be pure ensures that they cannot have side effects that could affect other objects being declared in the same specification-part. The requirement that they not be internal ensures that they cannot inquire, via host association, about other objects being declared in the same specification-part. The prohibition against recursion avoids the creation of a new instance of a procedure while construction of one is in progress.

5 6 7 8

6 A variable in a specification expression shall have its type and type parameters, if any, specified by a previous

declaration in the same scoping unit, by the implicit typing rules in effect for the scoping unit, or by host or use association. If a variable in a specification expression is typed by the implicit typing rules, its appearance in any subsequent type declaration statement shall confirm the implied type and type parameters.

9

7 If a specification expression includes a specification inquiry that depends on a type parameter, array bound,

10 11 12 13 14

or cobound of an entity specified in the same specification-part, the type parameter, array bound, or cobound shall be specified in a prior specification of the specification-part. The prior specification may be to the left of the specification inquiry in the same statement, but shall not be within the same entity-decl. If a specification expression includes a reference to the value of an element of an array specified in the same specification-part, the array shall be completely specified in prior declarations.

15

8 A generic entity referenced in a specification expression in the specification-part of a scoping unit shall have no

16

specific procedures defined in the scoping unit, or its host scoping unit, subsequent to the specification expression. NOTE 2 The following are examples of specification expressions: LBOUND (B, 1) + 5 M + LEN (C) 2 * PRECISION (A)

17 18 19 20 21 22 23

10.1.12

Constant expression

1 A constant expression is an expression with limitations that make it suitable for use as a kind type parameter,

initializer, or named constant. It is an expression in which each operation is intrinsic, and each primary is (1) (2) (3)

a constant or subobject of a constant, an array constructor where each element and each scalar-int-expr of each ac-implied-do-control is a constant expression, a structure constructor where each component-spec corresponding to (a) (b)

24 25 26

(c)

27 28 29 30 31

! B is an assumed-shape dummy array ! M and C are dummy arguments ! A is a real variable made accessible by a USE statement

(4) (5) (6)

an allocatable component is a reference to the intrinsic function NULL, a pointer component is an initialization target or a reference to the intrinsic function NULL, and any other component is a constant expression,

an enum constructor whose expr is a constant expression, an enumeration constructor whose expr is a constant expression, a specification inquiry where each designator or argument is (a)

a constant expression or

ISO/IEC JTC 1/SC 22/WG5/N2184

167

J3/21-007r1

(b)

1 2 3 4

(7) (8)

5 6 7 8 9 10

(9)

11 12

(10)

13 14

(11)

15

(12) (13) (14)

16 17 18

(15)

19

WD 1539-1

2021-05-21

a variable whose properties inquired about are not (i) assumed, (ii) deferred, or (iii) defined by an expression that is not a constant expression,

a reference to an elemental standard intrinsic function, where each argument is a constant expression, a reference to a standard intrinsic function that is transformational, other than COMMAND_ARGUMENT_COUNT, GET_TEAM, NULL, NUM_IMAGES, TEAM_NUMBER, THIS_IMAGE, or TRANSFER, where each argument is a constant expression, a reference to the intrinsic function NULL that does not have an argument with a type parameter that is assumed or is defined by an expression that is not a constant expression, a reference to the intrinsic function TRANSFER where each argument is a constant expression and each ultimate pointer component of the SOURCE argument is disassociated, a reference to a transformational function from the intrinsic module IEEE_ARITHMETIC or IEEE_EXCEPTIONS, where each argument is a constant expression, a previously declared kind type parameter of the derived type being defined, a data-i-do-variable within a data-implied-do, an ac-do-variable within an array constructor where each scalar-int-expr of the corresponding acimplied-do-control is a constant expression, or a constant expression enclosed in parentheses,

20 21

and where each subscript, section subscript, substring starting point, substring ending point, and type parameter value is a constant expression.

22

R1029 constant-expr

23

C1011 (R1029) constant-expr shall be a constant expression.

24

R1030 default-char-constant-expr

25

C1012 (R1030) default-char-constant-expr shall be a constant expression.

26

R1031 int-constant-expr

27

C1013 (R1031) int-constant-expr shall be a constant expression.

is

is

is

expr

default-char-expr

int-expr

28

2 If a constant expression includes a specification inquiry that depends on a type parameter or an array bound of

29 30 31 32

an entity specified in the same specification-part, the type parameter or array bound shall be specified in a prior specification of the specification-part. The prior specification may be to the left of the specification inquiry in the same statement, but shall not be within the same entity-decl unless the specification inquiry appears within an initialization.

33 34

3 A generic entity referenced in a constant expression in the specification-part of a scoping unit shall have no specific

procedures defined in that scoping unit, or its host scoping unit, subsequent to the constant expression. NOTE 1 The following are examples of constant expressions: 3 -3 + 4 ’AB’ ’AB’ // ’CD’ (’AB’ // ’CD’) // ’EF’ SIZE (A) DIGITS (X) + 4 4.0 * ATAN (1.0) CEILING (number_of_decimal_digits / LOG10 (REAL (RADIX (0.0))))

168

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) where A is an explicit-shape array with constant bounds, X is default real, and number_of_decimal_digits is an integer named constant.

1

10.2

Assignment

2

10.2.1

Assignment statement

3

10.2.1.1

General form

4

R1032 assignment-stmt

5

C1014 (R1032) The variable shall not be a whole assumed-size array.

is

variable = expr

NOTE 1 Examples of an assignment statement are: A = 3.5 + X * Y I = INT (A)

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

1 An assignment-stmt shall meet the requirements of either a defined assignment statement or an intrinsic assign-

ment statement. 10.2.1.2

Intrinsic assignment statement

1 An intrinsic assignment statement is an assignment statement that is not a defined assignment statement

(10.2.1.4). In an intrinsic assignment statement, (1)

if the variable is polymorphic it shall be allocatable, and not a coarray or a data object with a coarray component, (2) if expr is an array then the variable shall also be an array, (3) the variable and expr shall be conformable unless the variable is an allocatable array that has the same rank as expr and is not a coarray or of a type that has a coarray component, (4) if the variable is polymorphic it shall be type compatible with expr, (5) if expr is a boz-literal-constant, the variable shall be of type integer or real, (6) if the variable is not polymorphic and expr is not a boz-literal-constant, the declared types of the variable and expr shall conform as specified in Table 10.8, (7) if the variable is of type character and of ISO 10646, ASCII, or default character kind, expr shall be of ISO 10646, ASCII, or default character kind, (8) otherwise if the variable is of type character expr shall have the same kind type parameter, (9) if the variable is of derived type each kind type parameter of the variable shall have the same value as the corresponding kind type parameter of expr, and (10) if the variable is of derived type each length type parameter of the variable shall have the same value as the corresponding type parameter of expr unless the variable is allocatable, is not a coarray, and its corresponding type parameter is deferred. Table 10.8: Intrinsic assignment type conformance Type of the variable Type of expr integer real complex character

integer, real, complex integer, real, complex integer, real, complex character

ISO/IEC JTC 1/SC 22/WG5/N2184

169

J3/21-007r1

WD 1539-1

Intrinsic assignment type conformance Type of the variable Type of expr logical derived type enumeration type enum type

1 2 3 4 5 6

7 8 9 10 11 12 13 14 15 16

2021-05-21

(cont.)

logical same derived type as the variable same enumeration type same enum type, or integer; if of type integer, a primary in expr shall be an enumerator of the enum type

2 If the variable in an intrinsic assignment statement is a coindexed object,

• the variable shall not be polymorphic, • the variable shall not have an allocatable ultimate component, • the variable shall be conformable with expr, and • each deferred length type parameter of the variable shall have the same value as the corresponding type parameter of expr. 3 If the variable is a pointer, it shall be associated with a definable target such that the type, type parameters,

and shape of the target and expr conform. If the variable is a coarray or a coindexed object, it shall not be an unallocated allocatable variable. 10.2.1.3

Interpretation of intrinsic assignments

1 Execution of an intrinsic assignment causes, in effect, the evaluation of the expression expr and all expressions

within variable (10.1), the possible conversion of expr to the type and type parameters of the variable (Table 10.9), and the definition of the variable with the resulting value. The execution of the assignment shall have the same effect as if the evaluation of expr and the evaluation of all expressions in variable occurred before any portion of the variable is defined by the assignment. The evaluation of expressions within variable shall neither affect nor be affected by the evaluation of expr.

17

2 If the variable is a pointer, the value of expr is assigned to the target of the variable.

18

3 If the variable is an unallocated allocatable array, expr shall have the same rank. If the variable is an allocated

19 20 21 22

allocatable variable, it is deallocated if expr is an array of different shape, any corresponding length type parameter values of the variable and expr differ, or the variable is polymorphic and the dynamic type or any corresponding kind type parameter values of the variable and expr differ. If the variable is or becomes an unallocated allocatable variable, it is then allocated with

23

• the same dynamic type and kind type parameter values as expr if the variable is polymorphic, • each deferred type parameter equal to the corresponding type parameter of expr, • the same bounds as before if the variable is an array and expr is scalar, and • the shape of expr with each lower bound equal to the corresponding element of LBOUND (expr) if expr is an array.

24 25 26 27

NOTE 1 For example, given the declaration CHARACTER(:),ALLOCATABLE :: NAME then after the assignment statement NAME = ’Dr. ’//FIRST_NAME//’ ’//SURNAME NAME will have the length LEN (FIRST_NAME) + LEN (SURNAME) + 5, even if it had previously been unallocated, or allocated with a different length. However, the assignment statement NAME(:) = ’Dr. ’//FIRST_NAME//’ ’//SURNAME

170

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) is only conforming if NAME is already allocated at the time of the assignment; the assigned value is truncated or blank padded to the previously allocated length of NAME. 1

4 Both variable and expr may contain references to any portion of the variable.

NOTE 2 For example, in the character intrinsic assignment statement: STRING (2:5) = STRING (1:4) the assignment of the first character of STRING to the second character does not affect the evaluation of STRING (1:4). If the value of STRING prior to the assignment was ’ABCDEF’, the value following the assignment is ’AABCDF’. 2 3

5 If expr is a scalar and the variable is an array, the expr is treated as if it were an array of the same shape as the

4

6 If the variable is an array, the assignment is performed element-by-element on corresponding array elements of

5

variable with every element of the array equal to the scalar value of expr. the variable and expr. NOTE 3 For example, if A and B are arrays of the same shape, the array intrinsic assignment A = B assigns the corresponding elements of B to those of A; that is, the first element of B is assigned to the first element of A, the second element of B is assigned to the second element of A, etc. If C is an allocatable array of rank 1, then C = PACK (ARRAY, ARRAY>0) will cause C to contain all the positive elements of ARRAY in array element order; if C is not allocated or is allocated with the wrong size, it will be re-allocated to be of the correct size to hold the result of PACK.

6

7 The processor may perform the element-by-element assignment in any order.

NOTE 4 For example, the following program segment results in the values of the elements of array X being reversed: REAL X (10) ... X (1:10) = X (10:1:-1) 7 8 9

8 For an intrinsic assignment statement where the variable is of numeric type, the expr can have a different numeric

10 11

9 For an intrinsic assignment statement where the variable is of type integer or real, and expr is a boz-literal-

12

type or kind type parameter, in which case the value of expr is converted to the type and kind type parameter of the variable according to the rules of Table 10.9. constant, expr is converted to the type and kind type parameter of the variable according to the rules of Table 10.9. Table 10.9: Numeric conversion and the assignment statement Type of the variable

Value assigned

integer

INT (expr, KIND = KIND (variable))

real

REAL (expr, KIND = KIND (variable))

ISO/IEC JTC 1/SC 22/WG5/N2184

171

J3/21-007r1

WD 1539-1

2021-05-21

Numeric conversion and the assignment statement (cont.) Type of the variable Value Assigned complex

CMPLX (expr, KIND = KIND (variable))

NOTE

INT, REAL, CMPLX, and KIND are the generic names of functions defined in 16.9.

1 2

10 For an intrinsic assignment statement where the variable is of type logical, the expr can have a different kind

3 4

11 For an intrinsic assignment statement where the variable is of type character, the expr can have a different

type parameter, in which case the value of expr is converted to the kind type parameter of the variable. character length parameter in which case the conversion of expr to the length of the variable is as follows.

5 6

(1)

7 8

(2)

9 10 11

If the length of the variable is less than that of expr, the value of expr is truncated from the right until it is the same length as the variable. If the length of the variable is greater than that of expr, the value of expr is extended on the right with blanks until it is the same length as the variable.

12 For an intrinsic assignment statement where the variable is of type character, if expr has a different kind type para-

meter, each character c in expr is converted to the kind type parameter of the variable by ACHAR (IACHAR(c), KIND (variable)). NOTE 5 For nondefault character kinds, the blank padding character is processor dependent. When assigning a character expression to a variable of a different kind, each character of the expression that is not representable in the kind of the variable is replaced by a processor-dependent character.

12 13

13 For an intrinsic assignment where the variable is of enum type, if expr is of type integer, it is converted to the

14 15

14 For an intrinsic assignment of the type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING,

16

type of the variable as if by the enum constructor enum-type-name ( expr ). or of the type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, the variable becomes undefined if the variable and expr are not on the same image. NOTE 6 An intrinsic assignment statement for a variable of declared type C_PTR, C_FUNPTR, or TEAM_TYPE cannot involve a coindexed object, see C915, which prevents inappropriate copying from one image to another. However, such copying can occur for a component in a derived-type intrinsic assignment.

17 18 19 20 21 22 23

15 An intrinsic assignment where the variable is of derived type is performed as if each component of the variable

were assigned from the corresponding component of expr using pointer assignment (10.2.2) for each pointer component, defined assignment for each nonpointer nonallocatable component of a type that has a type-bound defined assignment consistent with the component, intrinsic assignment for each other nonpointer nonallocatable component, and intrinsic assignment for each allocated coarray component. For unallocated coarray components, the corresponding component of the variable shall be unallocated. For a noncoarray allocatable component the following sequence of operations is applied. (1) (2)

24 25 26 27 28 29 30

172

If the component of the variable is allocated, it is deallocated. If the component of the value of expr is allocated, the corresponding component of the variable is allocated with the same dynamic type and type parameters as the component of the value of expr. If it is an array, it is allocated with the same bounds. The value of the component of the value of expr is then assigned to the corresponding component of the variable using defined assignment if the declared type of the component has a type-bound defined assignment consistent with the component, and intrinsic assignment for the dynamic type of that component otherwise.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

16 The processor may perform the component-by-component assignment in any order or by any means that has the

same effect. NOTE 7 For an example of a derived-type intrinsic assignment statement, if C and D are of the same derived type with a pointer component P and nonpointer components S, T, U, and V of type integer, logical, character, and another derived type, respectively, the intrinsic assignment C = D pointer assigns D%P to C%P. It assigns D%S to C%S, D%T to C%T, and D%U to C%U using intrinsic assignment. It assigns D%V to C%V using defined assignment if objects of that type have a compatible type-bound defined assignment, and intrinsic assignment otherwise. NOTE 8 If an allocatable component of expr is unallocated, the corresponding component of the variable has an allocation status of unallocated after execution of the assignment.

3

10.2.1.4

Defined assignment statement

4 5

1 A defined assignment statement is an assignment statement that is defined by a subroutine and a generic interface

6

2 A subroutine defines the defined assignment x1 = x2 if

(7.5.5, 15.4.3.4.3) that specifies ASSIGNMENT (=).

7 8

(1)

9

(2)

the subroutine is specified with a SUBROUTINE (15.6.2.3) or ENTRY (15.6.2.6) statement that specifies two dummy arguments, d1 and d2 , either

10 11

(a)

12 13 14

(b)

15 16 17 18

(3) (4) (5)

20 21 22 23 24

the types of d1 and d2 are compatible with the dynamic types of x1 and x2 , respectively, the type parameters, if any, of d1 and d2 match the corresponding type parameters of x1 and x2 , respectively, and either (a) (b)

19

a generic interface (15.4.3.2) provides the subroutine with a generic-spec of ASSIGNMENT (=), or there is a generic binding (7.5.5) in the declared type of x1 or x2 with a generic-spec of ASSIGNMENT (=) and there is a corresponding binding to the subroutine in the dynamic type of x1 or x2 , respectively,

the ranks of x1 and x2 match those of d1 and d2 or the subroutine is elemental, x2 is scalar or has the same rank as x1 , and there is no other subroutine that defines the assignment.

3 If d1 or d2 is an array, the shapes of x1 and x2 shall match the shapes of d1 and d2 , respectively. If the subroutine

is elemental, x2 shall be conformable with x1 . 10.2.1.5

Interpretation of defined assignment statements

25

1 The interpretation of a defined assignment is provided by the subroutine that defines it.

26

2 If the defined assignment is an elemental assignment and the variable in the assignment is an array, the defined

27 28 29

assignment is performed element-by-element, on corresponding elements of the variable and expr. If expr is a scalar, it is treated as if it were an array of the same shape as the variable with every element of the array equal to the scalar value of expr.

ISO/IEC JTC 1/SC 22/WG5/N2184

173

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 The rules of defined assignment (15.4.3.4.3), procedure references (15.5), subroutine references (15.5.4), and elemental subroutine arguments (15.9.3) ensure that the defined assignment has the same effect as if the evaluation of all operations in x2 and x1 occurs before any portion of x1 is defined. If an elemental assignment is defined by a pure elemental subroutine, the element assignments can be performed simultaneously or in any order. 1

10.2.2

Pointer assignment

2

10.2.2.1

General

3

1 Pointer assignment causes a pointer to become associated with a target or causes its pointer association status

4

to become disassociated or undefined. Any previous association between the pointer and a target is broken.

5 6

2 Pointer assignment for a pointer component of a structure can also take place by execution of a derived-type

intrinsic assignment statement (10.2.1.3).

7

10.2.2.2

Syntax of the pointer assignment statement

8 9

R1033 pointer-assignment-stmt

is or or or

14 15

R1034 data-pointer-object

is variable-name or scalar-variable % data-pointer-component-name

16 17

C1015 (R1033) If data-target is not unlimited polymorphic, data-pointer-object shall be type compatible (7.3.3) with it and the corresponding kind type parameters shall be equal.

18 19

C1016 (R1033) If data-target is unlimited polymorphic, data-pointer-object shall be unlimited polymorphic, or of a type with the BIND attribute or the SEQUENCE attribute.

20 21

C1017 (R1033) If bounds-spec-list is specified, the number of bounds-specs shall equal the rank of data-pointerobject.

22 23

C1018 (R1033) If bounds-remapping-list is specified, the number of bounds-remappings shall equal the rank of data-pointer-object.

24 25

C1019 If lower-bounds-expr and upper-bounds-expr appear in a pointer-assignment-stmt, at least one of them shall be a rank-one array of constant size equal to the rank of data-pointer-object.

26 27

C1020 If lower-bounds-expr appears in a pointer-assignment-stmt but not upper-bounds-expr, it shall be a rankone array of constant size equal to the rank of data-pointer-object.

28 29

C1021 If neither bounds-remapping-list nor upper-bounds-expr appears in a pointer-assignment-stmt, the ranks of data-pointer-object and data-target shall be the same.

30 31

C1022 (R1033) A coarray data-target shall have the VOLATILE attribute if and only if the data-pointer-object has the VOLATILE attribute.

32

C1023 (R1034) A variable-name shall have the POINTER attribute.

33

C1024 (R1034) A scalar-variable shall be a data-ref .

34

C1025 (R1034) A data-pointer-component-name shall be the name of a component of scalar-variable that is a

10 11 12 13

174

data-pointer-object [ ( bounds-spec-list ) ] => data-target data-pointer-object ( lower-bounds-expr : ) => data-target data-pointer-object ( bounds-remapping-list ) => data-target data-pointer-object ( lower-bounds-expr : upper-bounds-expr ) => data-target or proc-pointer-object => proc-target

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

data pointer.

2

C1026 (R1034) A data-pointer-object shall not be a coindexed object.

3

R1035 bounds-spec

is

lower-bound-expr :

4

R1036 bounds-remapping

is

lower-bound-expr : upper-bound-expr

5

R1037 data-target

is

expr

6 7 8

C1027 (R1037) The expr shall be a designator that designates a variable with either the TARGET or POINTER attribute and is not an array section with a vector subscript, or it shall be a reference to a function that returns a data pointer.

9

C1028 (R1037) A data-target shall not be a coindexed object. NOTE 1 A data pointer and its target are always on the same image. A coarray can be of a derived type with pointer or allocatable subcomponents. For example, if PTR is a pointer component, and Z%PTR on image P has been associated with a target by execution of an ALLOCATE statement or a pointer assignment on image P, Z[P]%PTR will be a reference to that target.

10 11

R1038 proc-pointer-object

is proc-pointer-name or proc-component-ref

12

R1039 proc-component-ref

is

13

C1029 (R1039) The scalar-variable shall be a data-ref that is not a coindexed object.

14 15

C1030 (R1039) The procedure-component-name shall be the name of a procedure pointer component of the declared type of scalar-variable.

16 17

R1040 proc-target

scalar-variable % procedure-component-name

18

is expr or procedure-name or proc-component-ref

19

C1031 (R1040) An expr shall be a reference to a function whose result is a procedure pointer.

20 21 22

C1032 (R1040) A procedure-name shall be the name of an internal, module, or dummy procedure, a procedure pointer, a specific intrinsic function listed in Table 16.2, or an external procedure that is accessed by use or host association, referenced in the scoping unit as a procedure, or that has the EXTERNAL attribute.

23

C1033 (R1040) The proc-target shall not be a nonintrinsic elemental procedure.

24 25

1 In a pointer assignment statement, data-pointer-object or proc-pointer-object denotes the pointer object and

26 27

2 For pointer assignment performed by a derived-type intrinsic assignment statement, the pointer object is the

28

data-target or proc-target denotes the pointer target. pointer component of the variable and the pointer target is the corresponding component of expr. 10.2.2.3

Data pointer assignment

29

1 If the pointer object is not polymorphic (7.3.2.3) and the pointer target is polymorphic with dynamic type that

30 31

differs from its declared type, the assignment target is the ancestor component of the pointer target that has the type of the pointer object. Otherwise, the assignment target is the pointer target.

32 33 34

2 If the pointer target is not a pointer, the pointer object becomes pointer associated with the assignment target;

if the pointer target is a pointer with a target that is not on the same image, the pointer association status of the pointer object becomes undefined. Otherwise, the pointer association status of the pointer object becomes that

ISO/IEC JTC 1/SC 22/WG5/N2184

175

J3/21-007r1

1 2

WD 1539-1

2021-05-21

of the pointer target; if the pointer target is associated with an object, the pointer object becomes associated with the assignment target. If the pointer target is allocatable, it shall be allocated. NOTE 1 A pointer assignment statement is not permitted to involve a coindexed pointer or target, see C1026 and C1028. This prevents a pointer assignment statement from associating a pointer with a target on another image. If such an association would otherwise be implied, the association status of the pointer becomes undefined. For example, a derived-type intrinsic assignment where the variable and expr are on different images and the variable has an ultimate pointer component.

3 4 5

3 If the pointer object is polymorphic, it assumes the dynamic type of the pointer target. If the pointer object is

6 7

4 If the pointer target is a disassociated pointer, all nondeferred type parameters of the declared type of the pointer

8

of a type with the BIND attribute or the SEQUENCE attribute, the dynamic type of the pointer target shall be that type. object that correspond to nondeferred type parameters of the pointer target shall have the same values as the corresponding type parameters of the pointer target.

9 10

5 Otherwise, all nondeferred type parameters of the declared type of the pointer object shall have the same values

11 12

6 If the pointer object has nondeferred type parameters that correspond to deferred type parameters of the pointer

13

7 If the pointer object has the CONTIGUOUS attribute, the pointer target shall be contiguous.

14 15

8 If the target of a pointer is a coarray, the pointer shall have the VOLATILE attribute if and only if the coarray

16 17 18 19

9 If bounds-remapping-list appears, it specifies the upper and lower bounds of each dimension of the pointer,

20 21

as the corresponding type parameters of the pointer target. target, the pointer target shall not be a pointer with undefined association status.

has the VOLATILE attribute. and thus the extents; the pointer target shall be simply contiguous (9.5.4) or of rank one, and shall not be a disassociated or undefined pointer. The number of elements of the pointer target shall not be less than the number implied by the bounds-remapping-list. The elements of the pointer object are associated with those of the pointer target, in array element order; if the pointer target has more elements than specified for the pointer object, the remaining elements are not associated with the pointer object.

22 23 24

10 If lower-bounds-expr and upper-bounds-expr appear, the effect is the same as a bounds-remapping-list with each

25

11 If neither bounds-remapping-list nor upper-bounds-expr appears, the extent of a dimension of the pointer object is

26 27 28 29

the extent of the corresponding dimension of the pointer target. If bounds-spec-list or lower-bounds-expr appears, it specifies the lower bounds; otherwise, the lower bound of each dimension is the result of the intrinsic function LBOUND (16.9.119) applied to the corresponding dimension of the pointer target. The upper bound of each dimension is one less than the sum of the lower bound and the extent.

30

10.2.2.4

bounds-remapping comprising corresponding elements of the lower and upper bounds arrays, in array element order. If one of them is a scalar, the effect is as if it were broadcast to the same shape as the other.

Procedure pointer assignment

31 32 33 34 35

1 If the pointer target is not a pointer or dummy argument, the pointer object becomes pointer associated with

36

2 The host instance (15.6.2.4) of an associated procedure pointer is the host instance of its target.

37 38

3 If the pointer object has an explicit interface, its characteristics shall be the same as the pointer target except

the pointer target. If the pointer target is a nonpointer dummy argument, the pointer object becomes associated with the ultimate argument of the dummy argument. Otherwise, the pointer association status of the pointer object becomes that of the pointer target; if the pointer target is associated with a procedure, the pointer object becomes associated with the same procedure.

that the pointer target may be pure even if the pointer object is not pure, the pointer target may be simple even

176

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

if the pointer object is not simple, and the pointer target may be an elemental intrinsic procedure, even though the pointer object cannot be elemental.

3 4

4 If the characteristics of the pointer object or the pointer target are such that an explicit interface is required,

5 6 7

5 If the pointer object has an implicit interface and is explicitly typed or referenced as a function, the pointer target

8 9

6 If the pointer object is a function with an implicit interface, the pointer target shall be a function with the same

10

7 If procedure-name is a specific procedure name that is also a generic name, only the specific procedure is associated

both the pointer object and the pointer target shall have an explicit interface. shall be a function. If the pointer object has an implicit interface and is referenced as a subroutine, the pointer target shall be a subroutine. type; corresponding type parameters shall have the same value.

11

with the pointer object.

12

10.2.2.5

Examples of pointer assignment statements

NOTE 1 The following are examples of pointer assignment statements. (See 15.4.3.6, NOTE 1 for declarations of P and BESSEL.) NEW_NODE % LEFT => CURRENT_NODE SIMPLE_NAME => TARGET_STRUCTURE % SUBSTRUCT % COMPONENT PTR => NULL ( ) ROW => MAT2D (N, :) WINDOW => MAT2D (I-1:I+1, J-1:J+1) POINTER_OBJECT => POINTER_FUNCTION (ARG_1, ARG_2) EVERY_OTHER => VECTOR (1:N:2) WINDOW2 (0:, 0:) => MAT2D (ML:MU, NL:NU) ! P is a procedure pointer and BESSEL is a procedure with a ! compatible interface. P => BESSEL ! Likewise for a structure component. STRUCT % COMPONENT => BESSEL

NOTE 2 It is possible to obtain different-rank views of parts of an object by specifying upper bounds in pointer assignment statements. This requires that the object be either rank one or contiguous. Consider the following example, in which a matrix is under consideration. The matrix is stored as a rank-one object in MYDATA because its diagonal is needed for some reason – the diagonal cannot be gotten as a single object from a rank-two representation. The matrix is represented as a rank-two view of MYDATA. real, target :: MYDATA ( NR*NC ) ! An automatic array real, pointer :: MATRIX ( :, : ) ! A rank-two view of MYDATA real, pointer :: VIEW_DIAG ( : ) MATRIX (1:NR, 1:NC) => MYDATA ! The MATRIX view of the data VIEW_DIAG => MYDATA (1::NR+1) ! The diagonal of MATRIX Rows, columns, or blocks of the matrix can be accessed as sections of MATRIX. Rank remapping can be applied to CONTIGUOUS arrays, for example: REAL, CONTIGUOUS, POINTER :: A (:) REAL, CONTIGUOUS, TARGET :: B (:,:) ! Dummy argument A (1:SIZE(B)) => B ! Linear view of a rank-2 array

ISO/IEC JTC 1/SC 22/WG5/N2184

177

J3/21-007r1

WD 1539-1

1

10.2.3

Masked array assignment – WHERE

2

10.2.3.1

General form of the masked array assignment

3 4 5

2021-05-21

1 A masked array assignment is either a WHERE statement or a WHERE construct. It is used to mask the

evaluation of expressions and assignment of values in array assignment statements, according to the value of a logical array expression.

6

R1041 where-stmt

is

WHERE ( mask-expr ) where-assignment-stmt

7

R1042 where-construct

is

where-construct-stmt [ where-body-construct ] ... [ masked-elsewhere-stmt [ where-body-construct ] ... ] ... [ elsewhere-stmt [ where-body-construct ] ... ] end-where-stmt

14

R1043 where-construct-stmt

is

[where-construct-name:] WHERE ( mask-expr )

15 16 17

R1044 where-body-construct

is where-assignment-stmt or where-stmt or where-construct

18

R1045 where-assignment-stmt

is

assignment-stmt

19

R1046 mask-expr

is

logical-expr

20

R1047 masked-elsewhere-stmt

is

ELSEWHERE (mask-expr) [where-construct-name]

21

R1048 elsewhere-stmt

is

ELSEWHERE [where-construct-name]

22

R1049 end-where-stmt

is

END WHERE [where-construct-name]

23

C1034 (R1045) A where-assignment-stmt that is a defined assignment shall be elemental.

24 25 26 27 28

C1035 (R1042) If the where-construct-stmt is identified by a where-construct-name, the corresponding endwhere-stmt shall specify the same where-construct-name. If the where-construct-stmt is not identified by a where-construct-name, the corresponding end-where-stmt shall not specify a where-construct-name. If an elsewhere-stmt or a masked-elsewhere-stmt is identified by a where-construct-name, the corresponding where-construct-stmt shall specify the same where-construct-name.

29

C1036 (R1044) A statement that is part of a where-body-construct shall not be a branch target statement.

30 31

2 If a where-construct contains a where-stmt, a masked-elsewhere-stmt, or another where-construct then each mask-

8 9 10 11 12 13

32

expr within the where-construct shall have the same shape. In each where-assignment-stmt, the mask-expr and the variable being defined shall be arrays of the same shape. NOTE 1 Examples of masked array assignment are: WHERE (TEMP > 100.0) TEMP = TEMP - REDUCE_TEMP WHERE (PRESSURE <= 1.0) PRESSURE = PRESSURE + INC_PRESSURE TEMP = TEMP - 5.0 ELSEWHERE RAINING = .TRUE. END WHERE

178

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6

10.2.3.2

WD 1539-1

J3/21-007r1

Interpretation of masked array assignments

1 When a WHERE statement or a where-construct-stmt is executed, a control mask is established. In addition,

when a WHERE construct statement is executed, a pending control mask is established. If the statement does not appear as part of a where-body-construct, the mask-expr of the statement is evaluated, and the control mask is established to be the value of mask-expr. The pending control mask is established to have the value .NOT. maskexpr upon execution of a WHERE construct statement that does not appear as part of a where-body-construct.

7 8

2 The mask-expr in a WHERE statement, WHERE construct statement, or masked ELSEWHERE statement, is

9

3 Each statement in a WHERE construct is executed in sequence.

10

4 Upon execution of a masked-elsewhere-stmt, the following actions take place in sequence.

11 12 13

evaluated at most once per execution of the statement.

(1) (2) (3)

The control mask mc is established to have the value of the pending control mask. The pending control mask is established to have the value mc .AND. (.NOT. mask-expr). The control mask mc is established to have the value mc .AND. mask-expr.

14 15

5 Upon execution of an ELSEWHERE statement, the control mask is established to have the value of the pending

16 17 18 19

6 Upon execution of an ENDWHERE statement, the control mask and pending control mask are established to

control mask. No new pending control mask value is established. have the values they had prior to the execution of the corresponding WHERE construct statement. Following the execution of a WHERE statement that appears as a where-body-construct, the control mask is established to have the value it had prior to the execution of the WHERE statement. NOTE 1 The establishment of control masks and the pending control mask is illustrated with the following example: WHERE(cond1) ... ELSEWHERE(cond2) ... ELSEWHERE ... END WHERE

! Statement 1 ! Statement 2 ! Statement 3

Following execution of statement 1, the control mask has the value cond1 and the pending control mask has the value .NOT. cond1. Following execution of statement 2, the control mask has the value (.NOT. cond1) .AND. cond2 and the pending control mask has the value (.NOT. cond1) .AND. (.NOT. cond2). Following execution of statement 3, the control mask has the value (.NOT. cond1) .AND. (.NOT. cond2). The false condition values are propagated through the execution of the masked ELSEWHERE statement. 20 21 22

7 Upon execution of a WHERE construct statement that is part of a where-body-construct, the pending control

mask is established to have the value mc .AND. (.NOT. mask-expr). The control mask is then established to have the value mc .AND. mask-expr. The mask-expr is evaluated at most once.

23 24

8 Upon execution of a WHERE statement that is part of a where-body-construct, the control mask is established

25 26 27

9 If a nonelemental function reference occurs in the expr or variable of a where-assignment-stmt or in a mask-expr,

to have the value mc .AND. mask-expr. The pending control mask is not altered.

28 29

the function is evaluated without any masked control; that is, all of its argument expressions are fully evaluated and the function is fully evaluated. If the result is an array and the reference is not within the argument list of a nonelemental function, elements corresponding to true values in the control mask are selected for use in evaluating the expr, variable or mask-expr.

30

10 If an elemental operation or function reference occurs in the expr or variable of a where-assignment-stmt or in a

ISO/IEC JTC 1/SC 22/WG5/N2184

179

J3/21-007r1

WD 1539-1

2021-05-21

1 2

mask-expr, and is not within the argument list of a nonelemental function reference, the operation is performed or the function is evaluated only for the elements corresponding to true values of the control mask.

3 4

11 If an array constructor appears in a where-assignment-stmt or in a mask-expr, the array constructor is evaluated

5 6

12 When a where-assignment-stmt is executed, the values of expr that correspond to true values of the control mask

7 8 9 10

13 The value of the control mask is established by the execution of a WHERE statement, a WHERE construct

11

without any masked control and then the where-assignment-stmt is executed or the mask-expr is evaluated. are assigned to the corresponding elements of the variable. statement, an ELSEWHERE statement, a masked ELSEWHERE statement, or an ENDWHERE statement. Subsequent changes to the value of entities in a mask-expr have no effect on the value of the control mask. The execution of a function reference in the mask expression of a WHERE statement is permitted to affect entities in the assignment statement. NOTE 2 Examples of function references in masked array assignments are: WHERE (A > 0.0) A = LOG (A) A = A / SUM (LOG (A))

! LOG is invoked only for positive elements. ! LOG is invoked for all elements ! because SUM is transformational

END WHERE 12

10.2.4

FORALL

13

10.2.4.1

Form of the FORALL Construct

14 15

1 The FORALL construct allows multiple assignments, masked array (WHERE) assignments, and nested FORALL constructs and statements to be controlled by a single concurrent-control-list and scalar-mask-expr.

16 17 18

R1050

forall-construct

is

forall-construct-stmt [forall-body-construct ] ... end-forall-stmt

19

R1051

forall-construct-stmt

is

[forall-construct-name :] FORALL concurrent-header

20 21 22 23 24

R1052

forall-body-construct

is or or or or

forall-assignment-stmt where-stmt where-construct forall-construct forall-stmt

25 26

R1053

forall-assignment-stmt

is or

assignment-stmt pointer-assignment-stmt

27

R1054

end-forall-stmt

is

END FORALL [forall-construct-name ]

28 29 30

C1037

(R1054) If the forall-construct-stmt has a forall-construct-name, the end-forall-stmt shall have the same forall-constructname. If the end-forall-stmt has a forall-construct-name, the forall-construct-stmt shall have the same forall-constructname.

31

C1038

(R1052) A statement in a forall-body-construct shall not define an index-name of the forall-construct.

32 33

C1039

(R1052) Any procedure referenced in a forall-body-construct, including one referenced by a defined operation, assignment, or finalization, shall be a pure procedure.

34

C1040

(R1052) A forall-body-construct shall not be a branch target.

35

2 The scope and attributes of an index-name in a concurrent-header in a FORALL construct or statement are described in 19.4.

180

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

10.2.4.2

2

10.2.4.2.1

3 4 5 6 7 8 9 10 11

WD 1539-1

J3/21-007r1

Execution of the FORALL construct Execution stages

1 There are three stages in the execution of a FORALL construct: (1) (2) (3)

10.2.4.2.2

determination of the values for index-name variables, evaluation of the scalar-mask-expr, and execution of the FORALL body constructs.

Determination of the values for index variables

1 The values of the index variables are determined as they are for the DO CONCURRENT statement (11.1.7.4.2).

10.2.4.2.3

Evaluation of the mask expression

1 The mask expression is evaluated as it is for the DO CONCURRENT statement (11.1.7.4.2).

10.2.4.2.4

Execution of the FORALL body constructs

12 13

1 The forall-body-constructs are executed in the order in which they appear. Each construct is executed for all active combinations of

14 15 16

2 Execution of a forall-assignment-stmt that is an assignment-stmt causes the evaluation of expr and all expressions within variable

17 18 19 20 21

3 Execution of a forall-assignment-stmt that is a pointer-assignment-stmt causes the evaluation of all expressions within data-target

22

4 In a forall-assignment-stmt, a defined assignment subroutine shall not reference any variable that becomes defined by the statement.

the index-name values with the following interpretation:

for all active combinations of index-name values. These evaluations may be done in any order. After all these evaluations have been performed, each expr value is assigned to the corresponding variable. The assignments may occur in any order.

and data-pointer-object or proc-target and proc-pointer-object, the determination of any pointers within data-pointer-object or procpointer-object, and the determination of the target for all active combinations of index-name values. These evaluations may be done in any order. After all these evaluations have been performed, each data-pointer-object or proc-pointer-object is associated with the corresponding target. These associations may occur in any order.

NOTE 1 If a variable defined in an assignment statement within a FORALL construct is referenced in a later statement in that construct, the later statement uses the value(s) computed in the preceding assignment statement, not the value(s) the variable had prior to execution of the FORALL. 23 24 25

5 Each statement in a where-construct (10.2.3) within a forall-construct is executed in sequence. When a where-stmt, where-construct-

26 27

assignment-stmt is executed for all active combinations of index-name values, masked by the control mask in effect for the whereassignment-stmt.

28 29 30

6 Execution of a forall-stmt or forall-construct causes the evaluation of the concurrent-limit and concurrent-step expressions in the

31 32 33 34

outer index-name values; it also includes the outer index-name values. The scalar-mask-expr is then evaluated for all combinations of the index-name values of the inner construct to produce a set of active combinations for the inner construct. If there is no scalar-mask-expr, it is as if it appeared with the value true. Each statement in the inner FORALL is then executed for each active combination of the index-name values.

35

10.2.4.3

36 37

stmt or masked-elsewhere-stmt is executed, the statement’s mask-expr is evaluated for all active combinations of index-name values as determined by the outer forall-constructs, masked by any control mask corresponding to outer where-constructs. Any where-

concurrent-control-list for all active combinations of the index-name values of the outer FORALL construct. The set of combinations of index-name values for the inner FORALL is the union of the sets defined by these limits and steps for each active combination of the

The FORALL statement

1 The FORALL statement allows a single assignment statement or pointer assignment statement to be controlled by a set of index values and an optional mask expression.

ISO/IEC JTC 1/SC 22/WG5/N2184

181

J3/21-007r1

1

R1055

forall-stmt

WD 1539-1

is

2021-05-21

FORALL concurrent-header forall-assignment-stmt

2

2 A FORALL statement is equivalent to a FORALL construct containing a single forall-body-construct that is a forall-assignment-stmt.

3

3 The scope of an index-name in a forall-stmt is the statement itself (19.4).

4 5 6 7 8

10.2.4.4

Restrictions on FORALL constructs and statements

1 A many-to-one assignment is more than one assignment to the same object, or association of more than one target with the same pointer, whether the object is referenced directly or indirectly through a pointer. A many-to-one assignment shall not occur within a single statement in a FORALL construct or statement. It is possible to assign or pointer-assign to the same object in different assignment or pointer assignment statements in a FORALL construct.

NOTE 1 The appearance of each index-name in the identification of the left-hand side of an assignment statement is helpful in eliminating many-to-one assignments, but it is not sufficient to guarantee there will be none. For example, the following is allowed FORALL (I = 1:10) A (INDEX (I)) = B(I) END FORALL if and only if INDEX(1:10) contains no repeated values.

9 10

2 Within the scope of a FORALL construct, a nested FORALL statement or FORALL construct shall not have the same index-name. The concurrent-header expressions within a nested FORALL may depend on the values of outer index-name variables.

182

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

11 Execution control

2

11.1

Executable constructs containing blocks

3

11.1.1

Blocks

4 5 6 7 8 9 10 11 12 13

14 15 16 17

J3/21-007r1

1 The following are executable constructs that contain blocks:

• ASSOCIATE construct; • BLOCK construct; • CHANGE TEAM construct; • CRITICAL construct; • DO construct; • IF construct; • SELECT CASE construct; • SELECT RANK construct; • SELECT TYPE construct. is

R1101 block

[ execution-part-construct ] ...

2 Executable constructs can be used to control which blocks of a program are executed or how many times a block

is executed. Blocks are always bounded by statements that are particular to the construct in which they are embedded. NOTE 1 An example of a construct containing a block is: IF (A > 0.0) THEN B = SQRT (A) ! These two statements C = LOG (A) ! form a block. END IF

18

11.1.2

Rules governing blocks

19

11.1.2.1

Control flow in blocks

20 21 22

1 Transfer of control to the interior of a block from outside the block is prohibited, except for the return from a

23

2 Subroutine and function references (15.5.3, 15.5.4) may appear in a block.

24

procedure invoked within the block. Transfers within a block and transfers from the interior of a block to outside the block may occur.

11.1.2.2

Execution of a block

25

1 Execution of a block begins with the execution of the first executable construct in the block.

26

2 Execution of the block is completed when

27 28 29 30

• execution of the last executable construct in the block completes without branching to a statement within the block, • a branch (11.2) within the block that has a branch target outside the block occurs, • a RETURN statement within the block is executed, or

ISO/IEC JTC 1/SC 22/WG5/N2184

183

J3/21-007r1

1 2

WD 1539-1

2021-05-21

• an EXIT statement or CYCLE statement statement that belongs to a construct that contains the block is executed. NOTE 1 The action that takes place at the terminal boundary depends on the particular construct and on the block within that construct.

3

11.1.3

ASSOCIATE construct

4

11.1.3.1

Purpose and form of the ASSOCIATE construct

5 6

1 The ASSOCIATE construct associates named entities with expressions or variables during the execution of its

block. These named construct entities (19.4) are associating entities (19.5.1.6). The names are associate names.

7 8 9

R1102 associate-construct

is

associate-stmt block end-associate-stmt

10

R1103 associate-stmt

is

[ associate-construct-name : ] ASSOCIATE (association-list )

12

R1104 association

is

associate-name => selector

13 14

R1105 selector

is expr or variable

15 16 17

C1101 (R1104) If selector is not a variable or is a variable that has a vector subscript, neither associate-name nor any subobject thereof shall appear in a variable definition context (19.6.7) or pointer association context (19.6.8).

18

C1102 (R1104) An associate-name shall not be the same as another associate-name in the same associate-stmt.

19

C1103 (R1105) variable shall not be a coindexed object.

20

C1104 (R1105) expr shall not be a variable.

21 22

C1105 (R1105) expr shall not be a designator of a procedure pointer or a function reference that returns a procedure pointer.

23

R1106 end-associate-stmt

24 25 26 27

C1106 (R1106) If the associate-stmt of an associate-construct specifies an associate-construct-name, the corresponding end-associate-stmt shall specify the same associate-construct-name. If the associate-stmt of an associate-construct does not specify an associate-construct-name, the corresponding end-associate-stmt shall not specify an associate-construct-name.

28

11.1.3.2

11

is

END ASSOCIATE [ associate-construct-name ]

Execution of the ASSOCIATE construct

29 30 31 32 33

1 Execution of an ASSOCIATE construct causes evaluation of every expression within every selector that is a

34

2 The other attributes of the associating entity are described in 11.1.3.3.

35

3 It is permissible to branch to an end-associate-stmt only from within its ASSOCIATE construct.

variable designator and evaluation of every other selector, followed by execution of its block. During execution of that block each associate name identifies an entity which is associated (19.5.1.6) with the corresponding selector. The associating entity assumes the declared type and type parameters of the selector. If and only if the selector is polymorphic, the associating entity is polymorphic.

184

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10

11.1.3.3

WD 1539-1

J3/21-007r1

Other attributes of associate names

1 Within an ASSOCIATE, CHANGE TEAM, or SELECT TYPE construct, each associating entity has the same

rank as its associated selector. The lower bound of each dimension is the result of the intrinsic function LBOUND (16.9.119) applied to the corresponding dimension of selector. The upper bound of each dimension is one less than the sum of the lower bound and the extent. The associating entity does not have the ALLOCATABLE or POINTER attributes; it has the TARGET attribute if and only if the selector is a variable and has either the TARGET or POINTER attribute. 2 Within an ASSOCIATE, SELECT RANK, or SELECT TYPE construct, each associating entity has the same

corank as its associated selector. If the selector is a coarray, the cobounds of each codimension of the associating entity are the same as those of the selector.

11 12

3 Within a CHANGE TEAM construct, the associating entity is a coarray. Its corank and cobounds are as specified

13 14 15

4 Within an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT TYPE construct, the associating entity

16 17 18 19 20

in its codimension-decl. has the ASYNCHRONOUS or VOLATILE attribute if and only if the selector is a variable and has the attribute. If the associating entity is polymorphic, it assumes the dynamic type and type parameter values of the selector. The associating entity does not have the OPTIONAL attribute. If the selector has the OPTIONAL attribute, it cannot be absent (15.5.2.12). The associating entity is contiguous if and only if the selector is contiguous. 5 The associating entity itself is a variable, but if the selector is not a definable variable, the associating entity

21

is not definable and shall not be defined or become undefined. If a selector is not permitted to appear in a variable definition context (19.6.7), neither the associate name nor any subobject thereof shall appear in a variable definition context or pointer association context (19.6.8).

22

11.1.3.4

Examples of the ASSOCIATE construct

NOTE 1 The following example illustrates an association with an expression. ASSOCIATE ( Z => EXP (-(X**2+Y**2)) * COS (THETA) ) PRINT *, A+Z, A-Z END ASSOCIATE The following example illustrates an association with a derived-type variable. ASSOCIATE ( XC => AX%B(I,J)%C ) XC%DV = XC%DV + PRODUCT (XC%EV(1:N)) END ASSOCIATE The following example illustrates association with an array section. ASSOCIATE ( ARRAY => AX%B(I,:)%C ) ARRAY(N)%EV = ARRAY(N-1)%EV END ASSOCIATE The following example illustrates multiple associations. ASSOCIATE ( W => RESULT(I,J)%W, ZX => AX%B(I,J)%D, ZY => AY%B(I,J)%D ) W = ZX*X + ZY*Y END ASSOCIATE 23 24

11.1.4

BLOCK construct

1 The BLOCK construct is an executable construct that can contain declarations.

ISO/IEC JTC 1/SC 22/WG5/N2184

185

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

R1107 block-construct

is

block-stmt [ block-specification-part ] block end-block-stmt

5

R1108 block-stmt

is

[ block-construct-name : ] BLOCK

6 7 8 9

R1109 block-specification-part

is

[ use-stmt ]... [ import-stmt ] ... [ [ declaration-construct ] ... specification-construct ]

10

R1110 end-block-stmt

is

END BLOCK [ block-construct-name ]

11 12

C1107 (R1107) A block-specification-part shall not contain a COMMON, EQUIVALENCE, INTENT, NAMELIST, OPTIONAL, statement function, or VALUE statement.

13 14

C1108 (R1107) A SAVE statement in a BLOCK construct shall contain a saved-entity-list that does not specify a common-block-name .

15 16

C1109 (R1107) If the block-stmt of a block-construct specifies a block-construct-name, the corresponding endblock-stmt shall specify the same block-construct-name. If the block-stmt does not specify a blockconstruct-name, the corresponding end-block-stmt shall not specify a block-construct-name.

17 18 19 20 21

2 Except for the ASYNCHRONOUS and VOLATILE statements, specifications in a BLOCK construct declare

22

3 Execution of a BLOCK construct causes evaluation of the specification expressions within its specification part

23 24

construct entities whose scope is that of the BLOCK construct (19.4). The appearance of the name of an object that is not a construct entity in an ASYNCHRONOUS or VOLATILE statement in a BLOCK construct specifies that the object has the attribute within the construct even if it does not have the attribute outside the construct. in a processor-dependent order, followed by execution of its block. 4 It is permissible to branch to an end-block-stmt only from within its BLOCK construct.

NOTE 1 The following is an example of a BLOCK construct. IF (swapxy) THEN BLOCK REAL (KIND (x)) tmp tmp = x x = y y = tmp END BLOCK END IF Actions on a variable local to a BLOCK construct do not affect any variable of the same name outside the construct. For example, F = 254E-2 BLOCK REAL F F = 39.37 END BLOCK ! F is still equal to 254E-2. A SAVE statement outside a BLOCK construct does not affect variables local to the BLOCK construct, because a SAVE statement affects variables in its scoping unit rather than in its inclusive scope. For example,

186

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) SUBROUTINE S ... SAVE ... BLOCK REAL X ! Not saved. REAL,SAVE :: Y(100) ! SAVE attribute is allowed. Z = 3 ! Implicitly declared in S, thus saved. ... END BLOCK ... END SUBROUTINE 1

11.1.5

CHANGE TEAM construct

2

11.1.5.1

Purpose and form of the CHANGE TEAM construct

3 4

1 The CHANGE TEAM construct changes the current team. Named construct entities (19.4) can be associated

(19.5.1.6) with coarrays in the containing scoping unit, in the same way as for the ASSOCIATE construct.

5 6 7

R1111 change-team-construct

is

change-team-stmt block end-change-team-stmt

8

R1112 change-team-stmt

is

[ team-construct-name : ] CHANGE TEAM ( team-value [ , coarray-association-list ] [ , sync-stat-list ] )

10

R1113 coarray-association

is

codimension-decl => selector

11

R1114 end-change-team-stmt

is

END TEAM [ ( [ sync-stat-list ] ) ] [ team-construct-name ]

12

R1115 team-value

is

scalar-expr

13 14

C1110 A branch (11.2) within a CHANGE TEAM construct shall not have a branch target that is outside the construct.

15

C1111 A RETURN statement shall not appear within a CHANGE TEAM construct.

16 17 18 19

C1112 If the change-team-stmt of a change-team-construct specifies a team-construct-name, the corresponding end-change-team-stmt shall specify the same team-construct-name. If the change-team-stmt of a changeteam-construct does not specify a team-construct-name, the corresponding end-change-team-stmt shall not specify a team-construct-name.

20 21

C1113 In a change-team-stmt, a coarray-name in a codimension-decl shall not be the same as a selector, or another coarray-name, in that statement.

22

C1114 A team-value shall be of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.

23

C1115 No selector shall appear more than once in a given change-team-stmt.

24

C1116 A selector in a coarray-association shall be a named coarray.

9

25 26 27 28

2 Each coarray-name in a codimension-decl in the CHANGE TEAM statement is an associate name which is

associated with the corresponding selector. Each associating entity assumes the type and type parameters of its selector; it is polymorphic if and only if the selector is polymorphic. The other attributes of the associating entities are described in 11.1.3.3.

ISO/IEC JTC 1/SC 22/WG5/N2184

187

J3/21-007r1

1 2 3

11.1.5.2

WD 1539-1

2021-05-21

Execution of a CHANGE TEAM construct

1 The team-values on the active images that execute the CHANGE TEAM statement shall be those of team variables

4 5 6 7 8

defined by corresponding executions of the same FORM TEAM statement (11.7.9). When the CHANGE TEAM statement is executed, the current team shall be the team that was current when those team variables were defined. The current team for the statements of the CHANGE TEAM block is the team identified by the team-value. If team-value is a variable, the variable shall not be defined or become undefined during execution of the CHANGE TEAM construct. A CHANGE TEAM construct completes execution by executing its END TEAM statement, which restores the current team to the original team that was current for the CHANGE TEAM statement.

9

2 Execution of a CHANGE TEAM construct causes evaluation of the expressions within each codimension-decl in

10 11

the CHANGE TEAM statement, followed by execution of its block. Each selector shall be an established coarray when the CHANGE TEAM statement begins execution.

12

3 It is permissible to branch to an end-change-team-stmt only from within its CHANGE TEAM construct.

13 14 15

4 An allocatable coarray that was allocated immediately before executing a CHANGE TEAM statement shall not

16 17 18 19 20 21

be deallocated during execution of the construct. An allocatable coarray that was unallocated immediately before executing a CHANGE TEAM statement, and which is allocated immediately before executing the corresponding END TEAM statement, is deallocated by the execution of the END TEAM statement. 5 Successful execution of a CHANGE TEAM statement performs an implicit synchronization of all images of the

new team that is identified by team-value. All active images of the new team shall execute the same CHANGE TEAM statement. On each image of the new team, execution of the segment following the CHANGE TEAM statement is delayed until all other images of that team have executed the same statement the same number of times in the original team.

22 23 24 25

6 If the new team contains a failed image and no other error condition occurs, there is an implicit synchronization

26

7 If no error condition other than the new team containing a failed image occurs, the segments that executed before

27 28

the CHANGE TEAM statement on an active image of the new team precede the segments that execute after the CHANGE TEAM statement on another active image of that team.

29 30 31 32

8 When a CHANGE TEAM construct completes execution, there is an implicit synchronization of all active images

33 34

of all active images of the new team. On each active image of the new team, execution of the segment following the CHANGE TEAM statement is delayed until all other active images of that team have executed the same statement the same number of times in the original team.

in the new team. On each active image of the new team, execution of the segment following the END TEAM statement is delayed until all other active images of this team have executed the same construct the same number of times in this team. The segments that executed before the END TEAM statement on an active image of the new team precede the segments that execute after the END TEAM statement on another active image of that team. NOTE 1 Deallocation of an allocatable coarray that was not allocated at the beginning of a CHANGE TEAM construct, but is allocated at the end of execution of the construct, occurs even for allocatable coarrays with the SAVE attribute. NOTE 2 Execution of a CHANGE TEAM statement includes a synchronization of the executing image with the other images that will be in the same team after execution of the CHANGE TEAM statement. Synchronization of these images occurs again when the corresponding END TEAM statement is executed. If it is desired to synchronize all of the images in the team that was current when the CHANGE TEAM statement was executed, a SYNC TEAM statement that specifies the parent team can be executed immediately after the CHANGE TEAM statement. If similar semantics are desired following the END TEAM statement, a SYNC ALL statement could immediately follow the END TEAM statement.

188

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 3 A coarray that is established when a CHANGE TEAM statement is executed retains its corank and cobounds inside the block. If it is desired to perform remote accesses based on corank or cobounds different from those of the original coarray, an associating coarray can be used. An example of this is in C.7.7. 1 2

11.1.6

CRITICAL construct

1 A CRITICAL construct limits execution of a block to one image at a time.

3 4 5

R1116 critical-construct

is

critical-stmt block end-critical-stmt

6

R1117 critical-stmt

is

[ critical-construct-name : ] CRITICAL [ ( [ sync-stat-list ] ) ]

7

R1118 end-critical-stmt

is

END CRITICAL [ critical-construct-name ]

8 9 10 11

C1117 (R1116) If the critical-stmt of a critical-construct specifies a critical-construct-name, the corresponding end-critical-stmt shall specify the same critical-construct-name. If the critical-stmt of a critical-construct does not specify a critical-construct-name, the corresponding end-critical-stmt shall not specify a criticalconstruct-name.

12 13

C1118 (R1116) The block of a critical-construct shall not contain a RETURN statement or an image control statement.

14

C1119 A branch (11.2) within a CRITICAL construct shall not have a branch target that is outside the construct.

15 16 17

2 Execution of the CRITICAL construct is completed when execution of its block is completed, or the executing

18 19

3 The processor shall ensure that once an image has commenced executing block, no other image shall commence

20 21 22 23 24

image fails (5.3.6). A procedure invoked, directly or indirectly, from a CRITICAL construct shall not execute an image control statement. executing block until this image has completed execution of the construct. The image shall not execute an image control statement during the execution of block. The sequence of executed statements is therefore a segment (11.7.2). If image M completes execution of the construct without failing and image T is the next to execute the construct, the segment on image M precedes the segment on image T. Otherwise, if image M completes execution of the construct by failing, and image T is the next to execute the construct, the previous segment on image M precedes the segment on image T.

25

4 The effect of a STAT= or ERRMSG= specifier in a CRITICAL statement is specified in 11.7.11.

26

5 It is permissible to branch to an end-critical-stmt only from within its CRITICAL construct.

NOTE 1 If more than one image executes the block of a CRITICAL construct without failing, its execution by one image always either precedes or succeeds its execution by another nonfailed image. Typically no other statement ordering is needed. Consider the following example: CRITICAL GLOBAL_COUNTER[1] = GLOBAL_COUNTER[1] + 1 END CRITICAL The definition of GLOBAL_COUNTER [1] by a particular image will always precede the reference to the same variable by the next image to execute the block. NOTE 2 The following example permits a large number of jobs to be shared among the images:

ISO/IEC JTC 1/SC 22/WG5/N2184

189

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 (cont.) INTEGER :: NUM_JOBS[*], JOB ... IF (THIS_IMAGE() == 1) READ(*,*) NUM_JOBS SYNC ALL DO CRITICAL JOB = NUM_JOBS[1] NUM_JOBS[1] = JOB - 1 END CRITICAL IF (JOB > 0) THEN . . . ! Work on JOB ELSE EXIT END IF END DO SYNC ALL

1

11.1.7

DO construct

2

11.1.7.1

Purpose and form of the DO construct

3 4

1 The DO construct specifies the repeated execution of a sequence of executable constructs. Such a repeated

5 6 7 8

2 The number of iterations of a loop can be determined at the beginning of execution of the DO construct, or can

9 10

3 There are three phases in the execution of a DO construct: initiation of the loop, execution of each iteration of

11

4 The scope and attributes of an index-name in a concurrent-header (DO CONCURRENT) are described in 19.4.

sequence is called a loop. be left indefinite (“DO forever” or DO WHILE). The execution order of the iterations can be left indeterminate (DO CONCURRENT); except in this case, the loop can be terminated immediately (11.1.7.4.5). An iteration of the loop can be curtailed by executing a CYCLE statement (11.1.7.4.4). the loop, and termination of the loop.

12

11.1.7.2

Form of the DO construct

13 14 15

R1119 do-construct

is

do-stmt block end-do

16

R1120 do-stmt

is

nonlabel-do-stmt

or

label-do-stmt

is

[ do-construct-name : ] DO label [ loop-control ]

[ do-construct-name : ] DO [ loop-control ]

17 18

R1121

19

R1122 nonlabel-do-stmt

is

20 21 22

R1123 loop-control

is

24

R1124 do-variable

is

25

C1120 (R1124) The do-variable shall be a variable of type integer.

label-do-stmt

23

190

[ , ] do-variable = scalar-int-expr, scalar-int-expr [ , scalar-int-expr ] or [ , ] WHILE ( scalar-logical-expr ) or [ , ] CONCURRENT concurrent-header concurrent-locality scalar-int-variable-name

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

R1125 concurrent-header

is

( [ integer-type-spec :: ] concurrent-control-list [ , scalar-mask-expr ] )

2

R1126 concurrent-control

is

index-name = concurrent-limit : concurrent-limit [ : concurrent-step ]

3

R1127 concurrent-limit

is

scalar-int-expr

4

R1128 concurrent-step

is

scalar-int-expr

5

R1129 concurrent-locality

is

[ locality-spec ]...

6 7 8 9 10

R1130 locality-spec

is or or or or

LOCAL ( variable-name-list ) LOCAL_INIT ( variable-name-list ) REDUCE ( reduce-operation : variable-name-list ) SHARED ( variable-name-list ) DEFAULT ( NONE )

11

R1131 reduce-operation

is binary-reduce-op or function-reduction-name

R1132 binary-reduce-op

is or or or or or

12 13 14 15 16 17 18

+ * .AND. .OR. .EQV. .NEQV.

19 20

C1121 The function-reduction-name shall be the name of the standard intrinsic function IAND, IEOR, IOR, MAX, or MIN.

21 22

C1122 (R1125) Any procedure referenced in the scalar-mask-expr, including one referenced by a defined operation, shall be a pure procedure (15.7).

23

C1123 (R1126) The index-name shall be a named scalar variable of type integer.

24 25

C1124 (R1126) A concurrent-limit or concurrent-step in a concurrent-control shall not contain a reference to any index-name in the concurrent-control-list in which it appears.

26 27

C1125 A variable-name in a locality-spec shall be the name of a variable in the innermost executable construct or scoping unit that includes the DO CONCURRENT statement.

28 29

C1126 A variable-name in a locality-spec shall not be the same as an index-name in the concurrent-header of the same DO CONCURRENT statement.

30 31

C1127 The name of a variable shall not appear in more than one variable-name-list, or more than once in a variable-name-list, in a given concurrent-locality.

32

C1128 The DEFAULT ( NONE ) locality-spec shall not appear more than once in a given concurrent-locality.

33 34

C1129 A variable-name that appears in a LOCAL or LOCAL_INIT locality-spec shall not have the ALLOCATABLE, INTENT (IN), or OPTIONAL attribute, shall not be of finalizable type, shall not be a nonpointer polymorphic dummy argument, and shall not be a coarray or an assumed-size array. A variable-name that is not permitted to appear in a variable definition context shall not appear in a LOCAL or LOCAL_INIT locality-spec.

35 36 37

41

C1130 A variable-name that appears in a REDUCE locality-spec shall not have the ASYNCHRONOUS, INTENT (IN), OPTIONAL, or VOLATILE attribute, shall not be coindexed, and shall not be an assumed-size array. A variable-name that is not permitted to appear in a variable definition context shall not appear in a REDUCE locality-spec.

42

C1131 A variable-name that appears in a REDUCE locality-spec shall be of intrinsic type suitable for the intrinsic

38 39 40

ISO/IEC JTC 1/SC 22/WG5/N2184

191

J3/21-007r1

WD 1539-1

2021-05-21

operation or function specified by its reduce-operation.

1 2 3 4

C1132 A variable that is referenced by the scalar-mask-expr of a concurrent-header or by any concurrent-limit or concurrent-step in that concurrent-header shall not appear in a LOCAL locality-spec in the same DO CONCURRENT statement.

5 6 7

C1133 If the locality-spec DEFAULT ( NONE ) appears in a DO CONCURRENT statement, a variable that is a local or construct entity of a scope containing the DO CONCURRENT construct, and that appears in the block of the construct, shall have its locality explicitly specified by that statement.

8 9

R1133 end-do

10

R1134 end-do-stmt

11 12 13

C1134 (R1119) If the do-stmt of a do-construct specifies a do-construct-name, the corresponding end-do shall be an end-do-stmt specifying the same do-construct-name. If the do-stmt of a do-construct does not specify a do-construct-name, the corresponding end-do shall not specify a do-construct-name.

14

C1135 (R1119) If the do-stmt is a nonlabel-do-stmt, the corresponding end-do shall be an end-do-stmt.

15

C1136

16 17

is

end-do-stmt

or

continue-stmt

is

END DO [ do-construct-name ]

(R1119) If the do-stmt is a label-do-stmt, the corresponding end-do shall be identified with the same label.

1 It is permissible to branch to an end-do only from within its DO construct.

11.1.7.3

Active and inactive DO constructs

18 19

1 A DO construct is either active or inactive. Initially inactive, a DO construct becomes active only when its DO

20

2 Once active, the DO construct becomes inactive only when it terminates (11.1.7.4.5).

statement is executed.

21

11.1.7.4

22

11.1.7.4.1

23 24 25

Execution of a DO construct Loop initiation

1 When the DO statement is executed, the DO construct becomes active. If loop-control is

[ , ] do-variable = scalar-int-expr 1 , scalar-int-expr 2 [ , scalar-int-expr 3 ] the following steps are performed in sequence. (1)

26 27 28 29 30 31

(2) (3)

32 33 34

The initial parameter m1 , the terminal parameter m2 , and the incrementation parameter m3 are of type integer with the same kind type parameter as the do-variable. Their values are established by evaluating scalar-int-expr 1 , scalar-int-expr 2 , and scalar-int-expr 3 , respectively, including, if necessary, conversion to the kind type parameter of the do-variable according to the rules for numeric conversion (Table 10.9). If scalar-int-expr 3 does not appear, m3 has the value 1. The value of m3 shall not be zero. The DO variable becomes defined with the value of the initial parameter m1 . The iteration count is established and is the value of the expression (m2 − m1 + m3 )/m3 , unless that value is negative, in which case the iteration count is 0.

NOTE 1 The iteration count is zero whenever: m1 > m2 and m3 > 0, or m1 < m2 and m3 < 0. 35

2 If loop-control is omitted, no iteration count is calculated. The effect is as if a large positive iteration count,

192

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13

J3/21-007r1

impossible to decrement to zero, were established. If loop-control is [ , ] WHILE (scalar-logical-expr), the effect is as if loop-control were omitted and the following statement inserted as the first statement of the block: IF (.NOT. (scalar- logical-expr )) EXIT 3 For a DO CONCURRENT construct, the values of the index variables for the iterations of the construct are

determined by the rules in 11.1.7.4.2. 4 At the completion of the execution of the DO statement, the execution cycle begins.

11.1.7.4.2

DO CONCURRENT loop control

1 The concurrent-limit and concurrent-step expressions in the concurrent-control-list are evaluated. These ex-

pressions may be evaluated in any order. The set of values that a particular index-name variable assumes is determined as follows. (1)

14 15 16 17 18

WD 1539-1

(2)

19

The lower bound m1 , the upper bound m2 , and the step m3 are of type integer with the same kind type parameter as the index-name. Their values are established by evaluating the first concurrentlimit, the second concurrent-limit, and the concurrent-step expressions, respectively, including, if necessary, conversion to the kind type parameter of the index-name according to the rules for numeric conversion (Table 10.9). If concurrent-step does not appear, m3 has the value 1. The value m3 shall not be zero. Let the value of max be (m2 − m1 + m3 )/m3 . If max≤ 0 for some index-name, the execution of the construct is complete. Otherwise, the set of values for the index-name is m1 + (k − 1) × m3 where k = 1, 2, . . . , max.

20 21

2 The set of combinations of index-name values is the Cartesian product of the sets defined by each triplet specific-

22 23 24

3 The scalar-mask-expr, if any, is evaluated for each combination of index-name values. If there is no scalar-

25 26

4 The set of active combinations of index-name values is the subset of all possible combinations for which the

ation. An index-name becomes defined when this set is evaluated. mask-expr, it is as if it appeared with the value true. The index-name variables may be primaries in the scalar-mask-expr. scalar-mask-expr has the value true. NOTE 1 The index-name variables can appear in the mask, for example DO CONCURRENT (I=1:10, J=1:10, A(I) > 0.0 .AND. B(J) < 1.0) ...

27 28 29 30

11.1.7.4.3

1 The execution cycle of a DO construct that is not a DO CONCURRENT construct consists of the following steps

performed in sequence repeatedly until termination. (1)

31 32 33 34 35 36 37 38 39

The execution cycle

(2) (3)

The iteration count, if any, is tested. If it is zero, the loop terminates and the DO construct becomes inactive. If loop-control is [ , ] WHILE (scalar-logical-expr), the scalar-logical-expr is evaluated; if the value of this expression is false, the loop terminates and the DO construct becomes inactive. The block of the loop is executed. The iteration count, if any, is decremented by one. The DO variable, if any, is incremented by the value of the incrementation parameter m3 .

2 Except for the incrementation of the DO variable that occurs in step (3), the DO variable shall neither be redefined

nor become undefined while the DO construct is active. 3 The block of a DO CONCURRENT construct is executed for every active combination of the index-name values.

Each execution of the block is an iteration. The executions may occur in any order.

ISO/IEC JTC 1/SC 22/WG5/N2184

193

J3/21-007r1

1 2

11.1.7.4.4

WD 1539-1

2021-05-21

CYCLE statement

1 Execution of a loop iteration can be curtailed by executing a CYCLE statement that belongs to the construct.

is

3

R1135 cycle-stmt

4 5

C1137 If a do-construct-name appears on a CYCLE statement, the CYCLE statement shall be within that do-construct; otherwise, it shall be within at least one do-construct.

6 7

C1138 A cycle-stmt shall not appear within a CHANGE TEAM, CRITICAL, or DO CONCURRENT construct if it belongs to an outer construct.

8 9

2 A CYCLE statement belongs to a particular DO construct. If the CYCLE statement contains a DO construct

10 11

3 Execution of a CYCLE statement that belongs to a DO construct that is not a DO CONCURRENT construct

12 13

4 Execution of a CYCLE statement that belongs to a DO CONCURRENT construct completes execution of that

14 15

5 In a DO construct, a transfer of control to the end-do has the same effect as execution of a CYCLE statement

16

CYCLE [ do-construct-name ]

name, it belongs to that DO construct; otherwise, it belongs to the innermost DO construct in which it appears. causes immediate progression to step (3) of the execution cycle of the DO construct to which it belongs. iteration of the construct. belonging to that construct. 11.1.7.4.5

Loop termination

17 18

1 For a DO construct that is not a DO CONCURRENT construct, the loop terminates, and the DO construct

19

25

• The iteration count is determined to be zero or the scalar-logical-expr is false, when tested during step (1) of the above execution cycle. • An EXIT statement that belongs to the DO construct is executed. • An EXIT or CYCLE statement that belongs to an outer construct and is within the DO construct is executed. • A branch occurs within the DO construct and the branch target statement is outside the construct. • A RETURN statement within the DO construct is executed.

26

2 For a DO CONCURRENT construct, the loop terminates, and the DO construct becomes inactive when all of

20 21 22 23 24

27 28 29

becomes inactive, when any of the following occurs.

the iterations have completed execution. 3 When a DO construct becomes inactive, the DO variable, if any, of the DO construct retains its last defined

value.

30

11.1.7.5

31

C1139 A RETURN statement shall not appear within a DO CONCURRENT construct.

32

C1140 An image control statement shall not appear within a DO CONCURRENT construct.

33 34

C1141 A branch (11.2) within a DO CONCURRENT construct shall not have a branch target that is outside the construct.

35

C1142 A reference to an impure procedure shall not appear within a DO CONCURRENT construct.

36 37

C1143 A statement that might result in the deallocation of a polymorphic entity shall not appear within a DO CONCURRENT construct.

38 39

C1144 A reference to the procedure IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, or IEEE_GET_HALTING_MODE from the intrinsic module IEEE_EXCEPTIONS, shall not appear within a DO

194

Additional semantics for DO CONCURRENT constructs

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

WD 1539-1

J3/21-007r1

CONCURRENT construct. 1 The locality of a variable that appears in a DO CONCURRENT construct is LOCAL, LOCAL_INIT, REDUCE,

SHARED, or unspecified. A construct or statement entity of a construct or statement within the DO CONCURRENT construct has SHARED locality if it has the SAVE attribute. If it does not have the SAVE attribute, it is a different entity in each iteration, similar to LOCAL locality. 2 A variable that has LOCAL or LOCAL_INIT locality is a construct entity with the same type, type parameters,

and rank as the variable with the same name in the innermost executable construct or scoping unit that includes the DO CONCURRENT construct, and the outside variable is inaccessible by that name within the construct. The construct entity has the ASYNCHRONOUS, CONTIGUOUS, POINTER, TARGET, or VOLATILE attribute if and only if the outside variable has that attribute; it does not have the BIND, INTENT, PROTECTED, SAVE, or VALUE attribute, even if the outside variable has that attribute. If it is not a pointer, it has the same bounds as the outside variable. At the beginning of execution of each iteration, • if a variable with LOCAL locality is a pointer it has undefined pointer association status, and otherwise it is undefined except for any subobjects that are default-initialized; • a variable with LOCAL_INIT locality has the pointer association status and definition status of the outside variable with that name; the outside variable shall not be an undefined pointer or a nonallocatable nonpointer variable that is undefined. If a variable with LOCAL or LOCAL_INIT locality becomes an affector of a pending input/output operation, the operation shall have completed before the end of the iteration. If a variable with LOCAL or LOCAL_INIT locality has the TARGET attribute, a pointer associated with it during an iteration becomes undefined when execution of that iteration completes. 3 A variable that has REDUCE locality is a construct entity with the same type, type parameters, rank, and bounds

as the variable with the same name in the innermost executable construct or scoping unit that includes the DO CONCURRENT construct (the outside variable); the outside variable is inaccessible by that name within the construct. The outside variable shall not be an unallocated allocatable variable or a pointer that is not associated. The construct entity has the CONTIGUOUS attribute if and only if the outside variable has that attribute; it does not have the ALLOCATABLE, BIND, INTENT, POINTER, PROTECTED, SAVE, TARGET, or VALUE attribute, even if the outside variable has that attribute. Before execution of the iterations begins, the construct entity is assigned an initial value corresponding to its reduce-operation as specified in Table 11.1. Table 11.1: Initial values for reduction operations Operation Initial value + * .AND. .OR. .EQV. .NEQV. IAND IEOR IOR MAX MIN

0 1 .TRUE. .FALSE. .TRUE. .FALSE. All bits set 0 0 Least representable value of the type and kind Largest representable value of the type and kind

NOTE 1 A processor can implement a DO CONCURRENT construct in a manner such that a variable with REDUCE locality might not have the initial value from Table 11.1 at the start of every iteration. 30 31 32

4 A variable that has REDUCE locality shall only appear within the block of a DO CONCURRENT construct in

the designator of a variable, as the object-name, or as the leftmost part-name of an array-element or array-section, in an intrinsic assignment statement with the following forms:

ISO/IEC JTC 1/SC 22/WG5/N2184

195

J3/21-007r1

1 2

WD 1539-1

2021-05-21

variable = variable binary-reduce-op expr variable = expr binary-reduce-op variable variable = function-reduction-name ( [ expr, ]... variable [, expr ]... ) where each occurrence of variable has the same form.

3

5 If a variable has REDUCE locality, on termination of the DO CONCURRENT construct the outside variable

4 5

is updated by combining it with the values the construct entity had at completion of each iteration, using the reduce-operation. The processor may combine the values in any order.

6 7 8

6 If a variable has SHARED locality, appearances of the variable within the DO CONCURRENT construct refer

9 10 11 12 13

to the variable in the innermost executable construct or scoping unit that includes the DO CONCURRENT construct. If it is defined or becomes undefined during any iteration, it shall not be referenced, defined, or become undefined during any other iteration. If it is allocated, deallocated, nullified, or pointer-assigned during an iteration it shall not have its allocation or association status, dynamic type, array bounds, shape, or a deferred type parameter value inquired about in any other iteration. A noncontiguous array with SHARED locality shall not be supplied as an actual argument corresponding to a contiguous INTENT (INOUT) dummy argument. 7 If a variable has unspecified locality,

27 28 29

• if it is referenced in an iteration it shall either be previously defined during that iteration, or shall not be defined or become undefined during any other iteration; if it is defined or becomes undefined by more than one iteration it becomes undefined when the loop terminates; • if it is noncontiguous and is supplied as an actual argument corresponding to a contiguous INTENT (INOUT) dummy argument in an iteration, it shall either be previously defined in that iteration or shall not be defined in any other iteration; • if it is a pointer and is used in an iteration other than as the pointer in pointer assignment, allocation, or nullification, it shall either be previously pointer associated during that iteration or shall not have its pointer association changed during any iteration; • if it is a pointer whose pointer association is changed in more than one iteration, it has an association status of undefined when the construct terminates; • if it is allocatable and is allocated in more than one iteration, it shall have an allocation status of unallocated at the end of every iteration; • if it is allocatable and is referenced, defined, deallocated, or has its allocation status, dynamic type, or a deferred type parameter value inquired about, in any iteration, it shall either be previously allocated in that iteration or shall not be allocated or deallocated in any other iteration.

30

8 A DO CONCURRENT construct shall not contain an input/output statement that has an ADVANCE= specifier.

31

9 If data are written to a file record or position in one iteration, that record or position in that file shall not be

32 33

read from or written to in a different iteration. If records are written to a file connected for sequential access by more than one iteration, the ordering of records written by different iterations is processor dependent.

14 15 16 17 18 19 20 21 22 23 24 25 26

NOTE 2 The restrictions on referencing variables defined in an iteration of a DO CONCURRENT construct apply to any procedure invoked within the loop. NOTE 3 The restrictions on the statements in a DO CONCURRENT construct are designed to ensure there are no data dependencies between iterations of the loop. This permits code optimizations that might otherwise be difficult or impossible because they would depend on properties of the program not visible to the compiler. 34

11.1.7.6

196

Examples of DO constructs

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 The following program fragment computes a tensor product of two arrays: DO I = 1, M DO J = 1, N C (I, J) = DOT_PRODUCT (A (I, J, :), B(:, I, J)) END DO END DO NOTE 2 The following program fragment contains a DO construct that uses the WHILE form of loop-control. The loop will continue to execute until an end-of-file or input/output error is encountered, at which point the DO statement terminates the loop. When a negative value of X is read, the program skips immediately to the next READ statement, bypassing most of the block of the loop. READ (IUN, ’(1X, G14.7)’, IOSTAT = IOS) X DO WHILE (IOS == 0) IF (X >= 0.) THEN CALL SUBA (X) CALL SUBB (X) ... CALL SUBZ (X) ENDIF READ (IUN, ’(1X, G14.7)’, IOSTAT = IOS) X END DO NOTE 3 The following example behaves exactly the same as the one in NOTE 2. However, the READ statement has been moved to the interior of the loop, so that only one READ statement is needed. Also, a CYCLE statement has been used to avoid an extra level of IF nesting. DO

! A "DO WHILE + 1/2" loop READ (IUN, ’(1X, G14.7)’, IOSTAT = IOS) X IF (IOS /= 0) EXIT IF (X < 0.) CYCLE CALL SUBA (X) CALL SUBB (X) ... CALL SUBZ (X) END DO NOTE 4 The following example illustrates a case in which the user knows that there are no repeated values in the index array IND. The DO CONCURRENT construct makes it easier for the processor to generate vector gather/scatter code, unroll the loop, or parallelize the code for this loop, potentially improving performance. INTEGER :: A(N),IND(N) ... DO CONCURRENT (I=1:M) A(IND(I)) = I END DO NOTE 5 The following code demonstrates the use of the LOCAL clause so that the X inside the DO CONCURRENT construct is a temporary variable, and will not affect the X outside the construct.

ISO/IEC JTC 1/SC 22/WG5/N2184

197

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 5 (cont.) X = 1.0 DO CONCURRENT (I=1:10) LOCAL (X) IF (A (I) > 0) THEN X = SQRT (A (I)) A (I) = A (I) - X**2 END IF B (I) = B (I) - A (I) END DO PRINT *, X

! Always prints 1.0.

NOTE 6 Additional examples of DO constructs are in C.7.3. 1

11.1.8

IF construct and statement

2

11.1.8.1

Purpose and form of the IF construct

3

1 The IF construct selects for execution at most one of its constituent blocks. The selection is based on a sequence

4

of logical expressions.

5 6 7 8

R1136 if-construct

is

if-then-stmt block [ else-if-stmt block ] ... [ else-stmt block ] end-if-stmt

12

R1137 if-then-stmt

is

[ if-construct-name : ] IF ( scalar-logical-expr ) THEN

13

R1138 else-if-stmt

is

ELSE IF ( scalar-logical-expr ) THEN [ if-construct-name ]

14

R1139 else-stmt

is

ELSE [ if-construct-name ]

15

R1140 end-if-stmt

is

END IF [ if-construct-name ]

16 17 18 19 20

C1145 (R1136) If the if-then-stmt of an if-construct specifies an if-construct-name, the corresponding end-ifstmt shall specify the same if-construct-name. If the if-then-stmt of an if-construct does not specify an if-construct-name, the corresponding end-if-stmt shall not specify an if-construct-name. If an else-ifstmt or else-stmt specifies an if-construct-name, the corresponding if-then-stmt shall specify the same if-construct-name.

21

11.1.8.2

9 10 11

22 23 24 25 26 27 28 29 30

Execution of an IF construct

1 At most one of the blocks in the IF construct is executed. If there is an ELSE statement in the construct,

exactly one of the blocks in the construct is executed. The scalar logical expressions are evaluated in the order of their appearance in the construct until a true value is found or an ELSE statement or END IF statement is encountered. If a true value or an ELSE statement is found, the block immediately following is executed and this completes the execution of the construct. The scalar logical expressions in any remaining ELSE IF statements of the IF construct are not evaluated. If none of the evaluated expressions is true and there is no ELSE statement, the execution of the construct is completed without the execution of any block within the construct. 2 It is permissible to branch to an END IF statement only from within its IF construct. Execution of an END IF

statement has no effect.

198

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

11.1.8.3

WD 1539-1

J3/21-007r1

Examples of IF constructs

NOTE 1 IF (CVAR == ’RESET’) THEN I = 0; J = 0; K = 0 END IF PROOF_DONE: IF (PROP) THEN WRITE (3, ’(’’QED’’)’) STOP ELSE PROP = NEXTPROP END IF PROOF_DONE IF (A > 0) THEN B = C/A IF (B > 0) THEN D = 1.0 END IF ELSE IF (C > 0) THEN B = A/C D = -1.0 ELSE B = ABS (MAX (A, C)) D = 0 END IF 2 3

11.1.8.4

IF statement

1 The IF statement controls the execution of a single action statement based on a single logical expression.

is

4

R1141 if-stmt

5

C1146 (R1141) The action-stmt in the if-stmt shall not be an if-stmt.

6 7 8

IF ( scalar-logical-expr ) action-stmt

2 Execution of an IF statement causes evaluation of the scalar logical expression. If the value of the expression is

true, the action statement is executed. If the value is false, the action statement is not executed. 3 The execution of a function reference in the scalar logical expression may affect entities in the action statement.

NOTE 1 An example of an IF statement is: IF (A > 0.0) A = LOG (A)

9

11.1.9

SELECT CASE construct

10

11.1.9.1

Purpose and form of the SELECT CASE construct

11 12 13

1 The SELECT CASE construct selects for execution at most one of its constituent blocks. The selection is based

on the value of an expression. R1142 case-construct

is

select-case-stmt [ case-stmt block ] ... end-select-stmt

R1143 select-case-stmt

is

[ case-construct-name : ] SELECT CASE ( case-expr )

14 15 16 17

ISO/IEC JTC 1/SC 22/WG5/N2184

199

J3/21-007r1

WD 1539-1

2021-05-21

1

R1144 case-stmt

is

CASE case-selector [case-construct-name]

2

R1145 end-select-stmt

is

END SELECT [ case-construct-name ]

3 4 5 6 7

C1147 (R1142) If the select-case-stmt of a case-construct specifies a case-construct-name, the corresponding endselect-stmt shall specify the same case-construct-name. If the select-case-stmt of a case-construct does not specify a case-construct-name, the corresponding end-select-stmt shall not specify a case-constructname. If a case-stmt specifies a case-construct-name, the corresponding select-case-stmt shall specify the same case-construct-name.

8

R1146 case-expr

9

C1148 case-expr shall be of type character, integer, or logical, or of enumeration type.

10

R1147 case-selector

is

scalar-expr

11

is ( case-value-range-list ) or DEFAULT

12

C1149 (R1142) No more than one of the selectors of one of the CASE statements shall be DEFAULT.

13 14 15 16

R1148 case-value-range

is or or or

case-value case-value : : case-value case-value : case-value

17

R1149 case-value

is

scalar-constant-expr

18 19

C1150 (R1142) For a given case-construct, each case-value shall be of the same type as case-expr. For character type, the kind type parameters shall be the same; character length differences are allowed.

20

C1151 (R1142) A case-value-range using a colon shall not be used if case-expr is of type logical.

21 22

C1152 (R1142) For a given case-construct, there shall be no possible value of the case-expr that matches more than one case-value-range.

23

11.1.9.2

24 25 26

1 The execution of the SELECT CASE statement causes the case expression to be evaluated. For a case value

range list, a match occurs if the case expression value matches any of the case value ranges in the list. For a case expression with a value of c, a match is determined as follows. (1)

27 28 29

(2)

30 31

(3) (4) (5) (6)

32 33 34 35 36 37 38 39

Execution of a SELECT CASE construct

If the case value range contains a single value v without a colon, a match occurs for type logical if the expression c .EQV. v is true, and a match occurs for type integer or character if the expression c == v is true. If the case value range is of the form low : high, a match occurs if the expression low <= c .AND. c <= high is true. If the case value range is of the form low :, a match occurs if the expression low <= c is true. If the case value range is of the form : high, a match occurs if the expression c <= high is true. If no other selector matches and a DEFAULT selector appears, it matches the case index. If no other selector matches and the DEFAULT selector does not appear, there is no match.

2 The block following the CASE statement containing the matching selector, if any, is executed. This completes

execution of the construct. 3 It is permissible to branch to an end-select-stmt only from within its SELECT CASE construct.

11.1.9.3

200

Examples of SELECT CASE constructs

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 An integer signum function: INTEGER FUNCTION SIGNUM (N) SELECT CASE (N) CASE (:-1) SIGNUM = -1 CASE (0) SIGNUM = 0 CASE (1:) SIGNUM = 1 END SELECT END NOTE 2 A code fragment to check for balanced parentheses: CHARACTER (80) :: LINE ... LEVEL = 0 SCAN_LINE: DO I = 1, 80 CHECK_PARENS: SELECT CASE (LINE (I:I)) CASE (’(’) LEVEL = LEVEL + 1 CASE (’)’) LEVEL = LEVEL - 1 IF (LEVEL < 0) THEN PRINT *, ’UNEXPECTED RIGHT PARENTHESIS’ EXIT SCAN_LINE END IF CASE DEFAULT ! Ignore all other characters END SELECT CHECK_PARENS END DO SCAN_LINE IF (LEVEL > 0) THEN PRINT *, ’MISSING RIGHT PARENTHESIS’ END IF NOTE 3 The following three fragments are equivalent: IF (SILLY == 1) THEN CALL THIS ELSE CALL THAT END IF

! Fragment one

SELECT CASE (SILLY == 1) ! Fragment two CASE (.TRUE.) CALL THIS CASE (.FALSE.) CALL THAT END SELECT SELECT CASE (SILLY)

! Fragment three

ISO/IEC JTC 1/SC 22/WG5/N2184

201

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 3 (cont.) CASE DEFAULT CALL THAT CASE (1) CALL THIS END SELECT NOTE 4 A code fragment showing several selections of one block: SELECT CASE (N) CASE (1, 3:5, 8) CALL SUB CASE DEFAULT CALL OTHER END SELECT

! Selects 1, 3, 4, 5, 8

1

11.1.10

SELECT RANK construct

2

11.1.10.1

Purpose and form of the SELECT RANK construct

3

1 The SELECT RANK construct selects for execution at most one of its constituent blocks. The selection is based

4 5

on the rank of an assumed-rank variable. A name is associated with the variable (19.4, 19.5.1.6), in the same way as for the ASSOCIATE construct.

6 7 8 9

R1150 select-rank-construct

is

select-rank-stmt [ select-rank-case-stmt block ]... end-select-rank-stmt

10 11

R1151 select-rank-stmt

is

[ select-construct-name : ] SELECT RANK ( [ associate-name => ] selector )

12

C1153 The selector in a select-rank-stmt shall be the name of an assumed-rank array.

13 14 15

R1152 select-rank-case-stmt

16

C1154 A scalar-int-constant-expr in a select-rank-case-stmt shall be nonnegative.

17 18

C1155 For a given select-rank-construct, the same rank value shall not be specified in more than one select-rankcase-stmt.

19 20

C1156 For a given select-rank-construct, there shall be at most one RANK ( * ) select-rank-case-stmt and at most one RANK DEFAULT select-rank-case-stmt.

21 22

C1157 If select-construct-name appears on a select-rank-case-stmt the corresponding select-rank-stmt shall specify the same select-construct-name.

23 24

C1158 A SELECT RANK construct shall not have a select-rank-case-stmt that is RANK ( * ) if the selector has the ALLOCATABLE or POINTER attribute.

25

R1153 end-select-rank-stmt

26 27

C1159 If the select-rank-stmt of a select-rank-construct specifies a select-construct-name, the corresponding end-select-rank-stmt shall specify the same select-construct-name. If the select-rank-stmt of a select-

202

is RANK ( scalar-int-constant-expr ) [ select-construct-name ] or RANK ( * ) [ select-construct-name ] or RANK DEFAULT [ select-construct-name ]

is

END SELECT [ select-construct-name ]

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

rank-construct does not specify a select-construct-name, the corresponding end-select-rank-stmt shall not specify a select-construct-name.

3 4

2 The associate name of a SELECT RANK construct is the associate-name if specified; otherwise it is the name

5 6

3 The scalar-int-constant-expr in a select-rank-case-stmt may have a value greater than the maximum possible rank

7 8 9 10 11 12 13 14 15 16

that constitutes the selector. of the selector; in this case, its block will never be executed. 11.1.10.2

Execution of the SELECT RANK construct

1 A SELECT RANK construct selects at most one block to be executed. During execution of that block, the

associate name identifies an entity which is associated (19.5.1.6) with the selector. A RANK ( * ) statement matches the selector if the selector is argument associated with an assumed-size array. A RANK ( scalar-intconstant-expr ) statement matches the selector if the selector has that rank and is not argument associated with an assumed-size array. A RANK DEFAULT statement matches the selector if no other select-rank-case-stmt of the construct matches the selector. If a select-rank-case-stmt matches the selector, the block following that statement is executed; otherwise, control is transferred to the end-select-rank-stmt. 2 It is permissible to branch to an end-select-rank-stmt only from within its SELECT RANK construct.

11.1.10.3

Attributes of a SELECT RANK associate name

17 18

1 The associating entity (19.5.5) assumes the declared type and type parameters of the selector. It is polymorphic

19 20 21 22

2 Within the block following a RANK DEFAULT statement, the associating entity is assumed-rank and has exactly

23 24 25 26 27 28

if and only if the selector is polymorphic. the same attributes as the selector. Within the block following a RANK ( * ) statement, the associating entity has rank 1 and is assumed-size, as if it were declared with DIMENSION(1:*). Within the block following a RANK ( scalar-int-constant-expr ) statement, the associating entity has the specified rank; the lower bound of each dimension is the result of the intrinsic function LBOUND (16.9.119) applied to the corresponding dimension of the selector, and the upper bound of each dimension is the result of the intrinsic function UBOUND (16.9.215) applied to the corresponding dimension of the selector. 3 The associating entity has the ALLOCATABLE, POINTER, or TARGET attribute if the selector has that

attribute. The other attributes of the associating entity are described in 11.1.3.3. 11.1.10.4

Examples of the SELECT RANK construct

NOTE 1 This example shows how to use a SELECT RANK construct to process scalars and rank-2 arrays; anything else will be rejected as an error. SUBROUTINE process(x) REAL x(..) ! SELECT RANK(x) RANK (0) x = 0 RANK (2) IF (SIZE(x,2)>=2) x(:,2) = 2 RANK DEFAULT Print *, ’I did not expect rank’, RANK(x), ’shape’, SHAPE(x) ERROR STOP ’process bad arg’ END SELECT

ISO/IEC JTC 1/SC 22/WG5/N2184

203

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 The following example shows how to process assumed-size arrays, including how to use sequence association for multi-dimensional processing of an assumed-size array. SELECT RANK (y => x) RANK (*) IF (RANK(x)==2) THEN ! Special code for the rank two case. CALL sequence_assoc_2(y, LBOUND(x,1), UBOUND(x,1), LBOUND(x,2)) ELSE ! We just do all the other ranks in array element order. i = 1 DO IF (y(i)==0) Exit y(i) = -y(i) i = i + 1 END DO END IF END SELECT ... CONTAINS ... SUBROUTINE sequence_assoc_2(a, lb1, ub1, lb2) INTEGER, INTENT (IN) :: lb1, ub1, lb2 REAL a(lb1:ub1,lb2:*) j = lb2 outer: DO DO i=lb1,ub1 IF (a(i,j)==0) EXIT outer a(i,j) = a(i,j)**2 END DO j = j + 1 IF (ANY(a(:,j)==0)) EXIT j = j + 1 END DO outer END SUBROUTINE

1

11.1.11

SELECT TYPE construct

2

11.1.11.1

Purpose and form of the SELECT TYPE construct

3 4 5

1 The SELECT TYPE construct selects for execution at most one of its constituent blocks. The selection is based

on the dynamic type of an expression. A name is associated with the expression or variable (19.4, 19.5.1.6), in the same way as for the ASSOCIATE construct. R1154 select-type-construct

is

select-type-stmt [ type-guard-stmt block ] ... end-select-type-stmt

10 11

R1155 select-type-stmt

is

[ select-construct-name : ] SELECT TYPE ( [ associate-name => ] selector )

12

C1160 (R1155) If selector is not a named variable, associate-name => shall appear.

13

C1161 (R1155) If selector is not a variable or is a variable that has a vector subscript, neither associate-name

6 7 8 9

204

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

nor any subobject thereof shall appear in a variable definition context (19.6.7) or pointer association context (19.6.8).

3

C1162 (R1155) The selector in a select-type-stmt shall be polymorphic.

4

R1156 type-guard-stmt

5 6

is TYPE IS ( type-spec ) [ select-construct-name ] or CLASS IS ( derived-type-spec ) [ select-construct-name ] or CLASS DEFAULT [ select-construct-name ]

7

C1163 (R1156) The type-spec or derived-type-spec shall specify that each length type parameter is assumed.

8 9

C1164 (R1156) The type-spec or derived-type-spec shall not specify a derived type with the BIND attribute or the SEQUENCE attribute.

10 11

C1165 (R1154) If selector is not unlimited polymorphic, each TYPE IS or CLASS IS type-guard-stmt shall specify an extension of the declared type of selector.

12 13 14

C1166 (R1154) For a given select-type-construct, the same type and kind type parameter values shall not be specified in more than one TYPE IS type-guard-stmt and shall not be specified in more than one CLASS IS type-guard-stmt.

15

C1167 (R1154) For a given select-type-construct, there shall be at most one CLASS DEFAULT type-guard-stmt.

16

R1157 end-select-type-stmt

17 18 19 20 21

C1168 (R1154) If the select-type-stmt of a select-type-construct specifies a select-construct-name, the corresponding end-select-type-stmt shall specify the same select-construct-name. If the select-type-stmt of a selecttype-construct does not specify a select-construct-name, the corresponding end-select-type-stmt shall not specify a select-construct-name. If a type-guard-stmt specifies a select-construct-name, the corresponding select-type-stmt shall specify the same select-construct-name.

22

2 The associate name of a SELECT TYPE construct is the associate-name if specified; otherwise it is the name

23

that constitutes the selector.

24

11.1.11.2

is

END SELECT [ select-construct-name ]

Execution of the SELECT TYPE construct

25 26

1 Execution of a SELECT TYPE construct causes evaluation of every expression within a selector that is a variable

27 28

2 A SELECT TYPE construct selects at most one block to be executed. During execution of that block, the

29 30 31 32 33

3 A TYPE IS type guard statement matches the selector if the dynamic type and kind type parameter values of

34

4 The block to be executed is selected as follows.

designator, or evaluation of a selector that is not a variable designator. associate name identifies an entity which is associated (19.5.1.6) with the selector. the selector are the same as those specified by the statement. A CLASS IS type guard statement matches the selector if the dynamic type of the selector is an extension of the type specified by the statement and the kind type parameter values specified by the statement are the same as the corresponding type parameter values of the dynamic type of the selector.

35 36

(1)

37 38

(2)

39

(3)

40 41 42 43

(4)

If a TYPE IS type guard statement matches the selector, the block following that statement is executed. Otherwise, if exactly one CLASS IS type guard statement matches the selector, the block following that statement is executed. Otherwise, if several CLASS IS type guard statements match the selector, one of these statements will inevitably specify a type that is an extension of all the types specified in the others; the block following that statement is executed. Otherwise, if there is a CLASS DEFAULT type guard statement, the block following that statement is executed.

ISO/IEC JTC 1/SC 22/WG5/N2184

205

J3/21-007r1

(5)

1

WD 1539-1

2021-05-21

Otherwise, no block is executed.

NOTE 1 This algorithm does not examine the type guard statements in source text order when it looks for a match; it selects the most particular type guard when there are several potential matches. 2 3

5 Within the block following a TYPE IS type guard statement, the associating entity (19.5.5) is not polymorphic

4 5 6

6 Within the block following a CLASS IS type guard statement, the associating entity is polymorphic and has the

7 8 9

7 Within the block following a CLASS DEFAULT type guard statement, the associating entity is polymorphic and

(7.3.2.3), has the type named in the type guard statement, and has the type parameter values of the selector. declared type named in the type guard statement. The type parameter values of the associating entity are the corresponding type parameter values of the selector. has the same declared type as the selector. The type parameter values of the associating entity are those of the declared type of the selector. NOTE 2 If the declared type of the selector is T, specifying CLASS DEFAULT has the same effect as specifying CLASS IS (T).

10

8 The other attributes of the associating entity are described in 11.1.3.3.

11

9 It is permissible to branch to an end-select-type-stmt only from within its SELECT TYPE construct.

12

11.1.11.3

Examples of the SELECT TYPE construct

NOTE 1 TYPE POINT REAL :: X, Y END TYPE POINT TYPE, EXTENDS(POINT) :: POINT_3D REAL :: Z END TYPE POINT_3D TYPE, EXTENDS(POINT) :: COLOR_POINT INTEGER :: COLOR END TYPE COLOR_POINT TYPE(POINT), TARGET :: P TYPE(POINT_3D), TARGET :: P3 TYPE(COLOR_POINT), TARGET :: C CLASS(POINT), POINTER :: P_OR_C P_OR_C => C SELECT TYPE ( A => P_OR_C ) CLASS IS ( POINT ) ! "CLASS ( POINT ) :: A" implied here PRINT *, A%X, A%Y ! This block gets executed TYPE IS ( POINT_3D ) ! "TYPE ( POINT_3D ) :: A" implied here PRINT *, A%X, A%Y, A%Z END SELECT NOTE 2 The following example illustrates the omission of associate-name. It uses the declarations from NOTE 1.

206

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) P_OR_C => P3 SELECT TYPE ( P_OR_C ) CLASS IS ( POINT ) ! "CLASS ( POINT ) :: P_OR_C" implied here PRINT *, P_OR_C%X, P_OR_C%Y TYPE IS ( POINT_3D ) ! "TYPE ( POINT_3D ) :: P_OR_C" implied here PRINT *, P_OR_C%X, P_OR_C%Y, P_OR_C%Z ! This block gets executed END SELECT 1 2

11.1.12

EXIT statement

1 The EXIT statement provides one way of terminating a loop, or completing execution of another construct.

is

3

R1158 exit-stmt

EXIT [ construct-name ]

4 5

C1169 If a construct-name appears on an EXIT statement, the EXIT statement shall be within that construct; otherwise, it shall be within at least one do-construct.

6

2 An EXIT statement belongs to a particular construct. If a construct name appears, the EXIT statement belongs

7

to that construct; otherwise, it belongs to the innermost DO construct in which it appears.

8 9

C1170 An exit-stmt shall not appear within a DO CONCURRENT construct if it belongs to that construct or an outer construct.

10 11

C1171 An exit-stmt shall not appear within a CHANGE TEAM or CRITICAL construct if it belongs to an outer construct.

12

3 When an EXIT statement that belongs to a DO construct is executed, it terminates the loop (11.1.7.4.5) and

13 14 15 16 17

any active loops contained within the terminated loop. When an EXIT statement that belongs to a non-DO construct is executed, it terminates any active loops contained within that construct, and completes execution of that construct. If the EXIT statement belongs to a CHANGE TEAM construct, the effect is the same as transferring control to the END TEAM statement; if that statement contains a STAT= or ERRMSG= specifier, the stat-variable or errmsg-variable becomes defined as specified for that statement.

18

11.2

Branching

19

11.2.1

Branch concepts

20 21 22 23

1 Branching is used to alter the normal execution sequence. A branch causes a transfer of control from one statement

24 25 26 27 28

to a labeled branch target statement in the same inclusive scope. Branching can be caused by a GO TO statement, a computed GO TO statement, a CALL statement that has an alt-return-spec, or an input/output statement that has an END=, EOR=, or ERR= specifier. Although procedure references and control constructs can cause transfer of control, they are not branches. A branch target statement is an action-stmt, associate-stmt, end-associatestmt, if-then-stmt, end-if-stmt, select-case-stmt, end-select-stmt, select-rank-stmt, end-select-rank-stmt, selecttype-stmt, end-select-type-stmt, do-stmt, end-do-stmt, block-stmt, end-block-stmt, critical-stmt, end-critical-stmt, forall-construct-stmt, forall-stmt, where-construct-stmt, end-function-stmt, end-mp-subprogram-stmt, end-programstmt, or end-subroutine-stmt.

29

11.2.2

30

R1159 goto-stmt

31 32

C1172 (R1159) The label shall be the statement label of a branch target statement that appears in the same inclusive scope as the goto-stmt.

GO TO statement is

GO TO label

ISO/IEC JTC 1/SC 22/WG5/N2184

207

J3/21-007r1

1

WD 1539-1

2021-05-21

1 Execution of a GO TO statement causes a branch to the branch target statement identified by the label.

2

11.2.3

Computed GO TO statement

3

R1160

computed-goto-stmt

4 5

C1173

(R1160) Each label in label-list shall be the statement label of a branch target statement that appears in the same inclusive scope as the computed-goto-stmt.

is

GO TO ( label-list ) [ , ] scalar-int-expr

6 7

1 Execution of a computed GO TO statement causes evaluation of the scalar integer expression. If this value is i such that 1 ≤ i ≤ n

8

labels. If i is less than 1 or greater than n, the execution sequence continues as though a CONTINUE statement were executed.

9

11.3

10

where n is the number of labels in label-list, a branch occurs to the branch target statement identified by the ith label in the list of

CONTINUE statement

1 Execution of a CONTINUE statement has no effect.

is

11

R1161 continue-stmt

CONTINUE

12

11.4

13

R1162 stop-stmt

is

STOP [ stop-code ] [ , QUIET = scalar-logical-expr]

14

R1163 error-stop-stmt

is

ERROR STOP [ stop-code ] [ , QUIET = scalar-logical-expr]

15 16

R1164 stop-code

is scalar-default-char-expr or scalar-int-expr

17

C1174 (R1164) The scalar-int-expr shall be of default kind.

STOP and ERROR STOP statements

18 19

1 Execution of a STOP statement initiates normal termination of execution. Execution of an ERROR STOP

20

2 When an image is terminated by a STOP or ERROR STOP statement, its stop code, if any, is made available

21 22 23 24 25 26

in a processor-dependent manner. If the stop-code is an integer, it is recommended that the value be used as the process exit status, if the processor supports that concept. If the stop-code in a STOP statement is of type character or does not appear, or if an end-program-stmt is executed, it is recommended that the value zero be supplied as the process exit status, if the processor supports that concept. If the stop-code in an ERROR STOP statement is of type character or does not appear, it is recommended that a processor-dependent nonzero value be supplied as the process exit status, if the processor supports that concept.

27 28 29 30 31 32

33 34

statement initiates error termination of execution.

3 If QUIET= is omitted or the scalar-logical-expr has the value false:

• if any exception (17) is signaling on that image, the processor shall issue a warning indicating which exceptions are signaling, and this warning shall be on the unit identified by the named constant ERROR_UNIT from the intrinsic module ISO_FORTRAN_ENV (16.10.2.9); • if a stop code is specified, it is recommended that it be made available by formatted output to the same unit. 4 If QUIET= appears and the scalar-logical-expr has the value true, no output of signaling exceptions or stop code

shall be produced. NOTE 1 When normal termination occurs on more than one image, it is expected that a processor-dependent summary of any stop codes and signaling exceptions will be made available.

208

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 If the integer stop-code is used as the process exit status, the processor might be able to interpret only values within a limited range, or only a limited portion of the integer value (for example, only the least-significant 8 bits).

1

11.5

2

R1165 fail-image-stmt

3 4

FAIL IMAGE statement is

FAIL IMAGE

1 Execution of a FAIL IMAGE statement causes the executing image to cease participating in program execution

without initiating termination. No further statements are executed by that image. NOTE 1 The FAIL IMAGE statement enables testing of a recovery algorithm without needing an actual failure. On a processor that does not have the ability to detect that an image has failed, execution of a FAIL IMAGE statement might provide a simulated failure environment that provides debug information. In a piece of code that executes about once a second, invoking this subroutine on an image SUBROUTINE FAIL REAL :: X CALL RANDOM_NUMBER (X) IF (X<0.001) FAIL IMAGE END SUBROUTINE FAIL will cause that image to have approximately a 1/1000 chance of failure every second. Note that FAIL IMAGE is not an image control statement.

5 6 7

11.6

NOTIFY WAIT statement

1 The NOTIFY WAIT statement waits until the value of its notify-variable is greater than or equal to a threshold

value.

8

R1166 notify-wait-stmt

is

NOTIFY WAIT ( notify-variable [ , event-wait-spec-list ] )

9

R1167 notify-variable

is

scalar-variable

10

C1175 A notify-variable shall be of type NOTIFY_TYPE from the intrinsic module ISO_FORTRAN_ENV.

11

C1176 A notify-variable shall not be a coindexed object.

12

2 The notify-variable shall not depend on the value of stat-variable or errmsg-variable.

13

3 Execution of a NOTIFY WAIT statement consists of the following sequence of actions:

14 15

(1)

16 17

(2)

18 19

(3)

20 21

if the UNTIL_COUNT= specifier appears and its scalar-int-expr is greater than one, the threshold value is set to that value, otherwise, the threshold value is set to one; the executing image waits until the count of the notify variable is greater than or equal to the threshold value or an error condition occurs; if no error condition occurs, the count of the notify variable is atomically decremented by the threshold value.

4 If an error condition occurs during execution of an NOTIFY WAIT statement, the value of the count of its notify

variable is processor dependent.

ISO/IEC JTC 1/SC 22/WG5/N2184

209

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

5 Execution of an assignment statement whose variable has a NOTIFY= specifier is initially unsatisfied. Successful

5 6 7

6 The stat-variable of a NOTIFY WAIT statement shall not depend on the value of the notify variable or the

8 9 10

7 If a NOTIFY WAIT statement has a STAT= specifier, stat-variable is assigned the value zero if execution of

11

execution of a NOTIFY WAIT statement with a threshold value of k satisfies the first k unsatisfied executions of assignment statements whose NOTIFY= specifier specifies the same notify variable as the NOTIFY WAIT statement. errmsg-variable. The errmsg-variable of a NOTIFY WAIT statement shall not depend on the value of the notify variable or the stat-variable. the statement is successful, and a processor-dependent positive value that is different from the value of STAT_FAILED_IMAGE (16.10.2.28) and STAT_STOPPED_IMAGE (16.10.2.31) from the intrinsic module ISO_FORTRAN_ENV (16.10.2) if an error condition occurs.

12 13

8 If an error condition occurs during execution of a NOTIFY WAIT statement with no STAT=, error termination

14 15 16

9 If a NOTIFY WAIT statement has an ERRMSG= specifier and an error condition occurs, errmsg-variable is

17

10 The set of error conditions that can occur during execution of a NOTIFY WAIT statement is processor dependent.

is initiated. assigned an explanatory message, as if by intrinsic assignment. If no such condition occurs, the definition status and the value of errmsg-variable are unchanged.

18

11.7

Image execution control

19

11.7.1

Image control statements

20

1 The execution sequence on each image is specified in 5.3.5.

21 22

2 Execution of an image control statement divides the execution sequence on an image into segments. Each of the

23

• SYNC ALL statement; • SYNC IMAGES statement; • SYNC MEMORY statement; • SYNC TEAM statement; • ALLOCATE statement that has a coarray allocate-object; • DEALLOCATE statement that has an allocate-object that is a coarray or has a coarray ultimate component; • CHANGE TEAM or END TEAM statement (11.1.5); • CRITICAL or END CRITICAL statement (11.1.6); • EVENT POST or EVENT WAIT statement; • FORM TEAM statement; • LOCK or UNLOCK statement; • any statement that completes execution of a block or procedure and which results in the implicit deallocation of a coarray; • a CALL statement that references the intrinsic subroutine MOVE_ALLOC with coarray arguments; • STOP statement; • END statement of a main program.

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

39 40

following is an image control statement:

3 During an execution of a statement that invokes more than one procedure, at most one invocation shall cause

execution of an image control statement other than CRITICAL or END CRITICAL.

210

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

27

11.7.2

WD 1539-1

J3/21-007r1

Segments

1 On each image, the sequence of statements executed before the first execution of an image control statement,

between the execution of two image control statements, or after the last execution of an image control statement is a segment. The segment executed immediately before the execution of an image control statement includes the evaluation of all expressions within the statement. 2 By execution of image control statements or user-defined ordering (11.7.5), the program can ensure that the

execution of the ith segment on image P, Pi , either precedes or succeeds the execution of the j th segment on another image Q, Qj . If the program does not ensure this, segments Pi and Qj are unordered; depending on the relative execution speeds of the images, some or all of the execution of the segment Pi may take place at the same time as some or all of the execution of the segment Qj . 3 A coarray may be referenced or defined by execution of an atomic subroutine during the execution of a segment

that is unordered relative to the execution of a segment in which the coarray is referenced or defined by execution of an atomic subroutine. An event variable or notify variable may be referenced or defined during the execution of a segment that is unordered relative to the execution of another segment in which that event variable or notify variable is defined. A variable defined in an unordered segment only by execution an assignment statement with a NOTIFY= specifier may be referenced or defined after execution of a NOTIFY WAIT statement that satisfies that assignment statement execution. Otherwise, • if a variable is defined or becomes undefined on an image in a segment, it shall not be referenced, defined, or become undefined in a segment on another image unless the segments are ordered, • if the allocation of an allocatable subobject of a coarray or the pointer association of a pointer subobject of a coarray is changed on an image in a segment, that subobject shall not be referenced, defined, or have its allocation or association status, dynamic type, array bounds, shape, or a deferred type parameter value inquired about in a segment on another image unless the segments are ordered, and • if a procedure invocation on image P is in execution in segments Pi , Pi+1 , . . . , Pk and defines a noncoarray dummy argument, the effective argument shall not be referenced, defined, or become undefined on another image Q in a segment Qj unless Qj precedes Pi or succeeds Pk . 4 If, by execution of a statement in segment Pi on image P,

31 32 33

• a variable X is defined, referenced, becomes undefined, or has its allocation status, pointer association status, array bounds, dynamic type, or type parameters changed or inquired about, • segment Pi on image P precedes segment Qj on image Q, and • X is defined, referenced, becomes undefined, or has its allocation status, pointer association status, array bounds, dynamic type, or type parameters changed or inquired about by execution of a statement in segment Qj on image Q,

34 35

then the action regarding X in segment Pi on image P precedes the action regarding X in segment Qj on image Q.

28 29 30

NOTE 1 The set of all segments on all images is partially ordered: the segment Pi precedes segment Qj if and only if there is a sequence of segments starting with Pi and ending with Qj such that each segment of the sequence precedes the next either because they are consecutive segments on the same image or because of the execution of image control statements. NOTE 2 If the segments S1 , S2 , . . . , Sk on the distinct images P1 , P2 , . . . , Pk are all unordered with respect to each other, it is expected that the processor will ensure that each of these images is provided with an equitable share of resources for executing its segment.

ISO/IEC JTC 1/SC 22/WG5/N2184

211

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 3 Because of the restrictions on references and definitions in unordered segments, the processor can apply code motion optimizations within a segment as if it were the only image in execution, provided calls to atomic subroutines are not involved. NOTE 4 The model upon which the interpretation of a program is based is that there is a permanent memory location for each coarray and that all images on which it is established can access it. In practice, apart from executions of atomic subroutines, the processor could make a copy of a nonvolatile coarray on an image (in cache or a register, for example) and, as an optimization, defer copying a changed value back to the permanent memory location while it is still being used. Since the variable is not volatile, it is safe to defer this transfer until the end of the segment and thereafter to reload from permanent memory any coarray that was not defined within the segment. It might not be safe to defer these actions beyond the end of the segment since another image might reference the variable then. The value of the ATOM argument of an atomic subroutine might be accessed or modified by another concurrently executing image. Therefore, execution of an atomic subroutine that references the ATOM argument cannot rely on a local copy, but instead always gets its value from its permanent memory location. Execution of an atomic subroutine that defines the ATOM argument does not complete until the value of its ATOM argument has been sent to its permanent memory location. NOTE 5 The incorrect sequencing of image control statements can suspend execution indefinitely. For example, one image might be executing a SYNC ALL statement while another is executing an ALLOCATE statement for a coarray. 1

11.7.3

SYNC ALL statement

2

R1168 sync-all-stmt

is

3 4

R1169 sync-stat

is STAT = stat-variable or ERRMSG = errmsg-variable

5

C1177 No specifier shall appear more than once in a given sync-stat-list.

6

C1178 A stat-variable or errmsg-variable in a sync-stat shall not be a coindexed object.

7

1 The STAT= and ERRMSG= specifiers for image control statements are described in 11.7.11.

8

2 Successful execution of a SYNC ALL statement performs a synchronization of all images in the current team.

9 10 11 12

Execution on an image, M, of the segment following the SYNC ALL statement is delayed until each other image in the current team has executed a SYNC ALL statement as many times as has image M in this team. The segments that executed before the SYNC ALL statement on an image precede the segments that execute after the SYNC ALL statement on another image.

SYNC ALL [ ( [ sync-stat-list ] ) ]

NOTE 1 The processor might have special hardware or employ an optimized algorithm to make the SYNC ALL statement execute efficiently. Here is a simple example of its use. Image 1 reads data and broadcasts it to other images: REAL :: P[*] ... SYNC ALL IF (THIS_IMAGE()==1) THEN

212

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) READ (*,*) P DO I = 2, NUM_IMAGES() P[I] = P END DO END IF SYNC ALL

1

11.7.4

SYNC IMAGES statement

2

R1170 sync-images-stmt

is

3 4

R1171 image-set

is int-expr or *

5

C1179 An image-set that is an int-expr shall be scalar or of rank one.

6

C1180 The value of image-set shall not depend on the value of stat-variable or errmsg-variable.

SYNC IMAGES ( image-set [ , sync-stat-list ] )

7 8

1 If image-set is an array expression, the value of each element shall be positive and not greater than the number

9 10

2 If image-set is a scalar expression, its value shall be positive and not greater than the number of images in the

11

3 An image-set that is an asterisk specifies all images in the current team.

12 13 14 15 16

4 Execution of a SYNC IMAGES statement performs a synchronization of the image with each of the other images

17

of images in the current team, and there shall be no repeated values. current team.

in the image-set. Executions of SYNC IMAGES statements on images M and T correspond if the number of times image M has executed a SYNC IMAGES statement in the current team with T in its image set is the same as the number of times image T has executed a SYNC IMAGES statement with M in its image set in this team. The segments that executed before the SYNC IMAGES statement on either image precede the segments that execute after the corresponding SYNC IMAGES statement on the other image. NOTE 1 A SYNC IMAGES statement that specifies the single image index value THIS_IMAGE ( ) in its image set is allowed. This simplifies writing programs for an arbitrary number of images by allowing correct execution in the limiting case of the number of images being equal to one. NOTE 2 In a program that uses SYNC ALL as its only synchronization mechanism, every SYNC ALL statement could be replaced by a SYNC IMAGES (*) statement, but SYNC ALL might give better performance. SYNC IMAGES statements are not required to specify the entire image set, or even the same image set, on all images participating in the synchronization. In the following example, image 1 will wait for each of the other images to execute the statement SYNC IMAGES (1). The other images wait for image 1 to set up the data, but do not wait on any other image. IF (THIS_IMAGE() == 1) then ! Set up coarray data needed by all other images. SYNC IMAGES(*) ELSE SYNC IMAGES(1) ! Use the data set up by image 1. END IF

ISO/IEC JTC 1/SC 22/WG5/N2184

213

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 (cont.) When the following example runs on five or more images, each image synchronizes with both of its neighbors, in a circular fashion. INTEGER :: up, down ... IF (NUM_IMAGES () > 1) THEN up = THIS_IMAGE () + 1; IF (up>NUM_IMAGES ()) up = 1 down = THIS_IMAGE () - 1; IF (down==0) down = NUM_IMAGES () SYNC IMAGES ( (/ up, down /) ) END IF This might appear to have the same effect as SYNC ALL but there is no ordering between the preceding and succeeding segments on non-adjacent images. For example, the segment preceding the SYNC IMAGES statement on image 3 will be ordered before those succeeding it on images 2 and 4, but not those on images 1 and 5. NOTE 3 In the following example, each image synchronizes with its neighbor. INTEGER :: ME, NE, STEP, NSTEPS NE = NUM_IMAGES() ME = THIS_IMAGE() . . . ! Initial calculation SYNC ALL DO STEP = 1, NSTEPS IF (ME > 1) SYNC IMAGES(ME-1) . . . ! Perform calculation IF (ME < NE) SYNC IMAGES(ME+1) END DO SYNC ALL The calculation starts on image 1 since all the others will be waiting on SYNC IMAGES (ME−1). When this is done, image 2 can start and image 1 can perform its second calculation. This continues until they are all executing different steps at the same time. Eventually, image 1 will finish and then the others will finish one by one. 1 2 3 4 5 6 7 8 9 10 11 12 13 14

11.7.5

SYNC MEMORY statement

1 Execution of a SYNC MEMORY statement ends one segment and begins another; those two segments can be

ordered by a user-defined way with respect to segments on other images. R1172 sync-memory-stmt

is

SYNC MEMORY [ ( [ sync-stat-list ] ) ]

2 If, by execution of statements on image P,

• a variable X on image Q is defined, referenced, becomes undefined, or has its allocation status, pointer association status, array bounds, dynamic type, or type parameters changed or inquired about by execution of a statement, • that statement precedes a successful execution of a SYNC MEMORY statement, and • a variable Y on image Q is defined, referenced, becomes undefined, or has its allocation status, pointer association status, array bounds, dynamic type, or type parameters changed or inquired about by execution of a statement that succeeds execution of that SYNC MEMORY statement, then the action regarding X on image Q precedes the action regarding Y on image Q. 3 User-defined ordering of segment Pi on image P to precede segment Qj on image Q occurs when

214

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

5 6 7 8

WD 1539-1

J3/21-007r1

• image P executes an image control statement that ends segment Pi , and then executes statements that initiate a cooperative synchronization between images P and Q, and • image Q executes statements that complete the cooperative synchronization between images P and Q and then executes an image control statement that begins segment Qj . 4 Execution of the cooperative synchronization between images P and Q shall include a dependency that forces

execution on image P of the statements that initiate the synchronization to precede the execution on image Q of the statements that complete the synchronization. The mechanisms available for creating such a dependency are processor dependent. NOTE 1 SYNC MEMORY usually suppresses compiler optimizations that might reorder memory operations across the segment boundary defined by the SYNC MEMORY statement and ensures that all memory operations initiated in the preceding segments in its image complete before any memory operations in the subsequent segment in its image are initiated. It needs to do this unless it can establish that failure to do so could not alter processing on another image. NOTE 2 SYNC MEMORY can be used to implement specialized schemes for segment ordering. For example, the user might have access to an external procedure that performs synchronization between images. That library procedure might not be aware of the mechanisms used by the processor to manage remote data references and definitions, and therefore not, by itself, be able to ensure the correct memory state before and after its reference. The SYNC MEMORY statement provides the needed memory ordering that enables the safe use of the external synchronization routine. For example: INTEGER :: IAM REAL :: X[*] IAM = THIS_IMAGE () IF (IAM == 1) X = 1.0 SYNC MEMORY CALL EXTERNAL_SYNC () SYNC MEMORY IF (IAM == 2) WRITE (*,*) X[1] where executing the subroutine EXTERNAL_SYNC has an image synchronization effect similar to executing a SYNC ALL statement.

9

11.7.6

SYNC TEAM statement

10

R1173 sync-team-stmt

is

SYNC TEAM ( team-value [ , sync-stat-list ] )

11 12

1 The team-value shall identify an ancestor team, the current team, or a team whose parent is the current team.

13 14 15

2 Successful execution of a SYNC TEAM statement performs a synchronization of the team identified by team-

16 17

The executing image shall be a member of the specified team. value. Execution on an image, M, of the segment following the SYNC TEAM statement is delayed until each other image of the specified team has executed a SYNC TEAM statement specifying the same team as many times as has image M in this team. The segments that executed before the SYNC TEAM statement on an image precede the segments that execute after the corresponding SYNC TEAM statement on another image. NOTE 1 A SYNC TEAM statement synchronizes a particular team whereas a SYNC ALL statement synchronizes the current team.

ISO/IEC JTC 1/SC 22/WG5/N2184

215

J3/21-007r1

1 2

11.7.7

WD 1539-1

2021-05-21

EVENT POST statement

1 The EVENT POST statement posts an event.

3

R1174 event-post-stmt

is

EVENT POST ( event-variable [ , sync-stat-list ] )

4

R1175 event-variable

is

scalar-variable

5 6

C1181 (R1175) An event-variable shall be of type EVENT_TYPE from the intrinsic module ISO_FORTRAN_ENV (16.10.2).

7

2 The event-variable shall not depend on the value of stat-variable or errmsg-variable.

8 9

3 Successful execution of an EVENT POST statement atomically increments the count of the event variable by

10 11

one. If an error condition occurs during execution of an EVENT POST statement, the value of the count of the event variable is processor dependent. The completion of an EVENT POST statement does not depend on the execution of a corresponding EVENT WAIT statement.

12

11.7.8

13

EVENT WAIT statement

1 The EVENT WAIT statement waits until an event is posted.

14

R1176 event-wait-stmt

is

15 16

R1177 event-wait-spec

is until-spec or sync-stat

17

R1178 until-spec

is

18

C1182 (R1176) The event-variable in an event-wait-stmt shall not be coindexed.

19

C1183 No specifier shall appear more than once in a given event-wait-spec-list.

20

2 The event-variable shall not depend on the value of stat-variable or errmsg-variable.

21

3 Execution of an EVENT WAIT statement consists of the following sequence of actions:

EVENT WAIT ( event-variable [ , event-wait-spec-list ] )

UNTIL_COUNT = scalar-int-expr

22 23

1. if the UNTIL_COUNT= specifier does not appear, the threshold value is set to one; otherwise, the threshold value is set to the maximum of the value of the scalar-int-expr and one;

24 25

2. the executing image waits until the count of the event variable is greater than or equal to the threshold value or an error condition occurs;

26 27

3. if no error condition occurs, the count of the event variable is atomically decremented by the threshold value.

28

4 If an error condition occurs during execution of an EVENT WAIT statement, the value of the count of its event

29 30 31 32 33 34 35 36 37

variable is processor dependent. 5 An EVENT POST statement execution is initially unsatisfied. Successful execution of an EVENT WAIT state-

ment with a threshold of k satisfies the first k unsatisfied EVENT POST statement executions for that event variable. This EVENT WAIT statement execution causes the segment following the EVENT WAIT statement execution to succeed the segments preceding those k EVENT POST statement executions.

11.7.9

FORM TEAM statement

1 The FORM TEAM statement creates a set of sibling teams whose parent team is the current team.

R1179 form-team-stmt

216

is

FORM TEAM ( team-number, team-variable [ , form-team-spec-list ] )

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

R1180 team-number

is

scalar-int-expr

2

R1181 team-variable

is

scalar-variable

3

C1184 A team-variable shall be of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.

4 5

R1182 form-team-spec

6

C1185 No specifier shall appear more than once in a given form-team-spec-list.

is NEW_INDEX = scalar-int-expr or sync-stat

7 8 9 10

2 Successful execution of a FORM TEAM statement creates a new team for each unique team-number value specified

11

3 The value of the scalar-int-expr in a NEW_INDEX= specifier specifies the image index that the executing image

12 13

will have in its new team. It shall be positive, less than or equal to the number of images in the team, and different from the value specified by every other image that belongs to that team.

14 15 16

4 If the NEW_INDEX= specifier does not appear, the image index of the executing image in the new team is

17

5 If the FORM TEAM statement is executed on one image, the same statement shall be executed on all active

18 19 20 21 22

images of the current team. When a FORM TEAM statement is executed, there is an implicit synchronization of all active images in the current team. On those images, execution of the segment following the statement is delayed until all other active images in the current team have executed the same statement the same number of times in this team. The segments that executed before the FORM TEAM statement on an active image of this team precede the segments that execute after the FORM TEAM statement on another active image of this team. If an error condition other than detection of a failed image occurs, the team variable becomes undefined.

23 24 25

by the active images of the current team. The value of team-number shall be positive. Each executing image will belong to the team whose team number is equal to the value of team-number on that image, and the team-variable becomes defined with a value that identifies that team.

processor dependent. This image index will be positive, less than or equal to the number of images in the team, and different from that of every other image in the team.

6 If execution of a FORM TEAM statement assigns the value STAT_FAILED_IMAGE to the stat-variable, the

effect is the same as for the successful execution of FORM TEAM except for the value assigned to stat-variable. NOTE 1 Executing the statement FORM TEAM ( 2 - MOD (THIS_IMAGE (), 2), ODD_EVEN ) will create two subteams of the current team, with images whose image index is odd being in the team with number 1, and those with an even image index being in the team with number 2. NOTE 2 If the current team consists of P 2 images, with corresponding coarrays on each image representing parts of a larger array spread over a P × P square, the following code will establish teams for the rows with image indices equal to the column indices. USE, INTRINSIC :: ISO_FORTRAN_ENV TYPE(TEAM_TYPE) :: ROW REAL :: A [P, *] INTEGER :: ME (2) ME (:) = THIS_IMAGE (A) FORM TEAM (ME(1), ROW, NEW_INDEX=ME(2))

26

11.7.10

LOCK and UNLOCK statements

27

R1183 lock-stmt

is

LOCK ( lock-variable [ , lock-stat-list ] )

ISO/IEC JTC 1/SC 22/WG5/N2184

217

J3/21-007r1

WD 1539-1

2021-05-21

is ACQUIRED_LOCK = scalar-logical-variable or sync-stat

1 2

R1184 lock-stat

3

C1186 No specifier shall appear more than once in a given lock-stat-list.

4

R1185 unlock-stmt

is

UNLOCK ( lock-variable [ , sync-stat-list ] )

5

R1186 lock-variable

is

scalar-variable

6 7

C1187 (R1186) A lock-variable shall be of type LOCK_TYPE from the intrinsic module ISO_FORTRAN_ENV (16.10.2.19).

8 9 10

1 The lock-variable shall not depend on the value of stat-variable, errmsg-variable, or the scalar-logical-variable in

11

2 A lock variable is unlocked if and only if the value of each component is the same as its default value. If it has any

12 13 14

other value, it is locked. A lock variable is locked by an image if it was locked by execution of a LOCK statement on that image, has not been subsequently unlocked by execution of an UNLOCK statement on the same image, and that image has not failed.

15 16

3 Successful execution of a LOCK statement without an ACQUIRED_LOCK= specifier causes the lock variable

17

the ACQUIRED_LOCK= specifier. The scalar-logical-variable shall not depend on the value of the lock-variable, stat-variable, or errmsg-variable.

to become locked by that image. If the lock variable is already locked by another image, that LOCK statement causes the lock variable to become locked after the other image causes the lock variable to become unlocked.

18 19 20 21 22

4 If the lock variable is unlocked, successful execution of a LOCK statement with an ACQUIRED_LOCK= specifier

23 24

5 Successful execution of an UNLOCK statement causes the lock variable to become unlocked. Failure of an image

25 26 27 28

6 During execution of the program, the value of a lock variable changes through a sequence of locked and unlocked

29 30 31 32 33 34

causes the lock variable to become locked by that image and the scalar logical variable to become defined with the value true. If the lock variable is already locked by a different image, successful execution of a LOCK statement with an ACQUIRED_LOCK= specifier leaves the lock variable unchanged and causes the scalar logical variable to become defined with the value false. causes all lock variables that are locked by that image to become unlocked. states due to the execution of LOCK and UNLOCK statements, and by failure of an image while it is locked by that image. If a lock variable becomes unlocked by execution of an UNLOCK statement on image M and next becomes locked by execution of a LOCK statement on image T, the segments preceding the UNLOCK statement on image M precede the segments following the LOCK statement on image T. Execution of a LOCK statement that does not cause the lock variable to become locked does not affect segment ordering. 7 An error condition occurs if the lock variable in a LOCK statement is already locked by the executing image.

An error condition occurs if the lock variable in an UNLOCK statement is not already locked by the executing image. If an error condition occurs during execution of a LOCK or UNLOCK statement, the value of the lock variable is not changed and the value of the ACQUIRED_LOCK variable, if any, is not changed. NOTE 1 A lock variable is effectively defined atomically by a LOCK or UNLOCK statement. If LOCK statements on two images both attempt to acquire a lock, one will succeed and the other will either fail if an ACQUIRED_LOCK= specifier appears, or will wait until the lock is later released if an ACQUIRED_LOCK= specifier does not appear. NOTE 2 An image might wait for a LOCK statement to successfully complete for a long period of time if other images frequently lock and unlock the same lock variable. This situation might result from executing LOCK statements with ACQUIRED_LOCK= specifiers inside a spin loop.

218

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 3 The following example illustrates the use of LOCK and UNLOCK statements to manage a work queue: USE, INTRINSIC :: ISO_FORTRAN_ENV TYPE(LOCK_TYPE) :: queue_lock[*] ! Lock on each image to manage its work queue INTEGER :: work_queue_size[*] TYPE(Task) :: work_queue(100)[*] ! List of tasks to perform TYPE(Task) :: job ! Current task working on INTEGER :: me me = THIS_IMAGE() DO ! Process the next item in your work queue LOCK (queue_lock) ! New segment A starts ! This segment A is ordered with respect to ! segment B executed by image me-1 below because of lock exclusion IF (work_queue_size>0) THEN ! Fetch the next job from the queue job = work_queue(work_queue_size) work_queue_size = work_queue_size-1 END IF UNLOCK (queue_lock) ! Segment ends . . . Actually process the task. ! Add a new task on neighbors queue: LOCK(queue_lock[me+1]) ! Starts segment B ! This segment B is ordered with respect to ! segment A executed by image me+1 above because of lock exclusion IF (work_queue_size[me+1]<SIZE (work_queue)) THEN work_queue_size[me+1] = work_queue_size[me+1]+1 work_queue(work_queue_size[me+1])[me+1] = job END IF UNLOCK (queue_lock[me+1]) ! Ends segment B END DO 1

11.7.11

STAT= and ERRMSG= specifiers in image control statements

2 3 4 5 6

1 In an image control statement, the stat-variable in a sync-stat shall not depend on the value of an errmsg-variable

7 8

2 If a STAT= specifier appears in a sync-stat in an image control statement, the stat-variable is assigned the value

9 10 11 12

3 If the STAT= specifier appears in a sync-stat in an EVENT WAIT or SYNC MEMORY statement and an error

in a sync-stat, event-variable, lock-variable, team-variable, or the scalar-logical-variable in the ACQUIRED_LOCK= specifier. The errmsg-variable in a sync-stat shall not depend on the value of a stat-variable in a sync-stat, event-variable, lock-variable, team-variable, or the scalar-logical-variable in the ACQUIRED_LOCK= specifier. zero if execution of the statement is successful. condition occurs, stat-variable is assigned a processor-dependent positive value that is different from the value of STAT_FAILED_IMAGE (16.10.2.28) and STAT_STOPPED_IMAGE (16.10.2.31) from the intrinsic module ISO_FORTRAN_ENV (16.10.2).

ISO/IEC JTC 1/SC 22/WG5/N2184

219

J3/21-007r1

1 2 3 4 5

WD 1539-1

2021-05-21

4 The images involved in execution of an END TEAM, FORM TEAM, or SYNC ALL statement are those in the

current team. The images involved in execution of a CHANGE TEAM or SYNC TEAM statement are those of the specified team. The images involved in execution of a SYNC IMAGES statement are the images specified and the executing image. The images involved in execution of an EVENT POST statement are the image on which the event variable is located and the executing image.

6 7

5 If the STAT= specifier appears in a sync-stat in a CHANGE TEAM, END TEAM, EVENT POST, FORM

8 9

• if one of the images involved has stopped, stat-variable is assigned the value STAT_STOPPED_IMAGE (16.10.2.31) from the intrinsic module ISO_FORTRAN_ENV; • otherwise, if one of the images involved has failed and no other error condition occurs, the intended action is performed on the active images involved and stat-variable is assigned the value STAT_FAILED_IMAGE (16.10.2.28) from the intrinsic module ISO_FORTRAN_ENV; • otherwise, if any other error condition occurs, stat-variable is assigned a processor-dependent positive value that is different from the values of STAT_STOPPED_IMAGE and STAT_FAILED_IMAGE.

10 11 12 13 14

TEAM, SYNC ALL, SYNC IMAGES, or SYNC TEAM statement,

15 16 17

6 If the STAT= specifier appears in a sync-stat in a SYNC ALL, SYNC IMAGES, or SYNC TEAM statement

18

7 If the STAT= specifier appears in a sync-stat in a LOCK statement,

19 20 21 22 23 24 25 26 27 28 29 30 31 32

and the error condition STAT_STOPPED_IMAGE occurs, the effect is the same as that of executing the SYNC MEMORY statement, except for defining the stat-variable.

• if the image on which the lock variable is located has failed, the stat-variable becomes defined with the value STAT_FAILED_IMAGE; • otherwise, if the lock variable is locked by the executing image, the stat-variable becomes defined with the value of STAT_LOCKED (16.10.2.29) from the intrinsic module ISO_FORTRAN_ENV; • otherwise, if the lock variable is unlocked because of the failure of the image that locked it, stat-variable becomes defined with the value STAT_UNLOCKED_FAILED_IMAGE (16.10.2.33) from the intrinsic module ISO_FORTRAN_ENV. 8 If the STAT= specifier appears in a sync-stat in an UNLOCK statement,

• if the image on which the lock variable is located has failed, the stat-variable becomes defined with the value STAT_FAILED_IMAGE; • otherwise, if the lock variable has the value unlocked, the stat-variable becomes defined with the value of STAT_UNLOCKED (16.10.2.32) from the intrinsic module ISO_FORTRAN_ENV; • otherwise, if the lock variable is locked by a different image, the stat-variable becomes defined with the value STAT_LOCKED_OTHER_IMAGE (16.10.2.30) from the intrinsic module ISO_FORTRAN_ENV.

33 34 35 36

9 If the STAT= specifier appears in a sync-stat in a LOCK or UNLOCK statement and any other error condition

37 38 39 40 41

10 If an image completes execution of a CRITICAL statement that has a sync-stat that is a STAT= specifier and the

42

11 If an error condition occurs during execution of an image control statement that does not contain the STAT=

43 44 45 46

occurs during execution of that statement, the stat-variable becomes defined with a processor-dependent positive value that is different from STAT_LOCKED, STAT_LOCKED_OTHER_IMAGE, STAT_UNLOCKED, and STAT_UNLOCKED_FAILED_IMAGE. previous image to have entered the construct failed while executing it, the stat-variable becomes defined with the value STAT_FAILED_IMAGE and execution of the construct continues normally. If any other error condition occurs during execution of a CRITICAL statement that has a STAT= specifier, the stat-variable becomes defined with a processor-dependent positive value other than STAT_FAILED_IMAGE. specifier in a sync-stat, error termination is initiated. 12 If an ERRMSG= specifier appears in an image control statement and an error condition occurs, errmsg-variable

is assigned an explanatory message, as if by intrinsic assignment. If no such condition occurs, the definition status and value of errmsg-variable are unchanged.

220

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

13 The set of error conditions that can occur in an image control statement is processor dependent.

NOTE 1 A processor might detect communication failure between images and treat it as an error condition. A processor might also treat an invalid set of images in a SYNC IMAGES statement as an error condition.

ISO/IEC JTC 1/SC 22/WG5/N2184

221

J3/21-007r1

WD 1539-1

1

12 Input/output statements

2

12.1

3 4 5 6

2021-05-21

Input/output concepts

1 Input statements provide the means of transferring data from external media to internal storage or from an internal

file to internal storage. This process is called reading. Output statements provide the means of transferring data from internal storage to external media or from internal storage to an internal file. This process is called writing. Some input/output statements specify that editing of the data is to be performed.

7 8

2 In addition to the statements that transfer data, there are auxiliary input/output statements to manipulate the

9 10

3 The input/output statements are the BACKSPACE, CLOSE, ENDFILE, FLUSH, INQUIRE, OPEN, PRINT,

11

4 A file is composed of either a sequence of file storage units (12.3.5) or a sequence of records, which provide an

12 13 14 15

extra level of organization to the file. A file composed of records is called a record file. A file composed of file storage units is called a stream file. A processor may allow a file to be viewed both as a record file and as a stream file; in this case the relationship between the file storage units when viewed as a stream file and the records when viewed as a record file is processor dependent.

16

external medium, or to describe or inquire about the properties of the connection to the external medium. READ, REWIND, WAIT, and WRITE statements.

5 A file is either an external file (12.3) or an internal file (12.4).

17

12.2

Records

18

12.2.1

Definition of a record

19 20 21

1 A record is a sequence of values or a sequence of characters. For example, a line on a terminal is usually considered

to be a record. However, a record does not necessarily correspond to a physical entity. There are three kinds of records: (1) (2) (3)

22 23 24

formatted; unformatted; endfile.

NOTE 1 What is called a “record” in Fortran is commonly called a “logical record”. There is no concept in Fortran of a “physical record.” 25 26 27 28 29 30 31 32 33

12.2.2

Formatted record

1 A formatted record consists of a sequence of characters that are representable in the processor; however, a

processor may prohibit some control characters (6.1.1) from appearing in a formatted record. The length of a formatted record is measured in characters and depends primarily on the number of characters put into the record when it is written; however, it may depend on the processor and the external medium. The length may be zero. Formatted records shall be read or written only by formatted input/output statements.

12.2.3

Unformatted record

1 An unformatted record consists of a sequence of values in a processor-dependent form and may contain data

of any type or may contain no data. The length of an unformatted record is measured in file storage units

222

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

(12.3.5) and depends on the output list (12.6.3) used when it is written, as well as on the processor and the external medium. The length may be zero. Unformatted records shall be read or written only by unformatted input/output statements.

4

12.2.4

Endfile record

5 6 7 8

1 An endfile record is written explicitly by the ENDFILE statement; the file shall be connected for sequential

9 10 11

• a REWIND or BACKSPACE statement references the unit to which the file is connected, or • the unit is closed, either explicitly by a CLOSE statement, implicitly by normal termination, or implicitly by another OPEN statement for the same unit.

12

2 An endfile record shall occur only as the last record of a file. An endfile record does not have a length property.

access. An endfile record is written implicitly to a file connected for sequential access when the most recent data transfer statement referring to the file is an output statement, no intervening file positioning statement referring to the file has been executed, and

NOTE 1 An endfile record does not necessarily have any physical embodiment. The processor can use a record count or any other means to register the position of the file at the time an ENDFILE statement is executed, so that it can take appropriate action when that position is reached again during a read operation. The endfile record, however it is implemented, is considered to exist for the BACKSPACE statement (12.8.2).

13

12.3

External files

14

12.3.1

External file concepts

15

1 An external file is any file that exists in a medium external to the program.

16 17 18

2 At any given time, there is a processor-dependent set of allowed access methods, a processor-dependent set of

allowed forms, a processor-dependent set of allowed actions, and a processor-dependent set of allowed record lengths for a file. NOTE 1 For example, the processor-dependent set of allowed actions for a printer would likely include the write action, but not the read action.

19 20 21

3 A file may have a name; a file that has a name is called a named file. The name of a named file is represented by

a character string value. The set of allowable names for a file is processor dependent. Whether a named file on one image is the same as a file with the same name on another image is processor dependent. NOTE 2 If different files are needed on each image, using a different file name on each image will improve portability of the code. One technique is to incorporate the image index as part of the name.

22

4 An external file that is connected to a unit has a position property (12.3.4).

NOTE 3 For more explanatory information on external files, see C.8.1. 23 24 25

12.3.2

File existence

1 At any given time, there is a processor-dependent set of external files that exist for a program. A file may be

known to the processor, yet not exist for a program at a particular time.

ISO/IEC JTC 1/SC 22/WG5/N2184

223

J3/21-007r1

WD 1539-1

2021-05-21

1 2

2 To create a file means to cause a file to exist that did not exist previously. To delete a file means to terminate

3 4

3 All input/output statements may refer to files that exist. A CLOSE, ENDFILE, FLUSH, INQUIRE, OPEN,

the existence of the file.

5 6 7

PRINT, REWIND, or WRITE statement is permitted to refer to a file that does not exist. No other input/output statement shall refer to a file that does not exist. Execution of a WRITE, PRINT, or ENDFILE statement referring to a preconnected file that does not exist creates the file. This file is a different file from one preconnected on any other image.

8

12.3.3

File access

9

12.3.3.1

File access methods

10 11

1 There are three methods of accessing the data of an external file: sequential, direct, and stream. Some files may

have more than one allowed access method; other files may be restricted to one access method. NOTE 1 For example, a processor might provide only sequential access to a file on magnetic tape. Thus, the set of allowed access methods depends on the file and the processor.

12 13 14

2 The method of accessing a file is determined when the file is connected to a unit (12.5.4) or when the file is

created if the file is preconnected (12.5.5). 12.3.3.2

Sequential access

15

1 Sequential access is a method of accessing the records of an external record file in order.

16

2 While connected for sequential access, an external file has the following properties.

17 18 19 20 21 22 23 24 25 26

27

• The order of the records is the order in which they were written if the direct access method is not a member of the set of allowed access methods for the file. If the direct access method is also a member of the set of allowed access methods for the file, the order of the records is the same as that specified for direct access. In this case, the first record accessible by sequential access is the record whose record number is 1 for direct access. The second record accessible by sequential access is the record whose record number is 2 for direct access, etc. A record that has not been written since the file was created shall not be read. • The records of the file are either all formatted or all unformatted, except that the last record of the file can be an endfile record. Unless the previous reference to the file was an output statement, the last record, if any, of the file shall be an endfile record. • The records of the file shall be read or written only by sequential access data transfer statements. 12.3.3.3

Direct access

28

1 Direct access is a method of accessing the records of an external record file in arbitrary order.

29

2 While connected for direct access, an external file has the following properties.

30 31 32 33 34 35 36 37 38

• Each record of the file is uniquely identified by a positive integer called the record number. The record number of a record is specified when the record is written. Once established, the record number of a record can never be changed. The order of the records is the order of their record numbers. • The records of the file are either all formatted or all unformatted. If the sequential access method is also a member of the set of allowed access methods for the file, its endfile record, if any, is not considered to be part of the file while it is connected for direct access. If the sequential access method is not a member of the set of allowed access methods for the file, the file shall not contain an endfile record. • The records of the file shall be read or written only by direct access data transfer statements. • All records of the file have the same length.

224

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7

WD 1539-1

J3/21-007r1

• Records need not be read or written in the order of their record numbers. Any record may be written into the file while it is connected to a unit. For example, it is permissible to write record 3, even though records 1 and 2 have not been written. Any record may be read from the file while it is connected to a unit, provided that the record has been written since the file was created, and if a READ statement for this connection is permitted. • The records of the file shall not be read or written using list-directed formatting (13.10), namelist formatting (13.11), or a nonadvancing data transfer statement (12.3.4.2). NOTE 1 A record cannot be deleted; however, a record can be rewritten.

8

12.3.3.4

Stream access

9

1 Stream access is a method of accessing the file storage units (12.3.5) of an external stream file.

10 11 12

2 The properties of an external file connected for stream access depend on whether the connection is for unformatted

13

3 While connected for unformatted stream access, an external file has the following properties.

14 15 16 17 18 19 20 21

22 23 24 25 26 27 28 29 30 31 32 33

or formatted access. While connected for stream access, the file storage units of the file shall be read or written only by stream access data transfer statements.

• Each file storage unit in the file is uniquely identified by a positive integer called the position. The first file storage unit in the file is at position 1. The position of each subsequent file storage unit is one greater than that of its preceding file storage unit. • If it is possible to position the file, the file storage units need not be read or written in order of their position. For example, it might be permissible to write the file storage unit at position 3, even though the file storage units at positions 1 and 2 have not been written. Any file storage unit may be read from the file while it is connected to a unit, provided that the file storage unit has been written since the file was created, and if a READ statement for this connection is permitted. 4 While connected for formatted stream access, an external file has the following properties.

• Some file storage units of the file can contain record markers; this imposes a record structure on the file in addition to its stream structure. There might or might not be a record marker at the end of the file. If there is no record marker at the end of the file, the final record is incomplete. • No maximum length (12.5.6.16) is applicable to these records. • Writing an empty record with no record marker has no effect. • Each file storage unit in the file is uniquely identified by a positive integer called the position. The first file storage unit in the file is at position 1. The relationship between positions of successive file storage units is processor dependent; not all positive integers need correspond to valid positions. • If it is possible to position the file, the file position can be set to a position that was previously identified by the POS= specifier in an INQUIRE statement. • A processor may prohibit some control characters (6.1.1) from appearing in a formatted stream file. NOTE 1 Because the record structure is determined from the record markers that are stored in the file itself, an incomplete record at the end of the file is necessarily not empty. NOTE 2 There might be some character positions in the file that do not correspond to characters written; this is because on some processors a record marker could be written to the file as a carriage-return/line-feed or other sequence. The means of determining the position in a file connected for stream access is via the POS= specifier in an INQUIRE statement (12.10.2.23).

ISO/IEC JTC 1/SC 22/WG5/N2184

225

J3/21-007r1

1

12.3.4

File position

2

12.3.4.1

General

WD 1539-1

2021-05-21

3 4

1 Execution of certain input/output statements affects the position of an external file. Certain circumstances can

5 6 7

2 The initial point of a file is the position just before the first record or file storage unit. The terminal point is the

8 9

3 If a record file is positioned within a record, that record is the current record; otherwise, there is no current

10 11 12 13

4 Let n be the number of records in the file. If 1 < i ≤ n and a file is positioned within the ith record or between

14 15 16

5 If 1 ≤ i < n and a file is positioned within the ith record or between the ith and (i + 1)th record, the (i + 1)th

17 18

6 For a file connected for stream access, the file position is either between two file storage units, at the initial point

19

cause the position of a file to become indeterminate. position just after the last record or file storage unit. If there are no records or file storage units in the file, the initial point and the terminal point are the same position. record. the (i − 1)th record and the ith record, the (i − 1)th record is the preceding record. If n ≥ 1 and the file is positioned at its terminal point, the preceding record is the nth and last record. If n = 0 or if a file is positioned at its initial point or within the first record, there is no preceding record. record is the next record. If n ≥ 1 and the file is positioned at its initial point, the first record is the next record. If n = 0 or if a file is positioned at its terminal point or within the nth (last) record, there is no next record. of the file, at the terminal point of the file, or undefined. 12.3.4.2

Advancing and nonadvancing input/output

20 21

1 An advancing input/output statement always positions a record file after the last record read or written, unless

22 23 24 25

2 A nonadvancing input/output statement may position a record file at a character position within the current

there is an error condition.

26 27

record, or a subsequent record (13.8.2). Using nonadvancing input/output, it is possible to read or write a record of the file by a sequence of data transfer statements, each accessing a portion of the record. If a nonadvancing output statement leaves a file positioned within a current record and no further output statement is executed for the file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement is executed for it, the effect is as if the output statement were the corresponding advancing output statement.

28

12.3.4.3

File position prior to data transfer

29

1 The positioning of the file prior to data transfer depends on the method of access: sequential, direct, or stream.

30 31

2 For sequential access on input, if there is a current record, the file position is not changed. Otherwise, the file is

32 33

positioned at the beginning of the next record and this record becomes the current record. Input shall not occur if there is no next record or if there is a current record and the last data transfer statement accessing the file performed output.

34 35

3 If the file contains an endfile record, the file shall not be positioned after the endfile record prior to data transfer.

36 37

4 For sequential access on output, if there is a current record, the file position is not changed and the current record

38

However, a REWIND or BACKSPACE statement may be used to reposition the file. becomes the last record of the file. Otherwise, a new record is created as the next record of the file; this new record becomes the last and current record of the file and the file is positioned at the beginning of this record.

39 40

5 For direct access, the file is positioned at the beginning of the record specified by the REC= specifier. This record

41 42

6 For stream access, the file is positioned immediately before the file storage unit specified by the POS= specifier;

becomes the current record. if there is no POS= specifier, the file position is not changed.

226

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

7 File positioning for child data transfer statements is described in 12.6.4.8.

12.3.4.4

File position after data transfer

3 4 5

1 If an error condition (12.11) occurred, the position of the file is indeterminate. If no error condition occurred,

6

2 For unformatted stream input/output, if no error condition occurred, the file position is not changed.

7 8

but an end-of-file condition (12.11) occurred as a result of reading an endfile record, the file is positioned after the endfile record. For unformatted stream output, if the file position exceeds the previous terminal point of the file, the terminal point is set to the file position. NOTE 1 An unformatted stream output statement with a POS= specifier and an empty output list can have the effect of extending the terminal point of a file without actually writing any data.

9

3 For formatted stream input, if an end-of-file condition occurred, the file position is not changed.

10 11 12

4 For nonadvancing input, if no error condition or end-of-file condition occurred, but an end-of-record condition

13

(12.11) occurred, the file is positioned after the record just read. If no error condition, end-of-file condition, or end-of-record condition occurred in a nonadvancing input statement, the file position is not changed. If no error condition occurred in a nonadvancing output statement, the file position is not changed.

14 15

5 In all other cases, the file is positioned after the record just read or written and that record becomes the preceding

16 17

6 For a formatted stream output statement, if no error condition occurred, the terminal point of the file is set to

record. the next position after the highest-numbered position to which a datum was transferred by the statement. NOTE 2 The highest-numbered position might not be the current one if the output involved a T, TL, TR, or X edit descriptor (13.8.1) and the statement is a nonadvancing output statement.

18

12.3.5

File storage units

19 20 21

1 A file storage unit is the basic unit of storage in a stream file or an unformatted record file. It is the unit of file

22

2 Every value in a stream file or an unformatted record file shall occupy an integer number of file storage units; if

23 24 25

the stream or record file is unformatted, this number shall be the same for all scalar values of the same type and type parameters. The number of file storage units required for an item of a given type and type parameters can be determined using the IOLENGTH= specifier of the INQUIRE statement (12.10.3).

26 27

3 For a file connected for unformatted stream access, the processor shall not have alignment restrictions that prevent

28

4 The number of bits in a file storage unit is given by the constant FILE_STORAGE_SIZE (16.10.2.11) defined

29 30

in the intrinsic module ISO_FORTRAN_ENV. It is recommended that the file storage unit be an 8-bit octet where this choice is practical.

position for stream access, the unit of record length for unformatted files, and the unit of file size for all external files.

a value of any type from being stored at any positive integer file position.

NOTE 1 The requirement that every data value occupy an integer number of file storage units implies that data items inherently smaller than a file storage unit will require padding. This suggests that the file storage unit be small to avoid wasted space. Ideally, the file storage unit would be chosen such that padding is never required. A file storage unit of one bit would always meet this goal, but would likely be impractical because of the alignment requirements.

ISO/IEC JTC 1/SC 22/WG5/N2184

227

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) The prohibition on alignment restrictions prohibits the processor from requiring data alignments larger than the file storage unit. The 8-bit octet is recommended as a good compromise that is small enough to accommodate the requirements of many applications, yet not so small that the data alignment requirements are likely to cause significant performance problems.

1

12.4

Internal files

2

1 Internal files provide a means of transferring and converting data from internal storage to internal storage.

3

2 An internal file is a record file with the following properties.

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

• The file is a variable of default, ASCII, or ISO 10646 character kind that is not an array section with a vector subscript. • A record of an internal file is a scalar character variable. • If the file is a scalar character variable, it consists of a single record whose length is the same as the length of the scalar character variable. If the file is a character array, it is treated as a sequence of character array elements. Each array element, if any, is a record of the file. The ordering of the records of the file is the same as the ordering of the array elements in the array (9.5.3.3) or the array section (9.5.3.4). Every record of the file has the same length, which is the length of an array element in the array. • A record of the internal file becomes defined by writing the record. – If the internal file is an allocatable, deferred-length character scalar variable, it is assigned the characters written by intrinsic assignment, allocating or reallocating to have length equal to the number of characters written if necessary. – Otherwise, if the number of characters written in a record is less than the length of the record, the remaining portion of the record is filled with blanks; the number of characters to be written shall not exceed the length of the record. • A record shall be read only if the record is defined. • A record of an internal file can become defined (or undefined) by means other than an output statement. For example, the character variable can become defined by a character assignment statement. • An internal file is always positioned at the beginning of the first record prior to data transfer, except for child data transfer statements (12.6.4.8). This record becomes the current record. • The initial value of a connection mode (12.5.2) is the value that would be implied by an initial OPEN statement without the corresponding keyword. • Reading and writing records shall be accomplished only by sequential access formatted data transfer statements. • An internal file shall not be specified as the unit in a CLOSE, INQUIRE, or OPEN statement.

29

12.5

File connection

30

12.5.1

Referring to a file

31

1 A unit, specified by an io-unit, provides a means for referring to a file.

R1201 io-unit

is file-unit-number or * or internal-file-variable

35

R1202 file-unit-number

is

scalar-int-expr

36

R1203 internal-file-variable

is

char-variable

32 33 34

228

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

C1201 (R1203) The char-variable shall not be an array section with a vector subscript.

2

C1202 (R1203) The char-variable shall be default character, ASCII character, or ISO 10646 character.

3 4

2 A unit is either an external unit or an internal unit. An external unit is used to refer to an external file and

5 6 7 8 9

is specified by an asterisk or a file-unit-number. The value of file-unit-number shall be nonnegative, the unit argument of an active defined input/output procedure (12.6.4.8), a NEWUNIT value (12.5.6.13), or equal to one of the named constants INPUT_UNIT, OUTPUT_UNIT, or ERROR_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2). An internal unit is used to refer to an internal file and is specified by an internalfile-variable or a file-unit-number whose value is equal to the unit argument of an active defined input/output procedure. The value of a file-unit-number shall identify a valid unit.

10

3 On an image, the external unit identified by a particular value of a scalar-int-expr is the same external unit in

11

all program units. NOTE 1 In the example: SUBROUTINE A READ (6) X ... SUBROUTINE B N = 6 REWIND N the value 6 used in both program units identifies the same external unit.

12 13 14 15 16 17 18 19 20 21

4 In a READ statement, an io-unit that is an asterisk identifies an external unit that is preconnected for sequential

formatted input on image 1 in the initial team only (12.6.4.3); it is not preconnected on any other image. This unit is also identified by the value of the named constant INPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2.13). In a WRITE statement, an io-unit that is an asterisk identifies an external unit that is preconnected for sequential formatted output. This unit is also identified by the value of the named constant OUTPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2.24). 5 This document identifies a processor-dependent external unit for the purpose of error reporting. This unit shall

be preconnected for sequential formatted output. The processor may define this to be the same as the output unit identified by an asterisk. This unit is also identified by a unit number defined by the named constant ERROR_UNIT of the intrinsic module ISO_FORTRAN_ENV. NOTE 2 Even though OUTPUT_UNIT is connected to a separate file on each image, it is expected that the processor could merge the sequences of records from these files into a single sequence of records that is sent to the physical device associated with this unit, such as the user’s terminal. If ERROR_UNIT is associated with the same physical device, the sequences of records from files connected to ERROR_UNIT on each of the images could be merged into the same sequence generated from the OUTPUT_UNIT files. Otherwise, it is expected that the sequence of records in the files connected to ERROR_UNIT on each image could be merged into a single sequence of records that is sent to the physical device associated with ERROR_UNIT.

22

12.5.2

Connection modes

23 24 25 26

1 A connection for formatted input/output has several changeable modes: these are the blank interpretation mode

27 28 29

2 Values for the modes of a connection are established when the connection is initiated. If the connection is initiated

(13.8.7), delimiter mode (13.10.4, 13.11.4.2), sign mode (13.8.4), leading zero mode (13.8.5), decimal edit mode (13.8.9), input/output rounding mode (13.7.2.3.8), pad mode (12.6.4.5.3), and scale factor (13.8.6). A connection for unformatted input/output has no changeable modes. by an OPEN statement, the values are as specified, either explicitly or implicitly, by the OPEN statement. If the connection is initiated other than by an OPEN statement (that is, if the file is an internal file or preconnected file)

ISO/IEC JTC 1/SC 22/WG5/N2184

229

J3/21-007r1

1 2

WD 1539-1

2021-05-21

the values established are those that would be implied by an initial OPEN statement without the corresponding keywords.

3

3 The scale factor cannot be explicitly specified in an OPEN statement; it is implicitly 0.

4

4 The modes of a connection to an external file can be changed by a subsequent OPEN statement that modifies

5 6 7 8 9 10 11

the connection. 5 The modes of a connection can be temporarily changed by a corresponding keyword specifier in a data transfer

statement or by an edit descriptor. Keyword specifiers take effect at the beginning of execution of the data transfer statement. Edit descriptors take effect when they are encountered in format processing. When a data transfer statement terminates, the values for the modes are reset to the values in effect immediately before the data transfer statement was executed.

12.5.3

Unit existence

12

1 At any given time, there is a processor-dependent set of external units that exist for an image.

13

2 All input/output statements are permitted to refer to units that exist. The CLOSE, INQUIRE, and WAIT

14 15

statements are also permitted to refer to units that do not exist. No other input/output statement shall refer to a unit that does not exist.

16

12.5.4

Connection of a file to a unit

17 18 19

1 An external unit has a property of being connected or not connected. If connected, it refers to an external file. An

20 21

2 Every input/output statement except an OPEN, CLOSE, INQUIRE, or WAIT statement shall refer to a unit

22

3 A file may be connected and not exist (12.3.2).

external unit may become connected by preconnection or by the execution of an OPEN statement. The property of connection is symmetric; the unit is connected to a file if and only if the file is connected to the unit. that is connected to a file and thereby make use of or affect that file.

NOTE 1 An example is a preconnected external file that has not yet been written. 23 24 25

4 A unit shall not be connected to more than one file at the same time. However, means are provided to change

26 27 28

5 This document defines means of portable interoperation with C. C streams are described in ISO/IEC 9899:2011,

29 30 31 32 33 34 35

the status of an external unit and to connect a unit to a different file. It is processor dependent whether a file can be connected to more than one unit at the same time. 7.21.2. Whether a unit can be connected to a file that is also connected to a C stream is processor dependent. If a unit is connected to a file that is also connected to a C stream, the results of performing input/output operations on such a file are processor dependent. It is processor dependent whether the files connected to the units INPUT_UNIT, OUTPUT_UNIT, and ERROR_UNIT correspond to the predefined C text streams standard input, standard output, and standard error. If a main program or procedure defined by means of Fortran and a main program or procedure defined by means other than Fortran perform input/output operations on the same external file, the results are processor dependent. A main program or procedure defined by means of Fortran and a main program or procedure defined by means other than Fortran can perform input/output operations on different external files without interference.

36 37

6 If input/output operations are performed on more than one unit while they are connected to the same external

38 39 40

7 After an external unit has been disconnected by the execution of a CLOSE statement, it may be connected again

file, the results are processor dependent. within the same program to the same file or to a different file. After an external file has been disconnected by the execution of a CLOSE statement, it may be connected again within the same program to the same unit or

230

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

to a different unit. NOTE 2 The only means of referencing a file that has been disconnected is by the appearance of its name in an OPEN or INQUIRE statement. There might be no means of reconnecting an unnamed file once it is disconnected.

2

8 An internal unit is always connected to the internal file designated by the variable that identifies the unit.

NOTE 3 For more explanatory information on file connection properties, see C.8.4. 3 4 5

12.5.5

Preconnection

1 Preconnection means that the unit is connected to a file at the beginning of execution of the program and therefore

it may be specified in input/output statements without the prior execution of an OPEN statement.

6

12.5.6

OPEN statement

7

12.5.6.1

General

8 9 10

1 An OPEN statement initiates or modifies the connection between an external file and a specified unit. The OPEN

11

2 An external unit may be connected by an OPEN statement in the main program or any subprogram.

12 13

3 If the file to be connected to the unit does not exist but is the same as the file to which the unit is preconnected,

14 15 16

4 If the file to be connected to the unit is not the same as the file to which the unit is connected, the effect is as

17 18 19

5 If a unit is connected to a file that exists, execution of an OPEN statement for that unit is permitted. If the

20 21 22

6 If the file to be connected to the unit is the same as the file to which the unit is connected, a new connection is not

statement can be used to connect an existing file to a unit, create a file that is preconnected, create a file and connect it to a unit, or change certain modes of a connection between a file and a unit.

the modes specified by an OPEN statement become a part of the connection. if a CLOSE statement without a STATUS= specifier had been executed for the unit immediately prior to the execution of an OPEN statement. FILE= specifier is not included in such an OPEN statement, the file to be connected to the unit is the same as the file to which the unit is already connected.

23 24 25 26 27

established and values for any changeable modes (12.5.2) specified come into effect for the established connection; the current file position is unaffected. Before any effect on changeable modes, a wait operation is performed for any pending asynchronous data transfer operations for the specified unit. If the POSITION= specifier appears in such an OPEN statement, the value specified shall not disagree with the current position of the file. If the STATUS= specifier is included in such an OPEN statement, it shall be specified with the value OLD. Other than ERR=, IOSTAT=, and IOMSG=, and the changeable modes, the values of all other specifiers in such an OPEN statement shall not differ from those in effect for the established connection.

28

7 A STATUS= specifier with a value of OLD is always allowed when the file to be connected to the unit is the same

29 30 31

as the file to which the unit is connected. In this case, if the status of the file was SCRATCH before execution of the OPEN statement, the file will still be deleted when the unit is closed, and the file is still considered to have a status of SCRATCH.

32

12.5.6.2

33

R1204 open-stmt

is

34 35

R1205 connect-spec

is [ UNIT = ] file-unit-number or ACCESS = scalar-default-char-expr

Syntax of the OPEN statement OPEN ( connect-spec-list )

ISO/IEC JTC 1/SC 22/WG5/N2184

231

J3/21-007r1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

WD 1539-1

or or or or or or or or or or or or or or or or or or or

ACTION = scalar-default-char-expr ASYNCHRONOUS = scalar-default-char-expr BLANK = scalar-default-char-expr DECIMAL = scalar-default-char-expr DELIM = scalar-default-char-expr ENCODING = scalar-default-char-expr ERR = label FILE = file-name-expr FORM = scalar-default-char-expr IOMSG = iomsg-variable IOSTAT = stat-variable LEADING_ZERO = scalar-default-char-expr NEWUNIT = scalar-int-variable PAD = scalar-default-char-expr POSITION = scalar-default-char-expr RECL = scalar-int-expr ROUND = scalar-default-char-expr SIGN = scalar-default-char-expr STATUS = scalar-default-char-expr

2021-05-21

20

R1206 file-name-expr

is

scalar-default-char-expr

21

R1207 iomsg-variable

is

scalar-default-char-variable

22

C1203 No specifier shall appear more than once in a given connect-spec-list.

23 24

C1204 (R1204) If the NEWUNIT= specifier does not appear, a file-unit-number shall be specified; if the optional characters UNIT= are omitted, the file-unit-number shall be the first item in the connect-spec-list.

25

C1205 (R1204) If a NEWUNIT= specifier appears, a file-unit-number shall not appear.

26 27

C1206 (R1204) The label used in the ERR= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the OPEN statement.

28

1 Some specifiers that require a scalar-default-char-expr have a limited list of character values. These values are

29 30

listed for each such specifier. Any trailing blanks are ignored. The value specified is without regard to case. Some specifiers have a default value if the specifier is omitted.

31

2 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.

NOTE 1 An example of an OPEN statement is: OPEN (10, FILE = ’employee.names’, ACTION = ’READ’, PAD = ’YES’) NOTE 2 For more explanatory information on the OPEN statement, see C.8.3. 32 33 34 35 36 37

12.5.6.3

ACCESS= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to SEQUENTIAL, DIRECT, or STREAM. The ACCESS= specifier

specifies the access method for the connection of the file as being sequential, direct, or stream. If this specifier is omitted, the default value is SEQUENTIAL. For an existing file, the specified access method shall be included in the set of allowed access methods for the file. For a new file, the processor creates the file with a set of allowed access methods that includes the specified method.

232

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

12.5.6.4

WD 1539-1

J3/21-007r1

ACTION= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to READ, WRITE, or READWRITE. READ specifies that the

4 5 6 7 8

WRITE, PRINT, and ENDFILE statements shall not refer to this connection. WRITE specifies that READ statements shall not refer to this connection. READWRITE permits any input/output statements to refer to this connection. If this specifier is omitted, the default value is processor dependent. If READWRITE is included in the set of allowable actions for a file, both READ and WRITE also shall be included in the set of allowed actions for that file. For an existing file, the specified action shall be included in the set of allowed actions for the file. For a new file, the processor creates the file with a set of allowed actions that includes the specified action.

9

12.5.6.5

10 11 12 13

ASYNCHRONOUS= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to YES or NO. If YES is specified, asynchronous input/output on

the unit is allowed. If NO is specified, asynchronous input/output on the unit is not allowed. If this specifier is omitted, the default value is NO. 12.5.6.6

BLANK= specifier in the OPEN statement

14

1 The scalar-default-char-expr shall evaluate to NULL or ZERO. The BLANK= specifier is permitted only for a

15 16 17

connection for formatted input/output. It specifies the blank interpretation mode (13.8.7, 12.6.2.6) for input for this connection. This mode has no effect on output. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is NULL.

18

12.5.6.7

19 20

DECIMAL= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to COMMA or POINT. The DECIMAL= specifier is permitted only

21 22

for a connection for formatted input/output. It specifies the decimal edit mode (13.6, 13.8.9, 12.6.2.7) for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is POINT.

23

12.5.6.8

24 25

DELIM= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE. The DELIM= specifier is

26 27 28

permitted only for a connection for formatted input/output. It specifies the delimiter mode (12.6.2.8) for listdirected (13.10.4) and namelist (13.11.4.2) output for the connection. This mode has no effect on input. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is NONE.

29

12.5.6.9

30 31

ENCODING= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to UTF-8 or DEFAULT. The ENCODING= specifier is permitted

32 33 34 35

only for a connection for formatted input/output. The value UTF-8 specifies that the encoding form of the file is UTF-8 as specified in ISO/IEC 10646. Such a file is called a Unicode file, and all characters therein are of ISO 10646 character kind. The value UTF-8 shall not be specified if the processor does not support the ISO 10646 character kind. The value DEFAULT specifies that the encoding form of the file is processor dependent. If this specifier is omitted in an OPEN statement that initiates a connection, the default value is DEFAULT.

36

12.5.6.10

FILE= specifier in the OPEN statement

37 38 39

1 The value of the FILE= specifier is the name of the file to be connected to the specified unit. Any trailing blanks

40 41 42

2 This specifier shall appear if the STATUS= specifier has the value NEW or REPLACE. This specifier shall not

are ignored. The file-name-expr shall be a name that is allowed by the processor. The interpretation of case is processor dependent. appear if the STATUS= specifier has the value SCRATCH. If the STATUS= specifier has the value OLD, this specifier shall appear unless the unit is connected and the file connected to the unit exists. If this specifier

ISO/IEC JTC 1/SC 22/WG5/N2184

233

J3/21-007r1

WD 1539-1

2021-05-21

1 2

is omitted and the unit is not connected to a file, the STATUS= specifier shall be specified with a value of SCRATCH; in this case, the connection is made to a processor-dependent file.

3

12.5.6.11

FORM= specifier in the OPEN statement

4

1 The scalar-default-char-expr shall evaluate to FORMATTED or UNFORMATTED. The FORM= specifier de-

5 6 7 8 9

termines whether the file is being connected for formatted or unformatted input/output. If this specifier is omitted, the default value is UNFORMATTED if the file is being connected for direct access or stream access, and the default value is FORMATTED if the file is being connected for sequential access. For an existing file, the specified form shall be included in the set of allowed forms for the file. For a new file, the processor creates the file with a set of allowed forms that includes the specified form.

10

12.5.6.12

11 12 13 14 15

LEADING_ZERO= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to one of PRINT, SUPPRESS, or PROCESSOR_DEFINED. The

LEADING_ZERO= specifier is permitted only for a connection for formatted input/output. It specifies the leading zero mode (13.8.5, 12.6.2.10) for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is PROCESSOR_DEFINED. 12.5.6.13

NEWUNIT= specifier in the OPEN statement

16 17

1 If this specifier appears in an OPEN statement, either the FILE= specifier shall appear, or the STATUS= specifier

18 19 20

2 The variable is defined with a processor determined NEWUNIT value if no error condition occurs during the

21

3 A NEWUNIT value is a negative number, and shall not be equal to −1, any of the named constants ER-

22 23 24 25

ROR_UNIT, INPUT_UNIT, or OUTPUT_UNIT from the intrinsic module ISO_FORTRAN_ENV (16.10.2), any value used by the processor for the unit argument to a defined input/output procedure, nor any previous NEWUNIT value that identifies a file that is connected. The unit identified by a NEWUNIT value shall not be preconnected.

26

12.5.6.14

shall appear with a value of SCRATCH. execution of the OPEN statement. If an error condition occurs, the processor shall not change the value of the variable.

PAD= specifier in the OPEN statement

27

1 The scalar-default-char-expr shall evaluate to YES or NO. The PAD= specifier is permitted only for a connection

28 29 30

for formatted input/output. It specifies the pad mode (12.6.4.5.3, 12.6.2.11) for input for this connection. This mode has no effect on output. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is YES.

31

12.5.6.15

POSITION= specifier in the OPEN statement

32

1 The scalar-default-char-expr shall evaluate to ASIS, REWIND, or APPEND. The connection shall be for sequen-

33 34 35 36 37

tial or stream access. A new file is positioned at its initial point. REWIND positions an existing file at its initial point. APPEND positions an existing file such that the endfile record is the next record, if it has one. If an existing file does not have an endfile record, APPEND positions the file at its terminal point. ASIS leaves the position unchanged if the file exists and already is connected. If the file exists but is not connected, the position resulting from ASIS is processor dependent. If this specifier is omitted, the default value is ASIS.

38

12.5.6.16

39 40 41 42 43

RECL= specifier in the OPEN statement

1 The value of the RECL= specifier shall be positive. It specifies the length of each record in a file being connected

for direct access, or specifies the maximum length of a record in a file being connected for sequential access. This specifier shall not appear when a file is being connected for stream access. This specifier shall appear when a file is being connected for direct access. If this specifier is omitted when a file is being connected for sequential access, the default value is processor dependent. If the file is being connected for formatted input/output, the

234

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

5

length is the number of characters for all records that contain only characters of default kind. When a record contains any nondefault characters, the effect of the RECL= specifier is processor dependent. If the file is being connected for unformatted input/output, the length is measured in file storage units. For an existing file, the value of the RECL= specifier shall be included in the set of allowed record lengths for the file. For a new file, the processor creates the file with a set of allowed record lengths that includes the specified value.

6

12.5.6.17

1 2 3 4

7 8 9 10 11

ROUND= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to one of UP, DOWN, ZERO, NEAREST, COMPATIBLE, or PRO-

CESSOR_DEFINED. The ROUND= specifier is permitted only for a connection for formatted input/output. It specifies the input/output rounding mode (13.7.2.3.8, 12.6.2.14) for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the input/output rounding mode is processor dependent; it shall be one of the above modes. NOTE 1 A processor is free to select any input/output rounding mode for the default mode. The mode might correspond to UP, DOWN, ZERO, NEAREST, or COMPATIBLE; or it might be a completely different input/output rounding mode.

12 13 14 15 16 17

12.5.6.18

SIGN= specifier in the OPEN statement

1 The scalar-default-char-expr shall evaluate to one of PLUS, SUPPRESS, or PROCESSOR_DEFINED. The

SIGN= specifier is permitted only for a connection for formatted input/output. It specifies the sign mode (13.8.4, 12.6.2.15) for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the default value is PROCESSOR_DEFINED. 12.5.6.19

STATUS= specifier in the OPEN statement

18 19

1 The scalar-default-char-expr shall evaluate to OLD, NEW, SCRATCH, REPLACE, or UNKNOWN. If OLD is

20 21 22

2 Successful execution of an OPEN statement with NEW specified creates the file and changes the status to OLD.

23 24 25 26 27

specified, the file shall exist. If NEW is specified, the file shall not exist. If REPLACE is specified and the file does not already exist, the file is created and the status is changed to OLD. If REPLACE is specified and the file does exist, the file is deleted, a new file is created with the same name, and the status is changed to OLD. If SCRATCH is specified, the file is created and connected to the specified unit for use by the program but is deleted at the execution of a CLOSE statement referring to the same unit or at the normal termination of the program. 3 If UNKNOWN is specified, the status is processor dependent. If this specifier is omitted, the default value is

UNKNOWN. NOTE 1 SCRATCH cannot be specified if the FILE= specifier appears (12.5.6.10).

28

12.5.7

CLOSE statement

29

12.5.7.1

General

30

1 The CLOSE statement is used to terminate the connection of a specified unit to an external file.

31 32

2 Execution of a CLOSE statement for a unit may occur in any program unit of a program and need not occur in

33 34

3 Execution of a CLOSE statement performs a wait operation for any pending asynchronous data transfer operations

the same program unit as the execution of an OPEN statement referring to that unit. for the specified unit.

ISO/IEC JTC 1/SC 22/WG5/N2184

235

J3/21-007r1

WD 1539-1

2021-05-21

1 2

4 Execution of a CLOSE statement specifying a unit that does not exist, exists but is connected to a file that does

3 4

5 After a unit has been disconnected by execution of a CLOSE statement, it may be connected again within the

5 6 7 8 9

not exist, or has no file connected to it, is permitted and affects no file or unit. same program, either to the same file or to a different file. After a named file has been disconnected by execution of a CLOSE statement, it may be connected again within the same program, either to the same unit or to a different unit, provided that the file still exists. 6 During the completion step (5.3.7) of normal termination, all units that are connected are closed. Each unit is

closed with status KEEP unless the file status prior to termination of execution was SCRATCH, in which case the unit is closed with status DELETE. NOTE 1 The effect is as though a CLOSE statement without a STATUS= specifier were executed on each connected unit.

10

12.5.7.2

Syntax

11

R1208 close-stmt

is

CLOSE ( close-spec-list )

12 13 14 15

R1209 close-spec

16

is or or or or

[ UNIT = ] file-unit-number IOSTAT = stat-variable IOMSG = iomsg-variable ERR = label STATUS = scalar-default-char-expr

17

C1207 No specifier shall appear more than once in a given close-spec-list.

18 19

C1208 A file-unit-number shall be specified in a close-spec-list; if the optional characters UNIT= are omitted, the file-unit-number shall be the first item in the close-spec-list.

20 21

C1209 (R1209) The label used in the ERR= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the CLOSE statement.

22 23

1 The scalar-default-char-expr has a limited list of character values. Any trailing blanks are ignored. The value

24

2 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.

specified is without regard to case.

NOTE 1 An example of a CLOSE statement is: CLOSE (10, STATUS = ’KEEP’) 25 26 27 28 29 30 31 32

12.5.7.3

STATUS= specifier in the CLOSE statement

1 The scalar-default-char-expr shall evaluate to KEEP or DELETE. The STATUS= specifier determines the dis-

position of the file that is connected to the specified unit. KEEP shall not be specified for a file whose status prior to execution of a CLOSE statement is SCRATCH. If KEEP is specified for a file that exists, the file continues to exist after the execution of a CLOSE statement. If KEEP is specified for a file that does not exist, the file will not exist after the execution of a CLOSE statement. If DELETE is specified, the file will not exist after the execution of a CLOSE statement. If this specifier is omitted, the default value is KEEP, unless the file status prior to execution of the CLOSE statement is SCRATCH, in which case the default value is DELETE.

236

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

12.6

Data transfer statements

2

12.6.1

Form of input and output statements

3 4

J3/21-007r1

1 The READ statement is the data transfer input statement. The WRITE statement and the PRINT statement

are the data transfer output statements.

5 6

R1210 read-stmt

is READ ( io-control-spec-list ) [ input-item-list ] or READ format [ , input-item-list ]

7

R1211 write-stmt

is

WRITE ( io-control-spec-list ) [ output-item-list ]

8

R1212 print-stmt

is

PRINT format [ , output-item-list ]

NOTE 1 Examples of data transfer statements are: READ (6, *) SIZE READ 10, A, B WRITE (6, 10) A, S, J PRINT 10, A, S, J 10 FORMAT (2E16.3, I5) NOTE 2 A statement of the form READ (name ) where name is the name of a default character variable is a formatted input statement. The format expression “(name)” is the format. The statement cannot be an input statement that specifies an internal file because of C1220. 9

12.6.2

Control information list

10

12.6.2.1

Syntax

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

1 A control information list is an io-control-spec-list. It governs data transfer.

R1213 io-control-spec

is or or or or or or or or or or or or or or or or or or

[ UNIT = ] io-unit [ FMT = ] format [ NML = ] namelist-group-name ADVANCE = scalar-default-char-expr ASYNCHRONOUS = scalar-default-char-constant-expr BLANK = scalar-default-char-expr DECIMAL = scalar-default-char-expr DELIM = scalar-default-char-expr END = label EOR = label ERR = label ID = id-variable IOMSG = iomsg-variable IOSTAT = stat-variable LEADING_ZERO = scalar-default-char-expr PAD = scalar-default-char-expr POS = scalar-int-expr REC = scalar-int-expr ROUND = scalar-default-char-expr

ISO/IEC JTC 1/SC 22/WG5/N2184

237

J3/21-007r1

WD 1539-1

2021-05-21

or SIGN = scalar-default-char-expr or SIZE = scalar-int-variable

1 2

is

3

R1214 id-variable

4

C1210 No specifier shall appear more than once in a given io-control-spec-list.

5 6

C1211 An io-unit shall be specified in an io-control-spec-list; if the optional characters UNIT= are omitted, the io-unit shall be the first item in the io-control-spec-list.

7

C1212 (R1213) A DELIM=, LEADING_ZERO=, or SIGN= specifier shall not appear in a read-stmt.

8

C1213 (R1213) A BLANK=, PAD=, END=, EOR=, or SIZE= specifier shall not appear in a write-stmt.

9 10

C1214 (R1213) The label in the ERR=, EOR=, or END= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the data transfer statement.

11

C1215 (R1213) A namelist-group-name shall be the name of a namelist group.

12 13

C1216 (R1213) A namelist-group-name shall not appear if a REC= specifier, format, input-item-list, or an output-item-list appears in the data transfer statement.

14 15

C1217 (R1213) If format appears without a preceding FMT=, it shall be the second item in the io-control-speclist and the first item shall be io-unit.

16 17

C1218 (R1213) If namelist-group-name appears without a preceding NML=, it shall be the second item in the io-control-spec-list and the first item shall be io-unit.

18 19

C1219 (R1213) If io-unit is not a file-unit-number, the io-control-spec-list shall not contain a REC= specifier or a POS= specifier.

20 21

C1220 (R1213) If io-unit is an internal-file-variable, the io-control-spec-list shall contain a format or a namelistgroup-name.

22 23

C1221 (R1213) If the REC= specifier appears, an END= specifier shall not appear, and the format, if any, shall not be an asterisk.

24 25 26

C1222 (R1213) An ADVANCE= specifier shall appear only in a formatted sequential or stream data transfer statement with explicit format specification (13.2) whose io-control-spec-list does not contain an internalfile-variable as the io-unit.

27

C1223 (R1213) If an EOR= specifier appears, an ADVANCE= specifier also shall appear.

28 29

C1224 (R1213) The scalar-default-char-constant-expr in an ASYNCHRONOUS= specifier shall have the value YES or NO.

30 31

C1225 (R1213) An ASYNCHRONOUS= specifier with a value YES shall not appear unless io-unit is a fileunit-number.

32 33

C1226 (R1213) If an ID= specifier appears, an ASYNCHRONOUS= specifier with the value YES shall also appear.

34

C1227 (R1213) If a POS= specifier appears, the io-control-spec-list shall not contain a REC= specifier.

35 36

C1228 (R1213) If a DECIMAL=, BLANK=, LEADING_ZERO=, PAD=, SIGN=, or ROUND= specifier appears, a format or namelist-group-name shall also appear.

37 38

C1229 (R1213) If a DELIM= specifier appears, either format shall be an asterisk or namelist-group-name shall appear.

39

C1230 (R1214) The scalar-int-variable shall have a decimal exponent range no smaller than that of default

238

scalar-int-variable

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

integer.

2

2 If an EOR= specifier appears, an ADVANCE= specifier with the value NO shall also appear.

3 4

3 If the data transfer statement contains a format or namelist-group-name, the statement is a formatted in-

5

4 The ADVANCE=, ASYNCHRONOUS=, DECIMAL=, BLANK=, DELIM=, LEADING_ZERO=, PAD=, SIGN=,

6 7

and ROUND= specifiers have a limited list of character values. Any trailing blanks are ignored. The values specified are without regard to case.

8

put/output statement; otherwise, it is an unformatted input/output statement.

5 The IOSTAT=, ERR=, EOR=, END=, and IOMSG= specifiers are described in 12.11.

NOTE 1 An example of a READ statement is: READ (IOSTAT = IOS, UNIT = 6, FMT = ’(10F8.2)’) A, B

9 10 11 12 13

12.6.2.2

Format specification in a data transfer statement

1 The format specifier supplies a format specification or specifies list-directed formatting for a formatted in-

put/output statement. R1215 format

14 15 16

is default-char-expr or label or *

C1231 (R1215) The label shall be the label of a FORMAT statement that appears in the same inclusive scope as the statement containing the FMT= specifier.

17

2 The default-char-expr shall evaluate to a valid format specification (13.2.1 and 13.2.2).

18 19

3 If default-char-expr is an array, it is treated as if all of the elements of the array were specified in array element

20

4 If format is *, the statement is a list-directed input/output statement.

order and were concatenated.

NOTE 1 An example in which the format is a character expression is: READ (6, FMT = "(" // CHAR_FMT // ")" )

X, Y, Z

where CHAR_FMT is a default character variable. 21

12.6.2.3

NML= specifier in a data transfer statement

22 23

1 The NML= specifier supplies the namelist-group-name (8.9). This name identifies a particular collection of data

24

2 If a namelist-group-name appears, the statement is a namelist input/output statement.

25

objects on which transfer is to be performed.

12.6.2.4

ADVANCE= specifier in a data transfer statement

26

1 The scalar-default-char-expr shall evaluate to YES or NO. The ADVANCE= specifier determines whether advan-

27 28 29 30 31

cing input/output occurs for a nonchild data transfer statement. If YES is specified for a nonchild data transfer statement, advancing input/output occurs. If NO is specified, nonadvancing input/output occurs (12.3.4.2). If this specifier is omitted from a nonchild data transfer statement that allows the specifier, the default value is YES. A formatted child data transfer statement is a nonadvancing input/output statement, and any ADVANCE= specifier is ignored.

ISO/IEC JTC 1/SC 22/WG5/N2184

239

J3/21-007r1

1 2 3 4 5 6

12.6.2.5

WD 1539-1

2021-05-21

ASYNCHRONOUS= specifier in a data transfer statement

1 The ASYNCHRONOUS= specifier determines whether this data transfer statement is synchronous or asynchron-

ous. If YES is specified, the statement and the input/output operation are asynchronous. If NO is specified or if the specifier is omitted, the statement and the input/output operation are synchronous. 2 Asynchronous input/output is permitted only for external files opened with an ASYNCHRONOUS= specifier

with the value YES in the OPEN statement. NOTE 1 Both synchronous and asynchronous input/output are allowed for files opened with an ASYNCHRONOUS= specifier of YES. For other files, only synchronous input/output is allowed; this includes files opened with an ASYNCHRONOUS= specifier of NO, files opened without an ASYNCHRONOUS= specifier, preconnected files accessed without an OPEN statement, and internal files. The ASYNCHRONOUS= specifier value in a data transfer statement is a constant expression because it effects compiler optimizations and, therefore, needs to be known at compile time.

7 8 9 10 11 12 13 14 15

3 The processor may perform an asynchronous data transfer operation asynchronously, but it is not required to do

so. For each external file, records and file storage units read or written by asynchronous data transfer statements are read, written, and processed in the same order as they would have been if the data transfer statements were synchronous. The documentation of the Fortran processor should describe when input/output will be performed asynchronously. 4 If a variable is used in an asynchronous data transfer statement as

• an item in an input/output list, • a group object in a namelist, or • a SIZE= specifier,

16 17

the base object of the data-ref is implicitly given the ASYNCHRONOUS attribute in the scoping unit of the data transfer statement. This attribute may be confirmed by explicit declaration.

18 19

5 When an asynchronous input/output statement is executed, the set of storage units specified by the item list or

20

NML= specifier, plus the storage units specified by the SIZE= specifier, is defined to be the pending input/output storage sequence for the data transfer operation. NOTE 2 A pending input/output storage sequence is not necessarily a contiguous set of storage units.

21 22 23 24 25 26 27 28 29 30

6 A pending input/output storage sequence affector is a variable of which any part is associated with a storage unit

in a pending input/output storage sequence. 12.6.2.6

BLANK= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to NULL or ZERO. The BLANK= specifier temporarily changes

(12.5.2) the blank interpretation mode (13.8.7, 12.5.6.6) for the connection. If the specifier is omitted, the mode is not changed. 12.6.2.7

DECIMAL= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to COMMA or POINT. The DECIMAL= specifier temporarily changes

(12.5.2) the decimal edit mode (13.6, 13.8.9, 12.5.6.7) for the connection. If the specifier is omitted, the mode is not changed.

240

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

12.6.2.8

WD 1539-1

J3/21-007r1

DELIM= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE. The DELIM= specifier tem-

4

porarily changes (12.5.2) the delimiter mode (13.10.4, 13.11.4.2, 12.5.6.8) for the connection. If the specifier is omitted, the mode is not changed.

5

12.6.2.9

6 7 8 9 10

ID= specifier in a data transfer statement

1 Successful execution of an asynchronous data transfer statement containing an ID= specifier causes the variable

specified in the ID= specifier to become defined with a processor determined value. If this value is zero, the data transfer operation has been completed. A nonzero value is referred to as the identifier of the data transfer operation. This identifier is different from the identifier of any other pending data transfer operation for this unit. It can be used in a subsequent WAIT or INQUIRE statement to identify the particular data transfer operation.

11 12

2 If an error condition occurs during the execution of a data transfer statement containing an ID= specifier, the

13

3 A child data transfer statement shall not specify the ID= specifier.

14 15 16 17 18 19 20 21

variable specified in the ID= specifier becomes undefined.

12.6.2.10

LEADING_ZERO= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to PRINT, SUPPRESS, or PROCESSOR_DEFINED. The LEAD-

ING_ZERO= specifier temporarily changes (12.5.2) the leading zero mode (13.8.5, 12.5.6.12) for the connection. If the specifier is omitted, the mode is not changed. 12.6.2.11

PAD= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to YES or NO. The PAD= specifier temporarily changes (12.5.2) the

pad mode (12.6.4.5.3, 12.5.6.14) for the connection. If the specifier is omitted, the mode is not changed. 12.6.2.12

POS= specifier in a data transfer statement

22 23 24

1 The POS= specifier specifies the file position in file storage units. This specifier shall not appear in a data transfer

25 26

2 A processor may prohibit the use of POS= with particular files that do not have the properties necessary to

27

statement unless the statement specifies a unit connected for stream access. A child data transfer statement shall not specify this specifier. support random positioning. A processor may also prohibit positioning a particular file to any position prior to its current file position if the file does not have the properties necessary to support such positioning. NOTE 1 A unit that is connected to a device or data stream might not be positionable.

28 29 30 31

3 If the file is connected for formatted stream access, the file position specified by POS= shall be equal to either 1

(the beginning of the file) or a value previously returned by a POS= specifier in an INQUIRE statement for the file. 12.6.2.13

REC= specifier in a data transfer statement

32

1 The REC= specifier specifies the number of the record that is to be read or written. This specifier shall appear

33 34 35 36 37 38

only in a data transfer statement that specifies a unit connected for direct access; it shall not appear in a child data transfer statement. If the io-control-spec-list contains a REC= specifier, the statement is a direct access data transfer statement. A child data transfer statement is a direct access data transfer statement if the parent is a direct access data transfer statement. Any other data transfer statement is a sequential access data transfer statement or a stream access data transfer statement, depending on whether the file connection is for sequential access or stream access.

ISO/IEC JTC 1/SC 22/WG5/N2184

241

J3/21-007r1

1 2 3

12.6.2.14

WD 1539-1

2021-05-21

ROUND= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to one of UP, DOWN, ZERO, NEAREST, COMPATIBLE or PRO-

4

CESSOR_DEFINED. The ROUND= specifier temporarily changes (12.5.2) the input/output rounding mode (13.7.2.3.8, 12.5.6.17) for the connection. If the specifier is omitted, the mode is not changed.

5

12.6.2.15

6 7 8 9

SIGN= specifier in a data transfer statement

1 The scalar-default-char-expr shall evaluate to PLUS, SUPPRESS, or PROCESSOR_DEFINED. The SIGN=

specifier temporarily changes (12.5.2) the sign mode (13.8.4, 12.5.6.18) for the connection. If the specifier is omitted, the mode is not changed. 12.6.2.16

SIZE= specifier in a data transfer statement

10 11 12

1 The SIZE= specifier in an input statement causes the variable specified to become defined with the count of

13 14

2 For a synchronous input statement, this definition occurs when execution of the statement completes. For an

15 16

the characters transferred from the file by data edit descriptors during the input operation. Blanks inserted as padding are not counted. asynchronous input statement, this definition occurs when the corresponding wait operation is performed.

12.6.3

Data transfer input/output list

1 An input/output list specifies the entities whose values are transferred by a data transfer statement.

R1216 input-item

is variable or io-implied-do

19 20

R1217 output-item

is expr or io-implied-do

21

R1218 io-implied-do

is

22 23

R1219 io-implied-do-object

is input-item or output-item

24 25

R1220 io-implied-do-control

is

26

C1232 (R1216) A variable that is an input-item shall not be a whole assumed-size array.

27 28

C1233 (R1219) In an input-item-list, an io-implied-do-object shall be an input-item. In an output-item-list, an io-implied-do-object shall be an output-item.

29

C1234 (R1217) An expression that is an output-item shall not have a value that is a procedure pointer.

17 18

30 31

( io-implied-do-object-list , io-implied-do-control )

do-variable = scalar-int-expr , scalar-int-expr [ , scalar-int-expr ]

2 An input-item shall not appear as, nor be associated with, the do-variable of any io-implied-do that contains the

input-item. NOTE 1 A constant, an expression involving operators or function references that does not have a pointer result, or an expression enclosed in parentheses cannot appear as an input list item.

32 33 34

3 If an input item is a pointer, it shall be associated with a definable target and data are transferred from the file to

the associated target. If an output item is a pointer, it shall be associated with a target and data are transferred from the target to the file.

242

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 Data transfers always involve the movement of values between a file and internal storage. A pointer as such cannot be read or written. Therefore, a pointer shall not appear as an item in an input/output list unless it is associated with a target that can receive a value (input) or can deliver a value (output). 1

4 If an input item or an output item is allocatable, it shall be allocated.

2

5 A list item shall not be polymorphic unless it is processed by a defined input/output procedure (12.6.4.8).

3 4

6 A list item that is of an interoperable enum type is treated as if it were of type integer with the kind being the

5 6

7 A list item that is of an enumeration type shall not appear in a list-directed data transfer statement. In a

7 8

8 The do-variable of an io-implied-do that is in another io-implied-do shall not appear as, nor be associated with,

9 10

9 The following rules describing whether to expand an input/output list item are re-applied to each expanded list

11 12

• If an array appears as an input/output list item, it is treated as if the elements, if any, were specified in array element order (9.5.3.3). However, no element of that array shall affect the value of any expression in the input-item, nor shall any element appear more than once in a given input-item.

13

kind of its enumerators. formatted data transfer statement, it shall correspond to an I, B, O, or Z edit descriptor. the do-variable of the containing io-implied-do. item until none of the rules apply.

NOTE 3 For example: INTEGER A (100), J (100) ... READ *, A (A) READ *, A (LBOUND (A, 1) : UBOUND (A, 1)) READ *, A (J) A(1) = 1; A(10) = 10 READ *, A (A (1) : A (10)) 14 15 16 17 18 19 20 21

! Not allowed ! Allowed ! Allowed if no two elements ! of J have the same value ! Not allowed

• If a list item of derived type in an unformatted input/output statement is not processed by a defined input/output procedure (12.6.4.8), and if any subobject of that list item would be processed by a defined input/output procedure, the list item is treated as if all of the components of the object were specified in the list in component order (7.5.4.7); those components shall be accessible in the scoping unit containing the data transfer statement and shall not be pointers or allocatable. • An effective item of derived type in an unformatted input/output statement is treated as a single value in a processor-dependent form unless the list item or a subobject thereof is processed by a defined input/output procedure (12.6.4.8). NOTE 4 The appearance of a derived-type object as an input/output list item in an unformatted input/output statement is not equivalent to the list of its components. Unformatted input/output involving derived-type list items forms the single exception to the rule that the appearance of an aggregate list item (such as an array) is equivalent to the appearance of its expanded list of component parts. This exception permits the processor greater latitude in improving efficiency or in matching the processor-dependent sequence of values for a derived-type object to similar sequences for aggregate objects used by means other than Fortran. However, formatted input/output of all list items and unformatted input/output of list items other than those of derived types adhere to the above rule.

22

• If a list item of derived type in a formatted input/output statement is not processed by a defined in-

ISO/IEC JTC 1/SC 22/WG5/N2184

243

J3/21-007r1

1 2 3 4 5 6 7

WD 1539-1

2021-05-21

put/output procedure, that list item is treated as if all of the components of the list item were specified in the list in component order; those components shall be accessible in the scoping unit containing the input/output statement and shall not be pointers or allocatable. • If a derived-type list item is not processed by a defined input/output procedure and is not treated as a list of its individual components, all the subcomponents of that list item shall be accessible in the scoping unit containing the data transfer statement and shall not be pointers or allocatable. • For an io-implied-do, the loop initialization and execution are the same as for a DO construct (11.1.7.4). NOTE 5 An example of an output list with an implied DO is: WRITE (LP, FMT = ’(10F8.2)’) (LOG (A (I)), I = 1, N + 9, K), G

8

10 The scalar objects resulting when a data transfer statement’s list items are expanded according to the rules in

9 10 11

this subclause for handling array and derived-type list items are called effective items. Zero-sized arrays and io-implied-dos with an iteration count of zero do not contribute to the list of effective items. A scalar character item of zero length is an effective item. NOTE 6 In a formatted input/output statement, edit descriptors are associated with effective items, which are always scalar. The rules in 12.6.3 determine the set of effective items corresponding to each actual list item in the statement. These rules might have to be applied repetitively until all of the effective items are scalar items.

12 13 14 15 16 17

11 An input/output list shall not contain an effective item of nondefault character kind if the data transfer statement

specifies an internal file of default character kind. An input/output list shall not contain an effective item that is nondefault character except for ISO 10646 or ASCII character if the data transfer statement specifies an internal file of ISO 10646 character kind. An input/output list shall not contain an effective item of type character of any kind other than ASCII if the data transfer statement specifies an ASCII character internal file. 12 An output list shall not contain an effective item that is a boz-literal-constant.

18

12.6.4

Execution of a data transfer input/output statement

19

12.6.4.1

Data transfer sequence of operations

20 21

1 Execution of a WRITE or PRINT statement for a unit connected to a file that does not exist creates the file

22 23

2 The effect of executing a synchronous data transfer statement shall be as if the following operations were performed

unless an error condition occurs. in the order specified. (1) (2) (3)

24 25 26 27

(4) (5)

28 29

Determine the direction of data transfer (12.6.4.2). Identify the unit (12.6.4.3). Perform a wait operation for all pending input/output operations for the unit. If an error, end-of-file, or end-of-record condition occurs during any of the wait operations, steps 4 through 8 are skipped. Establish the format if one is specified. If the statement is not a child data transfer statement (12.6.4.8), (a) (b)

30 31 32 33

(6)

34

(7) (8)

35 36

244

position the file prior to data transfer (12.3.4.3), and for formatted data transfer, set the left tab limit (13.8.1.2).

Transfer data between the file and the entities specified by the input/output list (if any) or namelist, possibly mediated by defined input/output procedures (12.6.4.8). Determine whether an error, end-of-file, or end-of-record condition has occurred. Position the file after data transfer (12.3.4.4) unless the statement is a child data transfer statement (12.6.4.8).

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

WD 1539-1

J3/21-007r1

(9) Cause any variable specified in a SIZE= specifier to become defined. (10) If an error, end-of-file, or end-of-record condition occurred, processing continues as specified in 12.11; otherwise, any variable specified in an IOSTAT= specifier is assigned the value zero. 3 The effect of executing an asynchronous data transfer statement shall be as if the following operations were

performed in the order specified. (1) (2) (3)

Determine the direction of data transfer (12.6.4.2). Identify the unit (12.6.4.3). Optionally, perform wait operations for one or more pending input/output operations for the unit. If an error, end-of-file, or end-of-record condition occurs during any of the wait operations, steps 4 through 9 are skipped. (4) Establish the format if one is specified. (5) Position the file prior to data transfer (12.3.4.3) and, for formatted data transfer, set the left tab limit (13.8.1.2). (6) Establish the set of storage units identified by the input/output list. For an input statement, this might require some or all of the data in the file to be read if an input variable is used as a scalarint-expr in an io-implied-do-control in the input/output list, as a subscript, substring-range, stride, or is otherwise referenced. (7) Initiate an asynchronous data transfer between the file and the entities specified by the input/output list (if any) or namelist. The asynchronous data transfer may complete (and an error, end-of-file, or end-of-record condition may occur) during the execution of this data transfer statement or during a later wait operation. (8) Determine whether an error, end-of-file, or end-of-record condition has occurred. The conditions may occur during the execution of this data transfer statement or during the corresponding wait operation, but not both. (9) Position the file as if the data transfer had finished (12.3.4.4). (10) Cause any variable specified in a SIZE= specifier to become undefined. (11) If an error, end-of-file, or end-of-record condition occurred, processing continues as specified in 12.11; otherwise, any variable specified in an IOSTAT= specifier is assigned the value zero.

29 30 31

4 For an asynchronous data transfer statement, the data transfers may occur during execution of the statement,

32 33

5 For asynchronous output, a pending input/output storage sequence affector (12.6.2.5) shall not be redefined,

34

6 For asynchronous input, a pending input/output storage sequence affector shall not be referenced, become defined,

35 36

become undefined, become associated with a dummy argument that has the VALUE attribute, or have its pointer association status changed.

37 38 39 40

7 Error, end-of-file, and end-of-record conditions in an asynchronous data transfer operation may occur during

41 42 43 44 45

during execution of the corresponding wait operation, or anywhere between. The data transfer operation is considered to be pending until a corresponding wait operation is performed. become undefined, or have its pointer association status changed.

execution of either the data transfer statement or the corresponding wait operation. If an ID= specifier does not appear in the initiating data transfer statement, the conditions may occur during the execution of any subsequent data transfer or wait operation for the same unit. When a condition occurs for a previously executed asynchronous data transfer statement, a wait operation is performed for all pending data transfer operations on that unit. When a condition occurs during a subsequent statement, any actions specified by IOSTAT=, IOMSG=, ERR=, END=, and EOR= specifiers for that statement are taken. 8 If execution of the program is terminated during execution of an output statement, the contents of the file become

undefined. NOTE 1 Because end-of-file and error conditions for asynchronous data transfer statements without an ID= specifier can be reported by the processor during the execution of a subsequent data transfer statement, it might be

ISO/IEC JTC 1/SC 22/WG5/N2184

245

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) impossible for the user to determine which data transfer statement caused the condition. Reliably detecting which input statement caused an end-of-file condition requires that all asynchronous input statements for the unit include an ID= specifier. 1

12.6.4.2

Direction of data transfer

2

1 Execution of a READ statement causes values to be transferred from a file to the entities specified by the input

3 4 5

list, if any, or specified within the file itself for namelist input. Execution of a WRITE or PRINT statement causes values to be transferred to a file from the entities specified by the output list and format specification, if any, or by the namelist-group-name for namelist output.

6

12.6.4.3

7 8 9 10 11 12 13 14 15 16

Identifying a unit

1 A data transfer statement that contains an input/output control list includes a UNIT= specifier that identifies

an external or internal unit. A READ statement that does not contain an input/output control list specifies a particular processor-dependent unit, which is the same as the unit identified by * in a READ statement that contains an input/output control list (12.5.1) and is the same as the unit identified by the value of the named constant INPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2.13). The PRINT statement specifies some other processor-dependent unit, which is the same as the unit identified by * in a WRITE statement and is the same as the unit identified by the value of the named constant OUTPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2.24). Thus, each data transfer statement identifies an external or internal unit. 2 The unit identified by a data transfer statement shall be connected to a file when execution of the statement

begins. NOTE 1 The unit could be preconnected.

17 18 19 20

12.6.4.4

Establishing a format

1 If the input/output control list contains * as a format, list-directed formatting is established. If namelist-group-

name appears, namelist formatting is established. If no format or namelist-group-name is specified, unformatted data transfer is established. Otherwise, the format specified by format is established.

21 22

2 For output to an internal file, a format specification that is in the file or is associated with the file shall not be

23 24

3 An input list item, or an entity associated with it, shall not contain any portion of an established format spe-

specified. cification.

25

12.6.4.5

Data transfer

26

12.6.4.5.1

General

27 28 29 30 31 32

1 Data are transferred between the file and the entities specified by the input/output list or namelist. The list items

are processed in the order of the input/output list for all data transfer statements except namelist data transfer statements. The list items for a namelist input statement are processed in the order of the entities specified within the input records. The list items for a namelist output statement are processed in the order in which the variables are specified in the namelist-group-object-list. Effective items are derived from the input/output list items as described in 12.6.3.

33 34

2 All values needed to determine which entities are specified by an input/output list item are determined at the

35

3 All values are transmitted to or from the entities specified by a list item prior to the processing of any succeeding

beginning of the processing of that item.

246

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

list item for all data transfer statements. NOTE 1 In the example READ (N) N, X (N) the old value of N identifies the unit, but the new value of N is the subscript of X.

2 3 4 5 6

4 All values following the name= part of the namelist entity (13.11) within the input records are transmitted to

the matching entity specified in the namelist-group-object-list prior to processing any succeeding entity within the input record for namelist input statements. If an entity is specified more than once within the input record during a namelist input statement, the last occurrence of the entity specifies the value or values to be used for that entity.

7

5 If the input/output item is a pointer, data are transferred between the file and the associated target.

8

6 If an internal file has been specified, an input/output list item shall not be in the file or associated with the file.

9 10

7 During the execution of an output statement that specifies an internal file, no part of that internal file shall be

11

8 During the execution of an input statement that specifies an internal file, no part of that internal file shall be

12

referenced, defined, or become undefined as the result of evaluating any output list item. defined or become undefined as the result of transferring a value to any input list item.

13 14

9 A DO variable becomes defined and its iteration count established at the beginning of processing of the io-implied-

15

10 On output, every entity whose value is to be transferred shall be defined.

16

do-object-list an io-implied-do.

12.6.4.5.2

Unformatted data transfer

17

1 If the file is not connected for unformatted input/output, unformatted data transfer is prohibited.

18 19 20

2 During unformatted data transfer, data are transferred without editing between the file and the entities specified

21 22

3 A value in the file is stored in a contiguous sequence of file storage units, beginning with the file storage unit

23

4 After each value is transferred, the current file position is moved to a point immediately after the last file storage

24

by the input/output list. If the file is connected for sequential or direct access, exactly one record is read or written. immediately following the current file position. unit of the value.

25 26

5 On input from a file connected for sequential or direct access, the number of file storage units required by the

27 28

6 On input, if the file storage units transferred do not contain a value with the same type and type parameters as

29 30

• A complex entity may correspond to two real values with the same kind type parameter as the complex entity. • A default character list entity of length n may correspond to n default characters stored in the file, regardless of the length parameters of the entities that were written to these storage units of the file. If the file is connected for stream input, the characters may have been written by formatted stream output.

31 32 33

34 35 36

input list shall be less than or equal to the number of file storage units in the record. the input list entity, then the resulting value of the entity is processor dependent except in the following cases.

7 On output to a file connected for unformatted direct access, the output list shall not specify more values than

can fit into the record. If the file is connected for direct access and the values specified by the output list do not fill the record, the remainder of the record is undefined.

ISO/IEC JTC 1/SC 22/WG5/N2184

247

J3/21-007r1

1 2 3 4 5

WD 1539-1

2021-05-21

8 If the file is connected for unformatted sequential access, the record is created with a length sufficient to hold

the values from the output list. This length shall be one of the set of allowed record lengths for the file and shall not exceed the value specified in the RECL= specifier, if any, of the OPEN statement that established the connection. 12.6.4.5.3

Formatted data transfer

6

1 If the file is not connected for formatted input/output, formatted data transfer is prohibited.

7 8 9

2 During formatted data transfer, data are transferred with editing between the file and the entities specified by

10

3 The current record and possibly additional records are read or written.

11 12

4 During advancing input when the pad mode has the value NO, the input list and format specification shall not

13 14

5 During advancing input when the pad mode has the value YES, blank characters are supplied by the processor

15 16

6 During nonadvancing input when the pad mode has the value NO, an end-of-record condition (12.11) occurs if

17 18

the input/output list or by the namelist-group-name. Format control is initiated and editing is performed as described in Clause 13.

require more characters from the record than the record contains. if the input list and format specification require more characters from the record than the record contains. the input list and format specification require more characters from the record than the record contains, and the record is complete (12.3.3.4). If the record is incomplete, an end-of-file condition occurs instead of an end-of-record condition.

19 20 21 22

7 During nonadvancing input when the pad mode has the value YES, blank characters are supplied by the processor

23 24

8 If the file is connected for direct access, the record number is increased by one as each succeeding record is read

25 26

9 On output, if the file is connected for direct access or is an internal file and the characters specified by the output

27 28

10 On output, the output list and format specification shall not specify more characters for a record than have been

29 30 31

if an effective item and its corresponding data edit descriptors require more characters from the record than the record contains. If the record is incomplete, an end-of-file condition occurs; otherwise, an end-of-record condition occurs. or written. list and format do not fill a record, blank characters are added to fill the record. specified by a RECL= specifier in the OPEN statement or the record length of an internal file. 12.6.4.6

List-directed formatting

1 If list-directed formatting has been established, editing is performed as described in 13.10.

12.6.4.7

Namelist formatting

32

1 If namelist formatting has been established, editing is performed as described in 13.11.

33 34

2 Every allocatable namelist-group-object in the namelist group shall be allocated and every namelist-group-object

35 36

that is a pointer shall be associated with a target. If a namelist-group-object is polymorphic or has an ultimate component that is allocatable or a pointer, that object shall be processed by a defined input/output procedure (12.6.4.8).

37

12.6.4.8

38

12.6.4.8.1

39 40

Defined input/output General

1 Defined input/output allows a program to override the default handling of derived-type objects and values in

data transfer statements described in 12.6.3.

248

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

2 A defined input/output procedure is a procedure accessible by a defined-io-generic-spec (15.4.3.2). A particular

defined input/output procedure is selected as described in 12.6.4.8.4. 12.6.4.8.2

Defined input/output procedures

4

1 For a particular derived type and a particular set of kind type parameter values, there are four possible sets of

5 6 7 8 9 10

characteristics for defined input/output procedures; one each for formatted input, formatted output, unformatted input, and unformatted output. The program need not supply all four procedures. The procedures are specified to be used for derived-type input/output by interface blocks (15.4.3.2) or by generic bindings (7.5.5), with a defined-io-generic-spec (R1509). The defined-io-generic-specs for these procedures are READ (FORMATTED), READ (UNFORMATTED), WRITE (FORMATTED), and WRITE (UNFORMATTED), for formatted input, unformatted input, formatted output, and unformatted output respectively.

11 12

2 In the four interfaces, which specify the characteristics of defined input/output procedures, the following syntax

term is used: is TYPE( derived-type-spec ) or CLASS( derived-type-spec )

13 14

R1221 dtv-type-spec

15 16

C1235 (R1221) If derived-type-spec specifies an extensible type, the CLASS keyword shall be used; otherwise, the TYPE keyword shall be used.

17

C1236 (R1221) All length type parameters of derived-type-spec shall be assumed.

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

33 34 35 36 37 38 39 40 41 42 43

44 45

3 If the defined-io-generic-spec is READ (FORMATTED), the characteristics shall be the same as those specified

by the following interface: SUBROUTINE my_read_routine_formatted (dtv, unit, iotype, v_list, iostat, iomsg) ! the derived-type variable dtv-type-spec , INTENT(INOUT) :: dtv INTEGER, INTENT(IN) :: unit ! unit number ! the edit descriptor string CHARACTER (LEN=*), INTENT(IN) :: iotype INTEGER, INTENT(IN) :: v_list(:) INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg END

& & &

4 If the defined-io-generic-spec is READ (UNFORMATTED), the characteristics shall be the same as those specified

by the following interface: SUBROUTINE my_read_routine_unformatted (dtv, & unit, & iostat, iomsg) ! the derived-type variable dtv-type-spec , INTENT(INOUT) :: dtv INTEGER, INTENT(IN) :: unit INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg END 5 If the defined-io-generic-spec is WRITE (FORMATTED), the characteristics shall be the same as those specified

by the following interface:

ISO/IEC JTC 1/SC 22/WG5/N2184

249

J3/21-007r1

5 6 7 8 9 10 11 12 13

6 If the defined-io-generic-spec is WRITE (UNFORMATTED), the characteristics shall be the same as those

specified by the following interface: SUBROUTINE my_write_routine_unformatted (dtv, & unit, & iostat, iomsg) ! the derived-type value/variable dtv-type-spec , INTENT(IN) :: dtv INTEGER, INTENT(IN) :: unit INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg END

16 17 18 19 20 21 22 23 24

25 26 27 28

2021-05-21

SUBROUTINE my_write_routine_formatted (dtv, & unit, & iotype, v_list, & iostat, iomsg) ! the derived-type value/variable dtv-type-spec , INTENT(IN) :: dtv INTEGER, INTENT(IN) :: unit ! the edit descriptor string CHARACTER (LEN=*), INTENT(IN) :: iotype INTEGER, INTENT(IN) :: v_list(:) INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg END

1 2 3 4

14 15

WD 1539-1

7 The actual specific procedure names (the my_..._routine_... procedure names above) are not significant. In

the discussion here and elsewhere, the dummy arguments in these interfaces are referred to by the names given above; the names are, however, arbitrary. 12.6.4.8.3

Executing defined input/output data transfers

29

1 If a defined input/output procedure is selected for an effective item as specified in 12.6.4.8.4, the processor shall

30 31

call the selected defined input/output procedure for that item. The defined input/output procedure controls the actual data transfer operations for the derived-type list item.

32 33 34 35

2 A data transfer statement that includes a derived-type list item and that causes a defined input/output procedure

to be invoked is called a parent data transfer statement. A data transfer statement that is executed while a parent data transfer statement is being processed and that specifies the unit passed into a defined input/output procedure is called a child data transfer statement. NOTE 1 A defined input/output procedure will usually contain child data transfer statements that read values from or write values to the current record or at the current file position. The effect of executing the defined input/output procedure is similar to that of substituting the list items from any child data transfer statements into the parent data transfer statement’s list items, along with similar substitutions in the format specification. NOTE 2 A particular execution of a READ, WRITE or PRINT statement can be both a parent and a child data transfer statement. A defined input/output procedure can indirectly call itself or another defined input/output procedure by executing a child data transfer statement containing a list item of derived type, where a matching interface is accessible for that derived type. If a defined input/output procedure calls itself indirectly in this manner, it cannot be declared NON_RECURSIVE.

250

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

3 A child data transfer statement is processed differently from a nonchild data transfer statement in the following

3

• Executing a child data transfer statement does not position the file prior to data transfer. • An unformatted child data transfer statement does not position the file after data transfer is complete. • Any ADVANCE= specifier in a child input/output statement is ignored.

4 5

ways.

6 7

4 When a defined input/output procedure is invoked, the processor shall pass a unit argument that has a value as

8 9

• If the parent data transfer statement uses a file-unit-number, the value of the unit argument shall be that of the file-unit-number. • If the parent data transfer statement is a WRITE statement with an asterisk unit or a PRINT statement, the unit argument shall have the same value as the named constant OUTPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2). • If the parent data transfer statement is a READ statement with an asterisk unit or a READ statement without an io-control-spec-list, the unit argument shall have the same value as the INPUT_UNIT named constant of the intrinsic module ISO_FORTRAN_ENV (16.10.2). • Otherwise the parent data transfer statement accesses an internal file, in which case the unit argument shall have a processor-dependent negative value.

10 11 12 13 14 15 16 17

follows.

NOTE 3 The unit argument passed to a defined input/output procedure will be negative when the parent data transfer statement specified an internal unit, or specified an external unit that is a NEWUNIT value. When an internal unit is used with the INQUIRE statement, an error condition will occur, and any variable specified in an IOSTAT= specifier will be assigned the value IOSTAT_INQUIRE_INTERNAL_UNIT from the intrinsic module ISO_FORTRAN_ENV (16.10.2). 18 19 20 21 22

5 For formatted data transfer, the processor shall pass an iotype argument that has the value

• “LISTDIRECTED” if the parent data transfer statement specified list directed formatting, • “NAMELIST” if the parent data transfer statement specified namelist formatting, or • “DT” concatenated with the char-literal-constant, if any, of the DT edit descriptor in the format specification of the parent data transfer statement.

23 24 25

6 If the parent data transfer statement is an input statement, the dtv dummy argument is argument associated

26 27

7 If the parent data transfer statement is an output statement, the processor shall provide the value of the effective

28

8 If the v-list of the edit descriptor appears in the parent data transfer statement, the processor shall provide the

29 30 31

values from it in the v_list dummy argument, with the same number of elements in the same order as v-list. If there is no v-list in the edit descriptor or if the data transfer statement specifies list-directed or namelist formatting, the processor shall provide v_list as a zero-sized array.

with the effective item that caused the defined input procedure to be invoked, as if the effective item were an actual argument in this procedure reference (5.4.5). item in the dtv dummy argument.

NOTE 4 The user’s procedure might choose to interpret an element of the v_list argument as a field width, but this is not required. If it does, it would be appropriate to fill an output field with “*”s if the width is too small. 32 33

9 The iostat argument is used to report whether an error, end-of-record, or end-of-file condition (12.11) occurs.

If an error condition occurs, the defined input/output procedure shall assign a positive value to the iostat

ISO/IEC JTC 1/SC 22/WG5/N2184

251

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

argument. Otherwise, if an end-of-file condition occurs, the defined input procedure shall assign the value of the named constant IOSTAT_END (16.10.2.16) to the iostat argument. Otherwise, if an end-of-record condition occurs, the defined input procedure shall assign the value of the named constant IOSTAT_EOR (16.10.2.17) to iostat. Otherwise, the defined input/output procedure shall assign the value zero to the iostat argument.

5 6 7

10 If the defined input/output procedure returns a nonzero value for the iostat argument, the procedure shall also

return an explanatory message in the iomsg argument. Otherwise, the procedure shall not change the value of the iomsg argument. NOTE 5 The values of the iostat and iomsg arguments set in a defined input/output procedure need not be passed to all of the parent data transfer statements.

8 9 10

11 If the iostat argument of the defined input/output procedure has a nonzero value when that procedure returns,

11 12

12 While a parent READ statement is active, an input/output statement shall not read from any external unit other

13 14 15

13 While a parent WRITE or PRINT statement is active, an input/output statement shall not perform output to

16

14 While a parent data transfer statement is active, a data transfer statement that specifies an internal file is

17

and the processor therefore terminates execution of the program as described in 12.11, the processor shall make the value of the iomsg argument available in a processor-dependent manner. than the one specified by the unit dummy argument and shall not perform output to any external unit. any external unit other than the one specified by the unit dummy argument and shall not read from any external unit. permitted.

18 19

15 OPEN, CLOSE, BACKSPACE, ENDFILE, and REWIND statements shall not be executed while a parent data

20 21 22

16 A defined input/output procedure may use a format specification with a DT edit descriptor for handling a

23 24 25

17 Because a child data transfer statement does not position the file prior to data transfer, the child data transfer

26 27

18 The edit descriptors T and TL used on unit by a child data transfer statement shall not cause the file to be

transfer statement is active. component of the derived type that is itself of a derived type. A child data transfer statement that is a list directed or namelist input/output statement may contain a list item of derived type. statement starts transferring data from where the file was positioned by the parent data transfer statement’s most recently processed effective item or edit descriptor. This is not necessarily at the beginning of a record. positioned before the file position at the time the defined input/output procedure was invoked. NOTE 6 A defined input/output procedure could use INQUIRE to determine the settings of BLANK=, PAD=, ROUND=, DECIMAL=, and DELIM= for an external unit. The INQUIRE statement provides values as specified in 12.10.

28

19 Neither a parent nor child data transfer statement shall be asynchronous.

29 30 31

20 A defined input/output procedure, and any procedures invoked therefrom, shall not define, nor cause to become

undefined, any storage unit referenced by any input/output list item, the corresponding format, or any specifier in any active parent data transfer statement, except through the dtv argument. NOTE 7 A data transfer statement with an ID=, POS=, or REC= specifier cannot be a child data transfer statement in a standard-conforming program.

252

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 8 A simple example of derived type formatted output follows. The derived type variable chairman has two components. The type and an associated write formatted procedure are defined in a module so as to be accessible from wherever they might be needed. It would also be possible to check that iotype indeed has the value ’DT’ and to set iostat and iomsg accordingly. MODULE p TYPE :: person CHARACTER (LEN=20) :: name INTEGER :: age CONTAINS PROCEDURE,PRIVATE :: pwf GENERIC :: WRITE(FORMATTED) => pwf END TYPE person CONTAINS SUBROUTINE pwf (dtv,unit,iotype,vlist,iostat,iomsg) ! argument definitions CLASS(person), INTENT(IN) :: dtv INTEGER, INTENT(IN) :: unit CHARACTER (LEN=*), INTENT(IN) :: iotype INTEGER, INTENT(IN) :: vlist(:) INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg ! local variable CHARACTER (LEN=9) :: pfmt ! ! !

vlist(1) and (2) are to be used as the field widths of the two components of the derived type variable. First set up the format to be used for output. WRITE(pfmt,’(A,I2,A,I2,A)’ ) ’(A’, vlist(1), ’,I’, vlist(2), ’)’

!

now the basic output statement WRITE(unit, FMT=pfmt, IOSTAT=iostat) dtv%name, dtv%age END SUBROUTINE pwf

END MODULE p PROGRAM committee USE p INTEGER id, members TYPE (person) :: chairman ... WRITE(6, FMT="(I2, DT (15,6), I5)" ) id, chairman, members ! this writes a record with four fields, with lengths 2, 15, 6, 5 ! respectively END PROGRAM NOTE 9 In the following example, the variables of the derived type node form a linked list, with a single value at each node. The subroutine pwf is used to write the values in the list, one per line.

ISO/IEC JTC 1/SC 22/WG5/N2184

253

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 9 (cont.) MODULE p TYPE node INTEGER :: value = 0 TYPE (NODE), POINTER :: next_node => NULL ( ) CONTAINS PROCEDURE,PRIVATE :: pwf GENERIC :: WRITE(FORMATTED) => pwf END TYPE node CONTAINS SUBROUTINE pwf (dtv,unit,iotype,vlist,iostat,iomsg) ! Write the chain of values, each on a separate line in I9 format. CLASS(node), INTENT(IN) :: dtv INTEGER, INTENT(IN) :: unit CHARACTER (LEN=*), INTENT(IN) :: iotype INTEGER, INTENT(IN) :: vlist(:) INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg WRITE(unit,’(i9 /)’, IOSTAT = iostat) dtv%value IF(iostat/=0) RETURN IF(ASSOCIATED(dtv%next_node)) WRITE(unit,’(dt)’, IOSTAT=iostat) dtv%next_node END SUBROUTINE pwf END MODULE p

1

12.6.4.8.4

Resolving defined input/output procedure references

2 3 4 5

1 A suitable generic interface for defined input/output of an effective item is one that has a defined-io-generic-spec

6 7

2 When an effective item (12.6.3) that is of derived type is encountered during a data transfer, defined input/output

that is appropriate to the direction (read or write) and form (formatted or unformatted) of the data transfer as specified in 12.6.4.8.2, and has a specific interface whose dtv argument is compatible with the effective item according to the rules for argument association in 15.5.2.4. occurs if both of the following conditions are true. (1)

8 9

The circumstances of the input/output are such that defined input/output is permitted; that is, either

10 11

(a)

12 13

(b) (2)

14

A suitable defined input/output procedure is available; that is, either (a) (b)

15 16

the transfer was initiated by a list-directed, namelist, or unformatted input/output statement, or a format specification is supplied for the data transfer statement, and the edit descriptor corresponding to the effective item is a DT edit descriptor.

the declared type of the effective item has a suitable generic type-bound procedure, or a suitable generic interface is accessible.

17 18 19

3 If (2a) is true, the procedure referenced is determined as for explicit type-bound procedure references (15.5); that

20

4 If (2a) is false and (2b) is true, the reference is to the procedure identified by the appropriate specific interface

is, the binding with the appropriate specific interface is located in the declared type of the effective item, and the corresponding binding in the dynamic type of the effective item is selected.

254

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

in the interface block.

2

12.6.5

3 4 5 6 7 8 9 10 11 12

WD 1539-1

J3/21-007r1

Termination of data transfer statements

1 Termination of a data transfer statement occurs when

• format processing encounters a colon or data edit descriptor and there are no remaining elements in the input-item-list or output-item-list, • unformatted or list-directed data transfer exhausts the input-item-list or output-item-list, • namelist output exhausts the namelist-group-object-list, • an error condition occurs, • an end-of-file condition occurs, • a slash (/) is encountered as a value separator (13.10, 13.11) in the record being read during list-directed or namelist input, or • an end-of-record condition occurs during execution of a nonadvancing input statement (12.11).

13

12.7

Waiting on pending data transfer

14

12.7.1

Wait operation

15

1 Execution of an asynchronous data transfer statement in which neither an error, end-of-record, nor end-of-file

16 17 18 19

condition occurs initiates a pending data transfer operation. There may be multiple pending data transfer operations for the same or multiple units simultaneously. A pending data transfer operation remains pending until a corresponding wait operation is performed. A wait operation can be performed by a BACKSPACE, CLOSE, ENDFILE, FLUSH, INQUIRE, PRINT, READ, REWIND, WAIT, or WRITE statement.

20 21

2 A wait operation completes the processing of a pending data transfer operation. Each wait operation completes

22 23 24

3 If the actual data transfer is not yet complete, the wait operation first waits for its completion. If the data

25 26

4 If any error, end-of-file, or end-of-record conditions occur, the applicable actions specified by the IOSTAT=,

27

5 If an error or end-of-file condition occurs during a wait operation for a unit, the processor performs a wait

28

only a single data transfer operation, although a single statement may perform multiple wait operations. transfer operation is an input operation that completed without error, the storage units of the input/output storage sequence then become defined with the values as described in 12.6.2.16 and 12.6.4.5. IOMSG=, ERR=, END=, and EOR= specifiers of the statement that performs the wait operation are taken. operation for all pending data transfer operations for that unit. NOTE 1 Error, end-of-file, and end-of-record conditions can be raised either during the data transfer statement that initiates asynchronous input/output, a subsequent asynchronous data transfer statement for the same unit, or during the wait operation. If raised during a data transfer statement, they trigger actions according to the IOSTAT=, ERR=, END=, and EOR= specifiers of that statement; if raised during the wait operation, the actions are in accordance with the specifiers of the statement that performs the wait operation.

29 30 31 32 33

6 After completion of the wait operation, the data transfer operation and its input/output storage sequence are no

longer considered to be pending.

12.7.2

WAIT statement

1 A WAIT statement performs a wait operation for specified pending asynchronous data transfer operations.

R1222 wait-stmt

is

WAIT (wait-spec-list)

ISO/IEC JTC 1/SC 22/WG5/N2184

255

J3/21-007r1

1 2 3 4

R1223 wait-spec

5 6 7

WD 1539-1

is or or or or or or

2021-05-21

[ UNIT = ] file-unit-number END = label EOR = label ERR = label ID = scalar-int-expr IOMSG = iomsg-variable IOSTAT = stat-variable

8

C1237 No specifier shall appear more than once in a given wait-spec-list.

9 10

C1238 A file-unit-number shall be specified in a wait-spec-list; if the optional characters UNIT= are omitted, the file-unit-number shall be the first item in the wait-spec-list.

11 12

C1239 (R1223) The label in the ERR=, EOR=, or END= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the WAIT statement.

13

2 The IOSTAT=, ERR=, EOR=, END=, and IOMSG= specifiers are described in 12.11.

14 15 16

3 The value of the expression specified in the ID= specifier shall be zero or the identifier of a pending data transfer

17 18 19 20

operation for the specified unit. If the ID= specifier appears, a wait operation for the specified data transfer operation, if any, is performed. If the ID= specifier is omitted, wait operations for all pending data transfers for the specified unit are performed. 4 Execution of a WAIT statement specifying a unit that does not exist, has no file connected to it, or is not open

for asynchronous input/output is permitted, provided that the WAIT statement has no ID= specifier; such a WAIT statement does not cause an error or end-of-file condition to occur. NOTE 1 An EOR= specifier has no effect if the pending data transfer operation is not a nonadvancing read. An END= specifier has no effect if the pending data transfer operation is not a READ.

21

12.8

File positioning statements

22

12.8.1

Syntax

23

R1224 backspace-stmt

is BACKSPACE file-unit-number or BACKSPACE ( position-spec-list )

25 26

R1225 endfile-stmt

is ENDFILE file-unit-number or ENDFILE ( position-spec-list )

27 28

R1226 rewind-stmt

is REWIND file-unit-number or REWIND ( position-spec-list )

24

29

1 A unit that is connected for direct access shall not be referred to by a BACKSPACE, ENDFILE, or REWIND

30 31 32

statement. A unit that is connected for unformatted stream access shall not be referred to by a BACKSPACE statement. A unit that is connected with an ACTION= specifier having the value READ shall not be referred to by an ENDFILE statement.

33 34 35

R1227 position-spec

36

is or or or

37

C1240 No specifier shall appear more than once in a given position-spec-list.

38

C1241 A file-unit-number shall be specified in a position-spec-list; if the optional characters UNIT= are omitted,

256

[ UNIT = ] file-unit-number IOMSG = iomsg-variable IOSTAT = stat-variable ERR = label

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

J3/21-007r1

the file-unit-number shall be the first item in the position-spec-list.

1 2 3

WD 1539-1

C1242 (R1227) The label in the ERR= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the file positioning statement.

4

2 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.

5

3 Execution of a file positioning statement performs a wait operation for all pending asynchronous data transfer

6

operations for the specified unit.

7

12.8.2

8 9 10

BACKSPACE statement

1 Execution of a BACKSPACE statement causes the file connected to the specified unit to be positioned before

the current record if there is a current record, or before the preceding record if there is no current record. If the file is at its initial point, the position of the file is not changed. NOTE 1 If the preceding record is an endfile record, the file is positioned before the endfile record.

11 12

2 If a BACKSPACE statement causes the implicit writing of an endfile record, the file is positioned before the

13

3 Backspacing a file that is connected but does not exist is prohibited.

14

4 Backspacing over records written using list-directed or namelist formatting is prohibited.

record that precedes the endfile record.

NOTE 2 An example of a BACKSPACE statement is: BACKSPACE (10, IOSTAT = N)

15

12.8.3

ENDFILE statement

16 17 18 19

1 Execution of an ENDFILE statement for a file connected for sequential access writes an endfile record as the next

20 21 22

2 After execution of an ENDFILE statement for a file connected for sequential access, a BACKSPACE or REWIND

23 24 25

3 Execution of an ENDFILE statement for a file connected for stream access causes the terminal point of the file

26 27 28

record of the file. The file is then positioned after the endfile record, which becomes the last record of the file. If the file can also be connected for direct access, only those records before the endfile record are considered to have been written. Thus, only those records shall be read during subsequent direct access connections to the file. statement shall be used to reposition the file prior to execution of any data transfer input/output statement or ENDFILE statement. to become equal to the current file position. Only file storage units before the current position are considered to have been written; thus only those file storage units shall be subsequently read. Subsequent stream output statements may be used to write further data to the file. 4 Execution of an ENDFILE statement for a file that is connected but does not exist creates the file; if the file is

connected for sequential access, it is created prior to writing the endfile record. NOTE 1 An example of an ENDFILE statement is: ENDFILE K

ISO/IEC JTC 1/SC 22/WG5/N2184

257

J3/21-007r1

1 2

12.8.4

WD 1539-1

2021-05-21

REWIND statement

1 Execution of a REWIND statement causes the specified file to be positioned at its initial point.

NOTE 1 If the file is already positioned at its initial point, execution of this statement has no effect on the position of the file. 3 4

2 Execution of a REWIND statement for a file that is connected but does not exist is permitted and has no effect

on any file. NOTE 2 An example of a REWIND statement is: REWIND 10

5

12.9

FLUSH statement

6 7

R1228 flush-stmt

is FLUSH file-unit-number or FLUSH ( flush-spec-list )

8 9 10

R1229 flush-spec

11

is or or or

12

C1243 No specifier shall appear more than once in a given flush-spec-list.

13 14

C1244 A file-unit-number shall be specified in a flush-spec-list; if the optional characters UNIT= are omitted from the unit specifier, the file-unit-number shall be the first item in the flush-spec-list.

15 16

C1245 (R1229) The label in the ERR= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the FLUSH statement.

[UNIT =] file-unit-number IOSTAT = stat-variable IOMSG = iomsg-variable ERR = label

17

1 The IOSTAT=, IOMSG= and ERR= specifiers are described in 12.11.

18 19 20

2 Execution of a FLUSH statement causes data written to an external file to be available to other processes, or

21 22

3 Execution of a FLUSH statement for a file that is connected but does not exist is permitted and has no effect on

23

4 Execution of a FLUSH statement performs a wait operation for all pending asynchronous data transfer operations

24

causes data placed in an external file by means other than Fortran to be available to a READ statement. These actions are processor dependent. any file. A FLUSH statement has no effect on file position. for the specified unit. NOTE 1 Because this document does not specify the mechanism of file storage, the exact meaning of the flush operation is not precisely defined. It is expected that the flush operation will make all data written to a file available to other processes or devices, or make data recently added to a file by other processes or devices available to the program via a subsequent read operation. This is commonly called “flushing input/output buffers”. NOTE 2 An example of a FLUSH statement is: FLUSH (10, IOSTAT = N)

258

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

12.10

File inquiry statement

2

12.10.1

Forms of the INQUIRE statement

3 4 5 6 7

J3/21-007r1

1 The INQUIRE statement can be used to inquire about properties of a particular named file, of the connection

to a particular unit, or the number of file storage units required for an output list. There are three forms of the INQUIRE statement: inquire by file, which uses the FILE= specifier, inquire by unit, which uses the UNIT= specifier, and inquire by output list, which uses only the IOLENGTH= specifier. Assignments to specifier variables are converted, truncated, or padded according to the rules of intrinsic assignment.

8 9

2 For inquiry by unit, the unit specified need not exist or be connected to a file. If it is connected to a file, the

10 11

3 For inquiry by file, the file specified need not exist or be connected to a unit. If it is connected to a unit, the

12

4 An INQUIRE statement may be executed before, while, or after a file is connected to a unit. All values assigned

inquiry is being made about the connection and about the file connected. inquiry is being made about the connection as well as about the file.

13

by an INQUIRE statement are those that are current at the time the statement is executed.

14 15 16

R1230 inquire-stmt

is INQUIRE ( inquire-spec-list ) or INQUIRE ( IOLENGTH = scalar-int-variable ) output-item-list

NOTE 1 Examples of INQUIRE statements are: INQUIRE (IOLENGTH = IOL) A (1:N) INQUIRE (UNIT = JOAN, OPENED = LOG_01, NAMED = LOG_02, & FORM = CHAR_VAR, IOSTAT = IOS)

17

12.10.2

Inquiry specifiers

18

12.10.2.1

Syntax

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

1 Unless constrained, the following inquiry specifiers may be used in either of the inquire by file or inquire by unit

forms of the INQUIRE statement. R1231 inquire-spec

is or or or or or or or or or or or or or or or or or or or

[ UNIT = ] file-unit-number FILE = file-name-expr ACCESS = scalar-default-char-variable ACTION = scalar-default-char-variable ASYNCHRONOUS = scalar-default-char-variable BLANK = scalar-default-char-variable DECIMAL = scalar-default-char-variable DELIM = scalar-default-char-variable DIRECT = scalar-default-char-variable ENCODING = scalar-default-char-variable ERR = label EXIST = scalar-logical-variable FORM = scalar-default-char-variable FORMATTED = scalar-default-char-variable ID = scalar-int-expr IOMSG = iomsg-variable IOSTAT = stat-variable LEADING_ZERO = scalar-default-char-variable NAME = scalar-default-char-variable NAMED = scalar-logical-variable

ISO/IEC JTC 1/SC 22/WG5/N2184

259

J3/21-007r1

WD 1539-1

2021-05-21

17

or or or or or or or or or or or or or or or or or

18

C1246 No specifier shall appear more than once in a given inquire-spec-list.

19

C1247 An inquire-spec-list shall contain one FILE= specifier or one file-unit-number, but not both.

20 21

C1248 In the inquire by unit form of the INQUIRE statement, if the optional characters UNIT= are omitted, the file-unit-number shall be the first item in the inquire-spec-list.

22

C1249 If an ID= specifier appears in an inquire-spec-list, a PENDING= specifier shall also appear.

23 24

C1250 (R1229) The label in the ERR= specifier shall be the statement label of a branch target statement that appears in the same inclusive scope as the INQUIRE statement.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

NEXTREC = scalar-int-variable NUMBER = scalar-int-variable OPENED = scalar-logical-variable PAD = scalar-default-char-variable PENDING = scalar-logical-variable POS = scalar-int-variable POSITION = scalar-default-char-variable READ = scalar-default-char-variable READWRITE = scalar-default-char-variable RECL = scalar-int-variable ROUND = scalar-default-char-variable SEQUENTIAL = scalar-default-char-variable SIGN = scalar-default-char-variable SIZE = scalar-int-variable STREAM = scalar-default-char-variable UNFORMATTED = scalar-default-char-variable WRITE = scalar-default-char-variable

25

2 If file-unit-number identifies an internal unit (12.6.4.8.2), an error condition occurs.

26 27

3 When a returned value of a specifier other than the NAME= specifier is of type character, the value returned is

28

4 If an error condition occurs during execution of an INQUIRE statement, all of the inquiry specifier variables

29 30 31 32 33 34 35 36 37 38 39 40 41 42

in upper case. become undefined, except for variables in the IOSTAT= and IOMSG= specifiers (if any). 5 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.

12.10.2.2

FILE= specifier in the INQUIRE statement

1 The value of the file-name-expr in the FILE= specifier specifies the name of the file being inquired about. The

named file need not exist or be connected to a unit. The value of the file-name-expr shall be of a form acceptable to the processor as a file name. Any trailing blanks are ignored. The interpretation of case is processor dependent. 12.10.2.3

ACCESS= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the ACCESS= specifier is assigned the value SEQUENTIAL if the connection

is for sequential access, DIRECT if the connection is for direct access, or STREAM if the connection is for stream access. If there is no connection, it is assigned the value UNDEFINED. 12.10.2.4

ACTION= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the ACTION= specifier is assigned the value READ if the connection is for

input only, WRITE if the connection is for output only, and READWRITE if the connection is for both input and output. If there is no connection, the scalar-default-char-variable is assigned the value UNDEFINED.

260

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

12.10.2.5

WD 1539-1

J3/21-007r1

ASYNCHRONOUS= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the ASYNCHRONOUS= specifier is assigned the value YES if the connection

4

allows asynchronous input/output; it is assigned the value NO if the connection does not allow asynchronous input/output. If there is no connection, the scalar-default-char-variable is assigned the value UNDEFINED.

5

12.10.2.6

6 7 8

BLANK= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the BLANK= specifier is assigned the value ZERO or NULL, corresponding

9

to the blank interpretation mode in effect for a connection for formatted input/output. If there is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED.

10

12.10.2.7

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

DECIMAL= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the DECIMAL= specifier is assigned the value COMMA or POINT, corres-

ponding to the decimal edit mode in effect for a connection for formatted input/output. If there is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED. 12.10.2.8

DELIM= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the DELIM= specifier is assigned the value APOSTROPHE, QUOTE, or

NONE, corresponding to the delimiter mode in effect for a connection for formatted input/output. If there is no connection or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED. 12.10.2.9

DIRECT= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the DIRECT= specifier is assigned the value YES if DIRECT is included in

the set of allowed access methods for the file, NO if DIRECT is not included in the set of allowed access methods for the file, and UNKNOWN if the processor is unable to determine whether DIRECT is included in the set of allowed access methods for the file or if the unit identified by file-unit-number is not connected to a file. 12.10.2.10

ENCODING= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the ENCODING= specifier is assigned the value UTF-8 if the connection is

for formatted input/output with an encoding form of UTF-8, and is assigned the value UNDEFINED if the connection is for unformatted input/output. If there is no connection, it is assigned the value UTF-8 if the processor is able to determine that the encoding form of the file is UTF-8; if the processor is unable to determine the encoding form of the file or if the unit identified by file-unit-number is not connected to a file, the variable is assigned the value UNKNOWN. NOTE 1 The value assigned could be something other than UTF-8, UNDEFINED, or UNKNOWN if the processor supports other specific encoding forms (e.g. UTF-16BE).

32 33 34 35 36 37 38

12.10.2.11

EXIST= specifier in the INQUIRE statement

1 Execution of an INQUIRE by file statement causes the scalar-logical-variable in the EXIST= specifier to be

assigned the value true if there exists a file with the specified name; otherwise, false is assigned. Execution of an INQUIRE by unit statement causes true to be assigned if the specified unit exists; otherwise, false is assigned. 12.10.2.12

FORM= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the FORM= specifier is assigned the value FORMATTED if the connection

is for formatted input/output, and is assigned the value UNFORMATTED if the connection is for unformatted

ISO/IEC JTC 1/SC 22/WG5/N2184

261

J3/21-007r1

WD 1539-1

1

input/output. If there is no connection, it is assigned the value UNDEFINED.

2

12.10.2.13

2021-05-21

FORMATTED= specifier in the INQUIRE statement

3

1 The scalar-default-char-variable in the FORMATTED= specifier is assigned the value YES if FORMATTED is

4 5 6

included in the set of allowed forms for the file, NO if FORMATTED is not included in the set of allowed forms for the file, and UNKNOWN if the processor is unable to determine whether FORMATTED is included in the set of allowed forms for the file or if the unit identified by file-unit-number is not connected to a file.

7

12.10.2.14

8

ID= specifier in the INQUIRE statement

1 The value of the expression specified in the ID= specifier shall be the identifier of a pending data transfer operation

9

for the specified unit. This specifier interacts with the PENDING= specifier (12.10.2.22).

10

12.10.2.15

11 12

LEADING_ZERO= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the LEADING_ZERO= specifier is assigned the value PRINT, SUPPRESS,

13 14

or PROCESSOR_DEFINED, corresponding to the leading zero mode in effect for a connection for formatted input/output. If there is no connection, or if the connection is not for formatted input/output, the scalar-defaultchar-variable is assigned the value UNDEFINED.

15

12.10.2.16

16 17 18

NAME= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the NAME= specifier is assigned the value of the name of the file if the file

has a name; otherwise, it becomes undefined. The value assigned shall be suitable for use as the value of the file-name-expr in the FILE= specifier in an OPEN statement. NOTE 1 If this specifier appears in an INQUIRE by file statement, its value is not necessarily the same as the name given in the FILE= specifier. The processor could assign a file name qualified by a user identification, device, directory, or other relevant information.

19 20 21 22 23 24 25 26 27

2 The case of the characters assigned to scalar-default-char-variable is processor dependent.

12.10.2.17

NAMED= specifier in the INQUIRE statement

1 The scalar-logical-variable in the NAMED= specifier is assigned the value true if the file has a name; otherwise,

it is assigned the value false. 12.10.2.18

NEXTREC= specifier in the INQUIRE statement

1 The scalar-int-variable in the NEXTREC= specifier is assigned the value n + 1, where n is the record number of

28 29

the last record read from or written to the connection for direct access. If there is a connection but no records have been read or written since the connection, the scalar-int-variable is assigned the value 1. If there is no connection, the connection is not for direct access, or the position is indeterminate because of a previous error condition, the scalar-int-variable becomes undefined. If there are pending data transfer operations for the specified unit, the value assigned is computed as if all the pending data transfers had already completed.

30

12.10.2.19

31 32 33 34 35

NUMBER= specifier in the INQUIRE statement

1 Execution of an INQUIRE by file statement causes the scalar-int-variable in the NUMBER= specifier to be

assigned the value of the external unit number of the unit that is connected to the file. If more than one unit on an image is connected to the file, which of the connected external unit numbers is assigned to the scalar-intvariable is processor dependent. If there is no unit connected to the file, the value −1 is assigned. Execution of an INQUIRE by unit statement causes the scalar-int-variable to be assigned the value of file-unit-number.

262

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

12.10.2.20

WD 1539-1

J3/21-007r1

OPENED= specifier in the INQUIRE statement

1 Execution of an INQUIRE by file statement causes the scalar-logical-variable in the OPENED= specifier to be

4 5

assigned the value true if the file specified is connected to a unit; otherwise, false is assigned. Execution of an INQUIRE by unit statement causes the scalar-logical-variable to be assigned the value true if the specified unit is connected to a file; otherwise, false is assigned.

6

12.10.2.21

7 8

PAD= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the PAD= specifier is assigned the value YES or NO, corresponding to the

9

pad mode in effect for a connection for formatted input/output. If there is no connection or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED.

10

12.10.2.22

PENDING= specifier in the INQUIRE statement

11 12 13

1 The PENDING= specifier is used to determine whether previously pending asynchronous data transfers are

14

2 If an ID= specifier appears and the specified data transfer operation is complete, then the variable specified in

15 16

the PENDING= specifier is assigned the value false and the INQUIRE statement performs the wait operation for the specified data transfer.

17 18 19

3 If the ID= specifier is omitted and all previously pending data transfer operations for the specified unit are

20

4 In all other cases, the variable specified in the PENDING= specifier is assigned the value true, no wait operations

21 22

are performed, and the previously pending data transfers remain pending after the execution of the INQUIRE statement.

complete. A data transfer operation is previously pending if it is pending at the beginning of execution of the INQUIRE statement.

complete, then the variable specified in the PENDING= specifier is assigned the value false and the INQUIRE statement performs wait operations for all previously pending data transfers for the specified unit.

NOTE 1 The processor has considerable flexibility in defining when it considers a transfer to be complete. Any of the following approaches could be used: • The INQUIRE statement could consider an asynchronous data transfer to be incomplete until after the corresponding wait operation. In this case PENDING= would always return true unless there were no previously pending data transfers for the unit. • The INQUIRE statement could wait for all specified data transfers to complete and then always return false for PENDING=. • The INQUIRE statement could actually test the state of the specified data transfer operations.

23 24 25 26 27 28 29

12.10.2.23

POS= specifier in the INQUIRE statement

1 The scalar-int-variable in the POS= specifier is assigned the number of the file storage unit immediately following

30

the current position of a file connected for stream access. If the file is positioned at its terminal position, the variable is assigned a value one greater than the number of the highest-numbered file storage unit in the file. If there are pending data transfer operations for the specified unit, the value assigned is computed as if all the pending data transfers had already completed. If there is no connection, the file is not connected for stream access, or if the position of the file is indeterminate because of previous error conditions, the variable becomes undefined.

31

12.10.2.24

32 33

POSITION= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the POSITION= specifier is assigned the value REWIND if the connection

was opened for positioning at its initial point, APPEND if the connection was opened for positioning before its

ISO/IEC JTC 1/SC 22/WG5/N2184

263

J3/21-007r1

WD 1539-1

2021-05-21

5 6

endfile record or at its terminal point, and ASIS if the connection was opened without changing its position. If there is no connection or if the file is connected for direct access, the scalar-default-char-variable is assigned the value UNDEFINED. If the file has been repositioned since the connection, the scalar-default-char-variable is assigned a processor-dependent value, which shall not be REWIND unless the file is positioned at its initial point and shall not be APPEND unless the file is positioned so that its endfile record is the next record or at its terminal point if it has no endfile record.

7

12.10.2.25

1 2 3 4

8 9 10

READ= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the READ= specifier is assigned the value YES if READ is included in the

11

set of allowed actions for the file, NO if READ is not included in the set of allowed actions for the file, and UNKNOWN if the processor is unable to determine whether READ is included in the set of allowed actions for the file or if the unit identified by file-unit-number is not connected to a file.

12

12.10.2.26

13 14 15 16 17 18 19 20 21

READWRITE= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the READWRITE= specifier is assigned the value YES if READWRITE is

included in the set of allowed actions for the file, NO if READWRITE is not included in the set of allowed actions for the file, and UNKNOWN if the processor is unable to determine whether READWRITE is included in the set of allowed actions for the file or if the unit identified by file-unit-number is not connected to a file. 12.10.2.27

RECL= specifier in the INQUIRE statement

1 The scalar-int-variable in the RECL= specifier is assigned the value of the record length of a connection for direct

22 23

access, or the value of the maximum record length of a connection for sequential access. If the connection is for formatted input/output, the length is the number of characters for all records that contain only characters of default kind. If the connection is for unformatted input/output, the length is measured in file storage units. If there is no connection, the scalar-int-variable is assigned the value −1, and if the connection is for stream access, the scalar-int-variable is assigned the value −2.

24

12.10.2.28

25 26 27

ROUND= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the ROUND= specifier is assigned the value UP, DOWN, ZERO, NEAREST,

28 29 30

COMPATIBLE, or PROCESSOR_DEFINED, corresponding to the input/output rounding mode in effect for a connection for formatted input/output. If there is no connection or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED. The processor shall return the value PROCESSOR_DEFINED only if the behavior of the input/output rounding mode is different from that of the UP, DOWN, ZERO, NEAREST, and COMPATIBLE modes.

31

12.10.2.29

32 33

SEQUENTIAL= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the SEQUENTIAL= specifier is assigned the value YES if SEQUENTIAL is

34 35 36

included in the set of allowed access methods for the file, NO if SEQUENTIAL is not included in the set of allowed access methods for the file, and UNKNOWN if the processor is unable to determine whether SEQUENTIAL is included in the set of allowed access methods for the file or if the unit identified by file-unit-number is not connected to a file.

37

12.10.2.30

SIGN= specifier in the INQUIRE statement

38

1 The scalar-default-char-variable in the SIGN= specifier is assigned the value PLUS, SUPPRESS, or PRO-

39 40 41

CESSOR_DEFINED, corresponding to the sign mode in effect for a connection for formatted input/output. If there is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED.

264

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

12.10.2.31

WD 1539-1

J3/21-007r1

SIZE= specifier in the INQUIRE statement

1 The scalar-int-variable in the SIZE= specifier is assigned the size of the file in file storage units. If the file size

cannot be determined or if the unit identified by file-unit-number is not connected to a file, the variable is assigned the value −1.

5 6

2 For a file that can be connected for stream access, the file size is the number of the highest-numbered file storage

7 8

3 For a file that can be connected for sequential or direct access, the file size may be different from the number of

9

4 If there are pending data transfer operations for the specified unit, the value assigned is computed as if all the

unit in the file. storage units implied by the data in the records; the exact relationship is processor dependent.

10

pending data transfers had already completed.

11

12.10.2.32

12 13 14

STREAM= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the STREAM= specifier is assigned the value YES if STREAM is included in

15

the set of allowed access methods for the file, NO if STREAM is not included in the set of allowed access methods for the file, and UNKNOWN if the processor is unable to determine whether STREAM is included in the set of allowed access methods for the file or if the unit identified by file-unit-number is not connected to a file.

16

12.10.2.33

17 18 19 20

UNFORMATTED= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the UNFORMATTED= specifier is assigned the value YES if UNFORMAT-

21

TED is included in the set of allowed forms for the file, NO if UNFORMATTED is not included in the set of allowed forms for the file, and UNKNOWN if the processor is unable to determine whether UNFORMATTED is included in the set of allowed forms for the file or if the unit identified by file-unit-number is not connected to a file.

22

12.10.2.34

23 24 25 26 27

WRITE= specifier in the INQUIRE statement

1 The scalar-default-char-variable in the WRITE= specifier is assigned the value YES if WRITE is included in the

set of allowed actions for the file, NO if WRITE is not included in the set of allowed actions for the file, and UNKNOWN if the processor is unable to determine whether WRITE is included in the set of allowed actions for the file or if the unit identified by file-unit-number is not connected to a file.

12.10.3

Inquire by output list

28

1 The scalar-int-variable in the IOLENGTH= specifier is assigned the processor-dependent number of file storage

29 30 31 32 33

units that would be required to store the data of the output list in an unformatted file. The value shall be suitable as a RECL= specifier in an OPEN statement that connects a file for unformatted direct access if data will be read from or written to the file using data transfer statements with an input/output list that specifies transfer of a sequence of objects having the same types, type parameters, and extents, in the same order as the output list in the INQUIRE statement.

34

2 The output list in an INQUIRE statement shall not contain any derived-type list items that require a defined

35 36

input/output procedure as described in 12.6.3. If a derived-type list item appears in the output list, the value returned for the IOLENGTH= specifier assumes that no defined input/output procedure will be invoked.

37

12.11

Error, end-of-record, and end-of-file conditions

38

12.11.1

Occurrence of input/output conditions

39 40

1 The set of input/output error conditions is processor dependent. Except as otherwise specified, when an error

condition occurs or is detected is processor dependent.

ISO/IEC JTC 1/SC 22/WG5/N2184

265

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

2 An end-of-record condition occurs when a nonadvancing input statement attempts to transfer data from a position

4

3 An end-of-file condition occurs when

5 6 7

8 9 10

beyond the end of the current record, unless the file is a stream file and the current record is at the end of the file (an end-of-file condition occurs instead).

• an endfile record is encountered during the reading of a file connected for sequential access, • an attempt is made to read a record beyond the end of an internal file, or • an attempt is made to read beyond the end of a stream file. 4 An end-of-file condition may occur at the beginning of execution of an input statement. An end-of-file condition

11

also may occur during execution of a formatted input statement when more than one record is required by the interaction of the input list and the format. An end-of-file condition also may occur during execution of a stream input statement.

12

12.11.2

Error conditions and the ERR= specifier

13 14

1 If an error condition occurs during execution of an input/output statement, the position of the file becomes

15 16 17

2 If an error condition occurs during execution of an input/output statement that contains neither an ERR= nor

indeterminate. IOSTAT= specifier, error termination is initiated. If an error condition occurs during execution of an input/output statement that contains either an ERR= specifier or an IOSTAT= specifier then: (1) (2)

18 19 20 21 22

(3)

23

(4) (5)

24 25

(6)

26 27 28 29 30

(7)

31

12.11.3

32 33 34 35

processing of the input/output list, if any, terminates; if the statement is a data transfer statement or the error condition occurs during a wait operation, all do-variables in the statement that initiated the transfer become undefined; if an IOSTAT= specifier appears, the stat-variable in the IOSTAT= specifier becomes defined as specified in 12.11.5; if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 12.11.6; if the statement is a READ statement and it contains a SIZE= specifier, the scalar-int-variable in the SIZE= specifier becomes defined as specified in 12.6.2.16; if the statement is a READ statement or the error condition occurs in a wait operation for a transfer initiated by a READ statement, all input items or namelist group objects in the statement that initiated the transfer become undefined; if an ERR= specifier appears, a branch to the statement labeled by the label in the ERR= specifier occurs.

End-of-file condition and the END= specifier

1 If an end-of-file condition occurs during execution of an input/output statement that contains neither an END=

specifier nor an IOSTAT= specifier, error termination is initiated. If an end-of-file condition occurs during execution of an input/output statement that contains either an END= specifier or an IOSTAT= specifier, and an error condition does not occur then: (1) (2)

36 37 38 39 40 41

(3)

42 43

(4)

44 45

(5)

266

processing of the input list, if any, terminates; if the statement is a data transfer statement or the end-of-file condition occurs during a wait operation, all do-variables in the statement that initiated the transfer become undefined; if the statement is an input statement or the end-of-file condition occurs during a wait operation for a transfer initiated by an input statement, all input list items or namelist group objects in the statement that initiated the transfer become undefined; if the file specified in the input statement is an external record file, it is positioned after the endfile record; if an IOSTAT= specifier appears, the stat-variable in the IOSTAT= specifier becomes defined as specified in 12.11.5;

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9

(6) (7)

12.11.4

End-of-record condition and the EOR= specifier

1 If an end-of-record condition occurs during execution of an input/output statement that contains neither an

EOR= specifier nor an IOSTAT= specifier, error termination is initiated. If an end-of-record condition occurs during execution of an input/output statement that contains either an EOR= specifier or an IOSTAT= specifier, and an error condition does not occur then: (1)

if the pad mode has the value (a)

12

(b)

14 15 16 17 18 19 20 21

J3/21-007r1

if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 12.11.6; if an END= specifier appears, a branch to the statement labeled by the label in the END= specifier occurs.

10 11

13

WD 1539-1

(2) (3) (4) (5) (6) (7)

22 23

(8)

24

12.11.5

YES, the record is padded with blanks to satisfy the effective item (12.6.4.5.3) and corresponding data edit descriptors that require more characters than the record contains, NO, the input list item becomes undefined;

processing of the input list, if any, terminates; if the statement is a data transfer statement or the end-of-record condition occurs during a wait operation, all do-variables in the statement that initiated the transfer become undefined; the file specified in the input statement is positioned after the current record; if an IOSTAT= specifier appears, the stat-variable in the IOSTAT= specifier becomes defined as specified in 12.11.5; if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 12.11.6; if a SIZE= specifier appears, the scalar-int-variable in the SIZE= specifier becomes defined as specified in (12.6.2.16); if an EOR= specifier appears, a branch to the statement labeled by the label in the EOR= specifier occurs.

IOSTAT= specifier

25 26

1 Execution of an input/output statement containing the IOSTAT= specifier causes the stat-variable in the IO-

27

• a zero value if neither an error condition, an end-of-file condition, nor an end-of-record condition occurs, • the processor-dependent positive integer value of the constant IOSTAT_INQUIRE_INTERNAL_UNIT from the intrinsic module ISO_FORTRAN_ENV (16.10.2) if a unit number in an INQUIRE statement identifies an internal file, • a processor-dependent positive integer value different from IOSTAT_INQUIRE_INTERNAL_UNIT if any other error condition occurs, • the processor-dependent negative integer value of the constant IOSTAT_END (16.10.2.16) from the intrinsic module ISO_FORTRAN_ENV if an end-of-file condition occurs and no error condition occurs, • the processor-dependent negative integer value of the constant IOSTAT_EOR (16.10.2.17) from the intrinsic module ISO_FORTRAN_ENV if an end-of-record condition occurs and no error condition or end-of-file condition occurs, or • a processor-dependent negative integer value different from IOSTAT_EOR and IOSTAT_END, if the IOSTAT= specifier appears in a FLUSH statement and the processor does not support the flush operation for the specified unit.

28 29 30 31 32 33 34 35 36 37 38 39 40

STAT= specifier to become defined with

NOTE 1 An end-of-file condition can occur only for sequential or stream input and an end-of-record condition can occur only for nonadvancing input. For example, READ (FMT = "(E8.3)", UNIT = 3, IOSTAT = IOSS) X IF (IOSS < 0) THEN

ISO/IEC JTC 1/SC 22/WG5/N2184

267

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) ! Perform end-of-file processing on the file connected to unit 3. CALL END_PROCESSING ELSE IF (IOSS > 0) THEN ! Perform error processing CALL ERROR_PROCESSING END IF 1 2 3

12.11.6

IOMSG= specifier

1 If an error, end-of-file, or end-of-record condition occurs during execution of an input/output statement, iomsg-

4

variable is assigned an explanatory message, as if by intrinsic assignment. If no such condition occurs, the definition status and value of iomsg-variable are unchanged.

5

12.12

Restrictions on input/output statements

6 7

1 If a unit, or a file connected to a unit, does not have all of the properties required for the execution of certain

8 9 10

2 An input/output statement that is executed while another input/output statement is being executed is a recursive

11

input/output statements, those statements shall not refer to the unit. input/output statement. A recursive input/output statement shall not identify an external unit that is identified by another input/output statement being executed except that a child data transfer statement may identify its parent data transfer statement external unit.

12

3 An input/output statement shall not cause the value of any established format specification to be modified.

13 14

4 A recursive input/output statement shall not modify the value of any internal unit except that a recursive WRITE

15 16

5 The value of a specifier in an input/output statement shall not depend on the definition or evaluation of any other

17 18

statement may modify the internal unit identified by that recursive WRITE statement. specifier in the io-control-spec-list or inquire-spec-list in that statement. The value of an internal-file-variable or of a FMT=, ID=, IOMSG=, IOSTAT=, or SIZE= specifier shall not depend on the value of any input-item or io-implied-do do-variable in the same statement.

19 20 21

6 The value of any subscript or substring bound of a variable that appears in a specifier in an input/output

statement shall not depend on any input-item, io-implied-do do-variable, or on the definition or evaluation of any other specifier in the io-control-spec-list or inquire-spec-list in that statement.

22

7 In a data transfer statement, the variable specified in an IOSTAT=, IOMSG=, or SIZE= specifier, if any, shall

23 24

not be associated with any entity in the data transfer input/output list (12.6.3) or namelist-group-object-list, nor with a do-variable of an io-implied-do in the data transfer input/output list.

25 26 27

8 In a data transfer statement, if a variable specified in an IOSTAT=, IOMSG=, or SIZE= specifier is an array

28

9 A variable that can become defined or undefined as a result of its use in a specifier in an INQUIRE statement,

29

element reference, its subscript values shall not be affected by the data transfer, the io-implied-do processing, or the definition or evaluation of any other specifier in the io-control-spec-list. or any associated entity, shall not appear in another specifier in the same INQUIRE statement. NOTE 1 Restrictions on the evaluation of expressions (10.1.4) prohibit certain side effects.

268

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

13 Input/output editing

2

13.1

J3/21-007r1

Format specifications

3 4

1 A format used in conjunction with a data transfer statement provides information that directs the editing between

the internal representation of data and the characters of a sequence of formatted records.

5

2 A format (12.6.2.2) in a data transfer statement can refer to a FORMAT statement or to a character expression

6 7 8

that contains a format specification. A format specification provides explicit editing information. The format alternatively can be an asterisk (*), which indicates list-directed formatting (13.10). Namelist formatting (13.11) is indicated by specifying a namelist-group-name instead of a format.

9

13.2

Explicit format specification methods

10

13.2.1

FORMAT statement

11

R1301 format-stmt

is

12 13

R1302 format-specification

is ( [ format-items ] ) or ( [ format-items, ] unlimited-format-item )

14

C1301 (R1301) The format-stmt shall be labeled.

15 16 17

FORMAT format-specification

1 Blank characters may precede the initial left parenthesis of the format specification. Additional blank characters

may appear at any point within the format specification, with no effect on the interpretation of the format specification, except within a character string edit descriptor (13.9). NOTE 1 Examples of FORMAT statements are: 5 9

18 19 20

13.2.2

FORMAT (1PE12.4, I10) FORMAT (I12, /, ’ Dates: ’, 2 (2I3, I5))

Character format specification

1 A character expression used as a format in a formatted input/output statement shall evaluate to a character

string whose leading part is a valid format specification. NOTE 1 The format specification begins with a left parenthesis and ends with a right parenthesis.

21 22 23 24 25 26 27 28

2 All character positions up to and including the final right parenthesis of the format specification shall be defined

at the time the data transfer statement is executed, and shall not become redefined or undefined during the execution of the statement. Character positions, if any, following the right parenthesis that ends the format specification need not be defined and may contain any character data with no effect on the interpretation of the format specification. 3 If the format is a character array, it is treated as if all of the elements of the array were specified in array element

order and were concatenated. However, if a format is a character array element, the format specification shall be entirely within that array element.

ISO/IEC JTC 1/SC 22/WG5/N2184

269

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 If a character constant is used as a format in data transfer statement, care needs to be taken that the value of the character constant is a valid format specification. In particular, if a format specification delimited by apostrophes contains a character constant edit descriptor delimited with apostrophes, two apostrophes are needed to delimit the edit descriptor and four apostrophes are needed for each apostrophe that occurs within the edit descriptor. For example, the text: 2 ISN’T 3 can be written by various combinations of output statements and format specifications: WRITE (6, 100) 2, 3 100 FORMAT (1X, I1, 1X, ’ISN’’T’, 1X, I1) WRITE (6, ’(1X, I1, 1X, ’’ISN’’’’T’’, 1X, I1)’) 2, 3 WRITE (6, ’(A)’) ’ 2 ISN’’T 3’ Doubling of internal apostrophes usually can be avoided by using quotation marks to delimit the format specification and doubling of internal quotation marks usually can be avoided by using apostrophes as delimiters.

1

13.3

Form of a format item list

2

13.3.1

Syntax

3

R1303 format-items

is

format-item [ [ , ] format-item ] ...

4

R1304 format-item

is or or or

[ r ] data-edit-desc control-edit-desc char-string-edit-desc [ r ] ( format-items )

8

R1305 unlimited-format-item

is

* ( format-items )

9

R1306 r

is

int-literal-constant

10

C1302 (R1303) The optional comma shall not be omitted except

5 6 7

12

• between a P edit descriptor and an immediately following F, E, EN, ES, EX, D, or G edit descriptor (13.8.6), possibly preceded by a repeat specification,

13

• before a slash edit descriptor when the optional repeat specification does not appear (13.8.2),

14

• after a slash edit descriptor, or

15

• before or after a colon edit descriptor (13.8.3)

11

16

C1303 (R1305) An unlimited-format-item shall contain at least one data edit descriptor.

17

C1304 (R1306) r shall be positive.

18

C1305 (R1306) A kind parameter shall not be specified for r.

19 20 21

1 The integer literal constant r is called a repeat specification.

13.3.2

Edit descriptors

1 An edit descriptor is a data edit descriptor (data-edit-desc), control edit descriptor (control-edit-desc), or character

22

string edit descriptor (char-string-edit-desc).

23 24

R1307 data-edit-desc

270

is I w [ . m ] or B w [ . m ]

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1 2 3 4 5 6 7 8 9 10 11 12 13

or or or or or or or or or or or or or

Ow[. m] Zw[. m] Fw. d Ew. d [Ee] EN w . d [ E e ] ES w . d [ E e ] EX w . d [ E e ] Gw[. d [Ee]] Lw A[w] AT Dw. d DT [ char-literal-constant ] [ ( v-list ) ]

J3/21-007r1

14

R1308 w

is

int-literal-constant

15

R1309 m

is

int-literal-constant

16

R1310 d

is

int-literal-constant

17

R1311 e

is

int-literal-constant

18

R1312 v

is

signed-int-literal-constant

19 20

C1306 (R1308) w shall be zero or positive for the I, B, O, Z, D, E, EN, ES, EX, F, and G edit descriptors. w shall be positive for all other edit descriptors.

21

C1307 (R1307) For the G edit descriptor, d shall be specified if w is not zero.

22

C1308 (R1307) For the G edit descriptor, e shall not be specified if w is zero.

23 24

C1309 (R1307) A kind parameter shall not be specified for the char-literal-constant in the DT edit descriptor, or for w, m, d, e, and v.

25

2 An I, B, O, Z, F, E, EN, ES, EX, G, L, A, AT, D, or DT edit descriptor indicates the manner of editing.

R1313 control-edit-desc

is or or or or or or or or

blank-interp-edit-desc decimal-edit-desc leading-zero-edit-desc position-edit-desc round-edit-desc sign-edit-desc k P : [r ]/

35

R1314 k

is

signed-int-literal-constant

36

C1310 (R1314) A kind parameter shall not be specified for k.

26 27 28 29 30 31 32 33 34

37

3 In k P, k is called the scale factor.

R1315 position-edit-desc

is or or or

Tn TL n TR n nX

42

R1316 n

is

int-literal-constant

43

C1311 (R1316) n shall be positive.

38 39 40 41

ISO/IEC JTC 1/SC 22/WG5/N2184

271

J3/21-007r1

WD 1539-1

1

C1312 (R1316) A kind parameter shall not be specified for n.

2 3

R1317 blank-interp-edit-desc

is BN or BZ

4

R1318 decimal-edit-desc

is DC or DP

6 7 8

R1319 leading-zero-edit-desc

is LZS or LZP or LZ

9 10

R1320 round-edit-desc

is or or or or or

R1321 sign-edit-desc

is SS or SP or S

5

11 12 13 14 15 16 17 18 19

2021-05-21

RU RD RZ RN RC RP

4 A T, TL, TR, X, slash, colon, SS, SP, S, LZS, LZP, LZ, P, BN, BZ, RU, RD, RZ, RN, RC, RP, DC, or DP edit

descriptor indicates the manner of editing. is

20

R1322 char-string-edit-desc

char-literal-constant

21

C1313 (R1322) A kind parameter shall not be specified for the char-literal-constant.

22

5 Each rep-char in a character string edit descriptor shall be capable of representation by the processor.

23

6 A character string edit descriptor provides constant data to be output, and is not valid for input.

24

7 The edit descriptors are without regard to case except within a character string edit descriptor.

25 26 27

28

13.3.3

Fields

1 A field is a part of a record that is read on input or written on output when format control encounters a data

edit descriptor or a character string edit descriptor. The field width is the size in characters of the field.

13.4

Interaction between input/output list and format

29 30 31

1 The start of formatted data transfer using a format specification initiates format control (12.6.4.5.3). Each action

32 33

2 If an input/output list specifies at least one effective item, at least one data edit descriptor shall exist in the

of format control depends on information jointly provided by the next edit descriptor in the format specification and the next effective item in the input/output list, if one exists. format specification. NOTE 1 An empty format specification of the form ( ) can be used only if the input/output list has no effective item (12.6.4.5). A zero length character item is an effective item, but a zero sized array and an implied DO list with an iteration count of zero is not.

34 35

3 A format specification is interpreted from left to right. The exceptions are format items preceded by a repeat

specification r, and format reversion (described below).

272

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

4 A format item preceded by a repeat specification is processed as a list of r items, each identical to the format

item but without the repeat specification and separated by commas. NOTE 2 An omitted repeat specification is treated in the same way as a repeat specification whose value is one.

3 4 5 6 7

5 To each data edit descriptor interpreted in a format specification, there corresponds one effective item specified by

the input/output list (12.6.3), except that an input/output list item of type complex requires the interpretation of two F, E, EN, ES, EX, D, or G edit descriptors. For each control edit descriptor or character edit descriptor, there is no corresponding item specified by the input/output list, and format control communicates information directly with the record.

8 9 10 11

6 Whenever format control encounters a data edit descriptor in a format specification, it determines whether

12 13

7 If format control encounters a colon edit descriptor in a format specification and another effective item is not

14 15 16

8 If format control encounters the rightmost parenthesis of an unlimited format item, control reverts to the leftmost

17

9 If format control encounters the rightmost parenthesis of a complete format specification and another effective

18 19 20 21 22

item is not specified, format control terminates. However, if another effective item is specified, format control then reverts to the beginning of the format item terminated by the last preceding right parenthesis that is not part of a DT edit descriptor. If there is no such preceding right parenthesis, format control reverts to the first left parenthesis of the format specification. If any reversion occurs, the reused portion of the format specification shall contain at least one data edit descriptor. If format control reverts to a parenthesis that is preceded by a repeat specification, the repeat specification is reused. Reversion of format control, of itself, has no effect on the changeable modes. The file is positioned in a manner identical to the way it is positioned when a slash edit descriptor is processed (13.8.2).

23 24 25

there is a corresponding effective item specified by the input/output list. If there is such an item, it transmits appropriately edited information between the item and the record, and then format control proceeds. If there is no such item, format control terminates. specified, format control terminates. parenthesis of that unlimited format item. This reversion of format control has no effect on the changeable modes (12.5.2).

NOTE 3 Example: The format specification: 10 FORMAT (1X, 2(F10.3, I5)) with the output statement WRITE (10,10) 10.1, 3, 4.7, 1, 12.4, 5, 5.2, 6 produces the same output as the format specification: 10 FORMAT (1X, F10.3, I5, F10.3, I5/F10.3, I5, F10.3, I5)

NOTE 4 The effect of an unlimited-format-item is as if its enclosed list were preceded by a very large repeat count. There is no file positioning implied by unlimited-format-item reversion. This can be used to write what is commonly called a comma separated value record. For example, WRITE( 10, ’( "IARRAY =", *( I0, :, ","))’) IARRAY produces a single record with a header and a comma separated list of integer values.

ISO/IEC JTC 1/SC 22/WG5/N2184

273

J3/21-007r1

1

13.5

WD 1539-1

2021-05-21

Positioning by format control

2 3

1 After each data edit descriptor or character string edit descriptor is processed, the file is positioned after the last

4 5

2 After each T, TL, TR, or X edit descriptor is processed, the file is positioned as described in 13.8.1.1. After each

6 7

3 During formatted stream output, processing of an A or AT edit descriptor can cause file positioning to occur

8 9

4 If format control reverts as described in 13.4, the file is positioned in a manner identical to the way it is positioned

10 11

5 During a read operation, any unprocessed characters of the current record are skipped whenever the next record

12

character read or written in the current record. slash edit descriptor is processed, the file is positioned as described in 13.8.2. (13.7.4). when a slash edit descriptor is processed (13.8.2). is read.

13.6

Decimal symbol

13 14 15

1 The decimal symbol is the character that separates the whole and fractional parts in the decimal representation

16 17

2 If the decimal edit mode is COMMA during list-directed input/output, the character used as a value separator

of a real number in an internal or external file. When the decimal edit mode is POINT, the decimal symbol is a decimal point. When the decimal edit mode is COMMA, the decimal symbol is a comma. is a semicolon in place of a comma.

18

13.7

Data edit descriptors

19

13.7.1

Purpose of data edit descriptors

20 21 22 23

1 A data edit descriptor causes the conversion of data to or from its internal representation; during formatted

24

2 During input from a Unicode file,

25 26 27 28

29 30 31 32

33 34 35 36 37 38

stream output, an A or AT data edit descriptor can also cause file positioning. On input, the specified variable becomes defined unless an error condition, an end-of-file condition, or an end-of-record condition occurs. On output, the specified expression is evaluated.

• characters in the record that correspond to an ASCII character variable shall have a position in the ISO 10646 character collating sequence of 127 or less, and • characters in the record that correspond to a default character variable shall be representable as default characters. 3 During input from a non-Unicode file,

• characters in the record that correspond to a character variable shall have the kind of the character variable, and • characters in the record that correspond to a numeric or logical variable shall be default characters. 4 During output to a Unicode file, all characters transmitted to the record are of ISO 10646 character kind. If a

character input/output list item or character string edit descriptor contains a character that is not representable as an ISO 10646 character, the result is processor dependent. 5 During output to a non-Unicode file, characters transmitted to the record as a result of processing a character

string edit descriptor or as a result of evaluating a numeric, logical, or default character data entity, are of default kind.

274

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

13.7.2

Numeric editing

2

13.7.2.1

General rules

3 4 5 6 7

WD 1539-1

J3/21-007r1

1 The I, B, O, Z, F, E, EN, ES, EX, D, and G edit descriptors can be used to specify the input/output of integer,

real, and complex data. As interoperable enum type data is treated as integer for the purposes of input/output (12.6.3), the I, B, O, Z and G edit descriptors can also be used to specify the input/output of enum type data. The I, B, O, and Z edit descriptors can be used to specify input/output of enumeration type data. The following general rules apply.

8 9 10 11

(1)

12 13 14

(2)

15 16 17 18

(3)

19 20

(4)

21 22 23

(5)

24

On input, leading blanks are not significant. When the input field is not an IEEE exceptional specification or hexadecimal-significand number (13.7.2.3.2), the interpretation of blanks, other than leading blanks, is determined by the blank interpretation mode (13.8.7). Plus signs may be omitted. A field containing only blanks is considered to be zero. On input, with F, E, EN, ES, EX, D, and G editing, a decimal symbol appearing in the input field overrides the portion of an edit descriptor that specifies the decimal symbol location. The input field may have more digits than the processor uses to approximate the value of the datum. On output with I, F, E, EN, ES, EX, D, and G editing, the representation of a nonnegative internal value in the field may be prefixed with a plus sign, as controlled by the S, SP, and SS edit descriptors or the processor. The representation of a negative internal value in the field shall be prefixed with a minus sign. On output, the representation is right justified in the field. If the number of characters produced by the editing is smaller than the field width, leading blanks are inserted in the field. On output, if an exponent exceeds its specified or implied width using the E, EN, ES, EX, D, or G edit descriptor, or the number of characters produced exceeds the field width, the processor shall fill the entire field of width w with asterisks. However, the processor shall not produce asterisks if the field width is not exceeded when optional characters are omitted.

NOTE 1 When the sign mode is PLUS, a plus sign is not optional. 25 26 27

(6)

28

(7)

29

13.7.2.2

30 31 32 33

On output, with I, B, O, Z, D, E, EN, ES, EX, F, and G editing, the specified value of the field width w may be zero. In such cases, the processor selects the smallest positive actual field width that does not result in a field filled with asterisks. The specified value of w shall not be zero on input. On output of a real zero value, the digits in the exponent field shall all be zero. Integer editing

1 The Iw and Iw.m edit descriptors indicate that the field to be edited occupies w positions, except when w is zero.

When w is zero, the processor selects the field width. On input, w shall not be zero. The specified input/output list item shall be of type integer or of enumeration type. The G, B, O, and Z edit descriptor also may be used to edit integer data (13.7.5.2.2, 13.7.2.4).

34

2 On input, m has no effect.

35 36 37

3 In the standard form of the input field for the I edit descriptor, the character string is a signed-digit-string (R710),

38

4 The output field for the Iw edit descriptor consists of zero or more leading blanks followed by a minus sign if the

39 40

internal value is negative, or an optional plus sign otherwise, followed by the magnitude of the internal value as a digit-string without leading zeros.

except for the interpretation of blanks. If the input field does not have the standard form and is not acceptable to the processor, an error condition occurs.

NOTE 1 A digit-string always consists of at least one digit.

ISO/IEC JTC 1/SC 22/WG5/N2184

275

J3/21-007r1

1 2 3 4 5 6 7 8

consists of at least m digits. If necessary, sufficient leading zeros are included to achieve the minimum of m digits. The value of m shall not exceed the value of w, except when w is zero. If m is zero and the internal value is zero, the output field consists of only blank characters, regardless of the sign control in effect. When m and w are both zero, and the internal value is zero, one blank character is produced. 6 If the list item for output is of enumeration type, the value output is its ordinal position. If the list item for

input is of enumeration type, the value of the input field shall be positive and less than or equal to the number of enumerators; the value assigned to the list item is the enumeration value with that ordinal position. 13.7.2.3

10

13.7.2.3.1

14

2021-05-21

5 The output field for the Iw.m edit descriptor is the same as for the Iw edit descriptor, except that the digit-string

9

11 12 13

WD 1539-1

Real and complex editing General

1 The F, E, EN, ES, EX, and D edit descriptors specify the editing of real and complex data. An input/output list

item corresponding to an F, E, EN, ES, EX, or D edit descriptor shall be real or complex. The G, B, O, and Z edit descriptors also may be used to edit real and complex data (13.7.5.2.3, 13.7.2.4). 13.7.2.3.2

F editing

15 16 17

1 The Fw.d edit descriptor indicates that the field occupies w positions, except when w is zero in which case the

18 19

2 A lower-case letter is equivalent to the corresponding upper-case letter in an IEEE exceptional specification or

20

3 The standard form of the input field is an IEEE exceptional specification, a hexadecimal-significand number, or

21 22 23 24 25 26

consists of a mantissa optionally followed by an exponent. The form of the mantissa is an optional sign, followed by a string of one or more digits optionally containing a decimal symbol, including any blanks interpreted as zeros. The d has no effect on input if the input field contains a decimal symbol. If the decimal symbol is omitted, the rightmost d digits of the string, with leading zeros assumed if necessary, are interpreted as the fractional part of the value represented. The string of digits may contain more digits than a processor uses to approximate the value. The form of the exponent is one of the following:

processor selects the field width. The fractional part of the field consists of d digits. On input, w shall not be zero. the exponent in a numeric input field.

29

• a sign followed by a digit-string; • the letter E followed by zero or more blanks, followed by a signed-digit-string; • the letter D followed by zero or more blanks, followed by a signed-digit-string.

30

4 An exponent containing a D is processed identically to an exponent containing an E.

27 28

NOTE 1 If the input field does not contain an exponent, the effect is as if the basic form were followed by an exponent with a value of −k, where k is the established scale factor (13.8.6). 31 32 33 34 35 36 37 38

5 An input field that is an IEEE exceptional specification consists of optional blanks, followed by either

• an optional sign, followed by the string ’INF’ or the string ’INFINITY’, or • an optional sign, followed by the string ’NAN’, optionally followed by zero or more alphanumeric characters enclosed in parentheses, optionally followed by blanks. 6 The value specified by ’INF’ or ’INFINITY’ is an IEEE infinity; this form shall not be used if the processor does

not support IEEE infinities for the input variable. The value specified by ’NAN’ is an IEEE NaN; this form shall not be used if the processor does not support IEEE NaNs for the input variable. The NaN value is a quiet NaN if

276

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

the only nonblank characters in the field are ’NAN’ or ’NAN()’; otherwise, the NaN value is processor dependent. The interpretation of a sign in a NaN input field is processor dependent.

3 4

7 An input field that is a hexadecimal-significand number consists of an optional sign, followed by the hexadecimal

5 6 7 8 9 10

indicator which is the digit 0 immediately followed by the letter X, followed by a hexadecimal significand followed by a hexadecimal exponent. A hexadecimal significand is a string of one or more hexadecimal characters optionally containing a decimal symbol. The decimal symbol indicates the position of the hexadecimal point; if no decimal symbol appears, the hexadecimal point implicitly follows the last hexadecimal symbol. A hexadecimal exponent is the letter P followed by a (decimal) signed-digit-string. Embedded blanks are not permitted in a hexadecimalsignificand number; trailing blanks are ignored. The value is equal to the significand multiplied by two raised to the power of the exponent, negated if the optional sign is minus.

11 12

8 If the input field does not have one of the standard forms, and is not acceptable to the processor, an error

13 14 15 16

9 For an internal value that is an IEEE infinity, the output field consists of blanks, if necessary, followed by a minus

17 18 19 20 21 22 23 24

condition occurs. sign for negative infinity or an optional plus sign otherwise, followed by the letters ’Inf’ or ’Infinity’, right justified within the field. The minimum field width required for output of the form ’Inf’ is 3 if no sign is produced, and 4 otherwise. The minimum field width required for output of the form ’Infinity’ is 8 if no sign is produced, and 9 otherwise. If w is greater than or equal to the minimum required for the form ’Infinity’, the form ’Infinity’ is output. If w is zero or w is less than the minimum required for the form ’Infinity’ and greater than or equal to the minimum required for the form ’Inf’, the form ’Inf’ is output. Otherwise (w is greater than zero but less than the minimum required for any form), the field is filled with asterisks. 10 For an internal value that is an IEEE NaN, the output field consists of blanks, if necessary, followed by the

letters ’NaN’ and optionally followed by one to w−5 alphanumeric processor-dependent characters enclosed in parentheses, right justified within the field. If w is greater than zero and less than 3, the field is filled with asterisks. If w is zero, the output field is ’NaN’. NOTE 2 The processor-dependent characters following ’NaN’ might convey additional information about that particular NaN.

25 26 27 28 29

11 For an internal value that is neither an IEEE infinity nor a NaN, the output field consists of blanks, if necessary,

30

followed by a minus sign if the internal value is negative, or an optional plus sign otherwise, followed by a string of digits that contains a decimal symbol and represents the magnitude of the internal value, as modified by the established scale factor and rounded (13.7.2.3.8) to d fractional digits. Leading zeros are not permitted except for an optional zero immediately to the left of the decimal symbol if the magnitude of the value in the output field is less than one. The optional zero shall appear if there would otherwise be no digits in the output field.

31

13.7.2.3.3

32 33 34 35

E and D editing

1 The Ew.d, Dw.d, and Ew.d Ee edit descriptors indicate that the external field occupies w positions, except when

w is zero in which case the processor selects the field width. The fractional part of the field contains d digits, unless a scale factor greater than one is in effect. If e is positive the exponent part contains e digits, otherwise it contains the minimum number of digits required to represent the exponent value. The e has no effect on input.

36

2 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).

37

3 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.

38 39

4 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field for a scale factor

40 41 42 43

of zero is [ ± ] [0].x1 x2 . . . xd exp where: • ± signifies a plus sign or a minus sign; • . signifies a decimal symbol (13.6);

ISO/IEC JTC 1/SC 22/WG5/N2184

277

J3/21-007r1

1 2

WD 1539-1

2021-05-21

• x1 x2 . . . xd are the d most significant digits of the internal value after rounding (13.7.2.3.8); • exp is a decimal exponent having one of the forms specified in Table 13.1. Table 13.1: E and D exponent forms Edit Descriptor Absolute Value of Exponent Form of Exponent1 |exp| ≤ 99

E±z1 z2 or ±0z1 z2

99 < |exp| ≤ 999

±z1 z2 z3

Ew.d Ee with e > 0

|exp| ≤ 10e − 1

E±z1 z2 . . . ze

Ew.d E0

any

E±z1 z2 . . . zs

Dw.d

|exp| ≤ 99

D±z1 z2 or E±z1 z2 or ±0z1 z2

Ew.d

99 < |exp| ≤ 999 ±z1 z2 z3 (1) where each z is a digit, and s is the minimum number of digits required to represent the exponent. A plus sign is produced if the exponent value is zero.

3 4

5 The scale factor k controls the decimal normalization (13.3.2, 13.8.6). If −d < k ≤ 0, the output field contains

5 6

exactly |k| leading zeros and d − |k| significant digits after the decimal symbol. If 0 < k < d + 2, the output field contains exactly k significant digits to the left of the decimal symbol and d − k + 1 significant digits to the right of the decimal symbol. Other values of k are not permitted.

7

13.7.2.3.4

EN editing

8 9 10

1 The EN edit descriptor produces an output field in the form of a real number in engineering notation such that

11 12 13 14

2 The forms of the edit descriptor are ENw.d and ENw.d Ee indicating that the external field occupies w positions,

15

3 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).

16

4 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.

17 18 19

5 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is

20 21 22 23 24 25 26

the decimal exponent is divisible by three and the absolute value of the significand (R715) is greater than or equal to 1 and less than 1000, except when the output value is zero. The scale factor has no effect on output. except when w is zero in which case the processor selects the field width. The fractional part of the field contains d digits. If e is positive the exponent part contains e digits, otherwise it contains the minimum number of digits required to represent the exponent value.

[ ± ] yyy . x1 x2 . . . xd exp where: • ± signifies a plus sign or a minus sign; • yyy are the 1 to 3 decimal digits representative of the most significant digits of the internal value after rounding (13.7.2.3.8); • yyy is an integer such that 1 ≤ yyy < 1000 or, if the output value is zero, yyy = 0; • . signifies a decimal symbol (13.6); • x1 x2 . . . xd are the d next most significant digits of the internal value after rounding; • exp is a decimal exponent, divisible by three, having one of the forms specified in Table 13.2.

278

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

Edit Descriptor ENw.d ENw.d Ee with e > 0

J3/21-007r1

Table 13.2: EN exponent forms Absolute Value of Exponent Form of Exponent1 |exp| ≤ 99

E±z1 z2 or ±0z1 z2

99 < |exp| ≤ 999

±z1 z2 z3

e

|exp| ≤ 10 − 1

E±z1 z2 . . . ze

ENw.d E0 any E±z1 z2 . . . zs (1) where each z is a digit, and s is the minimum number of digits required to represent the exponent. A plus sign is produced if the exponent value is zero.

NOTE 1 Examples: Internal value 6.421 -.5 .00217 4721.3 1

13.7.2.3.5

Output field using SS, EN12.3 6.421E+00 -500.000E-03 2.170E-03 4.721E+03

ES editing

2 3 4

1 The ES edit descriptor produces an output field in the form of a real number in scientific notation such that the

5 6 7 8

2 The forms of the edit descriptor are ESw.d and ESw.d Ee indicating that the external field occupies w positions,

9

3 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).

10

4 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.

11 12 13

5 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is

14 15 16 17 18

absolute value of the significand (R715) is greater than or equal to 1 and less than 10, except when the output value is zero. The scale factor has no effect on output. except when w is zero in which case the processor selects the field width. The fractional part of the field contains d digits. If e is positive the exponent part contains e digits, otherwise it contains the minimum number of digits required to represent the exponent value.

[ ± ] y . x1 x2 . . . xd exp where: • ± signifies a plus sign or a minus sign; • y is a decimal digit representative of the most significant digit of the internal value after rounding (13.7.2.3.8); • . signifies a decimal symbol (13.6); • x1 x2 . . . xd are the d next most significant digits of the internal value after rounding; • exp is a decimal exponent having one of the forms specified in Table 13.3.

Edit Descriptor ESw.d ESw.d Ee with e > 0

Table 13.3: ES exponent forms Absolute Value of Exponent Form of Exponent1 |exp| ≤ 99

E±z1 z2 or ±0z1 z2

99 < |exp| ≤ 999

±z1 z2 z3

e

|exp| ≤ 10 − 1

E±z1 z2 . . . ze

ESw.d E0 any E±z1 z2 . . . zs (1) where each z is a digit, and s is the minimum number of digits required to represent the exponent. A plus sign is produced if the exponent value is zero.

ISO/IEC JTC 1/SC 22/WG5/N2184

279

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 Examples: Internal value 6.421 -.5 .00217 4721.3 1

13.7.2.3.6

Output field using SS, ES12.3 6.421E+00 -5.000E-01 2.170E-03 4.721E+03

EX editing

2

1 The EX edit descriptor produces an output field in the form of a hexadecimal-significand number.

3

2 The EXw.d and EXw.dEe edit descriptors indicate that the external field occupies w positions, except when w

4 5 6 7 8 9

is zero in which case the processor selects the field width. The fractional part of the field contains d hexadecimal digits, except when d is zero in which case the processor selects the number of hexadecimal digits to be the minimum required so that the output field is equal to the internal value; d shall not be zero if the radix of the internal value is not a power of two. The hexadecimal point, represented by a decimal symbol, appears after the first hexadecimal digit. For the form EXw.d, and for EXw.dE0, the exponent part contains the minimum number of digits needed to represent the exponent; otherwise the exponent contains e digits. The e has no effect on input. The scale factor has no effect on output.

10 11

3 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).

12

4 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.

13 14 15

5 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is

16 17 18 19 20 21 22 23 24

[ ± ] 0X x0 . x1 x2 . . . exp where: • ± signifies a plus sign or a minus sign; • . signifies a decimal symbol (13.6); • x0 x1 x2 . . . are the most significant hexadecimal digits of the internal value, after rounding if d is not zero (13.7.2.3.8); • exp is a binary exponent expressed as a decimal integer; for EXw.d and EXw.dE0, the form is P ±z1 . . . zn , where n is the minimum number of digits needed to represent exp, and for EXw.dEe with e greater than zero the form is P ±z1 . . . ze . The choice of binary exponent is processor dependent. If the most significant binary digits of the internal value are b0 b1 b2 . . ., the binary exponent might make the value of x0 be that of b0 , b0 b1 , b0 b1 b2 , or b0 b1 b2 b3 . A plus sign is produced if the exponent value is zero. NOTE 1 Examples: Internal value 1.375 −15.625 1048580.0 2.375

25 26 27 28 29 30

13.7.2.3.7

Edit descriptor EX0.1 EX14.4E3 EX0.0 EX0.1

Possible output with SS in effect 0X1.6P+0 -0X1.F400P+003 0X1.00004P+20 0X2.6P+0

Complex editing

1 A complex datum consists of a pair of separate real data. The editing of a scalar datum of complex type is

specified by two edit descriptors each of which specifies the editing of real data. The first edit descriptor specifies the editing for the real part; the second specifies it for the imaginary part. The two edit descriptors may be different. Control and character string edit descriptors may be processed between the edit descriptor for the real part and the edit descriptor for the imaginary part.

280

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

13.7.2.3.8

WD 1539-1

J3/21-007r1

Input/output rounding mode

2 3

1 The input/output rounding mode can be specified by an OPEN statement (12.5.2), a data transfer statement

4 5 6 7 8

2 In what follows, the term “decimal value” means the exact decimal number as given by the character string, while

9

3 When the input/output rounding mode is UP, the value resulting from conversion shall be the smallest represent-

10 11 12 13 14 15 16 17 18 19

able value that is greater than or equal to the original value. When the input/output rounding mode is DOWN, the value resulting from conversion shall be the largest representable value that is less than or equal to the original value. When the input/output rounding mode is ZERO, the value resulting from conversion shall be the value closest to the original value and no greater in magnitude than the original value. When the input/output rounding mode is NEAREST, the value resulting from conversion shall be the closer of the two nearest representable values if one is closer than the other. If the two nearest representable values are equidistant from the original value, it is processor dependent which one of them is chosen. When the input/output rounding mode is COMPATIBLE, the value resulting from conversion shall be the closer of the two nearest representable values or the value away from zero if halfway between them. When the input/output rounding mode is PROCESSOR_DEFINED, rounding during conversion shall be a processor-dependent default mode, which may correspond to one of the other modes.

20

4 On processors that support IEEE rounding on conversions (17.4), NEAREST shall correspond to round to nearest,

21

(12.6.2.14), or an edit descriptor (13.8.8). the term “internal value” means the number actually stored in the processor. For example, in dealing with the decimal constant 0.1, the decimal value is the mathematical quantity 1/10, which has no exact representation in binary form. Formatted output of real data involves conversion from an internal value to a decimal value; formatted input involves conversion from a decimal value to an internal value.

as specified in ISO/IEC 60559:2020. NOTE 1 On processors that support IEEE rounding on conversions, the input/output rounding modes COMPATIBLE and NEAREST will produce the same results except when the datum is halfway between the two nearest representable values. In that case, NEAREST will pick the even value, but COMPATIBLE will pick the value away from zero. The input/output rounding modes UP, DOWN, and ZERO have the same effect as those specified in ISO/IEC 60559:2020 for round toward +∞, round toward −∞, and round toward zero, respectively.

22

13.7.2.4

B, O, and Z editing

23 24 25

1 The Bw, Bw.m, Ow, Ow.m, Zw, and Zw.m edit descriptors indicate that the field to be edited occupies w

26

2 On input, m has no effect.

27

3 In the standard form of the input field for the B, O, and Z edit descriptors the character string consists of binary,

28 29 30 31

octal, or hexadecimal digits (as in R773, R774, R775) in the respective input field. The lower-case hexadecimal digits a through f in a hexadecimal input field are equivalent to the corresponding upper-case hexadecimal digits. If the input field does not have the standard form, and is not acceptable to the processor, an error condition occurs.

32 33

4 The value is INT (X) if the input list item is of type integer and REAL (X) if the input list item is of type real

34 35 36 37

positions, except when w is zero. When w is zero, the processor selects the field width. On input, w shall not be zero. The corresponding list item shall be of type integer, real, or complex, or of enumeration type.

or complex, where X is a boz-literal-constant that specifies the same bit sequence as the digits of the input field. If the list item is of enumeration type ET, the value is ET (INT (X)). 5 The output field for the Bw, Ow, and Zw descriptors consists of zero or more leading blanks followed by the

internal value in a form identical to the digits of a binary, octal, or hexadecimal constant, respectively, that specifies the same bit sequence but without leading zero bits.

ISO/IEC JTC 1/SC 22/WG5/N2184

281

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 A binary, octal, or hexadecimal constant always consists of at least one digit or hexadecimal digit. 1 2 3 4 5 6 7 8

R1323 hex-digit-string

is

hex-digit [ hex-digit ] ...

6 The output field for the Bw.m, Ow.m, and Zw.m edit descriptor is the same as for the Bw, Ow, and Zw edit

descriptor, except that the digit-string or hex-digit-string consists of at least m digits. If necessary, sufficient leading zeros are included to achieve the minimum of m digits. The value of m shall not exceed the value of w, except when w is zero. If m is zero and the internal value consists of all zero bits, the output field consists of only blank characters. When m and w are both zero, and the internal value consists of all zero bits, one blank character is produced.

13.7.3

Logical editing

9 10

1 The Lw edit descriptor indicates that the field occupies w positions. The specified input/output list item shall

11 12 13

2 The standard form of the input field consists of optional blanks, optionally followed by a period, followed by a T

14

3 A lower-case letter is equivalent to the corresponding upper-case letter in a logical input field.

be of type logical. The G edit descriptor also may be used to edit logical data (13.7.5.3). for true or F for false. The T or F may be followed by additional characters in the field, which are ignored. If the input field does not have the standard form, and is not acceptable to the processor, an error condition occurs.

NOTE 1 The logical constants .TRUE. and .FALSE. are acceptable input forms. 15 16 17 18 19 20 21

4 The output field consists of w−1 blanks followed by a T or F, depending on whether the internal value is true or

false, respectively.

13.7.4

Character editing

1 The A[w] edit descriptor is used with an input/output list item of type character. The AT edit descriptor is used

with an output list item of type character; it shall not be used for input. The G edit descriptor also may be used to edit character data (13.7.5.4). The kind type parameter of all characters transferred and converted under control of one A, AT, or G edit descriptor is implied by the kind of the corresponding list item.

22 23 24

2 If a field width w is specified with the A edit descriptor, the field consists of w characters. If a field width w is

25

3 Let len be the length of the input/output list item. If the specified field width w for an A edit descriptor

26 27 28

corresponding to an input item is greater than or equal to len, the rightmost len characters will be taken from the input field. If the specified field width w is less than len, the w characters will appear left justified with len−w trailing blanks in the internal value.

29 30 31

4 If the specified field width w for an A edit descriptor corresponding to an output item is greater than len, the

32 33 34 35

not specified with the A edit descriptor, the number of characters in the field is the length of the corresponding list item, regardless of the value of the kind type parameter.

output field will consist of w−len blanks followed by the len characters from the internal value. If the specified field width w is less than or equal to len, the output field will consist of the leftmost w characters from the internal value. 5 The field width for an AT edit descriptor is the length of the value of the output list item after any trailing blanks

are removed. The output field consists of the value of the output list item after any trailing blanks are removed; if the value of the output list item is all blanks, no output is produced by the edit descriptor.

282

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 For nondefault character kinds, the blank padding character is processor dependent. 1

6 If the file is connected for stream access, the output may be split across more than one record if it contains

2 3 4 5 6 7

newline characters. A newline character is a nonblank character returned by the intrinsic function NEW_LINE. Beginning with the first character of the output field, each character that is not a newline is written to the current record in successive positions; each newline character causes file positioning at that point as if by slash editing (the current record is terminated at that point, a new empty record is created following the current record, this new record becomes the last and current record of the file, and the file is positioned at the beginning of this new record). NOTE 2 If the intrinsic function NEW_LINE returns a blank character for a particular character kind, then the processor does not support using a character of that kind to cause record termination in a formatted stream file.

8

13.7.5

Generalized editing

9

13.7.5.1

Overview

10 11 12

1 The Gw, Gw.d and Gw.d Ee edit descriptors are used with an input/output list item of any intrinsic type. When

13 14

w is nonzero, these edit descriptors indicate that the external field occupies w positions. For real or complex data the fractional part consists of a maximum of d digits and the exponent part consists of e digits. When these edit descriptors are used to specify the input/output of integer, logical, or character data, d and e have no effect. When w is zero the processor selects the field width. On input, w shall not be zero.

15

13.7.5.2

16

13.7.5.2.1

17 18

Generalized numeric editing Overview

1 When used to specify the input/output of integer, real, and complex data, the Gw, Gw.d and Gw.d Ee edit

descriptors follow the general rules for numeric editing (13.7.2). NOTE 1 The Gw.d Ee edit descriptor follows any additional rules for the Ew.d Ee edit descriptor.

19 20 21 22

13.7.5.2.2

Generalized integer editing

1 When used to specify the input/output of integer data, the Gw, Gw.d, and Gw.d Ee edit descriptors follow the

rules for the Iw edit descriptor (13.7.2.2). Note that w cannot be zero for input editing (13.7.5.1). 13.7.5.2.3

Generalized real and complex editing

23 24

1 The form and interpretation of the input field for Gw.d and Gw.d Ee editing is the same as for Fw.d editing

25

2 If w is nonzero and d is zero, kPEw.0 or kPEw.0Ee editing is used for Gw.0 editing or Gw.0Ee editing respectively.

26 27

3 When used to specify the output of real or complex data that is not an IEEE infinity or NaN, the G0 and G0.d

28 29 30 31

(13.7.2.3.2). The rest of this subclause applies only to output editing.

edit descriptors follow the rules for the Gw.dEe edit descriptor, except that any leading or trailing blanks are removed. Reasonable processor-dependent values of w, d (if not specified), and e are used with each output value. 4 For an internal value that is an IEEE infinity or NaN, the form of the output field for the Gw.d and Gw.d Ee

edit descriptors is the same as for Fw.d, and the form of the output field for the G0 and G0.d edit descriptors is the same as for F0.0.

ISO/IEC JTC 1/SC 22/WG5/N2184

283

J3/21-007r1

1 2 3 4 5 6 7 8

WD 1539-1

2021-05-21

5 Otherwise, the method of representation in the output field depends on the magnitude of the internal value

being edited. If the internal value is zero, let s be one. If the internal value is a number other than zero, let N be the decimal value that is the result of converting the internal value to d significant digits according to the input/output rounding mode and let s be the integer such that 10s−1 ≤ |N | < 10s . If s < 0 or s > d, kPEw.d or kPEw.dEe editing is used for Gw.d editing or Gw.dEe editing respectively, where k is the scale factor (13.8.6). If 0 ≤ s ≤ d, the scale factor has no effect and F(w − n).(d − s),n(’b’) editing is used where b is a blank and n is 4 for Gw.d editing, e + 2 for Gw.dEe editing if e > 0, and 4 for Gw.dE0 editing. 6 The value of w−n shall be positive.

NOTE 1 The scale factor has no effect on output unless the magnitude of the datum to be edited is outside the range that permits effective use of F editing. 9 10 11 12 13

13.7.5.3

Generalized logical editing

1 When used to specify the input/output of logical data, the Gw.d and Gw.d Ee edit descriptors with nonzero w

follow the rules for the Lw edit descriptor (13.7.3). When used to specify the output of logical data, the G0 and G0.d edit descriptors follow the rules for the L1 edit descriptor. 13.7.5.4

Generalized character editing

14

1 When used to specify the input/output of character data, the Gw.d and Gw.d Ee edit descriptors with nonzero

15 16

w follow the rules for the Aw edit descriptor (13.7.4). When used to specify the output of character data, the G0 and G0.d edit descriptors follow the rules for the A edit descriptor with no field width.

17

13.7.6

User-defined derived-type editing

18 19

1 The DT edit descriptor specifies that a user-provided procedure shall be used instead of the processor’s default

20 21 22

2 The DT edit descriptor may include a character literal constant. The character value “DT” concatenated with the

input/output formatting for processing a list item of derived type. character literal constant is passed to the defined input/output procedure as the iotype argument (12.6.4.8). The v values of the edit descriptor are passed to the defined input/output procedure as the v_list array argument. NOTE 1 For the edit descriptor DT’Link List’(10, 4, 2), iotype is "DTLink List" and v_list is [10, 4, 2].

23 24 25

3 If a derived-type variable or value corresponds to a DT edit descriptor, there shall be an accessible interface to

a corresponding defined input/output procedure for that derived type (12.6.4.8). A DT edit descriptor shall not correspond to a list item that is not of a derived type.

26

13.8

Control edit descriptors

27

13.8.1

Position edit descriptors

28

13.8.1.1

Position editing

29 30 31 32

1 The position edit descriptors T, TL, TR, and X, specify the position at which the next character will be transmit-

33

2 On input, if the position specified by a position edit descriptor is before the current position, portions of a record

34

ted to or from the record. If any character skipped by a position edit descriptor is of type nondefault character, and the unit is a default character internal file or an external non-Unicode file, the result of that position editing is processor dependent. can be processed more than once, possibly with different editing.

284

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

3 On input, a position beyond the last character of the record may be specified if no characters are transmitted

3 4

4 On output, a position edit descriptor does not by itself cause characters to be transmitted and therefore does not

5 6 7 8 9 10

from such positions. by itself affect the length of the record. If characters are transmitted to positions at or after the position specified by a position edit descriptor, positions skipped and not previously filled are filled with blanks. The result is as if the entire record were initially filled with blanks. 5 On output, a character in the record can be replaced. A position edit descriptor never directly causes a character

already placed in the record to be replaced, but it might result in positioning such that subsequent editing causes a replacement. 13.8.1.2

T, TL, and TR editing

11 12 13 14

1 The left tab limit affects file positioning by the T and TL edit descriptors. Immediately prior to nonchild data

15 16

2 The Tn edit descriptor indicates that the transmission of the next character to or from a record is to occur at

17

transfer (12.6.4.8.3), the left tab limit becomes defined as the character position of the current record or the current position of the stream file. If, during data transfer, the file is positioned to another record, the left tab limit becomes defined as character position one of that record. the nth character position of the record, relative to the left tab limit. This position can be in either direction from the current position.

18 19 20 21

3 The TLn edit descriptor indicates that the transmission of the next character to or from the record is to occur at

22

4 The TRn edit descriptor indicates that the transmission of the next character to or from the record is to occur

the character position n characters backward from the current position. However, if n is greater than the difference between the current position and the left tab limit, the TLn edit descriptor indicates that the transmission of the next character to or from the record is to occur at the left tab limit.

23

at the character position n characters forward from the current position.

24

13.8.1.3

25 26

X editing

1 The nX edit descriptor indicates that the transmission of the next character to or from a record is to occur at

the character position n characters forward from the current position. NOTE 1 An nX edit descriptor has the same effect as a TRn edit descriptor.

27

13.8.2

Slash editing

28

1 The slash edit descriptor indicates the end of data transfer to or from the current record.

29 30

2 On input from a file connected for sequential or stream access, the remaining portion of the current record is

31 32 33 34 35 36

skipped and the file is positioned at the beginning of the next record. This record becomes the current record. On output to a file connected for sequential or stream access, a new empty record is created following the current record; this new record then becomes the last and current record of the file and the file is positioned at the beginning of this new record. 3 For a file connected for direct access, the record number is increased by one and the file is positioned at the

beginning of the record that has that record number, if there is such a record, and this record becomes the current record. NOTE 1 A record that contains no characters can be written on output. If the file is an internal file or a file connected for direct access, the record is filled with blank characters.

ISO/IEC JTC 1/SC 22/WG5/N2184

285

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) An entire record can be skipped on input. 1 2 3 4 5

4 The repeat specification is optional in the slash edit descriptor. If it is not specified, the default value is one.

13.8.3

Colon editing

1 The colon edit descriptor terminates format control if there are no more effective items in the input/output list

(12.6.3). The colon edit descriptor has no effect if there are more effective items in the input/output list.

13.8.4

SS, SP, and S editing

6 7 8

1 The SS, SP, and S edit descriptors temporarily change (12.5.2) the sign mode (12.5.6.18, 12.6.2.15) for the

9 10 11

2 The sign mode controls optional plus characters in numeric output fields. When the sign mode is PLUS, the

12 13 14 15 16

connection. The edit descriptors SS, SP, and S set the sign mode corresponding to the SIGN= specifier values SUPPRESS, PLUS, and PROCESSOR_DEFINED, respectively. processor shall produce a plus sign in any position that normally contains an optional plus sign. When the sign mode is SUPPRESS, the processor shall not produce a plus sign in such positions. When the sign mode is PROCESSOR_DEFINED, the processor has the option of producing a plus sign or not in such positions, subject to 13.7.2(5). 3 The SS, SP, and S edit descriptors affect only I, F, E, EN, ES, EX, D, and G editing during the execution of an

output statement. The SS, SP, and S edit descriptors have no effect during the execution of an input statement.

13.8.5

LZS, LZP and LZ editing

17 18 19

1 The LZS, LZP, and LZ edit descriptors temporarily change (12.5.2) the leading zero mode (12.5.6.12, 12.6.2.10)

20 21 22 23 24

2 The leading zero mode controls optional leading zero characters in numeric output fields. When the leading zero

25

3 The LZS, LZP, and LZ edit descriptors affect only F, E, D, and G editing during the execution of an output

26

statement. The LZS, LZP, and LZ edit descriptors have no effect during the execution of an input statement.

27

13.8.6

for the connection. The edit descriptors LZS, LZP, and LZ set the leading zero mode corresponding to the LEADING_ZERO= specifier values SUPPRESS, PRINT, and PROCESSOR_DEFINED, respectively. mode is PRINT, the processor shall produce a leading zero in any position that normally contains an optional leading zero. When the leading zero mode is SUPPRESS, the processor shall not produce a leading zero in such positions. When the leading zero mode is PROCESSOR_DEFINED, the processor has the option of producing a leading zero or not in such positions, subject to 13.7.2(5).

P editing

28

1 The kP edit descriptor temporarily changes (12.5.2) the scale factor for the connection to k. The scale factor

29

affects the editing done by the F, E, EN, ES, EX, D, and G edit descriptors for real and complex quantities.

30 31 32 33 34 35 36 37 38 39

2 The scale factor k affects the appropriate editing in the following manner.

• On input, with F, E, EN, ES, EX, D, and G editing (provided that no exponent exists in the field), the effect is that the externally represented number equals the internally represented number multiplied by 10k ; the scale factor is applied to the external decimal value and then this is converted using the input/output rounding mode. • On input, with F, E, EN, ES, EX, D, and G editing, the scale factor has no effect if there is an exponent in the field. • On output, with F output editing, the effect is that the externally represented number equals the internally represented number multiplied by 10k ; the internal value is converted using the input/output rounding mode and then the scale factor is applied to the converted decimal value.

286

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6

7

WD 1539-1

J3/21-007r1

• On output, with E and D editing, the effect is that the significand (R715) part of the quantity to be produced is multiplied by 10k and the exponent is reduced by k. • On output, with G editing, the effect is suspended unless the magnitude of the datum to be edited is outside the range that permits the use of F editing. If the use of E editing is required, the scale factor has the same effect as with E output editing. • On output, with EN, ES, and EX editing, the scale factor has no effect.

13.8.7

BN and BZ editing

8 9 10

1 The BN and BZ edit descriptors temporarily change (12.5.2) the blank interpretation mode (12.5.6.6, 12.6.2.6)

11 12 13 14 15

2 The blank interpretation mode controls the interpretation of nonleading blanks in numeric input fields. Such

16

3 The blank interpretation mode affects only numeric editing (13.7.2) and generalized numeric editing (13.7.5.2)

for the connection. The edit descriptors BN and BZ set the blank interpretation mode corresponding to the BLANK= specifier values NULL and ZERO, respectively. blank characters are interpreted as zeros when the blank interpretation mode has the value ZERO; they are ignored when the blank interpretation mode has the value NULL. The effect of ignoring blanks is to treat the input field as if blanks had been removed, the remaining portion of the field right justified, and the blanks replaced as leading blanks. However, a field containing only blanks has the value zero.

17

on input. It has no effect on output.

18

13.8.8

RU, RD, RZ, RN, RC, and RP editing

19

1 The round edit descriptors temporarily change (12.5.2) the connection’s input/output rounding mode (12.5.6.17,

20 21 22 23

12.6.2.14, 13.7.2.3.8). The round edit descriptors RU, RD, RZ, RN, RC, and RP set the input/output rounding mode corresponding to the ROUND= specifier values UP, DOWN, ZERO, NEAREST, COMPATIBLE, and PROCESSOR_DEFINED, respectively. The input/output rounding mode affects the conversion of real and complex values in formatted input/output. It affects only D, E, EN, ES, EX, F, and G editing.

24

13.8.9

DC and DP editing

25 26 27

1 The decimal edit descriptors temporarily change (12.5.2) the decimal edit mode (12.5.6.7, 12.6.2.7, 13.6) for

28 29 30

2 The decimal edit mode controls the representation of the decimal symbol (13.6) during conversion of real and

31

the connection. The edit descriptors DC and DP set the decimal edit mode corresponding to the DECIMAL= specifier values COMMA and POINT, respectively. complex values in formatted input/output. The decimal edit mode affects only D, E, EN, ES, EX, F, and G editing.

13.9

Character string edit descriptors

32

1 A character string edit descriptor shall not be used on input.

33 34

2 The character string edit descriptor causes characters to be written from the enclosed characters of the edit

35 36

descriptor itself, including blanks. For a character string edit descriptor, the width of the field is the number of characters between the delimiting characters. Within the field, two consecutive delimiting characters are counted as a single character. NOTE 1 A delimiter for a character string edit descriptor is either an apostrophe or quote.

ISO/IEC JTC 1/SC 22/WG5/N2184

287

J3/21-007r1

WD 1539-1

1

13.10

List-directed formatting

2

13.10.1

Purpose of list-directed formatting

3 4 5

2021-05-21

1 List-directed input/output allows data editing according to the type of the list item instead of by a format

specification. It also allows data to be free-field, that is, separated by commas (or semicolons) or blanks.

13.10.2

Values and value separators

6 7 8

1 The characters in one or more list-directed records constitute a sequence of values and value separators. The end

9

2 Each value is either a null value, c, r*c, or r*, where c is a literal constant, optionally signed if integer or real,

10 11 12 13 14

or an undelimited character constant and r is an unsigned, nonzero, integer literal constant. Neither c nor r shall have kind type parameters specified. The constant c is interpreted as though it had the same kind type parameter as the corresponding list item. The r*c form is equivalent to r successive appearances of the constant c, and the r* form is equivalent to r successive appearances of the null value. Neither of these forms shall contain embedded blanks, except where permitted within the constant c.

15 16 17 18 19 20 21 22

of a record has the same effect as a blank character, unless it is within a character constant. Any sequence of two or more consecutive blanks is treated as a single blank, unless it is within a character constant.

3 A value separator is

• a comma optionally preceded by one or more contiguous blanks and optionally followed by one or more contiguous blanks, unless the decimal edit mode is COMMA, in which case a semicolon is used in place of the comma, • a slash optionally preceded by one or more contiguous blanks and optionally followed by one or more contiguous blanks, or • one or more contiguous blanks between two nonblank values or following the last nonblank value, where a nonblank value is a constant, an r*c form, or an r* form. NOTE 1 Although a slash encountered in an input record is referred to as a separator, it actually causes termination of list-directed and namelist input statements; it does not actually separate two values. NOTE 2 If no list items are specified in a list-directed input/output statement, one input record is skipped or one empty output record is written.

23

13.10.3

List-directed input

24

13.10.3.1

List-directed input forms

25 26 27 28

1 Input forms acceptable to edit descriptors for a given type are acceptable for list-directed formatting, except as

29 30

2 For the r*c form of an input value, the constant c is interpreted as an undelimited character constant if the first

31 32

noted below. If the form of the input value is not acceptable to the processor for the type of the next effective item in the list, an error condition occurs. Blanks are never used as zeros, and embedded blanks are not permitted in constants, except within character constants and complex constants as specified below. list item corresponding to this value is default, ASCII, or ISO 10646 character, there is a nonblank character immediately after r*, and that character is not an apostrophe or a quotation mark; otherwise, c is interpreted as a literal constant. NOTE 1 The end of a record has the effect of a blank, except when it appears within a character constant.

288

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

3 When the next effective item is of type integer or of an interoperable enum type, the value in the input record is

3 4

4 When the next effective item is of type real, the input form is that of a numeric input field. A numeric input field

5 6 7 8 9 10 11

interpreted as if an Iw edit descriptor with a suitable value of w were used. is a field suitable for F editing (13.7.2.3.2) that is assumed to have no fractional digits unless a decimal symbol appears within the field. 5 When the next effective item is of type complex, the input form consists of a left parenthesis followed by an

ordered pair of numeric input fields separated by a comma (if the decimal edit mode is POINT) or semicolon (if the decimal edit mode is COMMA), and followed by a right parenthesis. The first numeric input field is the real part of the complex constant and the second is the imaginary part. Each of the numeric input fields may be preceded or followed by any number of blanks and ends of records. The end of a record may occur after the real part or before the imaginary part.

12 13

6 When the next effective item is of type logical, the input form shall not include value separators among the

14 15 16

7 When the next effective item is of type character, the input form consists of a possibly delimited sequence of zero

17 18 19 20 21 22 23 24 25 26 27

optional characters permitted for L editing. or more rep-chars whose kind type parameter is implied by the kind of the effective item. Character sequences may be continued from the end of one record to the beginning of the next record, but the end of record shall not occur between a doubled apostrophe in an apostrophe-delimited character sequence, nor between a doubled quote in a quote-delimited character sequence. The end of the record does not cause a blank or any other character to become part of the character sequence. The character sequence may be continued on as many records as needed. The characters blank, comma, semicolon, and slash may appear in default, ASCII, or ISO 10646 character sequences. 8 If the next effective item is default, ASCII, or ISO 10646 character and

• the character sequence does not contain value separators, • the character sequence does not cross a record boundary, • the first nonblank character is not a quotation mark or an apostrophe, • the leading characters are not digits followed by an asterisk, and • the character sequence contains at least one character,

28 29 30 31

the delimiting apostrophes or quotation marks are not required. If the delimiters are omitted, the character sequence is terminated by the first blank, comma (if the decimal edit mode is POINT), semicolon (if the decimal edit mode is COMMA), slash, or end of record; in this case apostrophes and quotation marks within the datum are not to be doubled.

32

9 Let len be the current length of the next effective item, and let w be the length of the character sequence. If len

33 34 35

is less than or equal to w, the leftmost len characters of the sequence are transmitted to the next effective item. If len is greater than w, the sequence is transmitted to the leftmost w characters of the next effective item and the remaining len−w characters of the next effective item are filled with blanks. NOTE 2 An allocatable, deferred-length character effective item does not have its allocation status or allocated length changed as a result of list-directed input.

36 37 38 39 40 41

13.10.3.2

Null values

1 A null value is specified by

• the r* form, • no characters between consecutive value separators, or • no characters before the first value separator in the first record read by each execution of a list-directed input statement.

ISO/IEC JTC 1/SC 22/WG5/N2184

289

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 The end of a record following any other value separator, with or without separating blanks, does not specify a null value in list-directed input. 1 2 3

2 A null value has no effect on the definition status of the next effective item. A null value shall not be used for

4 5 6

3 A slash encountered as a value separator during execution of a list-directed input statement causes termination

7 8

either the real or imaginary part of a complex constant, but a single null value may represent an entire complex constant. of execution of that input statement after the transference of the previous value. Any characters remaining in the current record are ignored. If there are additional items in the input list, the effect is as if null values had been supplied for them. Any do-variable in the input list becomes defined as if enough null values had been supplied for any remaining input list items. NOTE 2 All blanks encountered during list-directed input are considered to be part of some value separator except for • blanks embedded in a character sequence, • embedded blanks surrounding the real or imaginary part of a complex constant, and • leading blanks in the first record read by each execution of a list-directed input statement, unless immediately followed by a slash or comma.

NOTE 3 List-directed input example: INTEGER I; REAL X (8); CHARACTER (11) P; COMPLEX Z; LOGICAL G ... READ *, I, X, P, Z, G The input data records are: 12345,12345,,2*1.5,4* ISN’T_BOB’S,(123,0),.TEXAS$ The results are: Variable I X (1) X (2) X (3) X (4) X (5) – X (8) P Z G

9 10 11 12 13 14

13.10.4

Value 12345 12345.0 unchanged 1.5 1.5 unchanged ISN’T_BOB’S (123.0,0.0) true

List-directed output

1 The form of the values produced is the same as that required for input, except as noted otherwise. With the

exception of adjacent undelimited character sequences, the values are separated by one or more blanks or by a comma, or a semicolon if the decimal edit mode is COMMA, optionally preceded by one or more blanks and optionally followed by one or more blanks. Two undelimited character sequences are considered adjacent when both were written using list-directed input/output, no intervening data transfer or file positioning operations on

290

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

that unit occurred, and both were written either by a single data transfer statement, or during the execution of a parent data transfer statement along with its child data transfer statements. The form of the values produced by defined output (12.6.4.8) is determined by the defined output procedure; this form need not be compatible with list-directed input.

5 6 7

2 The processor may begin new records as necessary, but the end of record shall not occur within a constant except

8

3 Logical output values are T for the value true and F for the value false.

9

4 Integer output constants are produced with the effect of an Iw edit descriptor.

10 11

5 Real constants are produced with the effect of either an F edit descriptor or an E edit descriptor, depending on

12 13

as specified for complex constants and character sequences. The processor shall not insert blanks within character sequences or within constants, except as specified for complex constants.

the magnitude x of the value and a range 10d1 ≤ x < 10d2 , where d1 and d2 are processor-dependent integers. If the magnitude x is within this range or is zero, the constant is produced using 0PFw.d; otherwise, 1PEw.d Ee is used.

14 15

6 For numeric output, reasonable processor-dependent values of w, d, and e are used for each of the numeric

16 17

7 Complex constants are enclosed in parentheses with a separator between the real and imaginary parts, each

18 19 20 21 22 23 24 25 26 27 28

29 30 31

constants output. produced as defined above for real constants. The separator is a comma if the decimal edit mode is POINT; it is a semicolon if the decimal edit mode is COMMA. The end of a record shall not occur between the separator and the imaginary part unless the entire constant is as long as, or longer than, an entire record. The only embedded blanks permitted within a complex constant are between the separator and the end of a record and one blank at the beginning of the next record. 8 Character sequences produced when the delimiter mode has a value of NONE

• are not delimited by apostrophes or quotation marks, • are not separated from each other by value separators, • have each internal apostrophe or quotation mark represented externally by one apostrophe or quotation mark, and • have a blank character inserted by the processor at the beginning of any record that begins with the continuation of a character sequence from the preceding record. 9 Character sequences produced when the delimiter mode has a value of QUOTE are delimited by quotes, are

preceded and followed by a value separator, and have each internal quote represented on the external medium by two contiguous quotes.

32 33 34

10 Character sequences produced when the delimiter mode has a value of APOSTROPHE are delimited by apo-

35 36

11 If two or more successive values in an output record have identical values, the processor has the option of producing

37

12 Slashes, as value separators, and null values are not produced as output by list-directed formatting.

38 39

13 Except for new records created by explicit formatting within a defined output procedure or by continuation of

strophes, are preceded and followed by a value separator, and have each internal apostrophe represented on the external medium by two contiguous apostrophes. a repeated constant of the form r*c instead of the sequence of identical values.

delimited character sequences, each output record begins with a blank character. NOTE 1 The length of the output records is not specified and is processor dependent.

ISO/IEC JTC 1/SC 22/WG5/N2184

291

J3/21-007r1

WD 1539-1

1

13.11

Namelist formatting

2

13.11.1

Purpose of namelist formatting

3 4 5 6 7 8 9 10 11 12 13 14 15

2021-05-21

1 Namelist input/output allows data editing with name-value subsequences. This facilitates documentation of input

and output files and more flexibility on input.

13.11.2

Name-value subsequences

1 The characters in one or more namelist records constitute a sequence of name-value subsequences, each of which

consists of an object designator followed by an equals and followed by one or more values and value separators. The equals may optionally be preceded or followed by one or more contiguous blanks. The end of a record has the same effect as a blank character, unless it is within a character constant. Any sequence of two or more consecutive blanks is treated as a single blank, unless it is within a character constant. 2 Each object designator shall begin with a name from the namelist-group-object-list (8.9) and shall follow the

16 17 18 19 20

syntax of designator (R901). It shall not contain a vector subscript or an image-selector and shall not designate a zero-sized array, a zero-sized array section, or a zero-length character string. Each subscript, stride, and substring range expression shall be an optionally signed integer literal constant with no kind type parameter specified. If a section subscript list appears, the number of section subscripts shall be equal to the rank of the object. If the namelist group object is of derived type, the designator in the input record may be either the name of the variable or the designator of one of its components, indicated by qualifying the variable name with the appropriate component name. Successive qualifications may be applied as appropriate to the shape and type of the variable represented. Each designator may be preceded and followed by one or more optional blanks but shall not contain embedded blanks.

21

3 A value separator for namelist formatting is the same as for list-directed formatting (13.10.2), or one or more

22

contiguous blanks between a nonblank value and the following object designator or namelist comment (13.11.3.6).

23

13.11.3

Namelist input

24

13.11.3.1

Overall syntax

25

1 Input for a namelist input statement consists of

(1) (2)

26 27 28

(3) (4) (5)

29 30 31

optional blanks and namelist comments, the character & followed immediately by the namelist-group-name as specified in the NAMELIST statement, one or more blanks, a sequence of zero or more name-value subsequences separated by value separators, and a slash to terminate the namelist input.

NOTE 1 A slash encountered in a namelist input record causes the input statement to terminate. A slash cannot be used to separate two values in a namelist input statement. 32

2 The order of the name-value subsequences in the input records need not match the order of the namelist-group-

33 34

object-list. The input records need not specify all objects in the namelist-group-object-list. They may specify a part of an object more than once.

35 36 37 38

3 A group name or object name is without regard to case.

13.11.3.2

Namelist input processing

1 The name-value subsequences are evaluated serially, in left-to-right order. A namelist group object designator

may appear in more than one name-value subsequence. The definition status of an object that is not a subobject

292

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8

WD 1539-1

J3/21-007r1

of a designator in any name-value subsequence remains unchanged. 2 When the designator in the input record represents an array variable or a variable of derived type, the effect is

as if the variable represented were expanded into a sequence of scalar list items, in the same way that formatted input/output list items are expanded (12.6.3). The number of values following the equals shall not exceed the number of list items in the expanded sequence, but may be less; in the latter case, the effect is as if sufficient null values had been appended to match any remaining list items in the expanded sequence. Except as noted elsewhere in this subclause, if an input value is not acceptable to the processor for the type of the list item in the corresponding position in the expanded sequence, an error condition occurs. NOTE 1 For example, if the designator in the input record designates an integer array of size 100, at most 100 values, each of which is either a digit string or a null value, can follow the equals; these values would then be assigned to the elements of the array in array element order.

9

3 A slash encountered as a value separator during the execution of a namelist input statement causes termination

10 11

of execution of that input statement after transference of the previous value. If there are additional items in the namelist group object being transferred, the effect is as if null values had been supplied for them.

12 13

4 Successive namelist records are read by namelist input until a slash is encountered; the remainder of the record

14 15

5 A namelist comment may appear after any value separator except a slash (which terminates namelist input). A

is ignored.

16

namelist comment is also permitted to start in the first nonblank position of an input record except within a character literal constant.

17

13.11.3.3

18 19 20 21 22 23 24 25 26

Namelist input values

1 Each value is either a null value (13.11.3.4), c, r*c, or r*, where c is a literal constant, optionally signed if integer

or real, and r is an unsigned, nonzero, integer literal constant. A kind type parameter shall not be specified for c or r. The constant c is interpreted as though it had the same kind type parameter as the corresponding effective item. The r*c form is equivalent to r successive appearances of the constant c, and the r* form is equivalent to r successive null values. Neither of these forms shall contain embedded blanks, except where permitted within the constant c. 2 The datum c (13.11) is any input value acceptable to format specifications for a given type, except for restrictions

27 28 29 30 31

on the form of input values specified in this subclause. The form of a real or complex value is dependent on the decimal edit mode in effect (13.6). The form of an input value shall be acceptable for the type of the namelist group object list item. The number and forms of the input values that may follow the equals in a name-value subsequence depend on the shape and type of the object represented by the name in the input record. When the name in the input record is that of a scalar variable of an intrinsic type, the equals shall not be followed by more than one value. Blanks are never used as zeros, and embedded blanks are not permitted in constants except within character constants and complex constants as specified in this subclause.

32

3 When the next effective item is of type real, the input form of the input value is that of a numeric input field. A

33 34

numeric input field is a field suitable for F editing (13.7.2.3.2) that is assumed to have no fractional digits unless a decimal symbol appears within the field.

35 36 37 38

4 When the next effective item is of type complex, the input form of the input value consists of a left parenthesis

39 40 41

followed by an ordered pair of numeric input fields separated by a comma (if the decimal edit mode is POINT) or a semicolon (if the decimal edit mode is COMMA), and followed by a right parenthesis. The first numeric input field is the real part of the complex constant and the second field is the imaginary part. Each of the numeric input fields may be preceded or followed by any number of blanks and ends of records. The end of a record may occur between the real part and the comma or semicolon, or between the comma or semicolon and the imaginary part.

42

5 When the next effective item is of type logical, the input form of the input value shall not include equals or value

ISO/IEC JTC 1/SC 22/WG5/N2184

293

J3/21-007r1

1

WD 1539-1

2021-05-21

separators among the optional characters permitted for L editing (13.7.3).

2 3

6 When the next effective item is of type integer or of an interoperable enum type, the value in the input record is

4

7 When the next effective item is of type character, the input form consists of a sequence of zero or more rep-chars

5 6 7 8 9 10

whose kind type parameter is implied by the kind of the corresponding list item, delimited by apostrophes or quotes. Such a sequence may be continued from the end of one record to the beginning of the next record, but the end of record shall not occur between a doubled apostrophe in an apostrophe-delimited sequence, nor between a doubled quote in a quote-delimited sequence. The end of the record does not cause a blank or any other character to become part of the sequence. The sequence may be continued on as many records as needed. The characters blank, comma, semicolon, and slash may appear in such character sequences.

interpreted as if an Iw edit descriptor with a suitable value of w were used.

NOTE 1 The delimiters in the input form for a namelist input item of type character avoid the ambiguity that could arise between undelimited character sequences and object names. The value of the DELIM= specifier, if any, in the OPEN statement for an external file is ignored during namelist input (12.5.6.8). 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

8 Let len be the length of the next effective item, and let w be the length of the character sequence. If len is less

than or equal to w, the leftmost len characters of the sequence are transmitted to the next effective item. If len is greater than w, the constant is transmitted to the leftmost w characters of the next effective item and the remaining len−w characters of the next effective item are filled with blanks. The effect is as though the sequence were assigned to the next effective item in an intrinsic assignment statement (10.2.1.3). 13.11.3.4

Null values

1 A null value is specified by

• the r* form, • blanks between two consecutive nonblank value separators following an equals, • a value separator that is the first nonblank character following an equals, or • two consecutive nonblank value separators. 2 A null value has no effect on the definition status of the corresponding input list item. If the namelist group

object list item is defined, it retains its previous value; if it is undefined, it remains undefined. A null value shall not be used as either the real or imaginary part of a complex constant, but a single null value may represent an entire complex constant. NOTE 1 The end of a record following a value separator, with or without intervening blanks, does not specify a null value in namelist input.

26 27 28 29 30 31 32 33 34 35

13.11.3.5

Blanks

1 All blanks in a namelist input record are considered to be part of some value separator except for

• blanks embedded in a character constant, • embedded blanks surrounding the real or imaginary part of a complex constant, • leading blanks following the equals unless followed immediately by a slash or comma, or a semicolon if the decimal edit mode is COMMA, and • blanks between a name and the following equals. 13.11.3.6

Namelist comments

1 Except within a character literal constant, a “!” character after a value separator or in the first nonblank position

of a namelist input record initiates a comment. The comment extends to the end of the record and may contain

294

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

any graphic character in the processor-dependent character set. The comment is ignored. A slash within the namelist comment does not terminate execution of the namelist input statement. Namelist comments are not allowed in stream input because comments depend on record structure. NOTE 1 Namelist input example: INTEGER I; REAL X (8); CHARACTER (11) P; COMPLEX Z; LOGICAL G NAMELIST / TODAY / G, I, P, Z, X READ (*, NML = TODAY) The input data records are: &TODAY I = 12345, X(1) = 12345, X(3:4) = 2*1.5, I=6, ! This is a comment. P = ’’ISN’T_BOB’S’’, Z = (123,0)/ The results stored are: Variable I X (1) X (2) X (3) X (4) X (5) – X (8) P Z G

Value 6 12345.0 unchanged 1.5 1.5 unchanged ISN’T_BOB’S (123.0,0.0) unchanged

4

13.11.4

Namelist output

5

13.11.4.1

Form of namelist output

6 7 8 9 10 11

1 The form of the output produced by intrinsic namelist output shall be suitable for input, except for character

output. The names in the output are in upper case. With the exception of adjacent undelimited character values, the values are separated by one or more blanks or by a comma, or a semicolon if the decimal edit mode is COMMA, optionally preceded by one or more blanks and optionally followed by one or more blanks. The form of the output produced by defined output (12.6.4.8) is determined by the defined output procedure; this form need not be compatible with namelist input.

12

2 Namelist output shall not include namelist comments.

13 14 15

3 The processor may begin new records as necessary. However, except for complex constants and character values,

the end of a record shall not occur within a constant, character value, or name, and blanks shall not appear within a constant, character value, or name. NOTE 1 The length of the output records is not specified exactly and is processor dependent.

16 17

13.11.4.2

Namelist output editing

1 Values in namelist output records are edited as for list-directed output (13.10.4).

NOTE 1 Namelist output records produced with a DELIM= specifier with a value of NONE and which contain a character sequence might not be acceptable as namelist input records.

ISO/IEC JTC 1/SC 22/WG5/N2184

295

J3/21-007r1

1 2 3 4

13.11.4.3

WD 1539-1

2021-05-21

Namelist output records

1 If two or more successive values for the same namelist group item in an output record produced have identical

values, the processor has the option of producing a repeated constant of the form r*c instead of the sequence of identical values.

5 6

2 The name of each namelist group object list item is placed in the output record followed by an equals and a list

7 8 9

3 An ampersand character followed immediately by a namelist-group-name is placed at the start of the first output

10

4 A null value is not produced by namelist formatting.

11 12

5 Except for new records created by explicit formatting within a defined output procedure or by continuation of

of values of the namelist group object list item. record to indicate which particular group of data objects is being output. A slash is placed in the output record to indicate the end of the namelist formatting.

delimited character sequences, each output record begins with a blank character.

296

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

14 Program units

2

14.1

3 4

J3/21-007r1

Main program

1 A Fortran main program is a program unit that does not contain a SUBROUTINE, FUNCTION, MODULE,

SUBMODULE, or BLOCK DATA statement as its first statement. R1401 main-program

is

[ program-stmt ] [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-program-stmt

10

R1402 program-stmt

is

PROGRAM program-name

11

R1403 end-program-stmt

is

END [ PROGRAM [ program-name ] ]

12 13

C1401 (R1401) The program-name shall not be included in the end-program-stmt unless the optional programstmt is used. If included, it shall be identical to the program-name specified in the program-stmt.

5 6 7 8 9

NOTE 1 The program name is global to the program (19.2). For explanatory information about uses for the program name, see C.10.1. NOTE 2 An example of a main program is: PROGRAM ANALYZE REAL A, B, C (10,10) CALL FIND CONTAINS SUBROUTINE FIND ... END SUBROUTINE FIND END PROGRAM ANALYZE

! !

Specification part Execution part

!

Internal subprogram

14 15

2 The main program may be defined by means other than Fortran; in that case, the program shall not contain a

16

3 A reference to a Fortran main-program shall not appear in any program unit in the program, including itself.

main-program program unit.

17

14.2

Modules

18

14.2.1

Module syntax and semantics

19 20 21 22 23

1 A module contains declarations, specifications, and definitions. Public identifiers of module entities are accessible

to other program units by use association as specified in 14.2.2. A module that is provided as an inherent part of the processor is an intrinsic module. A nonintrinsic module is defined by a module program unit or a means other than Fortran. 2 Procedures and types defined in an intrinsic module are not themselves intrinsic.

ISO/IEC JTC 1/SC 22/WG5/N2184

297

J3/21-007r1

WD 1539-1

1 2 3 4

R1404 module

is

module-stmt [ specification-part ] [ module-subprogram-part ] end-module-stmt

5

R1405 module-stmt

is

MODULE module-name

6

R1406 end-module-stmt

is

END [ MODULE [ module-name ] ]

7 8

R1407 module-subprogram-part

is

contains-stmt [ module-subprogram ] ...

9 10

R1408 module-subprogram

is function-subprogram or subroutine-subprogram or separate-module-subprogram

11

2021-05-21

12 13

C1402 (R1404) If the module-name is specified in the end-module-stmt, it shall be identical to the module-name specified in the module-stmt.

14

C1403 (R1404) A module specification-part shall not contain a stmt-function-stmt , an entry-stmt, or a format-stmt.

15 16

3 If a procedure declared in the scoping unit of a module has an implicit interface, it shall be given the EXTERNAL

17 18 19

attribute in that scoping unit; if it is a function, its type and type parameters shall be explicitly declared in a type declaration statement in that scoping unit. 4 If an intrinsic procedure is declared in the scoping unit of a module, it shall explicitly be given the INTRINSIC

attribute in that scoping unit or be used as an intrinsic procedure in that scoping unit. NOTE 1 The module name is global to the program (19.2). NOTE 2 Although statement function definitions, ENTRY statements, and FORMAT statements cannot appear in the specification part of a module, they can appear in the specification part of a module subprogram in the module. NOTE 3 For a discussion of the impact of modules on dependent compilation, see C.10.2. NOTE 4 For examples of the use of modules, see C.10.3.

20 21 22 23 24 25 26 27 28 29 30 31

14.2.2

The USE statement and use association

1 The USE statement specifies use association. A USE statement is a reference to the module it specifies. At the

time a USE statement is processed, the public portions of the specified module shall be available. A module shall not reference itself, either directly or indirectly. 2 The USE statement provides the means by which a scoping unit accesses named data objects, derived types,

procedures, abstract interfaces, generic identifiers, and namelist groups in a module. The entities in the scoping unit are use associated with the entities in the module. The accessed entities have the attributes specified in the module, except that an accessed entity may have a different accessibility attribute, it may have the ASYNCHRONOUS attribute even if the associated module entity does not, and if it is not a coarray it may have the VOLATILE attribute even if the associated module entity does not. The entities made accessible are identified by the names or generic identifiers used to identify them in the module. By default, the accessed entities are identified by the same identifiers in the scoping unit containing the USE statement, but it is possible to specify

298

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

that different identifiers are used. A use-associated variable is considered to have been previously declared; any other use-associated entity is considered to have been previously defined. NOTE 1 The accessibility of module entities can be controlled by accessibility attributes (7.5.2.2, 8.5.2), and the ONLY option of the USE statement. Definability of module entities can be controlled by the PROTECTED attribute (8.5.15).

3 4 5

R1409 use-stmt

is USE [ [ , module-nature ] :: ] module-name [ , rename-list ] or USE [ [ , module-nature ] :: ] module-name , ONLY : [ only-list ]

6

R1410 module-nature

is INTRINSIC or NON_INTRINSIC

8 9 10

R1411 rename

is local-name => use-name or OPERATOR (local-defined-operator) => OPERATOR (use-defined-operator)

11 12

R1412 only

is generic-spec or only-use-name or rename

14

R1413 only-use-name

is

15

C1404 (R1409) If module-nature is INTRINSIC, module-name shall be the name of an intrinsic module.

16

C1405 (R1409) If module-nature is NON_INTRINSIC, module-name shall be the name of a nonintrinsic module.

17 18

C1406 (R1409) A scoping unit shall not directly reference an intrinsic module and a nonintrinsic module of the same name.

19

C1407 (R1411) OPERATOR (use-defined-operator) shall not identify a type-bound generic interface.

20

C1408 (R1412) The generic-spec shall not identify a type-bound generic interface.

7

13

use-name

NOTE 2 Constraints C1407 and C1408 do not prevent accessing a generic-spec that is declared by an interface block, even if a type-bound generic interface has the same generic-spec. 21 22

C1409 Each generic-spec, use-name, and use-defined-operator in a USE statement shall be a public identifier of the module.

23

C1410 An only-use-name shall be a nongeneric name.

24 25

R1414 local-defined-operator

is defined-unary-op or defined-binary-op

26 27

R1415 use-defined-operator

is defined-unary-op or defined-binary-op

28 29

3 A use-stmt without a module-nature provides access either to an intrinsic or to a nonintrinsic module. If the

30

4 The USE statement without the ONLY option provides access to all public entities in the specified module.

31 32

5 A USE statement with the ONLY option provides access only to those entities that appear as generic-specs,

module-name is the name of both an intrinsic and a nonintrinsic module, the nonintrinsic module is accessed.

use-names, or use-defined-operators in the only-list.

ISO/IEC JTC 1/SC 22/WG5/N2184

299

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

6 More than one USE statement for a given module may appear in a specification part. If one of the USE statements

4

7 An accessible entity in the referenced module is associated with one or more accessed entities, each with its own

5 6 7 8 9 10 11

12 13 14

is without an ONLY option, all public entities in the module are accessible. If all the USE statements have ONLY options, only those entities in one or more of the only-lists are accessible. identifier. These identifiers are • the identifier of the entity in the referenced module if that identifier appears as an only-use-name or as the defined-operator of a generic-spec in any only for that module, • each of the local-names or local-defined-operators that the entity is given in any rename for that module, and • the identifier of the entity in the referenced module if that identifier does not appear as a use-name or use-defined-operator in any rename for that module. 8 An ultimate entity is a module entity that is not accessed by use association. An accessed entity shall not be

associated with two or more ultimate entities unless its identifier is not used, or the ultimate entities are generic interfaces. Generic interfaces are handled as described in 15.4.3.4. NOTE 3 There is no prohibition against a use-name or use-defined-operator appearing multiple times in one USE statement or in multiple USE statements involving the same module. As a result, it is possible for one use-associated entity to be accessible by more than one local identifier.

15 16 17 18

9 The local identifier of an entity made accessible by a USE statement shall not appear in any other nonexecutable

19

10 An entity in a scoping unit that is accessed by use association through more than one use path, has the ASYN-

20 21

CHRONOUS or VOLATILE attribute in any of those use paths, and is not given that attribute in that scoping unit, shall have that attribute in all use paths.

statement that would cause any attribute (8.5) of the entity to be specified in the scoping unit that contains the USE statement, except that it may appear in a PUBLIC or PRIVATE statement in the scoping unit of a module and it may be given the ASYNCHRONOUS or VOLATILE attribute.

NOTE 4 The constraints in 8.10.1, 8.10.2, and 8.9 prohibit the local-name from appearing as a common-block-object in a COMMON statement, an equivalence-object in an EQUIVALENCE statement, or a namelist-group-name in a NAMELIST statement, respectively. There is no prohibition against the local-name appearing as a commonblock-name or a namelist-group-object. NOTE 5 For a discussion of the impact of the ONLY option and renaming on dependent compilation, see C.10.2.2. NOTE 6 Examples: USE STATS_LIB provides access to all public entities in the module STATS_LIB. USE MATH_LIB; USE STATS_LIB, SPROD => PROD provides access to all public identifiers in both MATH_LIB and STATS_LIB. If MATH_LIB contains an entity named PROD, it can be accessed by that name, while the entity PROD of STATS_LIB can be accessed by the name SPROD. USE STATS_LIB, ONLY: YPROD; USE STATS_LIB, ONLY : PROD provides access to YPROD and PROD in STAT_LIB.

300

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 6 (cont.) USE STATS_LIB, ONLY : YPROD; USE STATS_LIB provides access to all public identifiers in STAT_LIB.

1

14.2.3

Submodules

2 3

1 A submodule is a program unit that extends a module or another submodule. The program unit that it extends

4 5 6

2 A module or submodule is an ancestor program unit of all of its descendants, which are its submodules and their

is its host, and is specified by the parent-identifier in the submodule-stmt. descendants. The submodule identifier is the ordered pair whose first element is the ancestor module name and whose second element is the submodule name; the submodule name by itself is not a local or global identifier. NOTE 1 A module and its submodules stand in a tree-like relationship one to another, with the module at the root. Therefore, a submodule has exactly one ancestor module and can have one or more ancestor submodules.

7 8 9

3 A submodule may provide implementations for separate module procedures (15.6.2.5), each of which is declared

(15.4.3.2) within that submodule or one of its ancestors, and declarations and definitions of other entities that are accessible by host association in its descendants. R1416 submodule

is

submodule-stmt [ specification-part ] [ module-subprogram-part ] end-submodule-stmt

14

R1417 submodule-stmt

is

SUBMODULE ( parent-identifier ) submodule-name

15

R1418 parent-identifier

is

ancestor-module-name [ : parent-submodule-name ]

16

R1419 end-submodule-stmt

is

END [ SUBMODULE [ submodule-name ] ]

17

C1411 (R1416) A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt .

18 19

C1412 (R1418) The ancestor-module-name shall be the name of a nonintrinsic module that declares a separate module procedure; the parent-submodule-name shall be the name of a descendant of that module.

20 21

C1413 (R1416) If a submodule-name appears in the end-submodule-stmt, it shall be identical to the one in the submodule-stmt.

22

14.3

10 11 12 13

23

Block data program units

1 A block data program unit is used to provide initial values for data objects in named common blocks.

24 25 26

R1420

block-data

is

block-data-stmt [ specification-part ] end-block-data-stmt

27

R1421

block-data-stmt

is

BLOCK DATA [ block-data-name ]

28

R1422

end-block-data-stmt

is

END [ BLOCK DATA [ block-data-name ] ]

29 30

C1414

(R1420) The block-data-name shall be included in the end-block-data-stmt only if it was provided in the block-data-stmt and, if included, shall be identical to the block-data-name in the block-data-stmt.

31 32 33

C1415

(R1420) A block-data specification-part shall contain only derived-type definitions and ASYNCHRONOUS, BIND, COMMON, DATA, DIMENSION, EQUIVALENCE, IMPLICIT, INTRINSIC, PARAMETER, POINTER, SAVE, TARGET, USE, VOLATILE, and type declaration statements.

ISO/IEC JTC 1/SC 22/WG5/N2184

301

J3/21-007r1

1 2

C1416

WD 1539-1

2021-05-21

(R1420) A type declaration statement in a block-data specification-part shall not contain ALLOCATABLE, EXTERNAL, or BIND attribute specifiers.

3 4 5

2 If an object in a named common block is initially defined, all storage units in the common block storage sequence shall be specified

6

3 An object that is initially defined in a block data program unit shall be in a named common block.

7

4 The same named common block shall not be specified in more than one block data program unit in a program.

8

5 There shall not be more than one unnamed block data program unit in a program.

even if they are not all initially defined. More than one named common block may have objects initially defined in a single block data program unit.

302

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

15 Procedures

2

15.1

WD 1539-1

J3/21-007r1

Concepts

3 4 5

1 The concept of a procedure was introduced in 5.2.3. This clause contains a complete description of procedures.

6 7 8 9

2 The sequence of actions encapsulated by a procedure has access to entities in the procedure reference by way of

The actions specified by a procedure are performed when the procedure is invoked by execution of a reference to it. argument association (15.5.2). A name that appears as a dummy-arg-name in the SUBROUTINE, FUNCTION, or ENTRY statement in the declaration of a procedure (R1536) is a dummy argument. Dummy arguments are also specified for intrinsic procedures and procedures in intrinsic modules in Clauses 16, 17, and 18.

10

15.2

Procedure classifications

11

15.2.1

Procedure classification by reference

12

1 The definition of a procedure specifies it to be a function or a subroutine. A reference to a function either appears

13 14 15

explicitly as a primary within an expression, or is implied by a defined operation (10.1.6) within an expression. A reference to a subroutine is a CALL statement, a defined assignment statement (10.2.1.4), the appearance of an object processed by defined input/output (12.6.4.8) in an input/output list, or finalization (7.5.6).

16

2 A procedure is classified as elemental if it is a procedure that can be referenced elementally (15.9).

17

15.2.2

Procedure classification by means of definition

18

15.2.2.1

Intrinsic procedures

19 20

1 A procedure that is provided as an inherent part of the processor is an intrinsic procedure.

15.2.2.2

External, internal, and module procedures

21

1 An external procedure is a procedure that is defined by an external subprogram or by a means other than Fortran.

22 23 24 25

2 An internal procedure is a procedure that is defined by an internal subprogram. Internal subprograms may

26

appear in the main program, in an external subprogram, or in a module subprogram. Internal subprograms shall not appear in other internal subprograms. Internal subprograms are the same as external subprograms except that the name of the internal procedure is not a global identifier, an internal subprogram shall not contain an ENTRY statement, and the internal subprogram has access to host entities by host association.

27 28

3 A module procedure is a procedure that is defined by a module subprogram, or a specific procedure provided by

29 30

4 A subprogram defines a procedure for the SUBROUTINE or FUNCTION statement. If the subprogram has one or

31 32 33 34

an intrinsic module. more ENTRY statements, it also defines a procedure for each of them.

15.2.2.3

Dummy procedures

1 A dummy argument that is specified to be a procedure or appears as the procedure designator in a procedure

reference is a dummy procedure. A dummy procedure with the POINTER attribute is a dummy procedure pointer.

ISO/IEC JTC 1/SC 22/WG5/N2184

303

J3/21-007r1

1 2 3

15.2.2.4

WD 1539-1

2021-05-21

Procedure pointers

1 A procedure pointer is a procedure that has the EXTERNAL and POINTER attributes; it may be pointer

4

associated with an external procedure, an internal procedure, an intrinsic procedure, a module procedure, or a dummy procedure that is not a procedure pointer.

5

15.2.2.5

6

Statement functions

1 A function that is defined by a single statement is a statement function (15.6.4).

7

15.3

Characteristics

8

15.3.1

Characteristics of procedures

9 10

1 The characteristics of a procedure are the classification of the procedure as a function or subroutine, whether it

11

is pure, whether it is simple, whether it is elemental, whether it has the BIND attribute, the characteristics of its dummy arguments, and the characteristics of its function result if it is a function.

12

15.3.2

Characteristics of dummy arguments

13

15.3.2.1

General

14 15 16

1 Each dummy argument has the characteristic that it is a dummy data object, a dummy procedure, or an asterisk (alternate return indicator).

15.3.2.2

Characteristics of dummy data objects

17

1 The characteristics of a dummy data object are its declared type, its type parameters, its shape (unless it is

18 19 20 21 22 23

assumed-rank), its corank, its codimensions, its intent (8.5.10, 8.6.9), whether it is optional (8.5.12, 8.6.10), whether it is allocatable (8.5.3), whether it has the ASYNCHRONOUS (8.5.4), CONTIGUOUS (8.5.7), VALUE (8.5.19), or VOLATILE (8.5.20) attributes, whether it is polymorphic, and whether it is a pointer (8.5.14, 8.6.12) or a target (8.5.18, 8.6.15). If a type parameter of an object or a bound of an array is not a constant expression, the exact dependence on the entities in the expression is a characteristic. If a rank, shape, size, type, or type parameter is assumed or deferred, it is a characteristic.

24

15.3.2.3

25 26 27 28 29 30 31 32 33 34 35 36

Characteristics of dummy procedures

1 The characteristics of a dummy procedure are the explicitness of its interface (15.4.2), its characteristics as a

procedure if the interface is explicit, whether it is a pointer, and whether it is optional (8.5.12, 8.6.10). 15.3.2.4

Characteristics of asterisk dummy arguments

1 A dummy argument that is an asterisk has no other characteristic.

15.3.3

Characteristics of function results

1 The characteristics of a function result are its declared type, type parameters, rank, whether it is polymorphic,

whether it is allocatable, whether it is a pointer, whether it has the CONTIGUOUS attribute, and whether it is a procedure pointer. If a function result is an array that is not allocatable or a pointer, its shape is a characteristic. If a type parameter of a function result or a bound of a function result array is not a constant expression, the exact dependence on the entities in the expression is a characteristic. If type parameters of a function result are deferred, which parameters are deferred is a characteristic. Whether the length of a character function result is assumed is a characteristic.

304

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

15.4

Procedure interface

2

15.4.1

Interface and abstract interface

3 4 5 6 7 8 9

1 The interface of a procedure determines the forms of reference through which it can be invoked. The procedure’s

interface consists of its name, binding label, generic identifiers, characteristics, and the names of its dummy arguments. The characteristics and binding label of a procedure are fixed, but the remainder of the interface may differ in differing contexts, except that for a separate module procedure body (15.6.2.5), the dummy argument names and whether it has the NON_RECURSIVE attribute shall be the same as in its corresponding module procedure interface body (15.4.3.2). 2 An abstract interface is a set of procedure characteristics with the dummy argument names.

10

15.4.2

Implicit and explicit interfaces

11

15.4.2.1

Interfaces and scopes

12 13 14 15 16 17

J3/21-007r1

1 The interface of a procedure is either explicit or implicit. It is explicit if it is

• an internal procedure, module procedure, or intrinsic procedure, • a subroutine, or a function with a separate result name, within the scoping unit that defines it, or • a procedure declared by a procedure declaration statement that specifies an explicit interface, or by an interface body. Otherwise, the interface of the identifier is implicit. The interface of a statement function is always implicit. NOTE 1 For example, the subroutine LLS of C.10.3.4 has an explicit interface.

18 19 20 21 22 23 24

15.4.2.2

Explicit interface

1 Within the scope of a procedure identifier, the procedure shall have an explicit interface if it is not a statement function and

(1) (2) (3) (4)

a reference to the procedure appears with an argument keyword (15.5.2), the procedure is used in a context that requires it to be pure (15.7), the procedure is used in a context that requires it to be simple (15.8), the procedure has a dummy argument that (a)

25 26

(b) (c) (d) (e) (f)

27 28 29 30 31 32

(5)

34 35 36 37

the procedure has a result that (a) (b) (c)

33

(6) (7)

has the ALLOCATABLE, ASYNCHRONOUS, OPTIONAL, POINTER, TARGET, VALUE, or VOLATILE attribute, is an assumed-shape array, is assumed-rank, is a coarray, is of a parameterized derived type, or is polymorphic,

is an array, is a pointer or is allocatable, or has a nonassumed type parameter value that is not a constant expression,

the procedure is elemental, or the procedure has the BIND attribute.

ISO/IEC JTC 1/SC 22/WG5/N2184

305

J3/21-007r1

WD 1539-1

1

15.4.3

Specification of the procedure interface

2

15.4.3.1

General

3 4 5 6

2021-05-21

1 The interface for an internal, external, module, or dummy procedure is specified by a FUNCTION, SUB-

ROUTINE, or ENTRY statement and by specification statements for the dummy arguments and the result of a function. These statements may appear in the procedure definition, in an interface body, or both, except that the ENTRY statement shall not appear in an interface body. NOTE 1 An interface body cannot be used to describe the interface of an internal procedure, a module procedure that is not a separate module procedure, or an intrinsic procedure because the interfaces of such procedures are already explicit. However, the name of a procedure can appear in a PROCEDURE statement in an interface block (15.4.3.2).

7

15.4.3.2

Interface block

8 9 10

R1501 interface-block

is

11 12

R1502 interface-specification

is interface-body or procedure-stmt

13 14

R1503 interface-stmt

is INTERFACE [ generic-spec ] or ABSTRACT INTERFACE

15

R1504 end-interface-stmt

is

16 17 18

R1505 interface-body

is

22

R1506 procedure-stmt

is

[ MODULE ] PROCEDURE [ :: ] specific-procedure-list

23

R1507 specific-procedure

is

procedure-name

24

R1508 generic-spec

is or or or

generic-name OPERATOR ( defined-operator ) ASSIGNMENT ( = ) defined-io-generic-spec

R1509 defined-io-generic-spec

is or or or

READ (FORMATTED) READ (UNFORMATTED) WRITE (FORMATTED) WRITE (UNFORMATTED)

19 20 21

25 26 27 28 29 30 31

interface-stmt [ interface-specification ] ... end-interface-stmt

END INTERFACE [ generic-spec ]

function-stmt [ specification-part ] end-function-stmt or subroutine-stmt [ specification-part ] end-subroutine-stmt

32 33

C1501 (R1501) An interface-block in a subprogram shall not contain an interface-body for a procedure defined by that subprogram.

34 35 36

C1502 (R1501) If the end-interface-stmt includes a generic-spec, the interface-stmt shall specify the same generic-spec, except that if one generic-spec has a defined-operator that is .LT., .LE., .GT., .GE., .EQ., or .NE., the other generic-spec may have a defined-operator that is the corresponding operator <, <=, >, >=, ==, or /=.

37

306

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

C1503 (R1503) If the interface-stmt is ABSTRACT INTERFACE, then the function-name in the function-stmt or the subroutine-name in the subroutine-stmt shall not be the same as a keyword that specifies an intrinsic type.

4

C1504 (R1502) A procedure-stmt is allowed only in an interface block that has a generic-spec.

5 6

C1505 (R1505) An interface-body of a pure procedure shall specify the intents of all dummy arguments except alternate return indicators, dummy procedures, and arguments with the POINTER or VALUE attribute.

7

C1506 (R1505) An interface-body shall not contain a data-stmt, format-stmt, entry-stmt, or stmt-function-stmt .

8 9

C1507 (R1506) If MODULE appears in a procedure-stmt, each procedure-name in that statement shall denote a module procedure.

10

C1508 (R1507) A procedure-name shall denote a nonintrinsic procedure that has an explicit interface.

11 12

C1509 (R1501) An interface-specification in a generic interface block shall not specify a procedure that was specified previously in any accessible interface with the same generic identifier.

13

1 An external or module subprogram specifies a specific interface for each procedure defined in that subprogram.

14 15 16

2 An interface block introduced by ABSTRACT INTERFACE is an abstract interface block. An interface body

17

in an abstract interface block specifies an abstract interface. An interface block with a generic specification is a generic interface block. An interface block with neither ABSTRACT nor a generic specification is a specific interface block.

18 19

3 The name of the entity declared by an interface body is the function-name in the function-stmt or the subroutine-

20 21 22

4 A module procedure interface body is an interface body whose initial statement contains the keyword MODULE.

23 24 25 26 27 28 29

name in the subroutine-stmt that begins the interface body. It specifies the interface for a separate module procedure (15.6.2.5). A separate module procedure is accessible by use association if and only if its interface body is declared in the specification part of a module and is public. If a corresponding (15.6.2.5) separate module procedure is not defined, the interface may be used to specify an explicit specific interface but the procedure shall not be used in any other way. 5 An interface body in a generic or specific interface block specifies the EXTERNAL attribute and an explicit

specific interface for an external procedure, dummy procedure, or procedure pointer. If the name of the declared procedure is that of a dummy argument in the subprogram containing the interface body, the procedure is a dummy procedure. If the procedure has the POINTER attribute, it is a procedure pointer. If it is not a dummy procedure or procedure pointer, it is an external procedure.

30 31 32

6 An interface body specifies all of the characteristics of the explicit specific interface or abstract interface. The

33 34

7 If an explicit specific interface for an external procedure is specified by an interface body or a procedure declaration

35 36 37 38 39 40 41 42

specification part of an interface body may specify attributes or define values for data entities that do not determine characteristics of the procedure. Such specifications have no effect. statement (15.4.3.6), the characteristics shall be consistent with those specified in the procedure definition, except that the interface may specify a procedure that is not pure even if the procedure is defined to be pure, and the interface may specify a procedure that is not simple even if the procedure is defined to be simple. An interface for a procedure defined by an ENTRY statement may be specified by using the entry name as the procedure name in the interface body.

If an external procedure does not exist in the program, an interface body for it may be used to specify an explicit specific interface but the procedure shall not be used in any other way. A procedure shall not have more than one explicit specific interface in a given scoping unit, except that if the interface is accessed by use association, there may be more than one local name for the procedure. If a procedure is accessed by use association, each access shall be to the same procedure declaration or definition.

ISO/IEC JTC 1/SC 22/WG5/N2184

307

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 The dummy argument names in an interface body can be different from the corresponding dummy argument names in the procedure definition because the name of a dummy argument is not a characteristic. NOTE 2 An example of a specific interface block is: INTERFACE SUBROUTINE EXT1 (X, Y, Z) REAL, DIMENSION (100, 100) :: X, Y, Z END SUBROUTINE EXT1 SUBROUTINE EXT2 (X, Z) REAL X COMPLEX (KIND = 4) Z (2000) END SUBROUTINE EXT2 FUNCTION EXT3 (P, Q) LOGICAL EXT3 INTEGER P (1000) LOGICAL Q (1000) END FUNCTION EXT3 END INTERFACE This interface block specifies explicit interfaces for the three external procedures EXT1, EXT2, and EXT3. Invocations of these procedures can use argument keywords (15.5.2); for example: PRINT *, EXT3 (Q = P_MASK (N+1 : N+1000), P = ACTUAL_P)

1 2 3

15.4.3.3

GENERIC statement

1 A GENERIC statement specifies a generic identifier for one or more specific procedures, in the same way as a

generic interface block that does not contain interface bodies. is

4

R1510 generic-stmt

5 6

C1510 (R1510) A specific-procedure in a GENERIC statement shall not specify a procedure that was specified previously in any accessible interface with the same generic identifier.

7

GENERIC [ , access-spec ] :: generic-spec => specific-procedure-list

2 If access-spec appears, it specifies the accessibility (8.5.2) of generic-spec.

8

15.4.3.4

9

15.4.3.4.1

Generic interfaces Generic identifiers

10 11 12 13

1 A generic interface block specifies a generic interface for each of the procedures in the interface block. The

14 15 16 17 18

2 The generic-spec in an interface-stmt is a generic identifier for all the procedures in the interface block. The

19 20 21 22

PROCEDURE statement lists nonintrinsic procedures with explicit interfaces that have this generic interface. A GENERIC statement specifies a generic interface for each of the procedures named in its specific-procedure-list. A generic interface is always explicit. generic-spec in a GENERIC statement is a generic identifier for all of the procedures named in its specificprocedure-list. The rules specifying how any two procedures with the same generic identifier shall differ are given in 15.4.3.4.5. They ensure that any generic invocation applies to at most one specific procedure. If a specific procedure in a generic interface has a function dummy argument, that argument shall have its type and type parameters explicitly declared in the specific interface. 3 A generic name is a generic identifier that refers to all of the procedure names in the generic interface. A generic

name may be the same as any one of the procedure names in the generic interface, or the same as any accessible generic name.

308

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

4 A generic name may be the same as a derived-type name, in which case all of the procedures in the generic

3

5 An interface-stmt having a defined-io-generic-spec is an interface for a defined input/output procedure (12.6.4.8).

interface shall be functions.

NOTE 1 An example of a generic procedure interface is: INTERFACE SWITCH SUBROUTINE INT_SWITCH (X, Y) INTEGER, INTENT (INOUT) :: X, Y END SUBROUTINE INT_SWITCH SUBROUTINE REAL_SWITCH (X, Y) REAL, INTENT (INOUT) :: X, Y END SUBROUTINE REAL_SWITCH SUBROUTINE COMPLEX_SWITCH (X, Y) COMPLEX, INTENT (INOUT) :: X, Y END SUBROUTINE COMPLEX_SWITCH END INTERFACE SWITCH Any of these three subroutines (INT_SWITCH, REAL_SWITCH, COMPLEX_SWITCH) can be referenced with the generic name SWITCH, as well as by its specific name. For example, a reference to INT_SWITCH could take the form: CALL SWITCH (MAX_VAL, LOC_VAL) ! MAX_VAL and LOC_VAL are of type INTEGER

NOTE 2 A type-bound-generic-stmt within a derived-type definition (7.5.5) specifies a generic identifier for a set of type-bound procedures. 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

15.4.3.4.2

Defined operations

1 If OPERATOR is specified in a generic specification, all of the procedures specified in the generic interface shall

be functions that can be referenced as defined operations (10.1.6, 15.5). In the case of functions of two arguments, infix binary operator notation is implied. In the case of functions of one argument, prefix operator notation is implied. OPERATOR shall not be specified for functions with no arguments or for functions with more than two arguments. The dummy arguments shall be nonoptional dummy data objects and shall have the INTENT (IN) or VALUE attribute. The function result shall not have assumed character length. If the operator is an intrinsic-operator (R608), the number of dummy arguments shall be consistent with the intrinsic uses of that operator, and the types, kind type parameters, or ranks of the dummy arguments shall differ from those required for the intrinsic operation (10.1.5). 2 A defined operation is treated as a reference to the function.

For a unary defined operation, the operand corresponds to the function’s dummy argument; for a binary operation, the left-hand operand corresponds to the first dummy argument of the function and the right-hand operand corresponds to the second dummy argument. All restrictions and constraints that apply to actual arguments in a reference to the function also apply to the corresponding operands in the expression as if they were used as actual arguments.

3 A given defined operator may, as with generic names, apply to more than one function, in which case it is generic

in exact analogy to generic procedure names. For intrinsic operator symbols, the generic properties include the intrinsic operations they represent. Because both forms of each relational operator have the same interpretation (10.1.6.2), extending one form (such as <=) has the effect of defining both forms (<= and .LE.). NOTE 1 An example of the use of the OPERATOR generic specification is: INTERFACE OPERATOR ( * )

ISO/IEC JTC 1/SC 22/WG5/N2184

309

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) FUNCTION BOOLEAN_AND (B1, B2) LOGICAL, INTENT (IN) :: B1 (:), B2 (SIZE (B1)) LOGICAL :: BOOLEAN_AND (SIZE (B1)) END FUNCTION BOOLEAN_AND END INTERFACE OPERATOR ( * ) This allows, for example SENSOR (1:N) * ACTION (1:N) as an alternative to the function reference BOOLEAN_AND (SENSOR (1:N), ACTION (1:N))

1

15.4.3.4.3

! SENSOR and ACTION are of type LOGICAL

Defined assignments

2 3 4 5

1 If ASSIGNMENT ( = ) is specified in a generic specification, all the procedures in the generic interface shall

6

2 Each of these subroutines shall have exactly two dummy arguments. The dummy arguments shall be nonoptional

7 8 9 10 11 12

dummy data objects. The first argument shall have INTENT (OUT) or INTENT (INOUT) and the second argument shall have the INTENT (IN) or VALUE attribute. Either the second argument shall be an array whose rank differs from that of the first argument, the declared types and kind type parameters of the arguments shall not conform as specified in Table 10.8, or the first argument shall be of derived type. A defined assignment is treated as a reference to the subroutine, with the left-hand side as the first argument and the right-hand side enclosed in parentheses as the second argument. All restrictions and constraints that apply to actual arguments in a reference to the subroutine also apply to the left-hand-side and to the right-hand-side enclosed in parentheses as if they were used as actual arguments. The ASSIGNMENT generic specification specifies that assignment is extended or redefined.

13 14 15

be subroutines that can be referenced as defined assignments (10.2.1.4, 10.2.1.5). Defined assignment may, as with generic names, apply to more than one subroutine, in which case it is generic in exact analogy to generic procedure names.

NOTE 1 An example of the use of the ASSIGNMENT generic specification is: INTERFACE ASSIGNMENT ( = ) SUBROUTINE LOGICAL_TO_NUMERIC (N, B) INTEGER, INTENT (OUT) :: N LOGICAL, INTENT (IN) :: B END SUBROUTINE LOGICAL_TO_NUMERIC SUBROUTINE CHAR_TO_STRING (S, C) USE STRING_MODULE ! Contains definition of type STRING TYPE (STRING), INTENT (OUT) :: S ! A variable-length string CHARACTER (*), INTENT (IN) :: C END SUBROUTINE CHAR_TO_STRING END INTERFACE ASSIGNMENT ( = ) Example assignments are: KOUNT = SENSOR (J) NOTE = ’89AB’

! CALL LOGICAL_TO_NUMERIC (KOUNT, (SENSOR (J))) ! CALL CHAR_TO_STRING (NOTE, (’89AB’))

NOTE 2 A procedure which has a generic identifier of ASSIGNMENT ( = ) and whose second dummy argument has the ALLOCATABLE or POINTER attribute cannot be directly invoked by defined assignment. This is because the actual argument associated with that dummy argument is the right-hand side of the as-

310

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) signment enclosed in parentheses, which makes the actual argument an expression that does not have the ALLOCATABLE, POINTER, or TARGET attribute. 1 2 3 4 5 6 7

15.4.3.4.4

Defined input/output procedure interfaces

1 All of the procedures specified in an interface block for a defined input/output procedure shall be subroutines

that have interfaces as described in 12.6.4.8.2. 15.4.3.4.5

Restrictions on generic declarations

1 This subclause contains the rules that shall be satisfied by every pair of specific procedures that have the same

generic identifier within the scope of the identifier. If a generic procedure is accessed from a module, the rules apply to all the specific versions even if some of them are inaccessible by their specific names. NOTE 1 In most scoping units, the possible sources of procedures with a particular generic identifier are the accessible generic identifiers specified by generic interface blocks or GENERIC statements and the generic bindings other than names for the accessible objects in that scoping unit. In a type definition, they are the generic bindings, including those from a parent type.

8 9 10

2 A dummy argument is type, kind, and rank compatible, or TKR compatible, with another dummy argument if

11

3 Two dummy arguments are distinguishable if

the first is type compatible with the second, the kind type parameters of the first have the same values as the corresponding kind type parameters of the second, and both have the same rank or either is assumed-rank.

16

• one is a procedure and the other is a data object, • they are both data objects or known to be functions, and neither is TKR compatible with the other, • one has the ALLOCATABLE attribute and the other has the POINTER attribute and not the INTENT (IN) attribute, or • one is a function with nonzero rank and the other is not known to be a function.

17 18 19

C1511 Within the scope of a generic operator, if two procedures with that identifier have the same number of arguments, one shall have a dummy argument that corresponds by position in the argument list to a dummy argument of the other that is distinguishable from it.

20 21 22

C1512 Within the scope of the generic ASSIGNMENT (=) identifier, if two procedures have that identifier, one shall have a dummy argument that corresponds by position in the argument list to a dummy argument of the other that is distinguishable from it.

23 24

C1513 Within the scope of a defined-io-generic-spec, if two procedures have that generic identifier, their dtv arguments (12.6.4.8.2) shall be distinguishable.

25 26

C1514 Within the scope of a generic name, each pair of procedures identified by that name shall both be subroutines or both be functions, and

12 13 14 15

27

(1)

there is a non-passed-object dummy data object in one or the other of them such that

28 29 30

(a)

the number of dummy data objects in one that are nonoptional, are not passed-object, and with which that dummy data object is TKR compatible, possibly including that dummy data object itself,

31

exceeds

32 33

(b)

the number of non-passed-object dummy data objects, both optional and nonoptional, in the other that are not distinguishable from that dummy data object,

ISO/IEC JTC 1/SC 22/WG5/N2184

311

J3/21-007r1

1 2

(2)

3 4

(3)

5

(4)

WD 1539-1

2021-05-21

the number of nonoptional dummy procedures in one of them exceeds the number of dummy procedures in the other, both have passed-object dummy arguments and the passed-object dummy arguments are distinguishable, or at least one of them shall have both

6 7 8

(a)

9 10 11

(b)

12

and the dummy argument that disambiguates by position shall either be the same as or occur earlier in the argument list than the one that disambiguates by name.

13

a nonoptional non-passed-object dummy argument at an effective position such that either the other procedure has no dummy argument at that effective position or the dummy argument at that position is distinguishable from it, and a nonoptional non-passed-object dummy argument whose name is such that either the other procedure has no dummy argument with that name or the dummy argument with that name is distinguishable from it,

14 15

4 The effective position of a dummy argument is its position in the argument list after any passed-object dummy

16 17 18

5 Within the scope of a generic name that is the same as the generic name of an intrinsic procedure, the intrinsic

19

argument has been removed. procedure is not accessible by its generic name if the procedures in the interface and the intrinsic procedure are not all functions or not all subroutines. If a generic invocation is consistent with both a specific procedure from an interface and an accessible intrinsic procedure, it is the specific procedure from the interface that is referenced. NOTE 2 An extensive explanation of the application of these rules is in C.11.6.

20 21 22 23 24

15.4.3.5

EXTERNAL statement

1 An EXTERNAL statement specifies the EXTERNAL attribute (8.5.9) for a list of names.

is

R1511 external-stmt

EXTERNAL [ :: ] external-name-list

2 The appearance of the name of a block data program unit in an EXTERNAL statement confirms that the block

data program unit is a part of the program. NOTE 1 For explanatory information on potential portability problems with external procedures, see C.11.1. NOTE 2 An example of an EXTERNAL statement is: EXTERNAL FOCUS

25 26 27

15.4.3.6

Procedure declaration statement

1 A procedure declaration statement declares procedure pointers, dummy procedures, and external procedures. It

specifies the EXTERNAL attribute (8.5.9) for all entities in the proc-decl-list.

28 29

R1512 procedure-declaration-stmt

is

30 31

R1513 proc-interface

is interface-name or declaration-type-spec

32 33

R1514 proc-attr-spec

is access-spec or proc-language-binding-spec

312

PROCEDURE ( [ proc-interface ] ) [ [ , proc-attr-spec ] ... :: ] proc-decl-list

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5

WD 1539-1

or or or or or

INTENT ( intent-spec ) OPTIONAL POINTER PROTECTED SAVE

J3/21-007r1

6

R1515 proc-decl

is

procedure-entity-name [ => proc-pointer-init ]

7

R1516 interface-name

is

name

8 9

R1517 proc-pointer-init

is null-init or initial-proc-target

10

R1518 initial-proc-target

is

11 12 13

C1515 (R1516) The name shall be the name of an abstract interface or of a procedure that has an explicit interface. If name is declared by a procedure-declaration-stmt it shall be previously declared. If name

14

C1516 (R1516) The name shall not be the same as a keyword that specifies an intrinsic type.

15 16

C1517 (R1512) If a proc-interface describes an elemental procedure, each procedure-entity-name shall specify an external procedure.

17

C1518 (R1515) If => appears in proc-decl, the procedure entity shall have the POINTER attribute.

18 19

C1519 (R1518) The procedure-name shall be the name of a nonelemental external or module procedure, or a

20 21

C1520 (R1512) If proc-language-binding-spec with NAME= is specified, then proc-decl-list shall contain exactly one proc-decl, which shall neither have the POINTER attribute nor be a dummy procedure.

22

C1521 (R1512) If proc-language-binding-spec is specified, the proc-interface shall appear, it shall be an interfacename, and interface-name shall be declared with a proc-language-binding-spec.

23

procedure-name

denotes an intrinsic procedure it shall be one that is listed in Table 16.2.

specific intrinsic function listed in Table 16.2.

24 25 26 27

2 If proc-interface appears and consists of interface-name, it specifies an explicit specific interface (15.4.3.2) for the

28

3 If proc-interface appears and consists of declaration-type-spec, it specifies that the declared procedure entities are

29 30

functions having implicit interfaces and the specified result type. If a type is specified for an external function, its function definition (15.6.2.2) shall specify the same result type and type parameters.

31 32

4 If proc-interface does not appear, the procedure declaration statement does not specify whether the declared

33 34

5 If a proc-attr-spec other than a proc-language-binding-spec appears, it specifies that the declared procedure entities

35 36

declared procedure entities. The abstract interface (15.4) is that specified by the interface named by interfacename. The interface specified by interface-name shall not depend on any characteristic of a procedure identified by a procedure-entity-name in the proc-decl-list of the same procedure declaration statement.

procedure entities are subroutines or functions. have that attribute. These attributes are described in 8.5. If a proc-language-binding-spec with NAME= appears, it specifies a binding label or its absence, as described in 18.10.2. A proc-language-binding-spec without NAME= is allowed, but is redundant with the proc-interface required by C1521.

37 38 39 40

6 If => appears in a proc-decl in a procedure-declaration-stmt it specifies the initial association status of the

41 42 43

7 If procedure-entity-name has an explicit interface, its characteristics shall be the same as initial-proc-target except

corresponding procedure entity, and implies the SAVE attribute, which may be confirmed by explicit specification. If => null-init appears, the procedure entity is initially disassociated. If => initial-proc-target appears, the procedure entity is initially associated with the target. that initial-proc-target may be pure even if procedure-entity-name is not pure, initial-proc-target may be simple even if procedure-entity-name is not simple, and initial-proc-target may be an elemental intrinsic procedure.

ISO/IEC JTC 1/SC 22/WG5/N2184

313

J3/21-007r1

WD 1539-1

2021-05-21

1 2

8 If the characteristics of procedure-entity-name or initial-proc-target are such that an explicit interface is required,

3 4

9 If procedure-entity-name has an implicit interface and is explicitly typed or referenced as a function, initial-proc-

5 6

both procedure-entity-name and initial-proc-target shall have an explicit interface. target shall be a function. If procedure-entity-name has an implicit interface and is referenced as a subroutine, initial-proc-target shall be a subroutine. 10 If initial-proc-target and procedure-entity-name are functions, their results shall have the same characteristics.

NOTE 1 The following code illustrates procedure declaration statements. 10.2.2.5, NOTE 1 illustrates the use of the P and BESSEL defined by this code. ABSTRACT INTERFACE FUNCTION REAL_FUNC (X) REAL, INTENT (IN) :: X REAL :: REAL_FUNC END FUNCTION REAL_FUNC END INTERFACE INTERFACE SUBROUTINE SUB (X) REAL, INTENT (IN) :: X END SUBROUTINE SUB END INTERFACE !-- Some external or dummy procedures with explicit interface. PROCEDURE (REAL_FUNC) :: BESSEL, GFUN PROCEDURE (SUB) :: PRINT_REAL !-- Some procedure pointers with explicit interface, !-- one initialized to NULL(). PROCEDURE (REAL_FUNC), POINTER :: P, R => NULL () PROCEDURE (REAL_FUNC), POINTER :: PTR_TO_GFUN !-- A derived type with a procedure pointer component ... TYPE STRUCT_TYPE PROCEDURE (REAL_FUNC), POINTER, NOPASS :: COMPONENT END TYPE STRUCT_TYPE !-- ... and a variable of that type. TYPE(STRUCT_TYPE) :: STRUCT !-- An external or dummy function with implicit interface PROCEDURE (REAL) :: PSI

7 8

15.4.3.7

INTRINSIC statement

1 An INTRINSIC statement specifies the INTRINSIC attribute (8.5.11) for a list of names.

is

9

R1519 intrinsic-stmt

INTRINSIC [ :: ] intrinsic-procedure-name-list

10

C1522 (R1519) Each intrinsic-procedure-name shall be the name of an intrinsic procedure.

11

15.4.3.8

Implicit interface specification

12

1 If the interface of a function is implicit, the type and type parameters of the function result are specified by an

13 14 15

implicit or explicit type specification of the function name. The type, type parameters, and shape of the dummy arguments of a procedure invoked from where the interface of the procedure is implicit shall be such that each actual argument is consistent with the characteristics of the corresponding dummy argument.

314

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

15.5

Procedure reference

2

15.5.1

Syntax of a procedure reference

3 4

J3/21-007r1

1 The form of a procedure reference is dependent on the interface of the procedure or procedure pointer, but is

independent of the means by which the procedure is defined. The forms of procedure references are as follows. is

5

R1520 function-reference

6

C1523 (R1520) The procedure-designator shall designate a function.

7

C1524 (R1520) The actual-arg-spec-list shall not contain an alt-return-spec.

8

R1521 call-stmt

9

C1525 (R1521) The procedure-designator shall designate a subroutine.

10 11 12

R1522 procedure-designator

13

C1526 (R1522) A procedure-name shall be a generic name or the name of a procedure.

14

C1527 (R1522) A binding-name shall be a binding name (7.5.5) of the declared type of data-ref .

15

C1528 (R1522) A data-ref shall not be a polymorphic subobject of a coindexed object.

16

C1529 (R1522) If data-ref is an array, the referenced type-bound procedure shall have the PASS attribute.

17 18

2 The data-ref in a procedure-designator shall not be an unallocated allocatable variable or a pointer that is not

19

3 Resolving references to type-bound procedures is described in 15.5.6.

20 21

4 A function may also be referenced as a defined operation (10.1.6). A subroutine may also be referenced as a

is

procedure-designator ( [ actual-arg-spec-list ] )

CALL procedure-designator [ ( [ actual-arg-spec-list ] ) ]

is procedure-name or proc-component-ref or data-ref % binding-name

associated.

defined assignment (10.2.1.4, 10.2.1.5), by defined input/output (12.6.4.8), or by finalization (7.5.6). NOTE 1 When resolving type-bound procedure references, constraints on the use of coindexed objects ensure that the coindexed object (on the remote image) has the same dynamic type as the corresponding object on the local image. Thus a processor can resolve the type-bound procedure using the coarray variable on its own image and pass the coindexed object as the actual argument.

22

R1523 actual-arg-spec

is

[ keyword = ] actual-arg

23

R1524 actual-arg

is or or or or

expr variable procedure-name proc-component-ref

is

* label

24 25 26 27

alt-return-spec

28

R1525

29

C1530 (R1523) The keyword = shall not appear if the interface of the procedure is implicit.

30 31

C1531 (R1523) The keyword = shall not be omitted from an actual-arg-spec unless it has been omitted from each preceding actual-arg-spec in the argument list.

32

C1532 (R1523) Each keyword shall be the name of a dummy argument in the explicit interface of the procedure.

alt-return-spec

ISO/IEC JTC 1/SC 22/WG5/N2184

315

J3/21-007r1

WD 1539-1

2021-05-21

1

C1533 (R1524) A nonintrinsic elemental procedure shall not be used as an actual argument.

2 3

C1534 (R1524) A procedure-name shall be the name of an external, internal, module, or dummy procedure, a specific intrinsic function listed in Table 16.2, or a procedure pointer.

4

C1535 (R1524) expr shall not be a variable.

5

C1536 (R1525) The label shall be the statement label of a branch target statement that appears in the same inclusive scope as the

6 7

call-stmt.

C1537 An actual argument that is a coindexed object shall not have a pointer ultimate component. NOTE 2 Examples of procedure reference using procedure pointers: P => BESSEL WRITE (*, *) P(2.5)

!-- BESSEL(2.5)

S => PRINT_REAL CALL S(3.14) NOTE 3 An internal procedure cannot be invoked using a procedure pointer from either Fortran or C after the host instance completes execution, because the pointer is then undefined. While the host instance is active, however, if an internal procedure was passed as an actual argument or is the target of a procedure pointer, it could be invoked from outside of the host subprogram. Rb Assume there is a procedure with the following interface that calculates a f (x) dx. INTERFACE FUNCTION INTEGRATE(F, A, B) RESULT(INTEGRAL) BIND(C) USE ISO_C_BINDING INTERFACE FUNCTION F(X) BIND(C) ! Integrand USE ISO_C_BINDING REAL(C_FLOAT), VALUE :: X REAL(C_FLOAT) :: F END FUNCTION END INTERFACE REAL(C_FLOAT), VALUE :: A, B ! Bounds REAL(C_FLOAT) :: INTEGRAL END FUNCTION INTEGRATE END INTERFACE This procedure can be called from Fortran or C, and could be written in either Fortran or C. The argument F representing the mathematical function f (x) can be written as an internal procedure; this internal procedure will have access to any host instance local variables necessary to actually calculate f (x). For example: REAL FUNCTION MY_INTEGRATION(N, A, B) RESULT(INTEGRAL) ! Integrate f(x)=x^n over [a,b] USE ISO_C_BINDING INTEGER, INTENT(IN) :: N REAL, INTENT(IN) :: A, B INTEGRAL = INTEGRATE(MY_F, REAL (A, C_FLOAT), REAL (B, C_FLOAT)) ! This will call the internal function MY_F to calculate f(x). ! The above interface of INTEGRATE needs to be explicit and available.

316

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 3 (cont.) CONTAINS REAL(C_FLOAT) FUNCTION MY_F(X) BIND(C) ! Integrand REAL(C_FLOAT), VALUE :: X MY_F = X**N ! N is taken from the host instance of MY_INTEGRATION. END FUNCTION END FUNCTION MY_INTEGRATION The function INTEGRATE cannot retain a function pointer to MY_F and use it after INTEGRATE has finished execution, because the host instance of MY_F might no longer exist, making the pointer undefined. If such a pointer is retained, then it can only be used to invoke MY_F during the execution of the instance of MY_INTEGRATION that called INTEGRATE. 1

15.5.2

Actual arguments, dummy arguments, and argument association

2

15.5.2.1

Argument correspondence

3 4 5 6 7 8 9 10 11 12 13 14

1 In either a subroutine reference or a function reference, the actual argument list identifies the correspondence

between the actual arguments and the dummy arguments of the procedure. This correspondence can be established either by keyword or by position. If an argument keyword appears, the actual argument corresponds to the dummy argument whose name is the same as the argument keyword (using the dummy argument names from the interface accessible by the procedure reference). In the absence of an argument keyword, an actual argument corresponds to the dummy argument occupying the corresponding position in the reduced dummy argument list; that is, the first actual argument corresponds to the first dummy argument in the reduced list, the second actual argument corresponds to the second dummy argument in the reduced list, etc. The reduced dummy argument list is either the full dummy argument list or, if there is a passed-object dummy argument (7.5.4.5), the dummy argument list with the passed-object dummy argument omitted. Exactly one actual argument shall correspond to each nonoptional dummy argument. At most one actual argument shall correspond to each optional dummy argument. Each actual argument shall correspond to a dummy argument. NOTE 1 For example, the procedure defined by SUBROUTINE SOLVE (FUNCT, SOLUTION, METHOD, STRATEGY, PRINT) INTERFACE FUNCTION FUNCT (X) REAL FUNCT, X END FUNCTION FUNCT END INTERFACE REAL SOLUTION INTEGER, OPTIONAL :: METHOD, STRATEGY, PRINT ... can be invoked with CALL SOLVE (FUN, SOL, PRINT = 6) provided its interface is explicit, and if the interface is specified by an interface body, the name of the last argument is PRINT.

15 16 17 18

15.5.2.2

The passed-object dummy argument and argument correspondence

1 In a reference to a type-bound procedure, or a procedure pointer component, that has a passed-object dummy

argument (7.5.4.5), the data-ref of the function-reference or call-stmt corresponds, as an actual argument, with the passed-object dummy argument.

ISO/IEC JTC 1/SC 22/WG5/N2184

317

J3/21-007r1

1

15.5.2.3

WD 1539-1

2021-05-21

Argument association

2 3

1 Except in references to intrinsic inquiry functions, a pointer actual argument that corresponds to a nonoptional

4 5

2 If a nonpointer dummy argument without the VALUE attribute corresponds to a pointer actual argument that

nonpointer dummy argument shall be pointer associated with a target.

7 8

is pointer associated with a target, • if the dummy argument is polymorphic, it becomes argument associated with that target; • if the dummy argument is nonpolymorphic, it becomes argument associated with the declared type part of that target.

9

3 If a present nonpointer dummy argument without the VALUE attribute corresponds to a nonpointer actual

10

argument, • if the dummy argument is polymorphic, it becomes argument associated with that actual argument; • if the dummy argument is nonpolymorphic, it becomes argument associated with the declared type part of that actual argument.

6

11 12 13 14 15

4 A present dummy argument with the VALUE attribute becomes argument associated with a definable anonymous

16

5 A present pointer dummy argument that corresponds to a pointer actual argument becomes argument associated

17 18

with that actual argument. A present pointer dummy argument that does not correspond to a pointer actual argument is not argument associated.

data object whose initial value is the value of the actual argument.

19

6 The entity that is argument associated with a dummy argument is called its effective argument.

20 21 22

7 The ultimate argument is the effective argument if the effective argument is not a dummy argument or a subobject

23

of a dummy argument. If the effective argument is a dummy argument, the ultimate argument is the ultimate argument of that dummy argument. If the effective argument is a subobject of a dummy argument, the ultimate argument is the corresponding subobject of the ultimate argument of that dummy argument. NOTE 1 For the sequence of subroutine calls INTEGER :: X(100) CALL SUBA (X) ... SUBROUTINE SUBA(A) INTEGER :: A(:) CALL SUBB (A(1:5), A(5:1:-1)) ... SUBROUTINE SUBB(B, C) INTEGER :: B(:), C(:) the ultimate argument of B is X(1:5). The ultimate argument of C is X(5:1:-1) and this is not the same object as the ultimate argument of B. NOTE 2 Fortran argument association is usually similar to call by reference and call by value-result. If the VALUE attribute is specified, the effect is as if the actual argument were assigned to a temporary variable, and that variable were then argument associated with the dummy argument. Subsequent changes to the value or definition status of the dummy argument do not affect the actual argument. The actual mechanism by which this happens is determined by the processor.

24 25 26

15.5.2.4

Ordinary dummy variables

1 The requirements in this subclause apply to actual arguments that correspond to nonallocatable nonpointer

dummy data objects.

318

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5

WD 1539-1

J3/21-007r1

2 The dummy argument shall be type compatible with the actual argument. If the actual argument is a polymorphic

coindexed object, the dummy argument shall not be polymorphic. If the actual argument is a polymorphic assumed-size array, the dummy argument shall be polymorphic. If the actual argument is of a derived type that has type parameters, type-bound procedures, or final subroutines, the dummy argument shall not be assumedtype.

6 7 8 9 10

3 The kind type parameter values of the actual argument shall agree with the corresponding ones of the dummy

11 12 13 14 15

4 If a present scalar dummy argument is of type character with default kind or C character kind, the length len of

16

5 The values of assumed type parameters of a dummy argument are assumed from the corresponding type para-

17 18 19

argument. The length type parameter values of a present actual argument shall agree with the corresponding ones of the dummy argument that are not assumed, except for the case of the character length parameter of an actual argument of type character with default kind or C character kind (18.2.2) associated with a dummy argument that is not assumed-shape or assumed-rank. the dummy argument shall be less than or equal to the length of the actual argument. The dummy argument becomes associated with the leftmost len characters of the actual argument. If a present array dummy argument is of type character with default kind or C character kind and is not assumed-shape or assumed-rank, it becomes associated with the leftmost characters of the actual argument element sequence (15.5.2.11). meters of its effective argument. 6 If the actual argument is a coindexed object with an allocatable ultimate component, the dummy argument shall

have the INTENT (IN) or the VALUE attribute. NOTE 1 If the actual argument is a coindexed object, a processor that uses distributed memory might create a copy on the executing image of the actual argument, including copies of any allocated allocatable subobjects, and associate the dummy argument with that copy. If necessary, on return from the procedure, the value of the copy would be copied back to the actual argument.

20 21

7 Except in references to intrinsic inquiry functions, if the dummy argument is nonoptional and the actual argument

22 23 24 25 26

8 If the dummy argument does not have the TARGET attribute, any pointers associated with the effective argument

27

9 If the dummy argument has the TARGET attribute, does not have the VALUE attribute, and either the effective

28 29 30

argument is simply contiguous or the dummy argument is scalar, assumed-rank, or assumed-shape, and does not have the CONTIGUOUS attribute, and the effective argument has the TARGET attribute but is not a coindexed object or an array section with a vector subscript then

31

• any pointers associated with the effective argument become associated with the corresponding dummy argument on invocation of the procedure, and • when execution of the procedure completes, any pointers that do not become undefined (19.5.2.5) and are associated with the dummy argument remain associated with the effective argument.

32 33 34

is allocatable, the corresponding actual argument shall be allocated. do not become associated with the corresponding dummy argument on invocation of the procedure. If such a dummy argument is used as an actual argument that corresponds to a dummy argument with the TARGET attribute, whether any pointers associated with the original effective argument become associated with the dummy argument with the TARGET attribute is processor dependent.

35 36 37 38

10 If the dummy argument has the TARGET attribute and is an explicit-shape array, an assumed-shape array with

39 40

• on invocation of the procedure, whether any pointers associated with the effective argument become associated with the corresponding dummy argument is processor dependent, and • when execution of the procedure completes, the pointer association status of any pointer that is pointer associated with the dummy argument is processor dependent.

41 42

the CONTIGUOUS attribute, an assumed-rank object with the CONTIGUOUS attribute, or an assumed-size array, and the effective argument has the TARGET attribute but is not simply contiguous and is not an array section with a vector subscript then

ISO/IEC JTC 1/SC 22/WG5/N2184

319

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

11 If the dummy argument has the TARGET attribute and the effective argument does not have the TARGET

4

12 If the dummy argument has the TARGET attribute and the VALUE attribute, any pointers associated with the

5

attribute or is an array section with a vector subscript, any pointers associated with the dummy argument become undefined when execution of the procedure completes. dummy argument become undefined when execution of the procedure completes.

6

13 If the actual argument is a coindexed scalar, the corresponding dummy argument shall be scalar.

7

14 If the actual argument is a noncoindexed scalar, the corresponding dummy argument shall be scalar unless

8 9 10 11

• the actual argument is default character, of type character with the C character kind (18.2.2), or is an element or substring of an element of an array that is not an assumed-shape, pointer, or polymorphic array, • the dummy argument has assumed-rank, or • the dummy argument is an assumed-type assumed-size array.

12 13

15 If the procedure is nonelemental and is referenced by a generic name or as a defined operator or defined assignment,

14 15

16 If a dummy argument is an assumed-shape array, the rank of the actual argument shall be the same as the rank

16

17 An actual argument of any rank may correspond to an assumed-rank dummy argument. The rank and extents of

17 18 19

the dummy argument are the rank and extents of the corresponding actual argument. The lower bound of each dimension of the dummy argument is equal to one. The upper bound is equal to the extent, except for the last dimension when the actual argument is assumed-size.

20 21

18 Except when a procedure reference is elemental (15.9), each element of an array actual argument or of a sequence

22

the ranks of the actual arguments and corresponding dummy arguments shall agree. of the dummy argument, and the actual argument shall not be an assumed-size array.

in a sequence association (15.5.2.11) is associated with the element of the dummy array that has the same position in array element order (9.5.3.3). NOTE 2 For default character sequence associations, the interpretation of element is provided in 15.5.2.11.

23

19 A scalar dummy argument of a nonelemental procedure shall correspond only to a scalar actual argument.

24 25 26 27

20 If a dummy argument has INTENT (OUT) or INTENT (INOUT), the actual argument shall be definable. If a

28

21 If the procedure is nonelemental, the dummy argument does not have the VALUE attribute, and the actual

29 30

argument is an array section having a vector subscript, the dummy argument is not definable and shall not have the ASYNCHRONOUS, INTENT (OUT), INTENT (INOUT), or VOLATILE attributes.

31 32 33

22 If the dummy argument has a coarray ultimate component, the corresponding actual argument shall have the

34

dummy argument has INTENT (OUT), the effective argument becomes undefined at the time the association is established, except for direct components of an object of derived type for which default initialization has been specified.

VOLATILE attribute if and only if the dummy argument has the VOLATILE attribute. If the dummy argument is an array with a coarray ultimate component, the corresponding actual argument shall be simply contiguous or an element of a simply contiguous array. NOTE 3 Argument intent specifications serve several purposes. See 8.5.10, NOTE 4. NOTE 4 For more explanatory information on targets as dummy arguments, see C.11.4.

35

C1538 An actual argument that is a coindexed object with the ASYNCHRONOUS or VOLATILE attribute shall

320

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

not correspond to a dummy argument that has either the ASYNCHRONOUS or VOLATILE attribute, unless the dummy argument has the VALUE attribute.

3 4

C1539 (R1524) If an actual argument is a nonpointer array that has the ASYNCHRONOUS or VOLATILE attribute but is not simply contiguous (9.5.4), and the corresponding dummy argument has either the ASYNCHRONOUS or VOLATILE attribute, but does not have the VALUE attribute, that dummy argument shall be assumed-shape or assumed-rank and shall not have the CONTIGUOUS attribute.

5 6 7 8 9 10 11

C1540 (R1524) If an actual argument is an array pointer that has the ASYNCHRONOUS or VOLATILE attribute but does not have the CONTIGUOUS attribute, and the corresponding dummy argument has either the ASYNCHRONOUS or VOLATILE attribute, but does not have the VALUE attribute, that dummy argument shall be an array pointer, an assumed-shape array without the CONTIGUOUS attribute, or an assumed-rank entity without the CONTIGUOUS attribute. NOTE 5 The constraints on an actual argument with the ASYNCHRONOUS or VOLATILE attribute that corresponds to a dummy argument with either the ASYNCHRONOUS or VOLATILE attribute are designed to avoid forcing a processor to use the so-called copy-in/copy-out argument passing mechanism. Making a copy of an actual argument whose value is likely to change due to an asynchronous input/output operation completing or in some unpredictable manner will cause the new value to be lost when a called procedure returns and the copy-out overwrites the actual argument. NOTE 6 If an effective argument is a discontiguous array, and the dummy argument is an assumed-shape array with the CONTIGUOUS attribute, an assumed-rank dummy data object with the CONTIGUOUS attribute, an explicit-shape array, or an assumed-size array, the processor might need to use the so-called copy-in/copyout argument passing mechanism, so as to ensure that the dummy array is contiguous even when the actual argument is not.

12 13 14 15 16 17

15.5.2.5

Allocatable and pointer dummy variables

1 The requirements in this subclause apply to an actual argument with the ALLOCATABLE or POINTER attribute

that corresponds to a dummy argument with the same attribute. 2 The actual argument shall be polymorphic if and only if the associated dummy argument is polymorphic, and

either both the actual and dummy arguments shall be unlimited polymorphic, or the declared type of the actual argument shall be the same as the declared type of the dummy argument. NOTE 1 The dynamic type of a polymorphic allocatable or pointer dummy argument can change as a result of execution of an ALLOCATE statement or pointer assignment in the subprogram. Because of this the corresponding actual argument needs to be polymorphic and have a declared type that is the same as the declared type of the dummy argument or an extension of that type. However, type compatibility requires that the declared type of the dummy argument be the same as, or an extension of, the type of the actual argument. Therefore, the dummy and actual arguments need to have the same declared type. Dynamic type information is not maintained for a nonpolymorphic allocatable or pointer dummy argument. However, allocating or pointer-assigning such a dummy argument would require maintenance of this information if the corresponding actual argument is polymorphic. Therefore, the corresponding actual argument needs to be nonpolymorphic.

18 19 20 21

3 The rank of the actual argument shall be the same as that of the dummy argument, unless the dummy argument

is assumed-rank. The type parameter values of the actual argument shall agree with the corresponding ones of the dummy argument that are not assumed or deferred. The values of assumed type parameters of the dummy argument are assumed from the corresponding type parameters of its effective argument.

ISO/IEC JTC 1/SC 22/WG5/N2184

321

J3/21-007r1

1 2

WD 1539-1

2021-05-21

4 The actual argument shall have deferred the same type parameters as the dummy argument.

15.5.2.6

Allocatable dummy variables

3

1 The requirements in this subclause apply to actual arguments that correspond to allocatable dummy data objects.

4 5

2 The actual argument shall be allocatable. It is permissible for the actual argument to have an allocation status

6

3 The corank of the actual argument shall be the same as that of the dummy argument.

7

4 If the actual argument is a coindexed object, the dummy argument shall have the INTENT (IN) attribute.

8

5 If the dummy argument does not have the TARGET attribute, any pointers associated with the actual argument

9 10 11 12

do not become associated with the corresponding dummy argument on invocation of the procedure. If such a dummy argument is used as an actual argument that is associated with a dummy argument with the TARGET attribute, whether any pointers associated with the original actual argument become associated with the dummy argument with the TARGET attribute is processor dependent.

13 14

6 If the dummy argument has the TARGET attribute, does not have the INTENT (OUT) or VALUE attribute,

15 16

• any pointers associated with the actual argument become associated with the corresponding dummy argument on invocation of the procedure, and • when execution of the procedure completes, any pointers that do not become undefined (19.5.2.5) and are associated with the dummy argument remain associated with the actual argument.

17 18 19 20 21 22 23

of unallocated.

and the corresponding actual argument has the TARGET attribute then

7 If a dummy argument has INTENT (OUT) or INTENT (INOUT), the actual argument shall be definable. If a

dummy argument has INTENT (OUT) and its associated actual argument is allocated, the actual argument is deallocated on procedure invocation (9.7.3.2). 15.5.2.7

Pointer dummy variables

1 The requirements in this subclause apply to actual arguments that correspond to dummy data pointers.

24 25

C1541 The actual argument corresponding to a dummy pointer with the CONTIGUOUS attribute shall be simply contiguous (9.5.4).

26

C1542 The actual argument corresponding to a dummy pointer shall not be a coindexed object. NOTE 1 Constraint C1542 does not apply to any intrinsic procedure because an intrinsic procedure is defined in terms of its actual arguments.

27 28 29

2 If the dummy argument does not have INTENT (IN), the actual argument shall be a pointer. Otherwise, the

30 31

3 If the dummy argument has INTENT (OUT), the pointer association status of the actual argument becomes

actual argument shall be a pointer or a valid target for the dummy pointer in a pointer assignment statement. If the actual argument is not a pointer, the dummy pointer becomes pointer associated with the actual argument. undefined on invocation of the procedure. NOTE 2 For more explanatory information on pointers as dummy arguments, see C.11.4.

32 33 34

15.5.2.8

Coarray dummy variables

1 If the dummy argument is a coarray, the corresponding actual argument shall be a coarray and shall have the

VOLATILE attribute if and only if the dummy argument has the VOLATILE attribute.

322

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

2 If the dummy argument is an array coarray that has the CONTIGUOUS attribute or is not of assumed shape,

the corresponding actual argument shall be simply contiguous or an element of a simply contiguous array. NOTE 1 The requirements on an actual argument that corresponds to a dummy coarray that is not of assumedshape or has the CONTIGUOUS attribute are designed to avoid forcing a processor to use the so-called copy-in/copy-out argument passing mechanism. NOTE 2 Consider the invocation of a procedure on a particular image. Each dummy coarray is associated with its ultimate argument on the image. In addition, during this execution of the procedure, this image can access the coarray corresponding to the ultimate argument on any other image. For example, consider INTERFACE SUBROUTINE SUB(X) REAL :: X[*] END SUBROUTINE SUB END INTERFACE REAL :: A(1000)[*] ... CALL SUB(A(10)) During execution of this invocation of SUB, the executing image has access through the syntax X[P] to A(10) on image P. NOTE 3 Each invocation of a procedure with a nonallocatable coarray dummy argument establishes a dummy coarray for the image with its own bounds and cobounds. During this execution of the procedure, this image can use its own bounds and cobounds to access the coarray corresponding to the ultimate argument on any other image. For example, consider INTERFACE SUBROUTINE SUB(X,N) INTEGER :: N REAL :: X(N,N)[N,*] END SUBROUTINE SUB END INTERFACE REAL :: A(1000)[*] ... CALL SUB(A,10) During execution of this invocation of SUB, the executing image has access through the syntax X(1,2)[3,4] to A(11) on the image with image index 33.

3

15.5.2.9

Actual arguments associated with dummy procedure entities

4 5 6 7

1 If the interface of a dummy procedure is explicit, its characteristics as a procedure (15.3.1) shall be the same as

8 9 10 11 12

2 If the interface of a dummy procedure is implicit and either the dummy argument is explicitly typed or referenced

those of its effective argument, except that a pure effective argument may be associated with a dummy argument that is not pure, a simple effective argument may be associated with a dummy argument that is not simple, and an elemental intrinsic actual procedure may be associated with a dummy procedure (which cannot be elemental). as a function, it shall not be referenced as a subroutine and any corresponding actual argument shall be a function, function procedure pointer, or dummy procedure. If both the actual argument and dummy argument are known to be functions, they shall have the same type and type parameters. If only the dummy argument is known to be a function, the function that would be invoked by a reference to the dummy argument shall have the same

ISO/IEC JTC 1/SC 22/WG5/N2184

323

J3/21-007r1

WD 1539-1

2021-05-21

1 2

type and type parameters, except that an external function with assumed character length may be associated with a dummy argument with explicit character length.

3 4

3 If the interface of a dummy procedure is implicit and a reference to it appears as a subroutine reference, any

5 6 7

4 If a dummy argument is a dummy procedure without the POINTER attribute, its effective argument shall be an

8 9 10

5 If a dummy argument is a procedure pointer, the corresponding actual argument shall be a procedure pointer, a

11 12 13

corresponding actual argument shall be a subroutine, subroutine procedure pointer, or dummy procedure. external, internal, module, or dummy procedure, or a specific intrinsic procedure listed in Table 16.2. If the specific name is also a generic name, only the specific procedure is associated with the dummy argument.

reference to a function that returns a procedure pointer, a reference to the intrinsic function NULL, or a valid target for the dummy pointer in a pointer assignment statement. If the actual argument is not a pointer, the dummy argument shall have INTENT (IN); if the actual argument is not a dummy argument it becomes pointer associated with the actual argument, otherwise it becomes pointer associated with the ultimate argument of the actual argument.

14 15

6 When the actual argument is a procedure, the host instance of the dummy argument is the host instance of the

16

7 If an external procedure or a dummy procedure is used as an actual argument, its interface shall be explicit or it

actual argument (15.6.2.4).

17

shall be explicitly declared to have the EXTERNAL attribute.

18

15.5.2.10

19 20

Actual arguments and alternate return indicators

1 If a dummy argument is an asterisk (15.6.2.3), the corresponding actual argument shall be an alternate return specifier (R1525).

15.5.2.11

Sequence association

21 22

1 Sequence association only applies when the dummy argument is an explicit-shape or assumed-size array. The

23 24

2 An actual argument represents an element sequence if it is an array expression, an array element designator, a

25 26 27 28 29 30 31 32 33 34 35 36 37 38

rest of this subclause only applies in that case. default character scalar, or a scalar of type character with the C character kind (18.2.2). If the dummy argument is not of type character with default or C character kind, and the actual argument is an array expression, the element sequence consists of the elements in array element order. If the dummy argument is not of type character with default or C character kind, and the actual argument is an array element designator, the element sequence consists of that array element and each element that follows it in array element order. 3 If the dummy argument is of type character with default or C character kind, and has nonzero character length,

the storage unit sequence is as follows: • if the actual argument is an array expression, the storage units of the array; • if the actual argument is an array element or array element substring designator, the storage units starting from the first storage unit of the designator and continuing to the end of the array; • if the actual argument is scalar and not an array element or array element substring designator, the storage units of the scalar object. The element sequence is the sequence of consecutive groups of storage units in the storage unit sequence, grouped by the character length of the dummy array. The sequence terminates when the number of storage units left is less than the character length of the dummy array. NOTE 1 Some of the elements in the element sequence might consist of storage units from different elements of the original array.

39 40 41

4 If the dummy argument is of type character with default or C character kind, and has zero character length,

the element sequence consists of a sequence of elements each with zero character length, the number of elements being the maximum number that is supported by the processor.

324

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

WD 1539-1

J3/21-007r1

5 An actual argument that represents an element sequence and corresponds to a dummy argument that is an array

5 6

is sequence associated with the dummy argument. The rank and shape of the actual argument need not agree with the rank and shape of the dummy argument, but the number of elements in the dummy argument shall not exceed the number of elements in the element sequence of the actual argument. If the dummy argument is assumed-size, the number of elements in the dummy argument is exactly the number of elements in the element sequence.

7

15.5.2.12

8 9 10 11 12 13 14 15

Argument presence and restrictions on arguments not present

1 A dummy argument or an entity that is host associated with a dummy argument is not present if the dummy

argument • does not correspond to an actual argument, • corresponds to an actual argument that is not present, or • does not have the ALLOCATABLE or POINTER attribute, and corresponds to an actual argument that – has the ALLOCATABLE attribute and is not allocated, or – has the POINTER attribute and is disassociated; otherwise, it is present.

16

2 A nonoptional dummy argument shall be present. If an optional nonpointer dummy argument corresponds to a

17

present pointer actual argument, the pointer association status of the actual argument shall not be undefined.

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

3 An optional dummy argument that is not present is subject to the following restrictions.

(1)

If it is a data object, it shall not be referenced or be defined. If it is of a type that has default initialization, the initialization has no effect. (2) It shall not be used as the data-target or proc-target of a pointer assignment. (3) If it is a procedure or procedure pointer, it shall not be invoked. (4) It shall not be supplied as an actual argument corresponding to a nonoptional dummy argument other than as the argument of the intrinsic function PRESENT or as an argument of a function reference that is a constant expression. (5) A designator with it as the base object and with one or more subobject selectors shall not be supplied as an actual argument. (6) If it is an array, it shall not be supplied as an actual argument to an elemental procedure unless an array of the same rank is supplied as an actual argument corresponding to a nonoptional dummy argument of that elemental procedure. (7) If it is a pointer, it shall not be allocated, deallocated, nullified, pointer-assigned, or supplied as an actual argument corresponding to an optional nonpointer dummy argument. (8) If it is allocatable, it shall not be allocated, deallocated, or supplied as an actual argument corresponding to an optional nonallocatable dummy argument. (9) If it has length type parameters, they shall not be the subject of an inquiry. (10) It shall not be used as a selector in an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT TYPE construct. (11) It shall not be supplied as the data-ref in a procedure-designator. (12) If shall not be supplied as the scalar-variable in a proc-component-ref . 4 Except as noted in the list above, it may be supplied as an actual argument corresponding to an optional dummy

argument, which is then also considered not to be present. 15.5.2.13

Restrictions on entities associated with dummy arguments

1 While an entity is associated with a dummy argument, the following restrictions hold.

(1)

Action that affects the allocation status of the entity or a subobject thereof shall be taken through the dummy argument.

ISO/IEC JTC 1/SC 22/WG5/N2184

325

J3/21-007r1

1 2 3

(2)

4 5

(3)

7 8 9

(c)

10 11

(d)

12 13

(4)

14 15 16

18 19 20

(c)

21 22

(d)

23 24

the dummy argument has the POINTER attribute, the dummy argument is a scalar, assumed-shape, or assumed-rank object, and has the TARGET attribute but not the INTENT (IN) or CONTIGUOUS attributes, and the actual argument is a target other than a coindexed object or an array section with a vector subscript, the dummy argument is an assumed-rank object with the TARGET attribute and not the INTENT (IN) attribute, and the actual argument is a scalar target, or the dummy argument is a coarray and the action is a coindexed definition of the corresponding ultimate argument coarray by a different image.

If the value of the entity or any subobject of it is affected through the dummy argument, then at any time during the invocation and execution of the procedure, either before or after the definition, it shall be referenced only through that dummy argument unless (a) (b)

17

2021-05-21

If the allocation status of the entity or a subobject thereof is affected through the dummy argument, then at any time during the invocation and execution of the procedure, either before or after the allocation or deallocation, it shall be referenced only through the dummy argument. Action that affects the value of the entity or any subobject of it shall be taken only through the dummy argument unless (a) (b)

6

WD 1539-1

the dummy argument has the POINTER attribute, the dummy argument is a scalar, assumed-shape, or assumed-rank object, and has the TARGET attribute but not the INTENT (IN) or CONTIGUOUS attributes, and the actual argument is a target other than a coindexed object or an array section with a vector subscript, the dummy argument is an assumed-rank object with the TARGET attribute and not the INTENT (IN) attribute, and the actual argument is a scalar target, or the dummy argument is a coarray and the reference is a coindexed reference of its corresponding ultimate argument coarray by a different image.

NOTE 1 In SUBROUTINE OUTER REAL, POINTER :: A (:) ... ALLOCATE (A (1:N)) ... CALL INNER (A) ... CONTAINS SUBROUTINE INNER (B) REAL :: B (:) ... END SUBROUTINE INNER SUBROUTINE SET (C, D) REAL, INTENT (OUT) :: C REAL, INTENT (IN) :: D C = D END SUBROUTINE SET END SUBROUTINE OUTER an assignment statement such as A (1) = 1.0 would not be permitted during the execution of INNER because this would be changing A without using B, but statements such as B (1) = 1.0 or

326

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 (cont.) CALL SET (B (1), 1.0) would be allowed. Similarly, DEALLOCATE (A) would not be allowed because this affects the allocation of B without using B. In this case, DEALLOCATE (B) also would not be permitted. If B were declared with the POINTER attribute, either of the statements DEALLOCATE (A) and DEALLOCATE (B) would be permitted, but not both. NOTE 2 If there is a partial or complete overlap between the effective arguments of two different dummy arguments of the same procedure and the dummy arguments have neither the POINTER nor TARGET attribute, the overlapped portions cannot be defined, redefined, or become undefined during the execution of the procedure. For example, in CALL SUB (A (1:5), A (3:9)) the array section A (3:5) cannot be defined, redefined, or become undefined through the first dummy argument because it is part of the argument associated with the second dummy argument and cannot be defined, redefined, or become undefined through the second dummy argument because it is part of the argument associated with the first dummy argument. The array section A (1:2) remains definable through the first dummy argument and A (6:9) remains definable through the second dummy argument. This restriction applies equally to pointer targets. In REAL, DIMENSION (10), TARGET :: A REAL, DIMENSION (:), POINTER :: B, C B => A (1:5) C => A (3:9) CALL SUB (B, C) ! The dummy arguments of SUB are neither pointers nor targets. the array section B (3:5) cannot be defined because it is part of the argument associated with the second dummy argument. The array section C (1:3) cannot be defined because it is part of the argument associated with the first dummy argument. The array section A (1:2), which is associated with B (1:2), remains definable through the first dummy argument and A (6:9), which is associated with C (4:7), remains definable through the second dummy argument. NOTE 3 In MODULE DATA REAL :: W, X, Y, Z END MODULE DATA PROGRAM MAIN USE DATA ... CALL INIT (X) ... END PROGRAM MAIN

ISO/IEC JTC 1/SC 22/WG5/N2184

327

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 3 (cont.) SUBROUTINE INIT (V) USE DATA ... READ (*, *) V ... END SUBROUTINE INIT variable X cannot be directly referenced at any time during the execution of INIT because it is being defined through the dummy argument V. X can be (indirectly) referenced through V. W, Y, and Z can be directly referenced. X can, of course, be directly referenced once execution of INIT is complete. NOTE 4 The restrictions on entities associated with dummy arguments are intended to facilitate a variety of optimizations in the translation of the subprogram, including implementations of argument association in which the value of an actual argument that is neither a pointer nor a target is maintained in a register or in local storage. NOTE 5 The exception to the aliasing restrictions for dummy coarrays enables cross-image access while the procedure is executing. Because nonatomic accesses from different images typically need to be separated by an image control statement, code optimization within segments is not unduly inhibited. 1 2 3 4 5 6 7 8 9 10

15.5.3

Function reference

1 A function is invoked during expression evaluation by a function-reference or by a defined operation (10.1.6).

When it is invoked, all actual argument expressions are evaluated, then the arguments are associated, and then the function is executed. When execution of the function is complete, the value of the function result is available for use in the expression that caused the function to be invoked. The characteristics of the function result (15.3.3) are determined by the interface of the function. If a reference to an elemental function (15.9) is an elemental reference, all array arguments shall have the same shape.

15.5.4

Subroutine reference

1 A subroutine is invoked by execution of a CALL statement, execution of a defined assignment statement (10.2.1.4),

16 17 18

defined input/output (12.6.4.8.3), or finalization(7.5.6). When a subroutine is invoked, all actual argument expressions are evaluated, then the arguments are associated, and then the subroutine is executed. When the actions specified by the subroutine are completed, the execution of the CALL statement, the execution of the defined assignment statement, the processing of an input or output list item, or finalization of an object is also completed. If a CALL statement includes one or more alternate return specifiers among its arguments, a branch to one of the statements indicated might occur, depending on the action specified by the subroutine. If a reference to an elemental subroutine (15.9) is an elemental reference, at least one actual argument shall correspond to an INTENT (OUT) or INTENT (INOUT) dummy argument, all such actual arguments shall be arrays, and all actual arguments shall be conformable.

19

15.5.5

Resolving named procedure references

20

15.5.5.1

Establishment of procedure names

11 12 13 14 15

21 22 23 24

1 The rules for interpreting a procedure reference depend on whether the procedure name in the reference is

established by the available declarations and specifications to be generic in the scoping unit containing the reference, is established to be only specific in the scoping unit containing the reference, or is not established. 2 A procedure name is established to be generic in a scoping unit

328

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

(1) (2) (3)

5 6

(4)

7 8

(5)

9 10

if that scoping unit contains an interface block with that name; if that scoping unit contains a GENERIC statement with a generic-spec that is that name; if that scoping unit contains an INTRINSIC attribute specification for that name and it is the generic name of an intrinsic procedure; if that scoping unit contains a USE statement that makes that procedure name accessible and the corresponding name in the module is established to be generic; or if that scoping unit contains no declarations of that name, that scoping unit has a host scoping unit, and that name is established to be generic in the host scoping unit.

established to be generic. It is established to be specific (1)

13

(2) (3)

if that scoping unit contains a module subprogram, internal subprogram, or statement function statement that defines a procedure with that name; if that scoping unit is of a subprogram that defines a procedure with that name; if that scoping unit contains an INTRINSIC attribute specification for that name and it is the name of a specific intrinsic procedure;

15 16 17 18 19 20 21 22 23

J3/21-007r1

3 A procedure name is established to be only specific in a scoping unit if it is established to be specific and not

11 12

14

WD 1539-1

(4) (5)

if that scoping unit contains an explicit EXTERNAL attribute specification for that name; if that scoping unit contains a USE statement that makes that procedure name accessible and the corresponding name in the module is established to be specific; or if that scoping unit contains no declarations of that name, that scoping unit has a host scoping unit, and that name is established to be specific in the host scoping unit.

(6)

4 A procedure name is not established in a scoping unit if it is neither established to be generic nor established to

be specific. 15.5.5.2

Resolving procedure references to names established to be generic

24 25 26 27

1 If the reference is consistent with a nonelemental reference to one of the specific interfaces of a generic interface

28

2 Otherwise, if the reference is consistent with an elemental reference to one of the specific interfaces of a generic

29 30 31 32

interface that has that name and either is defined in the scoping unit in which the reference appears or is made accessible by a USE statement in the scoping unit, the reference is to the specific elemental procedure in the interface block that provides that interface. The rules in 15.4.3.4.5 ensure that there can be at most one such specific elemental procedure.

33 34

3 Otherwise, if the scoping unit contains either an INTRINSIC attribute specification for that name or a USE

35 36

that has that name and either is defined in the scoping unit in which the reference appears or is made accessible by a USE statement in the scoping unit, the reference is to the specific procedure in the interface block that provides that interface. The rules in 15.4.3.4.5 ensure that there can be at most one such specific procedure.

statement that makes that name accessible from a module in which the corresponding name is specified to have the INTRINSIC attribute, and if the reference is consistent with the interface of that intrinsic procedure, the reference is to that intrinsic procedure.

37 38 39 40

4 Otherwise, if the scoping unit has a host scoping unit, the name is established to be generic in that host scoping

41 42

5 Otherwise, if the name is that of an intrinsic procedure and the reference is consistent with that intrinsic procedure,

unit, and there is agreement between the scoping unit and the host scoping unit as to whether the name is a function name or a subroutine name, the name is resolved by applying the rules in this subclause to the host scoping unit as if the reference appeared there. the reference is to that intrinsic procedure. NOTE 1 Because of the renaming facility of the USE statement, the name in the reference can be different from the usual name of the intrinsic procedure.

ISO/IEC JTC 1/SC 22/WG5/N2184

329

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 These rules allow particular specific procedures with the same generic identifier to be used for particular array ranks and a general elemental version to be used for other ranks. For example, given an interface block such as INTERFACE RANF ELEMENTAL FUNCTION SCALAR_RANF(X) REAL, INTENT(IN) :: X END FUNCTION SCALAR_RANF FUNCTION VECTOR_RANDOM(X) REAL X(:) REAL VECTOR_RANDOM(SIZE(X)) END FUNCTION VECTOR_RANDOM END INTERFACE RANF and a declaration such as: REAL A(10,10), AA(10,10) then the statement A = RANF(AA) is an elemental reference to SCALAR_RANF. The statement A(6:10,2) = RANF(AA(6:10,2)) is a nonelemental reference to VECTOR_RANDOM. 1 2

15.5.5.3

Resolving procedure references to names established to be only specific

1 If the name has the EXTERNAL attribute,

6

• if it is a procedure pointer, the reference is to its target; • if it is a dummy procedure that is not a procedure pointer, the reference is to the effective argument corresponding to that name; • otherwise, the reference is to the external procedure with that name.

7

2 If the name is that of an accessible external procedure, internal procedure, module procedure, intrinsic procedure,

3 4 5

8

or statement function, the reference is to that procedure. NOTE 1 Because of the renaming facility of the USE statement, the name in the reference can be different from the original name of the procedure.

9

15.5.5.4

Resolving procedure references to names not established

10 11 12

1 If the name is the name of a dummy argument of the scoping unit, the dummy argument is a dummy procedure

13 14

2 Otherwise, if the name is the name of an intrinsic procedure, and if there is agreement between the reference and

15

3 Otherwise, the reference is to an external procedure with that name.

16 17 18

and the reference is to that dummy procedure. That is, the procedure invoked by executing that reference is the effective argument corresponding to that dummy procedure. the status of the intrinsic procedure as being a function or subroutine, the reference is to that intrinsic procedure.

15.5.6

Resolving type-bound procedure references

1 If the binding-name in a procedure-designator (R1522) is that of a specific type-bound procedure, the procedure

referenced is the one bound to that name in the dynamic type of the data-ref .

330

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

2 If the binding-name in a procedure-designator is that of a generic type bound procedure, the generic binding with

3 4

• If the reference is consistent with one of the specific bindings of that generic binding, that specific binding is selected. • Otherwise, the reference shall be consistent with an elemental reference to one of the specific bindings of that generic binding; that specific binding is selected.

5 6

7 8

that name in the declared type of the data-ref is used to select a specific binding using the following criteria.

3 The reference is to the procedure bound to the same name as the selected specific binding in the dynamic type

of the data-ref .

9

15.6

Procedure definition

10

15.6.1

Intrinsic procedure definition

11 12 13

1 Intrinsic procedures are defined as an inherent part of the processor. A standard-conforming processor shall

include the intrinsic procedures described in Clause 16, but may include others. However, a standard-conforming program shall not make use of intrinsic procedures other than those described in Clause 16.

14

15.6.2

Procedures defined by subprograms

15

15.6.2.1

General

16 17

1 A procedure is defined by the initial SUBROUTINE or FUNCTION statement of a subprogram, and each ENTRY

18 19

2 A subprogram is specified to have the NON_RECURSIVE attribute, or to be elemental (15.9), pure (15.7), or a

statement defines an additional procedure (15.6.2.6).

separate module subprogram (15.6.2.5) by a prefix in its initial SUBROUTINE or FUNCTION statement.

20

R1526 prefix

is

prefix-spec [ prefix-spec ] ...

21

R1527 prefix-spec

is or or or or or or or

declaration-type-spec ELEMENTAL IMPURE MODULE NON_RECURSIVE PURE RECURSIVE SIMPLE

22 23 24 25 26 27 28 29

C1543 (R1526) A prefix shall contain at most one of each prefix-spec.

30

C1544 (R1526) A prefix that specifies IMPURE shall specify neither PURE nor SIMPLE.

31

C1545 (R1526) A prefix shall not specify both NON_RECURSIVE and RECURSIVE.

32

C1546 An elemental procedure shall not have the BIND attribute.

33 34

C1547 (R1526) MODULE shall appear only in the function-stmt or subroutine-stmt of a module subprogram or of a nonabstract interface body that is declared in the scoping unit of a module or submodule.

35 36

C1548 (R1526) If MODULE appears in the prefix of a module subprogram, it shall have been declared to be a separate module procedure in the containing program unit or an ancestor of that program unit.

37 38

C1549 (R1526) If MODULE appears in the prefix of a module subprogram, the subprogram shall specify the same characteristics and dummy argument names as its corresponding module procedure interface body.

ISO/IEC JTC 1/SC 22/WG5/N2184

331

J3/21-007r1

WD 1539-1

2021-05-21

1 2

C1550 (R1526) If MODULE appears in the prefix of a module subprogram and a binding label is specified, it shall be the same as the binding label specified in the corresponding module procedure interface body.

3 4

C1551 (R1526) If MODULE appears in the prefix of a module subprogram, NON_RECURSIVE shall appear if and only if NON_RECURSIVE appears in the prefix in the corresponding module procedure interface body.

5 6 7 8 9

3 The NON_RECURSIVE prefix-spec shall not appear if any procedure defined by the subprogram directly or

10

4 If the prefix-spec PURE or the prefix-spec SIMPLE appears, or the prefix-spec ELEMENTAL appears and IM-

11 12 13

PURE does not appear, the subprogram is a pure subprogram and shall meet the additional constraints of 15.7. If the prefix-spec SIMPLE appears, the subprogram is a simple subprogram and shall meet the additional constraints of 15.8.

14 15

5 If the prefix-spec ELEMENTAL appears, the subprogram is an elemental subprogram and shall meet the additional

16

indirectly invokes itself or any other procedure defined by the subprogram. If a subprogram defines a function whose name is declared with an asterisk type-param-value, no procedure defined by the subprogram shall directly or indirectly invoke itself or any other procedure defined by the subprogram. The RECURSIVE prefix-spec is advisory only.

constraints of 15.9.1. R1528 proc-language-binding-spec

is

language-binding-spec

17 18

6 A proc-language-binding-spec specifies that the procedure defined or declared by the statement is interoperable

19 20 21

C1552 A proc-language-binding-spec with a NAME= specifier shall not be specified in the function-stmt or subroutine-stmt of an internal procedure, or of an interface body for an abstract interface or a dummy procedure.

22 23

C1553 If proc-language-binding-spec is specified for a function, the function result shall be an interoperable scalar variable.

24 25 26 27

C1554 If proc-language-binding-spec is specified for a procedure, each of its dummy arguments shall be an interoperable procedure (18.3.6) or a variable that is interoperable (18.3.4, 18.3.5), assumed-shape, assumedrank, assumed-type, of type CHARACTER with assumed length, or that has the ALLOCATABLE or POINTER attribute.

28 29

C1555 If proc-language-binding-spec is specified for a procedure, each dummy argument of type CHARACTER with the ALLOCATABLE or POINTER attribute shall have deferred character length.

30 31

C1556 A variable that is a dummy argument of a procedure that has a proc-language-binding-spec shall be assumed-type or of interoperable type and kind type parameters.

32 33

C1557 If proc-language-binding-spec is specified for a procedure, it shall not have a default-initialized dummy argument with the ALLOCATABLE or POINTER attribute.

34 35

C1558 If proc-language-binding-spec is specified for a procedure, it shall not have a dummy argument that is a coarray.

36 37

C1559 If proc-language-binding-spec is specified for a procedure, it shall not have an array dummy argument with the VALUE attribute.

38

15.6.2.2

39 40

(18.3.6).

Function subprogram

1 A function subprogram is a subprogram that has a FUNCTION statement as its first statement.

R1529 function-subprogram

41 42

332

is

function-stmt [ specification-part ] [ execution-part ]

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

[ internal-subprogram-part ] end-function-stmt

1 2

is

3 4

R1530 function-stmt

5 6

C1560 (R1530) If RESULT appears, result-name shall not be the same as function-name and shall not be the same as the entry-name in any ENTRY statement in the subprogram.

7 8

C1561 (R1530) If RESULT appears, the function-name shall not appear in any specification statement in the scoping unit of the function subprogram.

9

R1531 dummy-arg-name

10

C1562 (R1531) A dummy-arg-name shall be the name of a dummy argument.

11

R1532 suffix

is proc-language-binding-spec [ RESULT ( result-name ) ] or RESULT ( result-name ) [ proc-language-binding-spec ]

13

R1533 end-function-stmt

is

14

C1563 (R1529) An internal function subprogram shall not contain an internal-subprogram-part.

15 16

C1564 (R1533) If a function-name appears in the end-function-stmt, it shall be identical to the function-name specified in the function-stmt.

12

is

[ prefix ] FUNCTION function-name ( [ dummy-arg-name-list ] ) [ suffix ]

name

END [ FUNCTION [ function-name ] ]

17

2 The name of the function is function-name.

18 19 20 21 22 23

3 The type and type parameters (if any) of the result of the function defined by a function subprogram may be

24 25 26 27 28 29 30 31 32 33

specified by a type specification in the FUNCTION statement or by the name of the function result appearing in a type declaration statement in the specification part of the function subprogram. They shall not be specified both ways. If they are not specified either way, they are determined by the implicit typing rules in effect within the function subprogram. If the function result is an array, allocatable, or a pointer, this shall be specified by specifications of the name of the function result within the function body. The specifications of the function result attributes, the specification of dummy argument attributes, and the information in the procedure heading collectively define the characteristics of the function (15.3.1). 4 If RESULT appears, the name of the function result of the function is result-name and all occurrences of the

function name in execution-part statements in its scope refer to the function itself. If RESULT does not appear, the name of the function result is function-name and all occurrences of the function name in execution-part statements in its scope are references to the function result. On completion of execution of the function, the value returned is that of its function result. If the function result is a data pointer, the shape of the value returned by the function is determined by the shape of the function result when the execution of the function is completed. If the function result is not a pointer, its value shall be defined by the function. If the function result is a pointer, on return the pointer association status of the function result shall not be undefined. NOTE 1 The function result is similar to any other entity (variable or procedure pointer) local to a function subprogram. Its existence begins when execution of the function is initiated and ends when execution of the function is terminated. However, because the final value of this entity is used subsequently in the evaluation of the expression that invoked the function, an implementation might defer releasing the storage occupied by that entity until after its value has been used in expression evaluation. NOTE 2 The following is an example of the declaration of an interface body with the BIND attribute, and a reference to the procedure declared. USE, INTRINSIC :: ISO_C_BINDING

ISO/IEC JTC 1/SC 22/WG5/N2184

333

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 2 (cont.) INTERFACE FUNCTION JOE (I, J, R) BIND(C,NAME="FrEd") USE, INTRINSIC :: ISO_C_BINDING INTEGER(C_INT) :: JOE INTEGER(C_INT), VALUE :: I, J REAL(C_FLOAT), VALUE :: R END FUNCTION JOE END INTERFACE INT = JOE(1_C_INT, 3_C_INT, 4.0_C_FLOAT) END PROGRAM The invocation of the function JOE results in a reference to a function with a binding label "FrEd". FrEd could be a C function described by the C prototype int FrEd(int n, int m, float x);

1 2

15.6.2.3

Subroutine subprogram

1 A subroutine subprogram is a subprogram that has a SUBROUTINE statement as its first statement.

R1534 subroutine-subprogram

is

subroutine-stmt [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-subroutine-stmt

8 9

R1535 subroutine-stmt

is

[ prefix ] SUBROUTINE subroutine-name [ ( [ dummy-arg-list ] ) [ proc-language-binding-spec ] ]

10

C1565 (R1535) The prefix of a subroutine-stmt shall not contain a declaration-type-spec.

11

R1536 dummy-arg

is dummy-arg-name or *

13

R1537 end-subroutine-stmt

is

14

C1566 (R1534) An internal subroutine subprogram shall not contain an internal-subprogram-part.

15 16

C1567 (R1537) If a subroutine-name appears in the end-subroutine-stmt, it shall be identical to the subroutinename specified in the subroutine-stmt.

3 4 5 6 7

12

17 18

END [ SUBROUTINE [ subroutine-name ] ]

2 The name of the subroutine is subroutine-name.

15.6.2.4

Instances of a subprogram

19 20 21

1 When a procedure defined by a subprogram is invoked, an instance of that subprogram is created. Each instance

22

2 When a statement function is invoked, an instance of that statement function is created.

23

3 When execution of an instance completes it ceases to exist.

24 25 26

4 The caller of an instance of a procedure is the instance of the main program, subprogram, or statement function

has an independent sequence of execution and an independent set of dummy arguments, unsaved local variables, and unsaved local procedure pointers. Saved local entities are shared by all instances of the subprogram.

that invoked it. The call sequence of an instance of a procedure is its caller, followed by the call sequence of its caller. The call sequence of the main program is empty. The host instance of an instance of a statement function

334

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

WD 1539-1

J3/21-007r1

or an internal procedure that is invoked by its name is the first element of the call sequence that is an instance of the host of the statement function or internal subprogram. The host instance of an internal procedure that is

5

invoked via a dummy procedure or procedure pointer is the host instance of the associating entity from when the argument association or pointer association was established (19.5.5). The host instance of a module procedure is the module or submodule in which it is defined. A main program or external subprogram has no host instance.

6

15.6.2.5

7 8 9 10

Separate module procedures

1 A separate module procedure is a module procedure defined by a separate-module-subprogram, by a function-

subprogram whose initial statement contains the keyword MODULE, or by a subroutine-subprogram whose initial statement contains the keyword MODULE. R1538 separate-module-subprogram is

11 12 13 14

mp-subprogram-stmt [ specification-part ] [ execution-part ] [ internal-subprogram-part ] end-mp-subprogram-stmt

15

R1539 mp-subprogram-stmt

is

MODULE PROCEDURE procedure-name

16

R1540 end-mp-subprogram-stmt

is

END [PROCEDURE [procedure-name]]

17 18

C1568 (R1538) The procedure-name shall have been declared to be a separate module procedure in the containing program unit or an ancestor of that program unit.

19 20

C1569 (R1540) If a procedure-name appears in the end-mp-subprogram-stmt, it shall be identical to the procedurename in the mp-subprogram-stmt.

21

2 A separate module procedure shall not be defined more than once.

22

3 The interface of a procedure defined by a separate-module-subprogram is explicitly declared by the mp-subprogram-

23 24 25

stmt to be the same as its module procedure interface body. It has the NON_RECURSIVE attribute if and only if it was declared to have that attribute by the interface body. If it is a function its result name is determined by the FUNCTION statement in the interface body. NOTE 1 A separate module procedure can be accessed by use association only if its interface body is declared in the specification part of a module and is public.

26 27

15.6.2.6

ENTRY statement

1 An ENTRY statement permits a procedure reference to begin with a particular executable statement within the function or subroutine

28

subprogram in which the ENTRY statement appears.

29

R1541

entry-stmt

30 31

C1570

(R1541) If RESULT appears, the entry-name shall not appear in any specification or type declaration statement in the scoping unit of the function program.

32 33

C1571

(R1541) An entry-stmt shall appear only in an external-subprogram or a module-subprogram that does not define a separate module procedure. An entry-stmt shall not appear within an executable-construct.

34

C1572

(R1541) RESULT shall appear only if the entry-stmt is in a function subprogram.

35

C1573

(R1541) A dummy-arg shall not be an alternate return indicator if the ENTRY statement is in a function subprogram.

36 37

C1574

(R1541) If RESULT appears, result-name shall not be the same as the function-name in the FUNCTION statement and shall not be the same as the entry-name in any ENTRY statement in the subprogram.

38

is

ENTRY entry-name [ ( [ dummy-arg-list ] ) [ suffix ] ]

2 Optionally, a subprogram may have one or more ENTRY statements.

ISO/IEC JTC 1/SC 22/WG5/N2184

335

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

3 If the ENTRY statement is in a function subprogram, an additional function is defined by that subprogram. The name of the

5 6 7

result names identify the same entity, although their names need not be the same. Otherwise, they are storage associated and shall all be nonpointer, nonallocatable scalar variables that are default integer, default real, double precision real, default complex, or default logical.

8 9

4 If the ENTRY statement is in a subroutine subprogram, an additional subroutine is defined by that subprogram. The name of the

10

5 The order, number, types, kind type parameters, and names of the dummy arguments in an ENTRY statement may differ from the

11 12

order, number, types, kind type parameters, and names of the dummy arguments in the FUNCTION or SUBROUTINE statement in the containing subprogram.

13 14

6 Because an ENTRY statement defines an additional function or an additional subroutine, it is referenced in the same manner as any

15 16

7 In a subprogram, a dummy argument specified in an ENTRY statement shall not appear in an executable statement preceding that

17 18

statement. A function result specified by a result-name in an ENTRY statement shall not appear in any executable statement that precedes the first RESULT clause with that name.

19 20 21

8 In a subprogram, a dummy argument specified in an ENTRY statement shall not appear in the expression of a statement function

22

9 If a dummy argument appears in an executable statement, the execution of the executable statement is permitted during the

23 24

execution of a reference to the function or subroutine only if the dummy argument appears in the dummy argument list of the referenced procedure.

25 26 27

10 If a dummy argument is used in a specification expression to specify an array bound or character length of an object, the appearance

28

11 The NON_RECURSIVE and RECURSIVE keywords are not used in an ENTRY statement. Instead, the presence or absence of

29 30

NON_RECURSIVE in the initial SUBROUTINE or FUNCTION statement controls whether the procedure defined by an ENTRY statement is permitted to reference itself or another procedure defined by the subprogram.

31 32

12 The keywords PURE and IMPURE are not used in an ENTRY statement. Instead, the procedure defined by an ENTRY statement

33 34

13 The keyword ELEMENTAL is not used in an ENTRY statement. Instead, the procedure defined by an ENTRY statement is elemental

function is entry-name and the name of its result is result-name or is entry-name if no result-name is provided. The dummy arguments of the function are those specified in the ENTRY statement. If the characteristics of the result of the function named in the ENTRY statement are the same as the characteristics of the result of the function named in the FUNCTION statement, their

subroutine is entry-name. The dummy arguments of the subroutine are those specified in the ENTRY statement.

other function or subroutine (15.5).

ENTRY statement, unless it also appears in a FUNCTION, SUBROUTINE, or ENTRY statement that precedes the executable

that precedes the first dummy-arg with that name in the subprogram. A function result specified by a result-name in an ENTRY statement shall not appear in the expression of a statement function that precedes the first RESULT clause with that name.

of the object in a statement that is executed during a procedure reference is permitted only if the dummy argument appears in the dummy argument list of the referenced procedure and it is present (15.5.2.12).

is pure if and only if the subprogram is a pure subprogram.

if and only if ELEMENTAL is specified in the SUBROUTINE or FUNCTION statement.

35

15.6.2.7

RETURN statement

36

R1542 return-stmt

37

C1575 (R1542) The return-stmt shall be in the inclusive scope of a function or subroutine subprogram.

38

C1576 (R1542) The scalar-int-expr is allowed only in the inclusive scope of a subroutine subprogram.

is

RETURN [ scalar-int-expr ]

39 40

1 Execution of the RETURN statement completes execution of the instance of the subprogram in which it appears.

41 42 43

that invoked the subroutine branches (11.2) to the branch target statement identified by the nth alternate return specifier in the actual argument list of the referenced procedure. If the expression is omitted or has a value outside the required range, there is no transfer of control to an alternate return.

If the expression appears and has a value n between 1 and the number of asterisks in the dummy argument list, the CALL statement

336

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

of a RETURN statement with no expression. 15.6.2.8

4

R1543 contains-stmt

8

J3/21-007r1

2 Execution of an end-function-stmt, end-mp-subprogram-stmt, or end-subroutine-stmt is equivalent to execution

3

5 6 7

WD 1539-1

CONTAINS statement is

CONTAINS

1 The CONTAINS statement separates the body of a main program, module, submodule, or subprogram from any

internal or module subprograms it might contain, or it introduces the type-bound procedure part of a derived-type definition (7.5.5). The CONTAINS statement is not executable.

15.6.3

Definition and invocation of procedures by means other than Fortran

9 10 11

1 A procedure may be defined by means other than Fortran. The interface of a procedure defined by means other

12

2 A procedure defined by means other than Fortran that is invoked by a Fortran procedure and does not cause

13

than Fortran may be specified by an interface body or procedure declaration statement. A reference to such a procedure is made as though it were defined by an external subprogram. termination of execution shall return to its caller. NOTE 1 Examples of code that might cause a transfer of control that bypasses the normal return mechanism of a Fortran procedure are setjmp and longjmp in C and exception handling in other languages. No such behavior is permitted by this document.

14

3 If the interface of a procedure has a proc-language-binding-spec, the procedure is interoperable (18.10).

15

4 Interoperation with C functions is described in 18.10.

NOTE 2 For explanatory information on definition of procedures by means other than Fortran, see C.11.2. 16 17

15.6.4

Statement function

1 A statement function is a function defined by a single statement.

18

R1544

stmt-function-stmt

19 20 21 22 23 24

C1577

(R1544) Each primary in scalar-expr shall be a constant (literal or named), a reference to a variable, a reference to a function, or an expression in parentheses. Each operation shall be intrinsic. If scalar-expr contains a reference to a function, the reference shall not require an explicit interface, the function shall not require an explicit interface unless it is an intrinsic function, the function shall not be a transformational intrinsic, and the result shall be scalar. If an argument to a function is an array, it shall be an array name. If a reference to a statement function appears in scalar-expr, its definition shall have been provided earlier in the scoping unit and shall not be the name of the statement function being defined.

25 26 27

C1578

(R1544) Named constants in scalar-expr shall have been declared earlier in the scoping unit or made accessible by use or host association. If array elements appear in scalar-expr, the array shall have been declared as an array earlier in the scoping unit or made accessible by use or host association.

28 29 30

C1579

(R1544) If a dummy-arg-name, variable, function reference, or dummy function reference is typed by the implicit typing rules, its appearance in any subsequent type declaration statement shall confirm this implied type and the values of any implied type parameters.

31

C1580

(R1544) The function-name and each dummy-arg-name shall be specified, explicitly or implicitly, to be scalar.

32

C1581

(R1544) A given dummy-arg-name shall not appear more than once in a given dummy-arg-name-list.

33

C1582

A statement function shall not be of a parameterized derived type.

34 35

is

function-name ( [ dummy-arg-name-list ] ) = scalar-expr

2 The definition of a statement function with the same name as an accessible entity from the host shall be preceded by the declaration of its type in a type declaration statement.

ISO/IEC JTC 1/SC 22/WG5/N2184

337

J3/21-007r1

WD 1539-1

2021-05-21

1 2

3 The dummy arguments have a scope of the statement function statement. Each dummy argument has the same type and type

3

4 A statement function shall not be supplied as an actual argument.

4

5 Execution of a statement function consists of evaluating the expression using the values of the actual arguments for the values of the

5

corresponding dummy arguments and, if necessary, converting the result to the declared type and type parameters of the function.

6 7

6 A function reference in the scalar expression shall not cause a dummy argument of the statement function to become redefined or

8 9 10 11 12 13 14 15 16 17 18

parameters as the entity of the same name in the scoping unit containing the statement function statement.

undefined.

15.7

Pure procedures

1 A pure procedure is

• a simple procedure, • a pure intrinsic procedure (16.1), • a module procedure in an intrinsic module, if it is specified to be pure, • defined by a pure subprogram, • a dummy procedure that has been specified to be PURE, • a procedure pointer that has been specified to be PURE, • a type-bound procedure that is bound to a pure procedure, or • a statement function that references only pure functions and does not contain the designator of a variable with the VOLATILE attribute.

19 20 21

2 A pure subprogram is a subprogram that has the prefix-spec PURE or the prefix-spec SIMPLE, or that has the

22 23

C1583 The specification-part of a pure function subprogram shall specify that all its nonpointer dummy data objects have the INTENT (IN) or the VALUE attribute.

24 25

C1584 The function result of a pure function shall not be such that finalization of a reference to the function would reference an impure procedure.

26 27

C1585 The function result of a pure function shall not be both polymorphic and allocatable, or have a polymorphic allocatable ultimate component.

28 29

C1586 The specification-part of a pure subroutine subprogram shall specify the intents of all its nonpointer dummy data objects that do not have the VALUE attribute.

30 31

C1587 An INTENT (OUT) dummy argument of a pure procedure shall not be such that finalization of the actual argument would reference an impure procedure.

32 33

C1588 An INTENT (OUT) dummy argument of a pure procedure shall not be polymorphic or have a polymorphic allocatable ultimate component.

34 35

C1589 A local variable of a pure subprogram, or of a BLOCK construct within a pure subprogram, shall not have the SAVE or VOLATILE attribute.

prefix-spec ELEMENTAL and does not have the prefix-spec IMPURE. The following additional constraints apply to pure subprograms.

NOTE 1 Variable initialization in a type-declaration-stmt or a data-stmt implies the SAVE attribute; therefore, such initialization is also disallowed. 36

C1590 The specification-part of a pure subprogram shall specify that all its dummy procedures are pure.

338

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

C1591 If a procedure that is neither an intrinsic procedure nor a statement function is used in a context that requires it to be pure, then its interface shall be explicit in the scope of that use. The interface shall specify that the procedure is pure.

4

C1592 All internal subprograms in a pure subprogram shall be pure.

5

C1593 A designator of a variable with the VOLATILE attribute shall not appear in a pure subprogram.

6 7 8 9

C1594 In a pure subprogram any designator with a base object that is in common or accessed by use or host association, is a pointer dummy argument of a pure function, is a dummy argument with the INTENT (IN) attribute, is a coindexed object, or an object that is storage associated with any such variable, shall not be used

10 11 12 13 14

(1) (2) (3) (4)

15 16

(5)

17 18

(6)

19

(7) (8)

20

in a variable definition context (19.6.7), in a pointer association context (19.6.8), as the data-target in a pointer-assignment-stmt, as the expr corresponding to a component in a structure-constructor if the component has the POINTER attribute or has a pointer component at any level of component selection, as the expr of an intrinsic assignment statement in which the variable is of a derived type if the derived type has a pointer component at any level of component selection, as the source-expr in a SOURCE= specifier if the designator is of a derived type that has a pointer component at any level of component selection, as an actual argument corresponding to a dummy argument with the POINTER attribute, or as the actual argument to the function C_LOC from the intrinsic module ISO_C_BINDING.

NOTE 2 Item 5 requires that processors be able to determine if entities with the PRIVATE attribute or with private components have a pointer component. 21 22

C1595 Any procedure referenced in a pure subprogram, including one referenced via a defined operation, defined assignment, defined input/output, or finalization, shall be pure.

23

C1596 A statement that might result in the deallocation of a polymorphic entity is not permitted in a pure procedure.

24

NOTE 3 This includes intrinsic assignment to a variable that has a potential subobject component that is polymorphic and allocatable. 25 26

C1597 A pure subprogram shall not contain a print-stmt, open-stmt, close-stmt, backspace-stmt, endfile-stmt, rewind-stmt, flush-stmt, wait-stmt, or inquire-stmt.

27

C1598 A pure subprogram shall not contain a read-stmt or write-stmt whose io-unit is a file-unit-number or *.

28

C1599 A pure subprogram shall not contain an image control statement (11.7.1). NOTE 4 The above constraints are designed to guarantee that a pure procedure is free from side effects (modifications of data visible outside the procedure), which means that it is safe to reference it in constructs such as DO CONCURRENT and FORALL, where there is no explicit order of evaluation. The constraints on pure subprograms appear to be complicated, but it is not necessary for a programmer to be intimately familiar with them. From the programmer’s point of view, these constraints can be summarized as follows: a pure subprogram cannot contain any operation that could conceivably result in an assignment or pointer assignment to a common variable, a variable accessed by use or host association, or an INTENT (IN) dummy argument; nor can a pure subprogram contain any operation that could conceivably

ISO/IEC JTC 1/SC 22/WG5/N2184

339

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 4 (cont.) perform any external file input/output or execute an image control statement (including a STOP statement). Note the use of the word conceivably; it is not sufficient for a pure subprogram merely to be side-effect free in practice. For example, a function that contains an assignment to a global variable but in a block that is not executed in any invocation of the function is nevertheless not a pure function. The exclusion of functions of this nature is required if strict compile-time checking is to be used. It is expected that most library procedures will conform to the constraints required of pure procedures, and so can be declared pure and referenced in DO CONCURRENT constructs, FORALL statements and constructs, and within user-defined pure procedures. NOTE 5 Pure subroutines are included to allow subroutine calls from pure procedures in a safe way, and to allow forall-assignment-stmts to be defined assignments. The constraints for pure subroutines are based on the same principles as for pure functions, except that side effects to INTENT (OUT), INTENT (INOUT), and pointer dummy arguments are permitted.

1 2 3 4 5 6 7 8 9 10

15.8

Simple procedures

1 A simple procedure is

• an intrinsic procedure (16.1), if it is specified to be simple, • a module procedure, if it is specified to be simple, • a procedure defined by a simple subprogram, • a dummy procedure that has been specified to be simple, • a procedure pointer that has been specified to be simple, • a type-bound procedure that is bound to a simple procedure, • a deferred type-bound procedure whose interface specifies it to be simple, • a statement function defined in a simple subprogram.

11 12

2 A simple procedure is also a pure procedure and is subject to the constraints for pure procedures (15.7). A simple

13 14

3 A simple subprogram is a subprogram that has the prefix-spec SIMPLE. The following additional constraints

15

C15100 The specification-part of a simple subprogram shall specify that all of its dummy procedures are simple.

16 17 18

C15101 If a procedure that is not an intrinsic procedure, a module procedure of an intrinsic module, or a statement function is used in a context that requires it to be simple, then its interface shall be explicit in the scope of that use. The interface shall specify that the procedure is simple.

19

C15102 All internal subprograms in a simple subprogram shall be simple.

20

C15103 Any procedure referenced in a simple subprogram shall be simple.

21 22

C15104 A simple subprogram shall not contain a designator of a variable that is accessed by use or host association, unless the designator is part of a specification inquiry (10.1.11) that is a constant expression.

23

C15105 A simple subprogram shall not contain a reference to a variable in a common block.

24

C15106 A simple subprogram shall not contain an ENTRY statement.

procedure can also be an elemental procedure. apply to simple subprograms.

340

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

15.9

Elemental procedures

2

15.9.1

Elemental procedure declaration and interface

3 4 5 6 7 8

J3/21-007r1

1 An elemental procedure is

• an elemental intrinsic procedure (16.1), • a module procedure in an intrinsic module, if it is specified to be elemental, • a procedure that is defined by an elemental subprogram, or • a type-bound procedure that is bound to an elemental procedure. An elemental procedure has only scalar dummy arguments, but may have array actual arguments.

9

2 A dummy procedure or procedure pointer shall not be specified to be ELEMENTAL.

10 11

3 An elemental subprogram has the prefix-spec ELEMENTAL. An elemental subprogram is a pure subprogram

12 13

C15107 All dummy arguments of an elemental procedure shall be scalar noncoarray dummy data objects and shall not have the POINTER or ALLOCATABLE attribute.

14 15

C15108 The result of an elemental function shall be scalar, and shall not have the POINTER or ALLOCATABLE attribute.

16 17

C15109 The specification-part of an elemental subprogram shall specify the intents of all of its dummy arguments that do not have the VALUE attribute.

18 19

C15110 In the specification-expr that specifies a type parameter value of the result of an elemental function, an object designator with a dummy argument of the function as the base object shall appear only as the subject of a specification inquiry (10.1.11), and that specification inquiry shall not depend on a property that is deferred.

20 21 22 23 24 25

unless it has the prefix-spec IMPURE. The following additional constraints apply to elemental subprograms.

4 In a reference to an elemental procedure, if any argument is an array, each actual argument that corresponds to

26

an INTENT (OUT) or INTENT (INOUT) dummy argument shall be an array. All actual arguments shall be conformable. An array actual argument is considered to be associated with the scalar dummy arguments of the procedure throughout the entire execution of the elemental reference; thus, the restrictions on actions specified in 15.5.2.13 apply to the entirety of the actual array argument.

27

15.9.2

28 29 30 31 32

Elemental function actual arguments and results

1 If a generic name or a specific name is used to reference an elemental function, the shape of the result is the

same as the shape of the actual argument with the greatest rank. If there are no actual arguments or the actual arguments are all scalar, the result is scalar. In the array case, the values of the elements, if any, of the result are the same as would have been obtained if the scalar function had been applied separately, in array element order, to corresponding elements of each array actual argument. NOTE 1 An example of an elemental reference to the intrinsic function MAX: if X and Y are arrays with bounds (1:M, 1:N), then MAX (X, 0.0, Y) is an array expression of shape [M, N] whose elements in order have the values of [ ((MAX (X(I, J),

33 34 35

15.9.3

0.0, Y(I, J)), I = 1, M), J = 1, N) ]

Elemental subroutine actual arguments

1 In a reference to an elemental subroutine, if the actual arguments corresponding to INTENT (OUT) and INTENT

(INOUT) dummy arguments are arrays, the values of the elements, if any, of the results are the same as would

ISO/IEC JTC 1/SC 22/WG5/N2184

341

J3/21-007r1

1 2

WD 1539-1

2021-05-21

be obtained if the subroutine had been applied separately, in array element order, to corresponding elements of each array actual argument.

342

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

16 Intrinsic procedures and modules

2

16.1

J3/21-007r1

Classes of intrinsic procedures

3 4 5

1 Intrinsic procedures are divided into eight classes: inquiry functions, elemental functions, transformational func-

6 7 8 9 10 11

2 An intrinsic inquiry function is one whose result depends on the properties of one or more of its arguments instead

12

tions, elemental subroutines, simple subroutines, atomic subroutines, collective subroutines, and (impure) subroutines. of their values; in fact, these argument values may be undefined. Unless the description of an intrinsic inquiry function states otherwise, these arguments are permitted to be unallocated allocatable variables or pointers that are undefined or disassociated. An elemental intrinsic function is one that is specified for scalar arguments, but may be applied to array arguments as described in 15.9. All other intrinsic functions are transformational functions; they almost all have one or more array arguments or an array result. All standard intrinsic functions are simple.

13 14

3 An atomic subroutine is an intrinsic subroutine that performs an atomic action. The semantics of atomic actions

15 16

4 A collective subroutine is an intrinsic subroutine that performs a cooperative calculation on a team of images

17

5 The subroutine MOVE_ALLOC with noncoarray argument FROM, the subroutine SPLIT, the subroutine

18 19

TOKENIZE, and the elemental subroutine MVBITS, are simple. No other standard intrinsic subroutine is pure or simple.

20 21 22

6 Generic names of standard intrinsic procedures are listed in 16.7. In most cases, generic functions accept argu-

23

7 If an intrinsic procedure is used as an actual argument to a procedure, its specific name shall be used and it shall be referenced in

24 25

the called procedure only with scalar arguments. If an intrinsic procedure does not have a specific name, it shall not be used as an actual argument (15.5.2.9).

26

are described in 16.5. without requiring synchronization. The semantics of collective subroutines are described in 16.6.

ments of more than one type and the type of the result is the same as the type of the arguments. Specific names of standard intrinsic functions with corresponding generic names are listed in 16.8.

8 Elemental intrinsic procedures behave as described in 15.9.

27

16.2

Arguments to intrinsic procedures

28

16.2.1

General rules

29 30 31 32 33 34 35

1 All intrinsic procedures can be invoked with either positional arguments or argument keywords (15.5). The

descriptions in 16.7 through 16.9 give the argument keyword names and positional sequence for standard intrinsic procedures. 2 Many of the intrinsic procedures have optional arguments.

These arguments are identified by the notation “optional” in the argument descriptions. In addition, the names of the optional arguments are enclosed in square brackets in description headings and in lists of procedures. The valid forms of reference for procedures with optional arguments are described in 15.5.2. NOTE 1 The text CMPLX (X [, Y, KIND]) indicates that Y and KIND are both optional arguments. Valid reference forms include CMPLX(x), CMPLX(x, y), CMPLX(x, KIND=kind), CMPLX(x, y, kind), and CM-

ISO/IEC JTC 1/SC 22/WG5/N2184

343

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) PLX(KIND=kind, X=x, Y=y). NOTE 2 Some intrinsic procedures impose additional requirements on their optional arguments. For example, SELECTED_REAL_KIND requires that at least one of its optional arguments be present, and RANDOM_SEED requires that at most one of its optional arguments be present. 1 2

3 The dummy arguments of the specific intrinsic procedures in 16.8 have INTENT (IN). The dummy arguments of the intrinsic

procedures in 16.9 have INTENT (IN) if the intent is not stated explicitly.

3 4 5

4 The actual argument corresponding to an intrinsic function dummy argument named KIND shall be a scalar

6 7

5 Intrinsic subroutines that assign values to arguments of type character do so in accordance with the rules of

8 9 10 11 12

6 In a reference to the intrinsic subroutine MVBITS, the actual arguments corresponding to the TO and FROM

13

7 An argument to an intrinsic procedure other than ASSOCIATED, NULL, or PRESENT shall be a data object.

14 15 16 17

integer constant expression and its value shall specify a representation method for the function result that exists on the processor. intrinsic assignment (10.2.1.3). dummy arguments may be the same variable and may be associated scalar variables or associated array variables all of whose corresponding elements are associated. Apart from this, the actual arguments in a reference to an intrinsic subroutine shall be such that the execution of the intrinsic subroutine would satisfy the restrictions of 15.5.2.13.

16.2.2

The shape of array arguments

1 Unless otherwise specified, the intrinsic inquiry functions accept array arguments for which the shape need not

be defined. The shape of array arguments to transformational and elemental intrinsic functions shall be defined.

16.2.3

Mask arguments

18

1 Some array intrinsic functions have an optional MASK argument of type logical that is used by the function to

19 20

select the elements of one or more arguments to be operated on by the function. Any element not selected by the mask need not be defined at the time the function is invoked.

21 22

2 The MASK affects only the value of the function, and does not affect the evaluation, prior to invoking the

23

function, of arguments that are array expressions.

16.2.4

DIM arguments and reduction functions

24 25 26

1 Some array intrinsic functions are “reduction” functions; that is, they reduce the rank of an array by collapsing

27

2 The process of reducing a dimension usually combines the selected elements with a simple operation such as

28 29

addition or an intrinsic function such as MAX, but more sophisticated reductions are also provided, e.g. by COUNT and MAXLOC.

one dimension (or all dimensions, usually producing a scalar result). These functions have a DIM argument that can specify the dimension to be reduced.

344

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

16.3

Bit model

2

16.3.1

General

WD 1539-1

J3/21-007r1

3 4

1 The bit manipulation procedures are described in terms of a model for the representation and behavior of bits

5 6

2 For the purposes of these procedures, a bit is defined to be a binary digit w located at position k of a nonnegative

on a processor. integer scalar object based on a model nonnegative integer defined by j=

z−1 X

wk × 2k

k=0

7 8 9 10

and for which wk has the value 0 or 1. This defines a sequence of bits wz−1 . . . w0 , with wz−1 the leftmost bit and w0 the rightmost bit. The positions of bits in the sequence are numbered from right to left, with the position of the rightmost bit being zero. The length of a sequence of bits is z. An example of a model number compatible with the examples used in 16.4 would have z = 32, thereby defining a 32-bit integer.

11

3 The interpretation of a negative integer as a sequence of bits is processor dependent.

12

4 The inquiry function BIT_SIZE provides the value of the parameter z of the model.

13 14 15 16 17

5 Effectively, this model defines an integer object to consist of z bits in sequence numbered from right to left from

18

0 to z − 1. This model is valid only in the context of the use of such an object as the argument or result of an intrinsic procedure that interprets that object as a sequence of bits. In all other contexts, the model defined for an integer in 16.4 applies. In particular, whereas the models are identical for r = 2 and wz−1 = 0, they do not correspond for r ̸= 2 or wz−1 = 1 and the interpretation of bits in such objects is processor dependent.

16.3.2

Bit sequence comparisons

19 20

1 When bit sequences of unequal length are compared, the shorter sequence is considered to be extended to the

21 22 23 24

2 Bit sequences are compared from left to right, one bit at a time, until unequal bits are found or all bits have been

25 26

length of the longer sequence by padding with zero bits on the left. compared and found to be equal. If unequal bits are found, the sequence with zero in the unequal position is considered to be less than the sequence with one in the unequal position. Otherwise the sequences are considered to be equal.

16.3.3

Bit sequences as arguments to INT and REAL

1 When a boz-literal-constant is the argument A of the intrinsic function INT or REAL,

32

• if the length of the sequence of bits specified by A is less than the size in bits of a scalar variable of the same type and kind type parameter as the result, the boz-literal-constant is treated as if it were extended to a length equal to the size in bits of the result by padding on the left with zero bits, and • if the length of the sequence of bits specified by A is greater than the size in bits of a scalar variable of the same type and kind type parameter as the result, the boz-literal-constant is treated as if it were truncated from the left to a length equal to the size in bits of the result.

33 34

C1601 If a boz-literal-constant is truncated as an argument to the intrinsic function REAL, the discarded bits shall all be zero.

27 28 29 30 31

NOTE 1 The result values of the intrinsic functions CMPLX and DBLE are defined by references to the intrinsic function REAL with the same arguments. Therefore, the padding and truncation of boz-literal-constant arguments to those intrinsic functions is the same as for the intrinsic function REAL.

ISO/IEC JTC 1/SC 22/WG5/N2184

345

J3/21-007r1

1

16.4

WD 1539-1

2021-05-21

Numeric models

2 3 4

1 The numeric manipulation and inquiry functions are described in terms of a model for the representation and

5

2 The model set for integer i is defined by

behavior of numbers on a processor. The model has parameters that are determined so as to make the model best fit the machine on which the program is executed.

q−1 X

i=s×

wk × rk

k=0

6 7 8

where r is an integer exceeding one, q is a positive integer, each wk is a nonnegative integer less than r, and s is +1 or −1. The integer parameters r and q determine the set of model integers. 3 The model set for real x is defined by

x=

 0 or   e   s×b ×

p X

fk × b−k

k=1

9 10 11 12

where b and p are integers exceeding one; each fk is a nonnegative integer less than b, with f1 nonzero; s is +1 or −1; and e is an integer that lies between some integer maximum emax and some integer minimum emin inclusively. For x = 0, its exponent e and digits fk are defined to be zero. The integer parameters b, p, emin , and emax determine the set of model floating-point numbers.

13 14

4 The parameters of the integer and real models are available for each representation method of the integer and

15 16 17

real types. The parameters characterize the set of available numbers in the definition of the model. Intrinsic functions provide the values of some parameters and other values related to the models. 5 There is also an extended model set for each kind of real x; this extended model is the same as the ordinary

model except that there are no limits on the range of the exponent e. NOTE 1 Some of the function descriptions use the models

i=s×

30 X

wk × 2k

k=0

and 24

e

x = 0 or s × 2 ×

1 X + fk × 2−k 2

! , −126 ≤ e ≤ 127

k=2

18

16.5

Atomic subroutines

19 20 21

1 An atomic subroutine is an intrinsic subroutine that performs an action on its ATOM argument, and if it has an

22

2 For any two executions in unordered segments of atomic subroutines whose ATOM argument is the same object,

23 24 25

the effect is as if one of the executions is performed completely before the other execution begins. Which execution is performed first is processor dependent. The sequence of atomic actions within ordered segments is specified in 5.3.5. If successive atomic subroutine invocations on image P redefine a variable atomically in segments Pi and

OLD argument, determination of the value to be assigned to that argument, atomically. Definition or evaluation of any argument other than ATOM is not performed atomically.

346

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7

WD 1539-1

J3/21-007r1

Pj , atomic references to that variable from image Q in a segment Qk that is unordered relative to Pi and Pj may observe the changes in the value of that variable in any order. If a variable X on image P is defined by an atomic subroutine on image Q, image R repeatedly references X [P ] by an atomic subroutine in an unordered segment, and no other image defines X [P ] in an unordered segment, image R shall eventually receive the value assigned by image Q, even if none of the images P , Q, or R execute an image control statement until after the definition of X [P ] by image Q and the reception of that value by image R.

3 Atomic operations shall make asynchronous progress.

8 9

4 If the STAT argument is present in an invocation of an atomic subroutine and no error condition occurs, it is

10

5 If the STAT argument is present in an invocation of an atomic subroutine and an error condition occurs, any

11 12 13 14

other argument that is not INTENT (IN) becomes undefined. If the ATOM argument is on a failed image, an error condition occurs and the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV is assigned to the STAT argument. If any other error condition occurs, the STAT argument is assigned a processor-dependent positive value that is different from the value of STAT_FAILED_IMAGE.

15 16

6 If the STAT argument is not present in an invocation of an atomic subroutine and an error condition occurs,

assigned the value zero.

error termination is initiated. NOTE 1 The properties of atomic subroutines are intended to support custom synchronization mechanisms. The program will need to handle all possible orderings of sequences of atomic subroutine executions that can arise as a consequence of the above rules; note that the orderings can appear to be different on different images even in the same program execution.

17

16.6

Collective subroutines

18 19 20 21

1 Successful execution of a collective subroutine performs a calculation on all the images of the current team and

22 23 24 25 26

2 Before execution of the first CHANGE TEAM statement on an image, in between executions of CHANGE

27

C1602 A reference to a collective subroutine shall not appear in a context where an image control statement is not permitted to appear.

28

assigns a computed value on one or all of them. If it is invoked by one image, it shall be invoked by the same statement on all active images of its current team in segments that are not ordered with respect to each other; corresponding references participate in the same collective computation. TEAM and/or END TEAM statements, and after the last execution of an END TEAM statement, the sequence of invocations of collective subroutines shall be the same on all active images of a team. A collective subroutine shall not be referenced when an image control statement is not permitted to be executed (for example, in a procedure invoked from a CRITICAL construct).

29 30

3 If the A argument in a reference to a collective subroutine is a coarray, the corresponding ultimate arguments on

31

4 If the STAT argument is present in a reference to a collective subroutine on one image:

32 33 34 35 36 37 38 39

all active images of the current team shall be corresponding coarrays as described in 5.4.7. • it shall be present on all the corresponding references; • if no error condition occurs on that image, it is assigned the value zero; • if an error condition occurs on that image, the A argument becomes undefined; • if an error condition occurs other than that an image in the current team has stopped or failed, the STAT argument is assigned a processor-dependent positive value that is different from the value of STAT_STOPPED_IMAGE or STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV. 5 A reference to a collective subroutine on an image may be successful even if an error condition occurs during the

corresponding reference on another image. If error conditions occur on more than one image, the error conditions

ISO/IEC JTC 1/SC 22/WG5/N2184

347

J3/21-007r1

1 2 3 4 5 6

WD 1539-1

2021-05-21

may be different. 6 If the current team contains an image that is known to have stopped, an error condition occurs, and if the

STAT argument is present it is assigned the value STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV. Otherwise, if the current team contained an image that is known to have failed, an error condition occurs, and if the STAT argument is present it is assigned the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV.

7 8

7 If the STAT argument is not present in a reference to a collective subroutine and an error condition occurs, error

9 10

8 If the ERRMSG argument is present in a reference to a collective subroutine and an error condition occurs, it is

11

termination is initiated. assigned an explanatory message by intrinsic assignment. If no error condition occurs, the definition status and value of ERRMSG are unchanged. NOTE 1 The argument A becomes undefined if an error condition occurs during execution of a collective subroutine because it is intended to allow the processor to use A for intermediate values during calculation. NOTE 2 Although the calculations performed by a collective subroutine have some internal synchronizations, a reference to a collective subroutine is not an image control statement.

12 13 14

16.7

Standard generic intrinsic procedures

1 For all of the standard intrinsic procedures, the arguments shown are the names that shall be used for argument

keywords if the keyword form is used for actual arguments. NOTE 1 For example, a reference to CMPLX can be written in the form CMPLX (A, B, M) or in the form CMPLX (Y = B, KIND = M, X = A). NOTE 2 Many of the argument keywords have names that are indicative of their usage. For example: KIND STRING, STRING_A BACK

Describes the kind type parameter of the result An arbitrary character string Controls the direction of string scan (forward or backward) A mask to be applied to the arguments A selected dimension of an array argument

MASK DIM 15 16 17 18 19 20 21 22 23 24

2 In the Class column of Table 16.1,

A indicates that the procedure is an atomic subroutine, C indicates that the procedure is a collective subroutine, E indicates that the procedure is an elemental function, ES indicates that the procedure is a simple elemental subroutine, I indicates that the procedure is an inquiry function, PS indicates that the procedure is a simple subroutine when the FROM argument is not a coarray, S indicates that the procedure is an impure subroutine, SS indicates that the procedure is a simple subroutine, and T indicates that the procedure in a transformational function.

348

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Table 16.1: Standard generic intrinsic procedure summary Procedure (arguments) Class Description ABS (A) E Absolute value. ACHAR (I [, KIND]) E Character from ASCII code value. ACOS (X) E Arccosine (inverse cosine) function. ACOSD (X) E Arc cosine function in degrees. ACOSH (X) E Inverse hyperbolic cosine function. ACOSPI (X) E Circular arc cosine function. ADJUSTL (STRING) E Left-justified string value. ADJUSTR (STRING) E Right-justified string value. AIMAG (Z) E Imaginary part of a complex number. AINT (A [, KIND]) E Truncation toward 0 to a whole number. ALL (MASK) or ALL (MASK, DIM) T Array reduced by .AND. operator. ALLOCATED (ARRAY) or ALLOCATED (SCALAR) I Allocation status of allocatable variable. ANINT (A [, KIND]) E Nearest whole number. ANY (MASK) or ANY (MASK, DIM) T Array reduced by .OR. operator. ASIN (X) E Arcsine (inverse sine) function. ASIND (X) E Arc sine function in degrees. ASINH (X) E Inverse hyperbolic sine function. ASINPI (X) E Circular arc sine function. ASSOCIATED (POINTER [, TARGET]) I Pointer association status inquiry. ATAN (X) or ATAN (Y, X) E Arctangent (inverse tangent) function. ATAN2 (Y, X) E Arctangent (inverse tangent) function. ATAN2D (Y, X) E Arc tangent function in degrees. ATAN2PI (Y, X) E Circular arc tangent function. ATAND (X) or ATAND (Y, X) E Arc tangent function in degrees. ATANH (X) E Inverse hyperbolic tangent function. ATANPI (X) or ATANPI (Y, X) E Circular arc tangent function. ATOMIC_ADD (ATOM, VALUE [, STAT]) A Atomic addition. ATOMIC_AND (ATOM, VALUE [, STAT]) A Atomic bitwise AND. ATOMIC_CAS (ATOM, OLD, COMPARE, NEW[, STAT]) A Atomic compare and swap. ATOMIC_DEFINE (ATOM, VALUE [, STAT]) A Define a variable atomically. ATOMIC_FETCH_ADD (ATOM, VALUE, OLD [, STAT]) A Atomic fetch and add. ATOMIC_FETCH_AND (ATOM, VALUE, OLD [, STAT]) A Atomic fetch and bitwise AND. ATOMIC_FETCH_OR (ATOM, VALUE, OLD [, STAT]) A Atomic fetch and bitwise OR. ATOMIC_FETCH_XOR (ATOM, VALUE, OLD [, STAT]) A Atomic fetch and bitwise exclusive OR. ATOMIC_OR (ATOM, VALUE [, STAT]) A Atomic bitwise OR. ATOMIC_REF (VALUE, ATOM [, STAT]) A Reference a variable atomically. ATOMIC_XOR (ATOM, VALUE [, STAT]) A Atomic bitwise exclusive OR. BESSEL_J0 (X) E Bessel function of the 1st kind, order 0. BESSEL_J1 (X) E Bessel function of the 1st kind, order 1. BESSEL_JN (N, X) E Bessel function of the 1st kind, order N. BESSEL_JN (N1, N2, X) T Bessel functions of the 1st kind. BESSEL_Y0 (X) E Bessel function of the 2nd kind, order 0. BESSEL_Y1 (X) E Bessel function of the 2nd kind, order 1. BESSEL_YN (N, X) E Bessel function of the 2nd kind, order N. BESSEL_YN (N1, N2, X) T Bessel functions of the 2nd kind. BGE (I, J) E Bitwise greater than or equal to. BGT (I, J) E Bitwise greater than. BIT_SIZE (I) I Number of bits in integer model 16.3. BLE (I, J) E Bitwise less than or equal to. BLT (I, J) E Bitwise less than. BTEST (I, POS) E Test single bit in an integer. CEILING (A [, KIND]) E Least integer greater than or equal to A. CHAR (I [, KIND]) E Character from code value.

ISO/IEC JTC 1/SC 22/WG5/N2184

349

J3/21-007r1

WD 1539-1

2021-05-21

Table 16.1: Standard generic intrinsic procedure summary (cont.) Procedure (arguments) Class Description CMPLX (X [, KIND]) or CMPLX (X [, Y, KIND]) E Conversion to complex type. CO_BROADCAST (A, SOURCE_IMAGE [, STAT, C Broadcast value to images. ERRMSG]) CO_MAX (A [, RESULT_IMAGE, STAT, ERRMSG]) C Compute maximum value across images. CO_MIN (A [, RESULT_IMAGE, STAT, ERRMSG]) C Compute minimum value across images. CO_REDUCE (A, OPERATION [, RESULT_IMAGE, C Generalized reduction across images. STAT, ERRMSG]) CO_SUM (A [, RESULT_IMAGE, STAT, ERRMSG]) C Compute sum across images. COMMAND_ARGUMENT_COUNT ( ) T Number of command arguments. CONJG (Z) E Conjugate of a complex number. COS (X) E Cosine function. COSD (X) E Degree cosine function. COSH (X) E Hyperbolic cosine function. COSHAPE (COARRAY [, KIND]) I Sizes of codimensions of a coarray. COSPI (X) E Circular cosine function. COUNT (MASK [, DIM, KIND]) T Array reduced by counting true values. CPU_TIME (TIME) S Processor time used. CSHIFT (ARRAY, SHIFT [, DIM]) T Circular shift of an array. DATE_AND_TIME ([DATE, TIME, ZONE, VALUES]) S Date and time. DBLE (A) E Conversion to double precision real. DIGITS (X) I Significant digits in numeric model. DIM (X, Y) E Maximum of X − Y and zero. DOT_PRODUCT (VECTOR_A, VECTOR_B) T Dot product of two vectors. DPROD (X, Y) E Double precision real product. DSHIFTL (I, J, SHIFT) E Combined left shift. DSHIFTR (I, J, SHIFT) E Combined right shift. EOSHIFT (ARRAY, SHIFT [, BOUNDARY, DIM]) T End-off shift of the elements of an array. EPSILON (X) I Model number that is small compared to 1. ERF (X) E Error function. ERFC (X) E Complementary error function. ERFC_SCALED (X) E Scaled complementary error function. EVENT_QUERY (EVENT, COUNT [, STAT]) S Query event count. EXECUTE_COMMAND_LINE (COMMAND [, WAIT, S Execute a command line. EXITSTAT, CMDSTAT, CMDMSG]) EXP (X) E Exponential function. EXPONENT (X) E Exponent of floating-point number. EXTENDS_TYPE_OF (A, MOLD) I Dynamic type extension inquiry. FAILED_IMAGES ([TEAM, KIND]) T Indices of failed images. FINDLOC (ARRAY, VALUE [, MASK, KIND, BACK]) or T Location(s) of a specified value. FINDLOC (ARRAY, VALUE, DIM [, MASK, KIND, BACK]) FLOOR (A [, KIND]) E Greatest integer less than or equal to A. FRACTION (X) E Fractional part of number. GAMMA (X) E Gamma function. GET_COMMAND ([COMMAND, LENGTH, STATUS, S Get program invocation command. ERRMSG]) GET_COMMAND_ARGUMENT (NUMBER [, VALUE, S Get program invocation argument. LENGTH, STATUS, ERRMSG]) GET_ENVIRONMENT_VARIABLE (NAME [, VALUE, S Get environment variable. LENGTH, STATUS, TRIM_NAME, ERRMSG]) GET_TEAM ([LEVEL]) T Team. HUGE (X) I Largest model value. HYPOT (X, Y) E Euclidean distance function. IACHAR (C [, KIND]) E ASCII code value for character.

350

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Table 16.1: Standard generic intrinsic procedure summary (cont.) Procedure (arguments) Class Description IALL (ARRAY, DIM [, MASK]) or IALL (ARRAY [, MASK]) T Array reduced by IAND function. IAND (I, J) E Bitwise AND. IANY (ARRAY, DIM [, MASK]) or IANY (ARRAY [, MASK]) T Array reduced by IOR function. IBCLR (I, POS) E I with bit POS replaced by zero. IBITS (I, POS, LEN) E Specified sequence of bits. IBSET (I, POS) E I with bit POS replaced by one. ICHAR (C [, KIND]) E Code value for character. IEOR (I, J) E Bitwise exclusive OR. IMAGE_INDEX (COARRAY, SUB, TEAM_NUMBER) or T Image index from cosubscripts. IMAGE_INDEX (COARRAY, SUB, TEAM) or IMAGE_INDEX (COARRAY, SUB) IMAGE_STATUS (IMAGE [, TEAM]) E Image execution state. INDEX (STRING, SUBSTRING [, BACK, KIND]) E Character string search. INT (A [, KIND]) E Conversion to integer type. IOR (I, J) E Bitwise inclusive OR. IPARITY (ARRAY, DIM [, MASK]) or T Array reduced by IEOR function. IPARITY (ARRAY [, MASK]) ISHFT (I, SHIFT) E Logical shift. ISHFTC (I, SHIFT [, SIZE]) E Circular shift of the rightmost bits. IS_CONTIGUOUS (ARRAY) I Array contiguity test (8.5.7). IS_IOSTAT_END (I) E IOSTAT value test for end of file. IS_IOSTAT_EOR (I) E IOSTAT value test for end of record. KIND (X) I Value of the kind type parameter of X. LBOUND (ARRAY [, DIM, KIND]) I Lower bound(s). LCOBOUND (COARRAY [, DIM, KIND]) I Lower cobound(s) of a coarray. LEADZ (I) E Number of leading zero bits. LEN (STRING [, KIND]) I Length of a character entity. LEN_TRIM (STRING [, KIND]) E Length without trailing blanks. LGE (STRING_A, STRING_B) E ASCII greater than or equal. LGT (STRING_A, STRING_B) E ASCII greater than. LLE (STRING_A, STRING_B) E ASCII less than or equal. LLT (STRING_A, STRING_B) E ASCII less than. LOG (X) E Natural logarithm. LOG_GAMMA (X) E Logarithm of the absolute value of the gamma function. LOG10 (X) E Common logarithm. LOGICAL (L [, KIND]) E Conversion between kinds of logical. MASKL (I [, KIND]) E Left justified mask. MASKR (I [, KIND]) E Right justified mask. MATMUL (MATRIX_A, MATRIX_B) T Matrix multiplication. MAX (A1, A2 [, A3, ...]) E Maximum value. MAXEXPONENT (X) I Maximum exponent of a real model. MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or T Location(s) of maximum value. MAXLOC (ARRAY [, MASK, KIND, BACK]) MAXVAL (ARRAY, DIM [, MASK]) or T Maximum value(s) of array. MAXVAL (ARRAY [, MASK]) MERGE (TSOURCE, FSOURCE, MASK) E Expression value selection. MERGE_BITS (I, J, MASK) E Merge of bits under mask. MIN (A1, A2 [, A3, ...]) E Minimum value. MINEXPONENT (X) I Minimum exponent of a real model. MINLOC (ARRAY, DIM [, MASK, KIND, BACK]) or T Location(s) of minimum value. MINLOC (ARRAY [, MASK, KIND, BACK]) MINVAL (ARRAY, DIM [, MASK]) or T Minimum value(s) of array.

ISO/IEC JTC 1/SC 22/WG5/N2184

351

J3/21-007r1

WD 1539-1

2021-05-21

Table 16.1: Standard generic intrinsic procedure summary (cont.) Procedure (arguments) Class Description MINVAL (ARRAY [, MASK]) MOD (A, P) E Remainder function. MODULO (A, P) E Modulo function. MOVE_ALLOC (FROM, TO [, STAT, ERRMSG]) PS Move an allocation. MVBITS (FROM, FROMPOS, LEN, TO, TOPOS) ES Copy a sequence of bits. NEAREST (X, S) E Adjacent machine number. NEW_LINE (A) I Newline character. NEXT (A [, STAT]) E Next enumeration value. NINT (A [, KIND]) E Nearest integer. NORM2 (X) or NORM2 (X, DIM) T L2 norm of an array. NOT (I) E Bitwise complement. NULL ([MOLD]) T Disassociated pointer or unallocated allocatable entity. NUM_IMAGES ( ) or NUM_IMAGES (TEAM) or T Number of images. NUM_IMAGES (TEAM_NUMBER) OUT_OF_RANGE (X, MOLD [, ROUND]) E Whether a value cannot be converted safely. PACK (ARRAY, MASK [, VECTOR]) T Array packed into a vector. PARITY (MASK) or PARITY (MASK, DIM) T Array reduced by .NEQV. operator. POPCNT (I) E Number of one bits. POPPAR (I) E Parity expressed as 0 or 1. PRECISION (X) I Decimal precision of a real model. PRESENT (A) I Presence of optional argument. PREVIOUS (A [, STAT]) E Previous enumeration value. PRODUCT (ARRAY, DIM [, MASK]) or T Array reduced by multiplication. PRODUCT (ARRAY [, MASK]) RADIX (X) I Base of a numeric model. RANDOM_INIT (REPEATABLE, IMAGE_DISTINCT) S Initialize pseudorandom number generator. RANDOM_NUMBER (HARVEST) S Generate pseudorandom number(s). RANDOM_SEED ([SIZE, PUT, GET]) S Pseudorandom number generator control. RANGE (X) I Decimal exponent range of a numeric model (16.4). RANK (A) I Rank of a data object. REAL (A [, KIND]) E Conversion to real type. REDUCE (ARRAY, OPERATION [, MASK, IDENTITY, T General reduction of array ORDERED]) or REDUCE (ARRAY, OPERATION, DIM [, MASK, IDENTITY, ORDERED]) REPEAT (STRING, NCOPIES) T Repetitive string concatenation. RESHAPE (SOURCE, SHAPE [, PAD, ORDER]) T Arbitrary shape array construction. RRSPACING (X) E Reciprocal of relative spacing of model numbers. SAME_TYPE_AS (A, B) I Dynamic type equality test. SCALE (X, I) E Real number scaled by radix power. SCAN (STRING, SET [, BACK, KIND]) E Character set membership search. SELECTED_CHAR_KIND (NAME) T Character kind selection. SELECTED_INT_KIND (R) T Integer kind selection. SELECTED_LOGICAL_KIND (BITS) T Logical kind selection. SELECTED_REAL_KIND ([P, R, RADIX]) T Real kind selection. SET_EXPONENT (X, I) E Real value with specified exponent. SHAPE (SOURCE [, KIND]) I Shape of an array or a scalar. SHIFTA (I, SHIFT) E Right shift with fill. SHIFTL (I, SHIFT) E Left shift. SHIFTR (I, SHIFT) E Right shift.

352

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Table 16.1: Standard generic intrinsic procedure summary (cont.) Procedure (arguments) Class Description SIGN (A, B) E Magnitude of A with the sign of B. SIN (X) E Sine function. SIND (X) E Degree sine function. SINH (X) E Hyperbolic sine function. SINPI (X) E Circular sine function. SIZE (ARRAY [, DIM, KIND]) I Size of an array or one extent. SPACING (X) E Spacing of model numbers. SPLIT (STRING, SET, POS [, BACK]) SS Parse a string into tokens, one at a time. SPREAD (SOURCE, DIM, NCOPIES) T Value replicated in a new dimension. SQRT (X) E Square root. STOPPED_IMAGES ([TEAM, KIND]) T Indices of stopped images. STORAGE_SIZE (A [, KIND]) I Storage size in bits. SUM (ARRAY, DIM [, MASK]) or SUM (ARRAY [, MASK]) T Array reduced by addition. SYSTEM_CLOCK ([COUNT, COUNT_RATE, S Query system clock. COUNT_MAX]) TAN (X) E Tangent function. TAND (X) E Degree tangent function. TANH (X) E Hyperbolic tangent function. TANPI (X) E Circular tangent function. TEAM_NUMBER ([TEAM]) T Team number. THIS_IMAGE ([TEAM]) T Index of the invoking image. THIS_IMAGE (COARRAY [, TEAM]) or T Cosubscript(s) for this image. THIS_IMAGE (COARRAY, DIM [, TEAM]) TINY (X) I Smallest positive model number. TOKENIZE (STRING, SET, TOKENS [, SEPARATOR]) or SS Parse a string into tokens. TOKENIZE (STRING, SET, FIRST, LAST) TRAILZ (I) E Number of trailing zero bits. TRANSFER (SOURCE, MOLD [, SIZE]) T Transfer physical representation. TRANSPOSE (MATRIX) T Transpose of an array of rank two. TRIM (STRING) T String without trailing blanks. UBOUND (ARRAY [, DIM, KIND]) I Upper bound(s). UCOBOUND (COARRAY [, DIM, KIND]) I Upper cobound(s) of a coarray. UNPACK (VECTOR, MASK, FIELD) T Vector unpacked into an array. VERIFY (STRING, SET [, BACK, KIND]) E Character set non-membership search.

1 2

3 The effect of calling EXECUTE_COMMAND_LINE on any image other than image 1 in the initial team is

3 4

4 The use of all other standard intrinsic procedures in unordered segments is subject only to their argument use

5

processor dependent. following the rules in 11.7.2.

16.8

Specific names for standard intrinsic functions

6 7

1 Except for AMAX0, AMIN0, MAX1, and MIN1, the result type of the specific function is the same that the result type of the

8 9 10

2 A function listed in Table 16.3 is not permitted to be used as an actual argument (15.5.1, C1534), as a target in a procedure

corresponding generic function reference would be if it were invoked with the same arguments as the specific function.

pointer assignment statement (10.2.2.2, C1032), as an initial target in a procedure declaration statement (15.4.3.6, C1519), or to specify an interface (15.4.3.6, C1515). Table 16.2: Unrestricted specific intrinsic functions Specific name

Generic name

Argument type and kind

ABS

ABS

default real

ISO/IEC JTC 1/SC 22/WG5/N2184

353

J3/21-007r1

WD 1539-1

Unrestricted specific intrinsic functions

2021-05-21 (cont.)

Specific name

Generic name

Argument type and kind

ACOS AIMAG AINT ALOG ALOG10 AMOD ANINT ASIN ATAN ATAN2 CABS CCOS CEXP CLOG CONJG COS COSH CSIN CSQRT DABS DACOS DASIN DATAN DATAN2 DCOS DCOSH DDIM DEXP DIM DINT DLOG DLOG10 DMOD DNINT DPROD DSIGN DSIN DSINH DSQRT DTAN DTANH EXP IABS IDIM IDNINT INDEX ISIGN LEN MOD NINT SIGN SIN SINH SQRT TAN TANH

ACOS AIMAG AINT LOG LOG10 MOD ANINT ASIN ATAN (X) ATAN2 ABS COS EXP LOG CONJG COS COSH SIN SQRT ABS ACOS ASIN ATAN ATAN2 COS COSH DIM EXP DIM AINT LOG LOG10 MOD ANINT DPROD SIGN SIN SINH SQRT TAN TANH EXP ABS DIM NINT INDEX SIGN LEN MOD NINT SIGN SIN SINH SQRT TAN TANH

default real default complex default real default real default real default real default real default real default real default real default complex default complex default complex default complex default complex default real default real default complex default complex double precision real double precision real double precision real double precision real double precision real double precision real double precision real double precision real double precision real default real double precision real double precision real double precision real double precision real double precision real default real double precision real double precision real double precision real double precision real double precision real double precision real default real default integer default integer double precision real default character default integer default character default integer default real default real default real default real default real default real default real

Table 16.3: Restricted specific intrinsic functions

354

Specific name

Generic name

Argument type and kind

AMAX0 (. . . ) AMAX1 AMIN0 (. . . ) AMIN1 CHAR

REAL (MAX (. . . )) MAX REAL (MIN (. . . )) MIN CHAR

default integer default real default integer default real default integer

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Restricted specific intrinsic functions

(cont.)

Specific name

Generic name

Argument type and kind

DMAX1 DMIN1 FLOAT ICHAR IDINT IFIX INT LGE LGT LLE LLT MAX0 MAX1 (. . . ) MIN0 MIN1 (. . . ) REAL SNGL

MAX MIN REAL ICHAR INT INT INT LGE LGT LLE LLT MAX INT (MAX (. . . )) MIN INT (MIN (. . . )) REAL REAL

double precision real double precision real default integer default character double precision real default real default real default character default character default character default character default integer default real default integer default real default integer double precision real

1

16.9

Specifications of the standard intrinsic procedures

2

16.9.1

General

3

1 Detailed specifications of the standard generic intrinsic procedures are provided in 16.9 in alphabetical order.

4 5 6 7 8

2 The types and type parameters of standard intrinsic procedure arguments and function results are determined

9 10

3 When an allocatable deferred-length character scalar corresponding to an INTENT (INOUT) or INTENT (OUT)

11 12 13 14

4 If an IEEE infinity is assigned or returned by an intrinsic procedure, the intrinsic module IEEE_ARITHMETIC

by these specifications. The “Argument(s)” paragraphs specify requirements on the actual arguments of the procedures. The result characteristics are sometimes specified in terms of the characteristics of the arguments. A program shall not invoke an intrinsic procedure under circumstances where a value to be assigned to a subroutine argument or returned as a function result is not representable by objects of the specified type and type parameters. argument is assigned a value, the value is assigned as if by intrinsic assignment.

15 16

is accessible, and the actual arguments were finite numbers, the flag IEEE_OVERFLOW or IEEE_DIVIDE_BY_ZERO shall signal. If an IEEE NaN is assigned or returned, the actual arguments were finite numbers, the intrinsic module IEEE_ARITHMETIC is accessible, and the exception IEEE_INVALID is supported, the flag IEEE_INVALID shall signal. If no IEEE infinity or NaN is assigned or returned, these flags shall have the same status as when the intrinsic procedure was invoked.

17

16.9.2

ABS (A)

18

1 Description. Absolute value.

19

2 Class. Elemental function.

20

3 Argument. A shall be of type integer, real, or complex.

21

4 Result Characteristics. The same as A except that if A is complex, the result is real.

22

5 Result Value. If A is of type integer or real, the value of thep result is |A|; if A is complex with value (x, y),

23 24 25

the result is equal to a processor-dependent approximation to underflow.

x2 + y 2 computed without undue overflow or

6 Example. ABS ((3.0, 4.0)) has the value 5.0 (approximately).

ISO/IEC JTC 1/SC 22/WG5/N2184

355

J3/21-007r1

1

16.9.3

WD 1539-1

ACHAR (I [, KIND])

2

1 Description. Character from ASCII code value.

3

2 Class. Elemental function.

4

3 Arguments.

5

I

6

KIND (optional) shall be a scalar integer constant expression.

7 8

2021-05-21

shall be of type integer.

4 Result Characteristics. Character of length one. If KIND is present, the kind type parameter is that specified

by the value of KIND; otherwise, the kind type parameter is that of default character.

9 10 11 12

5 Result Value. If I has a value in the range 0 ≤ I ≤ 127, the result is the character in position I of the ASCII

13

6 Example. ACHAR (88) has the value ’X’.

14

collating sequence, provided the processor is capable of representing that character in the character kind of the result; otherwise, the result is processor dependent. ACHAR (IACHAR (C)) shall have the value C for any character C capable of representation as a default character.

16.9.4

ACOS (X)

15

1 Description. Arccosine (inverse cosine) function.

16

2 Class. Elemental function.

17

3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1, or of type complex.

18

4 Result Characteristics. Same as X.

19

5 Result Value. The result has a value equal to a processor-dependent approximation to arccos(X). If it is real

20 21

it is expressed in radians and lies in the range 0 ≤ ACOS (X) ≤ π. If it is complex the real part is expressed in radians and lies in the range 0 ≤ REAL (ACOS (X)) ≤ π.

22 23

6 Example. ACOS (0.54030231) has the value 1.0 (approximately).

16.9.5

ACOSD (X)

24

1 Description. Arc cosine function in degrees.

25

2 Class. Elemental function.

26

3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1.

27

4 Result Characteristics. Same as X.

28 29

5 Result Value. The result has a value equal to a processor-dependent approximation to the arc cosine of X. It

30

6 Example. ACOSD (−1.0) has the value 180.0 (approximately).

31

is expressed in degrees and lies in the range 0 ≤ ACOSD (X) ≤ 180.

16.9.6

ACOSH (X)

32

1 Description. Inverse hyperbolic cosine function.

33

2 Class. Elemental function.

34

3 Argument. X shall be of type real or complex.

35

4 Result Characteristics. Same as X.

356

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic

4

6 Example. ACOSH (1.5430806) has the value 1.0 (approximately).

5

cosine function of X. If the result is complex the real part is nonnegative, and the imaginary part is expressed in radians and lies in the range −π ≤ AIMAG (ACOSH (X)) ≤ π

16.9.7

ACOSPI (X)

6

1 Description. Circular arc cosine function.

7

2 Class. Elemental function.

8

3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1.

9

4 Result Characteristics. Same as X.

10

5 Result Value. The result has a value equal to a processor-dependent approximation to the arc cosine of X. It

11 12 13

is expressed in half-revolutions and lies in the range 0 ≤ ACOS (X) ≤ 1. 6 Example. ACOSPI (−1.0) has the value 180.0 (approximately).

16.9.8

ADJUSTL (STRING)

14

1 Description. Left-justified string value.

15

2 Class. Elemental function.

16

3 Argument. STRING shall be of type character.

17

4 Result Characteristics. Character of the same length and kind type parameter as STRING.

18 19

5 Result Value. The value of the result is the same as STRING except that any leading blanks have been deleted

20

6 Example. ADJUSTL (’ WORD’) has the value ’WORD ’.

21

and the same number of trailing blanks have been inserted.

16.9.9

ADJUSTR (STRING)

22

1 Description. Right-justified string value.

23

2 Class. Elemental function.

24

3 Argument. STRING shall be of type character.

25

4 Result Characteristics. Character of the same length and kind type parameter as STRING.

26 27

5 Result Value. The value of the result is the same as STRING except that any trailing blanks have been deleted

28

6 Example. ADJUSTR (’WORD ’) has the value ’ WORD’.

29

and the same number of leading blanks have been inserted.

16.9.10

AIMAG (Z)

30

1 Description. Imaginary part of a complex number.

31

2 Class. Elemental function.

32

3 Argument. Z shall be of type complex.

33

4 Result Characteristics. Real with the same kind type parameter as Z.

ISO/IEC JTC 1/SC 22/WG5/N2184

357

J3/21-007r1

WD 1539-1

1

5 Result Value. If Z has the value (x, y), the result has the value y.

2

6 Example. AIMAG ((2.0, 3.0)) has the value 3.0.

3

16.9.11

2021-05-21

AINT (A [, KIND])

4

1 Description. Truncation toward 0 to a whole number.

5

2 Class. Elemental function.

6

3 Arguments.

7

A

shall be of type real.

8

KIND (optional) shall be a scalar integer constant expression.

9 10

4 Result Characteristics. The result is of type real. If KIND is present, the kind type parameter is that specified

11 12

5 Result Value. If |A| < 1, AINT (A) has the value 0; if |A| ≥ 1, AINT (A) has a value equal to the integer

13 14 15

by the value of KIND; otherwise, the kind type parameter is that of A. whose magnitude is the largest integer that does not exceed the magnitude of A and whose sign is the same as the sign of A. 6 Examples. AINT (2.783) has the value 2.0. AINT (−2.783) has the value −2.0.

16.9.12

ALL (MASK) or ALL (MASK, DIM)

16

1 Description. Array reduced by .AND. operator.

17

2 Class. Transformational function.

18

3 Arguments.

19

MASK

shall be a logical array.

20

DIM

shall be an integer scalar with value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.

21 22 23

4 Result Characteristics. The result is of type logical with the same kind type parameter as MASK. It is scalar

24

5 Result Value.

if DIM does not appear or n = 1; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of MASK.

25 26

Case (i):

The result of ALL (MASK) has the value true if all elements of MASK are true or if MASK has size zero, and the result has value false if any element of MASK is false. If MASK has rank one, ALL (MASK, DIM) is equal to ALL (MASK). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of ALL (MASK, DIM) is equal to ALL (MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )).

27 28 29

Case (ii):

30

6 Examples.

31

Case (i):

32

Case (ii):

The value of ALL ([.TRUE., .FALSE., .TRUE.]) is false.     1 3 5 0 3 5 If B is the array and C is the array then ALL (B /= C, DIM = 1) is 2 4 6 7 4 8 [true, false, false] and ALL (B /= C, DIM = 2) is [false, false].

16.9.13

ALLOCATED (ARRAY) or ALLOCATED (SCALAR)

33 34 35

1 Description. Allocation status of allocatable variable.

36

2 Class. Inquiry function.

37

3 Arguments.

358

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

ARRAY

shall be an allocatable array.

2

SCALAR

shall be an allocatable scalar.

J3/21-007r1

3

4 Result Characteristics. Default logical scalar.

4 5

5 Result Value. The result has the value true if the argument (ARRAY or SCALAR) is allocated and has the

6

value false if the argument is unallocated.

16.9.14

ANINT (A [, KIND])

7

1 Description. Nearest whole number.

8

2 Class. Elemental function.

9

3 Arguments.

10

A

11

KIND (optional) shall be a scalar integer constant expression.

shall be of type real.

12 13

4 Result Characteristics. The result is of type real. If KIND is present, the kind type parameter is that specified

14 15

5 Result Value. The result is the integer nearest A, or if there are two integers equally near A, the result is

16

6 Examples. ANINT (2.783) has the value 3.0. ANINT (−2.783) has the value −3.0.

17

by the value of KIND; otherwise, the kind type parameter is that of A. whichever such integer has the greater magnitude.

16.9.15

ANY (MASK) or ANY (MASK, DIM)

18

1 Description. Array reduced by .OR. operator.

19

2 Class. Transformational function.

20

3 Arguments.

21

MASK

shall be a logical array.

22

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.

23 24 25

4 Result Characteristics. The result is of type logical with the same kind type parameter as MASK. It is scalar

26

5 Result Value.

if DIM does not appear or n = 1; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of MASK.

27 28

Case (i):

29 30

Case (ii):

31 32

6 Examples.

33

Case (i):

34

Case (ii):

35

The result of ANY (MASK) has the value true if any element of MASK is true and has the value false if no elements are true or if MASK has size zero. If MASK has rank one, ANY (MASK, DIM) is equal to ANY (MASK). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of ANY (MASK, DIM) is equal to ANY (MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )).

The value of ANY ([.TRUE., .FALSE., .TRUE.]) is true.     1 3 5 0 3 5 If B is the array and C is the array then ANY (B /= C, DIM = 1) is 2 4 6 7 4 8 [true, false, true] and ANY (B /= C, DIM = 2) is [true, true].

ISO/IEC JTC 1/SC 22/WG5/N2184

359

J3/21-007r1

1

16.9.16

WD 1539-1

2021-05-21

ASIN (X)

2

1 Description. Arcsine (inverse sine) function.

3

2 Class. Elemental function.

4

3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1, or of type complex.

5

4 Result Characteristics. Same as X.

6 7 8

5 Result Value. The result has a value equal to a processor-dependent approximation to arcsin(X). If it is real it

9

6 Example. ASIN (0.84147098) has the value 1.0 (approximately).

10

is expressed in radians and lies in the range −π/2 ≤ ASIN (X) ≤ π/2. If it is complex the real part is expressed in radians and lies in the range −π/2 ≤ REAL (ASIN (X)) ≤ π/2.

16.9.17

ASIND (X)

11

1 Description. Arc sine function in degrees.

12

2 Class. Elemental function.

13

3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1.

14

4 Result Characteristics. Same as X.

15

5 Result Value. The result has a value equal to a processor-dependent approximation to the arc sine of X. It is

16 17 18

expressed in degrees and lies in the range −90 ≤ ASIND (X) ≤ 90. 6 Example. ASIND (1.0) has the value 90.0 (approximately).

16.9.18

ASINH (X)

19

1 Description. Inverse hyperbolic sine function.

20

2 Class. Elemental function.

21

3 Argument. X shall be of type real or complex.

22

4 Result Characteristics. Same as X.

23 24 25

5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic

26

6 Example. ASINH (1.1752012) has the value 1.0 (approximately).

27

sine function of X. If the result is complex the imaginary part is expressed in radians and lies in the range −π/2 ≤ AIMAG (ASINH (X)) ≤ π/2.

16.9.19

ASINPI (X)

28

1 Description. Circular arc sine function.

29

2 Class. Elemental function.

30

3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1.

31

4 Result Characteristics. Same as X.

32 33

5 Result Value. The result has a value equal to a processor-dependent approximation to the arc sine of X. It is

34

6 Example. ASINPI (1.0) has the value 0.5 (approximately).

expressed in half-revolutions and lies in the range − 12 ≤ ASINPI (X) ≤ 21 .

360

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

16.9.20

WD 1539-1

J3/21-007r1

ASSOCIATED (POINTER [, TARGET])

2

1 Description. Pointer association status inquiry.

3

2 Class. Inquiry function.

4

3 Arguments.

5 6

POINTER

7 8 9

TARGET (optional) shall be allowable as the data-target or proc-target in a pointer assignment statement (10.2.2) in which POINTER is data-pointer-object or proc-pointer-object. If TARGET is a pointer then its pointer association status shall not be undefined.

shall be a pointer. It may be of any type or may be a procedure pointer. Its pointer association status shall not be undefined.

10

4 Result Characteristics. Default logical scalar.

11

5 Result Value.

12 13 14

Case (i): Case (ii):

15 16 17

Case (iii):

18 19 20

Case (iv):

21 22 23

Case (v):

24 25

Case (vi):

26 27 28 29 30 31

Case (vii):

If TARGET is absent, the result is true if and only if POINTER is associated with a target. If TARGET is present and is a procedure, the result is true if and only if POINTER is associated with TARGET and, if TARGET is an internal procedure, they have the same host instance. If TARGET is present and is a procedure pointer, the result is true if and only if POINTER and TARGET are associated with the same procedure and, if the procedure is an internal procedure, they have the same host instance. If TARGET is present and is a scalar target, the result is true if and only if TARGET is not a zerosized storage sequence and POINTER is associated with a target that occupies the same storage units as TARGET. If TARGET is present and is an array target, the result is true if and only if POINTER is associated with a target that has the same shape as TARGET, is neither of size zero nor an array whose elements are zero-sized storage sequences, and occupies the same storage units as TARGET in array element order. If TARGET is present and is a scalar pointer, the result is true if and only if POINTER and TARGET are associated, the targets are not zero-sized storage sequences, and they occupy the same storage units. If TARGET is present and is an array pointer, the result is true if and only if POINTER and TARGET are both associated, have the same shape, are neither of size zero nor arrays whose elements are zero-sized storage sequences, and occupy the same storage units in array element order.

NOTE 1 The references to TARGET in the above cases are referring to properties that might be possessed by the actual argument, so the case of TARGET being a disassociated pointer will be covered by case (iii), (vi), or (vii). 32 33 34 35

6 Examples. ASSOCIATED (CURRENT, HEAD) is true if CURRENT is associated with the target HEAD.

36 37

After the execution of A_PART => A (:N) ASSOCIATED (A_PART, A) is true if N is equal to UBOUND (A, DIM = 1). After the execution of NULLIFY (CUR); NULLIFY (TOP) ASSOCIATED (CUR, TOP) is false.

38

16.9.21

ATAN (X) or ATAN (Y, X)

39

1 Description. Arctangent (inverse tangent) function.

40

2 Class. Elemental function.

ISO/IEC JTC 1/SC 22/WG5/N2184

361

J3/21-007r1

1

WD 1539-1

2021-05-21

3 Arguments.

2

Y

shall be of type real.

3 4

X

If Y appears, X shall be of type real with the same kind type parameter as Y. If Y has the value zero, X shall not have the value zero. If Y does not appear, X shall be of type real or complex.

5

4 Result Characteristics. Same as X.

6 7 8

5 Result Value. If Y appears, the result is the same as the result of ATAN2 (Y,X). If Y does not appear, the

9

6 Example. ATAN (1.5574077) has the value 1.0 (approximately).

10

result has a value equal to a processor-dependent approximation to arctan(X) whose real part is expressed in radians and lies in the range −π/2 ≤ ATAN (X) ≤ π/2.

16.9.22

ATAN2 (Y, X)

11

1 Description. Arctangent (inverse tangent) function.

12

2 Class. Elemental function.

13

3 Arguments.

14

Y

shall be of type real.

15 16

X

shall be of the same type and kind type parameter as Y. If Y has the value zero, X shall not have the value zero.

17

4 Result Characteristics. Same as X.

18

5 Result Value. The result has a value equal to a processor-dependent approximation to the principal value of

19 20 21 22 23 24

the argument of the complex number (X, Y), expressed in radians. It lies in the range −π ≤ ATAN2 (Y,X) ≤ π and is equal to a processor-dependent approximation to a value of arctan(Y/X) if X ̸= 0. If Y > 0, the result is positive. If Y = 0 and X > 0, the result is Y. If Y = 0 and X < 0, then the result is approximately π if Y is positive real zero or the processor does not distinguish between positive and negative real zero, and approximately −π if Y is negative real zero. If Y < 0, the result is negative. If X = 0, the absolute value of the result is approximately π/2.   1 1 6 Examples. ATAN2 (1.5574077, 1.0) has the value 1.0 (approximately). If Y has the value and X −1 −1     −1 1 3π/4 π/4 has the value , the value of ATAN2 (Y, X) is approximately . −1 1 −3π/4 −π/4

25 26

27

16.9.23

ATAN2D (Y, X)

28

1 Description. Arc tangent function in degrees.

29

2 Class. Elemental function.

30

3 Arguments.

31 32

Y X

33

shall be of type real. shall be of the same type and kind type parameter as Y. If Y has the value zero, X shall not have the value zero.

34

4 Result Characteristics. Same as X.

35 36

5 Result Value. The result is expressed in degrees and lies in the range −180 ≤ ATAN2D (Y, X) ≤ 180. It has

a value equal to a processor-dependent approximation to ATAN2 (Y, X)×180/π. 

37

6 Examples. ATAN2D (1.0, 1.0) has the value 45.0 (approximately). If Y has the value

362

ISO/IEC JTC 1/SC 22/WG5/N2184

1 −1

1 −1

 and X has

2021-05-21 

WD 1539-1   135.0 , the value of ATAN2D (Y, X) is approximately −135.0

1

the value

−1 −1

2

16.9.24

ATAN2PI (Y, X)

1 1

3

1 Description. Circular arc tangent function.

4

2 Class. Elemental function.

5

3 Arguments.

J3/21-007r1

45.0 −45.0

 .

6

Y

shall be of type real.

7 8

X

shall be of the same type and kind type parameter as Y. If Y has the value zero, X shall not have the value zero.

9

4 Result Characteristics. Same as X.

10 11

5 Result Value. The result is expressed in degrees and lies in the range −1 ≤ ATAN2PI (Y, X) ≤ 1. It has a

12

6 Examples. ATAN2PI (1.0, 1.0) has the value 0.25 (approximately). If Y has the value

value equal to a processor-dependent approximation to ATAN2 (Y, X)÷π.  

1 −1

1 −1

 and X has

   1 0.75 0.25 , the value of ATAN2PI (Y, X) is approximately . 1 −0.75 −0.25

13

the value

−1 −1

14

16.9.25

ATAND (X) or ATAND (Y, X)

15

1 Description. Arc tangent function in degrees.

16

2 Class. Elemental function.

17

3 Arguments.

18

Y

shall be of type real.

19 20

X

If Y appears, X shall be of type real with the same kind type parameter as Y. If Y has the value zero, X shall not have the value zero. If Y does not appear, X shall be of type real.

21

4 Result Characteristics. Same as X.

22 23 24

5 Result Value. If Y appears, the result is the same as the result of ATAN2D (Y, X). If Y does not appear,

25

6 Example. ATAND (1.0) has the value 45.0 (approximately).

26

the result has a value equal to a processor-dependent approximation to the arc tangent of X; it is expressed in degrees and lies in the range −90 ≤ ATAND (X) ≤ 90.

16.9.26

ATANH (X)

27

1 Description. Inverse hyperbolic tangent function.

28

2 Class. Elemental function.

29

3 Argument. X shall be of type real or complex.

30

4 Result Characteristics. Same as X.

31 32 33

5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic

34

6 Example. ATANH (0.76159416) has the value 1.0 (approximately).

tangent function of X. If the result is complex the imaginary part is expressed in radians and lies in the range −π/2 ≤ AIMAG (ATANH (X)) ≤ π/2.

ISO/IEC JTC 1/SC 22/WG5/N2184

363

J3/21-007r1

1

16.9.27

WD 1539-1

2021-05-21

ATANPI (X) or ATANPI (Y, X)

2

1 Description. Circular arc tangent function.

3

2 Class. Elemental function.

4

3 Arguments.

5

Y

shall be of type real.

6 7

X

If Y appears, X shall be of type real with the same kind type parameter as Y. If Y has the value zero, X shall not have the value zero. If Y does not appear, X shall be of type real.

8

4 Result Characteristics. Same as X.

9 10 11

5 Result Value. If Y appears, the result is the same as the result of ATAN2PI (Y, X). If Y does not appear,

12

6 Example. ATANPI (1.0) has the value 0.25 (approximately).

13

the result has a value equal to a processor-dependent approximation to the arc tangent of X; it is expressed in half-revolutions and lies in the range −0.5 ≤ ATANPI (X) ≤ 0.5.

16.9.28

ATOMIC_ADD (ATOM, VALUE [, STAT])

14

1 Description. Atomic addition.

15

2 Class. Atomic subroutine.

16

3 Arguments.

17 18 19 20

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of ATOM + VALUE.

21

VALUE

22

shall be an integer scalar. It is an INTENT (IN) argument. The values of VALUE and ATOM + VALUE shall be representable in kind ATOMIC_INT_KIND.

23 24 25

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

26 27

4 Example. CALL ATOMIC_ADD (I [3], 42) will cause I on image 3 to become defined with the value 46 if the

28

value of I [3] is 4 when the atomic operation is executed.

16.9.29

ATOMIC_AND (ATOM, VALUE [, STAT])

29

1 Description. Atomic bitwise AND.

30

2 Class. Atomic subroutine.

31

3 Arguments.

32 33 34 35

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of IAND (ATOM, INT (VALUE, ATOMIC_INT_KIND)).

36 37

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be representable in kind ATOMIC_INT_KIND.

38 39

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

40

364

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

4 Example. CALL ATOMIC_AND (I [3], 6) will cause I on image 3 to become defined with the value 4 if the

value of I [3] is 5 when the atomic operation is executed.

16.9.30

ATOMIC_CAS (ATOM, OLD, COMPARE, NEW [, STAT])

4

1 Description. Atomic compare and swap.

5

2 Class. Atomic subroutine.

6

3 Arguments.

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV, or of type logical with kind ATOMIC_LOGICAL_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, if ATOM is of type integer and equal to COMPARE, or of type logical and equivalent to COMPARE, it becomes defined with the value of NEW.

13 14 15

OLD

shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that ATOM had at the start of the atomic operation.

16

COMPARE shall be scalar and of the same type and kind as ATOM. It is an INTENT (IN) argument.

17

NEW

18 19 20

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

21 22 23

4 Example. If the value of I on image 3 is equal to 13 at the beginning of the atomic operation performed by

7 8 9 10 11 12

shall be scalar and of the same type and kind as ATOM. It is an INTENT (IN) argument.

24 25

CALL ATOMIC_CAS (I [3], OLD, 0, 1), the value of I on image 3 will be unchanged, and OLD will become defined with the value 13. If the value of I on image 3 is equal to 0 at the beginning of the atomic operation performed by CALL ATOMIC_CAS (I [3], OLD, 0, 1), I on image 3 will become defined with the value 1, and OLD will become defined with the value 0.

26

16.9.31

ATOMIC_DEFINE (ATOM, VALUE [, STAT])

27

1 Description. Define a variable atomically.

28

2 Class. Atomic subroutine.

29

3 Arguments.

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV, or of type logical with kind ATOMIC_LOGICAL_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (OUT) argument. On successful execution, it becomes defined with the value of VALUE. If an error condition occurs, it becomes undefined.

35

VALUE

shall be scalar and of the same type as ATOM. It is an INTENT (IN) argument.

36 37 38

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

30 31 32 33 34

39 40

4 Example. CALL ATOMIC_DEFINE (I [3], 4) causes I on image 3 to become defined with the value 4.

16.9.32

ATOMIC_FETCH_ADD (ATOM, VALUE, OLD [, STAT])

41

1 Description. Atomic fetch and add.

42

2 Class. Atomic subroutine.

ISO/IEC JTC 1/SC 22/WG5/N2184

365

J3/21-007r1

1

WD 1539-1

2021-05-21

3 Arguments.

2 3 4 5

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of ATOM + VALUE.

6 7

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The values of VALUE and ATOM + VALUE shall be representable in kind ATOMIC_INT_KIND.

8

OLD

9 10

shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that ATOM had at the start of the atomic operation.

11 12 13

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

14 15

4 Example. CALL ATOMIC_FETCH_ADD (I [3], 7, J) will cause I on image 3 to become defined with the value

16

12, and J to become defined with the value 5, if the value of I [3] is 5 when the atomic operation is executed.

16.9.33

ATOMIC_FETCH_AND (ATOM, VALUE, OLD [, STAT])

17

1 Description. Atomic fetch and bitwise AND.

18

2 Class. Atomic subroutine.

19

3 Arguments.

20 21 22 23

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of IAND (ATOM, INT (VALUE, ATOMIC_INT_KIND)).

24 25

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be representable in kind ATOMIC_INT_KIND.

26

OLD

27 28

shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that ATOM had at the start of the atomic operation.

29 30 31

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

32 33

4 Example. CALL ATOMIC_FETCH_AND (I [3], 6, J) will cause I on image 3 to become defined with the value

34

4, and J to become defined with the value 5, if the value of I [3] is 5 when the atomic operation is executed.

16.9.34

ATOMIC_FETCH_OR (ATOM, VALUE, OLD [, STAT])

35

1 Description. Atomic fetch and bitwise OR.

36

2 Class. Atomic subroutine.

37

3 Arguments.

38 39 40 41

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of IOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).

42

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be representable in kind ATOMIC_INT_KIND. shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If

43 44

OLD

366

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that ATOM had at the start of the atomic operation.

3 4 5

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

6 7

4 Example. CALL ATOMIC_FETCH_OR (I [3], 1, J) will cause I on image 3 to become defined with the value

8

3, and J to become defined with the value 2, if the value of I [3] is 2 when the atomic operation is executed.

16.9.35

ATOMIC_FETCH_XOR (ATOM, VALUE, OLD [, STAT])

9

1 Description. Atomic fetch and bitwise exclusive OR.

10

2 Class. Atomic subroutine.

11

3 Arguments.

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of IEOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).

16 17

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be representable in kind ATOMIC_INT_KIND.

18 19 20

OLD

shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that ATOM had at the start of the atomic operation.

21 22 23

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

24 25

4 Example. CALL ATOMIC_FETCH_XOR (I [3], 1, J) will cause I on image 3 to become defined with the value

12 13 14 15

26

2, and J to become defined with the value 3, if the value of I [3] is 3 when the atomic operation is executed.

16.9.36

ATOMIC_OR (ATOM, VALUE [, STAT])

27

1 Description. Atomic bitwise OR.

28

2 Class. Atomic subroutine.

29

3 Arguments.

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of IOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).

34 35

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be representable in kind ATOMIC_INT_KIND.

36 37 38

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

39 40

4 Example. CALL ATOMIC_OR (I [3], 1) will cause I on image 3 to become defined with the value 3 if the value

30 31 32 33

of I [3] is 2 when the atomic operation is executed.

ISO/IEC JTC 1/SC 22/WG5/N2184

367

J3/21-007r1

1

16.9.37

WD 1539-1

2021-05-21

ATOMIC_REF (VALUE, ATOM [, STAT])

2

1 Description. Reference a variable atomically.

3

2 Class. Atomic subroutine.

4

3 Arguments.

5 6 7

VALUE

shall be scalar and of the same type as ATOM. It is an INTENT (OUT) argument. On successful execution, it becomes defined with the value of ATOM. If an error condition occurs, it becomes undefined.

8 9 10

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV, or of type logical with kind ATOMIC_LOGICAL_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (IN) argument.

11 12

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

13 14 15

4 Example. CALL ATOMIC_REF (VAL, I [3]) causes VAL to become defined with the value of I on image 3.

16.9.38

ATOMIC_XOR (ATOM, VALUE [, STAT])

16

1 Description. Atomic bitwise exclusive OR.

17

2 Class. Atomic subroutine.

18

3 Arguments.

ATOM

shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value of IEOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).

23 24

VALUE

shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be representable in kind ATOMIC_INT_KIND.

25 26 27

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs and STAT is not present, error termination is initiated.

28 29

4 Example. CALL ATOMIC_XOR (I [3], 1) will cause I on image 3 to become defined with the value 2 if the

19 20 21 22

30

value of I [3] is 3 when the atomic operation is executed.

16.9.39

BESSEL_J0 (X)

31

1 Description. Bessel function of the 1st kind, order 0.

32

2 Class. Elemental function.

33

3 Argument. X shall be of type real.

34

4 Result Characteristics. Same as X.

35 36

5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of

37

6 Example. BESSEL_J0 (1.0) has the value 0.765 (approximately).

the first kind and order zero of X.

368

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

16.9.40

WD 1539-1

J3/21-007r1

BESSEL_J1 (X)

2

1 Description. Bessel function of the 1st kind, order 1.

3

2 Class. Elemental function.

4

3 Argument. X shall be of type real.

5

4 Result Characteristics. Same as X.

6 7

5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of

8

6 Example. BESSEL_J1 (1.0) has the value 0.440 (approximately).

9

the first kind and order one of X.

16.9.41

BESSEL_JN (N, X) or BESSEL_JN (N1, N2, X)

10

1 Description. Bessel functions of the 1st kind.

11

2 Class.

13

Case (i): Case (ii):

14

3 Arguments.

12

BESSEL_JN (N,X) is an elemental function. BESSEL_JN (N1,N2,X) is a transformational function.

15

N

shall be of type integer and nonnegative.

16

N1

shall be an integer scalar with a nonnegative value.

17

N2

shall be an integer scalar with a nonnegative value.

18

X

shall be of type real; if the function is transformational, X shall be scalar.

19 20

4 Result Characteristics. Same type and kind as X. The result of BESSEL_JN (N1, N2, X) is a rank-one array

21

5 Result Value.

with extent MAX (N2−N1+1, 0).

22 23

Case (i):

24 25

Case (ii):

26 27

The result value of BESSEL_JN (N, X) is a processor-dependent approximation to the Bessel function of the first kind and order N of X. Element i of the result value of BESSEL_JN (N1, N2, X) is a processor-dependent approximation to the Bessel function of the first kind and order N1+i − 1 of X.

6 Example. BESSEL_JN (2, 1.0) has the value 0.115 (approximately).

16.9.42

BESSEL_Y0 (X)

28

1 Description. Bessel function of the 2nd kind, order 0.

29

2 Class. Elemental function.

30

3 Argument. X shall be of type real. Its value shall be greater than zero.

31

4 Result Characteristics. Same as X.

32 33

5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of

34

6 Example. BESSEL_Y0 (1.0) has the value 0.088 (approximately).

the second kind and order zero of X.

ISO/IEC JTC 1/SC 22/WG5/N2184

369

J3/21-007r1

1

16.9.43

WD 1539-1

2021-05-21

BESSEL_Y1 (X)

2

1 Description. Bessel function of the 2nd kind, order 1.

3

2 Class. Elemental function.

4

3 Argument. X shall be of type real. Its value shall be greater than zero.

5

4 Result Characteristics. Same as X.

6 7

5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of

8

6 Example. BESSEL_Y1 (1.0) has the value −0.781 (approximately).

9

the second kind and order one of X.

16.9.44

BESSEL_YN (N, X) or BESSEL_YN (N1, N2, X)

10

1 Description. Bessel functions of the 2nd kind.

11

2 Class.

13

Case (i): Case (ii):

14

3 Arguments.

12

BESSEL_YN (N, X) is an elemental function. BESSEL_YN (N1, N2, X) is a transformational function.

15

N

shall be of type integer and nonnegative.

16

N1

shall be an integer scalar with a nonnegative value.

17

N2

shall be an integer scalar with a nonnegative value.

18 19

X

shall be of type real; if the function is transformational, X shall be scalar. Its value shall be greater than zero.

20 21 22

4 Result Characteristics. Same type and kind as X. The result of BESSEL_YN (N1, N2, X) is a rank-one array

with extent MAX (N2−N1+1, 0). 5 Result Value.

23 24

Case (i):

25 26

Case (ii):

27 28

The result value of BESSEL_YN (N, X) is a processor-dependent approximation to the Bessel function of the second kind and order N of X. Element i of the result value of BESSEL_YN (N1, N2, X) is a processor-dependent approximation to the Bessel function of the second kind and order N1+i − 1 of X.

6 Example. BESSEL_YN (2, 1.0) has the value −1.651 (approximately).

16.9.45

BGE (I, J)

29

1 Description. Bitwise greater than or equal to.

30

2 Class. Elemental function.

31

3 Arguments.

32

I

shall be of type integer or a boz-literal-constant.

33

J

shall be of type integer or a boz-literal-constant.

34

4 Result Characteristics. Default logical.

35

5 Result Value. The result is true if the sequence of bits represented by I is greater than or equal to the sequence

36 37

of bits represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false.

370

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an

3 4

7 Example. If BIT_SIZE (J) has the value 8, BGE (Z’FF’, J) has the value true for any value of J. BGE (0, −1)

5

integer value as a sequence of bits is described in 16.3. has the value false.

16.9.46

BGT (I, J)

6

1 Description. Bitwise greater than.

7

2 Class. Elemental function.

8

3 Arguments.

9

I

shall be of type integer or a boz-literal-constant.

10

J

shall be of type integer or a boz-literal-constant.

11

4 Result Characteristics. Default logical.

12 13

5 Result Value. The result is true if the sequence of bits represented by I is greater than the sequence of bits

14

6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an

15 16 17

represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false. integer value as a sequence of bits is described in 16.3. 7 Example. BGT (Z’FF’, Z’FC’) has the value true. BGT (0, −1) has the value false.

16.9.47

BIT_SIZE (I)

18

1 Description. Number of bits in integer model 16.3.

19

2 Class. Inquiry function.

20

3 Argument. I shall be of type integer. It may be a scalar or an array.

21

4 Result Characteristics. Scalar integer with the same kind type parameter as I.

22 23

5 Result Value. The result has the value of the number of bits z of the model integer defined for bit manipulation

24

6 Example. BIT_SIZE (1) has the value 32 if z of the model is 32.

25

contexts in 16.3.

16.9.48

BLE (I, J)

26

1 Description. Bitwise less than or equal to.

27

2 Class. Elemental function.

28

3 Arguments.

29

I

shall be of type integer or a boz-literal-constant.

30

J

shall be of type integer or a boz-literal-constant.

31

4 Result Characteristics. Default logical.

32 33

5 Result Value. The result is true if the sequence of bits represented by I is less than or equal to the sequence of

34 35

6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an

bits represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false. integer value as a sequence of bits is described in 16.3.

ISO/IEC JTC 1/SC 22/WG5/N2184

371

J3/21-007r1

1 2

16.9.49

BLT (I, J)

1 Description. Bitwise less than.

4

2 Class. Elemental function.

5

3 Arguments.

7

2021-05-21

7 Example. BLE (0, J) has the value true for any value of J. BLE (−1, 0) has the value false.

3

6

WD 1539-1

I J

shall be of type integer or a boz-literal-constant. shall be of type integer or a boz-literal-constant.

8

4 Result Characteristics. Default logical.

9 10

5 Result Value. The result is true if the sequence of bits represented by I is less than the sequence of bits

11 12

6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an

13

7 Example. BLT (0, −1) has the value true. BLT (Z’FF’, Z’FC’) has the value false.

14

represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false. integer value as a sequence of bits is described in 16.3.

16.9.50

BTEST (I, POS)

15

1 Description. Test single bit in an integer.

16

2 Class. Elemental function.

17

3 Arguments.

18

I

shall be of type integer.

19

POS

shall be of type integer. It shall be nonnegative and be less than BIT_SIZE (I).

20

4 Result Characteristics. Default logical.

21 22

5 Result Value. The result has the value true if bit POS of I has the value 1 and has the value false if bit POS

23 24

25

of I has the value 0. The model for the interpretation of an integer value as a sequence of bits is in 16.3.   1 2 6 Examples. BTEST (8, 3) has the value true. If A has the value , the value of BTEST (A, 2) is 3 4     false false true false and the value of BTEST (2, A) is . false true false false

16.9.51

CEILING (A [, KIND])

26

1 Description. Least integer greater than or equal to A.

27

2 Class. Elemental function.

28

3 Arguments.

29

A

shall be of type real.

30

KIND (optional) shall be a scalar integer constant expression.

31 32

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

33

5 Result Value. The result has a value equal to the least integer greater than or equal to A.

KIND; otherwise, the kind type parameter is that of default integer type.

372

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

6 Examples. CEILING (3.7) has the value 4. CEILING (−3.7) has the value −3.

16.9.52

CHAR (I [, KIND])

3

1 Description. Character from code value.

4

2 Class. Elemental function.

5

3 Arguments.

shall be of type integer with a value in the range 0 ≤ I ≤ n − 1, where n is the number of characters in the collating sequence associated with the specified kind type parameter.

6 7

I

8

KIND (optional) shall be a scalar integer constant expression.

9 10

4 Result Characteristics. Character of length one. If KIND is present, the kind type parameter is that specified

11 12

5 Result Value. The result is the character in position I of the collating sequence associated with the spe-

by the value of KIND; otherwise, the kind type parameter is that of default character.

13 14

cified kind type parameter. ICHAR (CHAR (I, KIND (C))) shall have the value I for 0 ≤ I ≤ n − 1 and CHAR (ICHAR (C), KIND (C)) shall have the value C for any character C capable of representation in the processor.

15

6 Example. CHAR (88) has the value ’X’ on a processor using the ASCII collating sequence for default characters.

16

16.9.53

CMPLX (X [, KIND]) or CMPLX (X [, Y, KIND])

17

1 Description. Conversion to complex type.

18

2 Class. Elemental function.

19

3 Arguments for CMPLX(X [, KIND]).

20

X

21

KIND (optional) shall be a scalar integer constant expression.

22

shall be of type complex.

4 Arguments for CMPLX(X [, Y, KIND]).

23

X

24

Y (optional) shall be of type integer or real, or a boz-literal-constant.

shall be of type integer or real, or a boz-literal-constant.

25

KIND (optional) shall be a scalar integer constant expression.

26 27

5 Result Characteristics. The result is of type complex. If KIND is present, the kind type parameter is that

28 29 30

6 Result Value. If Y is absent and X is not complex, it is as if Y were present with the value zero. If KIND is

31 32 33

specified by the value of KIND; otherwise, the kind type parameter is that of default real kind. absent, it is as if KIND were present with the value KIND (0.0). If X is complex, the result is the same as that of CMPLX (REAL (X), AIMAG (X), KIND). The result of CMPLX (X, Y, KIND) has the complex value whose real part is REAL (X, KIND) and whose imaginary part is REAL (Y, KIND). 7 Example. CMPLX (−3) has the value (−3.0, 0.0).

16.9.54

CO_BROADCAST (A, SOURCE_IMAGE [, STAT, ERRMSG])

34

1 Description. Broadcast value to images.

35

2 Class. Collective subroutine.

36

3 Arguments.

37 38

A

shall have the same shape, dynamic type, and type parameter values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument. If no error condition

ISO/IEC JTC 1/SC 22/WG5/N2184

373

J3/21-007r1

WD 1539-1

2021-05-21

1 2

occurs, A becomes defined, as if by intrinsic assignment, on all images in the current team with the value of A on image SOURCE_IMAGE.

3 4 5

SOURCE_IMAGE shall be an integer scalar. It is an INTENT (IN) argument. Its value shall be that of an image index of an image in the current team. The value shall be the same in all corresponding references.

6 7

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument.

8

ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.

9

4 The semantics of STAT and ERRMSG are described in 16.6.

10

5 Example. If A is the array [1, 5, 3] on image one, after execution of

CALL CO_BROADCAST (A, 1)

11 12

the value of A on all images of the current team is [1, 5, 3].

13

16.9.55

CO_MAX (A [, RESULT_IMAGE, STAT, ERRMSG])

14

1 Description. Compute maximum value across images.

15

2 Class. Collective subroutine.

16

3 Arguments.

17 18 19 20 21

A

shall be of type integer, real, or character. It shall have the same shape, type, and type parameter values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument. If it is scalar, the computed value is equal to the maximum value of A in all corresponding references. If it is an array each element of the computed value is equal to the maximum value of all corresponding elements of A in all corresponding references.

23 24

The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes undefined.

25 26 27

RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value if present, shall be the same in all corresponding references. If it is present, its value shall be that of an image index in the current team.

28 29

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument.

30

ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.

22

31

4 The semantics of STAT and ERRMSG are described in 16.6.

32 33

5 Example. If the number of images in the current team is two and A is the array [1, 5, 3] on one image and [4,

34

1, 6] on the other image, the value of A after executing the statement CALL CO_MAX (A) is [4, 5, 6] on both images.

35

16.9.56

CO_MIN (A [, RESULT_IMAGE, STAT, ERRMSG])

36

1 Description. Compute minimum value across images.

37

2 Class. Collective subroutine.

38

3 Arguments.

39 40

A

41

374

shall be of type integer, real, or character. It shall have the same shape, type, and type parameter values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument. If it is scalar, the computed value is equal to the minimum value of A in all corresponding

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

references. If it is an array each element of the computed value is equal to the minimum value of all corresponding elements of A in all corresponding references.

3 4 5

The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes undefined.

6 7 8

RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value if present, shall be the same in all corresponding references. If it is present, its value shall be that of an image index in the current team.

9 10

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument.

11

ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.

12

4 The semantics of STAT and ERRMSG are described in 16.6.

13 14 15

5 Example. If the number of images in the current team is two and A is the array [1, 5, 3] on one image and [4,

16

1, 6] on the other image, the value of A after executing the statement CALL CO_MIN (A) is [1, 1, 3] on both images.

16.9.57

CO_REDUCE (A, OPERATION [, RESULT_IMAGE, STAT, ERRMSG])

17

1 Description. Generalized reduction across images.

18

2 Class. Collective subroutine.

19

3 Arguments.

24 25

shall not be polymorphic. It shall have the same shape, type, and type parameter values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument. If A is scalar, the computed value is the result of the reduction operation of applying OPERATION to the values of A in all corresponding references. If A is an array, each element of the computed value is equal to the result of the reduction operation of applying OPERATION to corresponding elements of A in all corresponding references.

26 27 28

The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes undefined.

29 30 31 32 33 34

OPERATION shall be a pure function with exactly two arguments; the result and each argument shall be a scalar, nonallocatable, nonpointer, nonpolymorphic data object with the same type and type parameters as A. The arguments shall not be optional. If one argument has the ASYNCHRONOUS, TARGET, or VALUE attribute, the other shall have that attribute. OPERATION shall implement a mathematically associative operation. OPERATION shall be the same function on all images in corresponding references.

35 36 37 38

The computed value of a reduction operation over a set of values is the result of an iterative process. Each iteration involves the evaluation of OPERATION (x, y) for x and y in the set, the removal of x and y from the set, and the addition of the value of OPERATION (x, y) to the set. The process terminates when the set has only one element; this is the computed value.

39 40 41

RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value if present, shall be the same in all corresponding references. If it is present, its value shall be that of an image index in the current team.

42 43

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument.

44

ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.

20 21 22 23

A

45

4 The semantics of STAT and ERRMSG are described in 16.6.

46

5 Example. The subroutine below demonstrates how to use CO_REDUCE to create a collective counterpart to

ISO/IEC JTC 1/SC 22/WG5/N2184

375

J3/21-007r1

1

WD 1539-1

2021-05-21

the intrinsic function ALL: SUBROUTINE co_all(boolean) LOGICAL, INTENT(INOUT) :: boolean CALL CO_REDUCE(boolean,both) CONTAINS PURE FUNCTION both(lhs,rhs) RESULT(lhs_and_rhs) LOGICAL, INTENT(IN) :: lhs,rhs LOGICAL :: lhs_and_rhs lhs_and_rhs = lhs .AND. rhs END FUNCTION both END SUBROUTINE co_all

2 3 4 5 6 7 8 9 10 11

NOTE 1 If the OPERATION function is not mathematically commutative, the result of calling CO_REDUCE can depend on the order of evaluations. 12

16.9.58

CO_SUM (A [, RESULT_IMAGE, STAT, ERRMSG])

13

1 Description. Compute sum across images.

14

2 Class. Collective subroutine.

15

3 Arguments.

16 17 18 19 20 21

A

shall be of numeric type. It shall have the same shape, type, and type parameter values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument. If it is scalar, the computed value is equal to a processor-dependent approximation to the sum of the values of A in corresponding references. If it is an array, each element of the computed value is equal to a processor-dependent approximation to the sum of all corresponding elements of A in corresponding references.

23 24

The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes undefined.

25 26 27

RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value if present, shall be the same in all corresponding references. If it is present, its value shall be that of an image index in the current team.

28 29

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument.

30

ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.

22

31

4 The semantics of STAT and ERRMSG are described in 16.6.

32 33

5 Example. If the number of images in the current team is two and A is the array [1, 5, 3] on one image and [4,

34

1, 6] on the other image, the value of A after executing the statement CALL CO_SUM(A) is [5, 6, 9] on both images.

35

16.9.59

COMMAND_ARGUMENT_COUNT ( )

36

1 Description. Number of command arguments.

37

2 Class. Transformational function.

38

3 Argument. None.

376

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

4 Result Characteristics. Default integer scalar.

2 3 4

5 Result Value. The result value is equal to the number of command arguments available. If there are no

5 6 7

command arguments available or if the processor does not support command arguments, then the result has the value zero. If the processor has a concept of a command name, the command name does not count as one of the command arguments. 6 Example. See 16.9.93.

16.9.60

CONJG (Z)

8

1 Description. Conjugate of a complex number.

9

2 Class. Elemental function.

10

3 Argument. Z shall be of type complex.

11

4 Result Characteristics. Same as Z.

12

5 Result Value. If Z has the value (x, y), the result has the value (x, −y).

13

6 Example. CONJG ((2.0, 3.0)) has the value (2.0, −3.0).

14

16.9.61

COS (X)

15

1 Description. Cosine function.

16

2 Class. Elemental function.

17

3 Argument. X shall be of type real or complex.

18

4 Result Characteristics. Same as X.

19 20

5 Result Value. The result has a value equal to a processor-dependent approximation to cos(X). If X is of type

21

6 Example. COS (1.0) has the value 0.54030231 (approximately).

22

real, it is regarded as a value in radians. If X is of type complex, its real part is regarded as a value in radians.

16.9.62

COSD (X)

23

1 Description. Degree cosine function.

24

2 Class. Elemental function.

25

3 Argument. X shall be of type real.

26

4 Result Characteristics. Same as X.

27 28

5 Result Value. The result has a value equal to a processor-dependent approximation to the cosine of X, which

29

6 Example. COSD (180.0) has the value −1.0 (approximately).

30

is regarded as a value in degrees.

16.9.63

COSH (X)

31

1 Description. Hyperbolic cosine function.

32

2 Class. Elemental function.

33

3 Argument. X shall be of type real or complex.

ISO/IEC JTC 1/SC 22/WG5/N2184

377

J3/21-007r1

WD 1539-1

2021-05-21

1

4 Result Characteristics. Same as X.

2 3

5 Result Value. The result has a value equal to a processor-dependent approximation to cosh(X). If X is of type

4

6 Example. COSH (1.0) has the value 1.5430806 (approximately).

5

complex its imaginary part is regarded as a value in radians.

16.9.64

COSHAPE (COARRAY [, KIND])

6

1 Description. Sizes of codimensions of a coarray.

7

2 Class. Inquiry function.

8

3 Arguments.

9 10

COARRAY shall be a coarray of any type. It shall not be an unallocated allocatable coarray. If its designator has more than one part-ref , the rightmost part-ref shall have nonzero corank.

11

KIND (optional) shall be a scalar integer constant expression.

12 13 14

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value

15 16

5 Result Value. The result has a value whose ith element is equal to the size of the ith codimension of COARRAY,

17 18 19

6 Example.

20 21 22 23 24

25

of KIND; otherwise the kind type parameter is that of default integer type. The result is an array of rank one whose size is equal to the corank of COARRAY. as given by UCOBOUND (COARRAY, i) − LCOBOUND (COARRAY, i) +1. The following code allocates the coarray D with the same size in each codimension as that of the coarray C, with the lower cobound 1. REAL, ALLOCATABLE :: C[:,:], D[:,:] INTEGER, ALLOCATABLE :: COSHAPE_C(:) ... COSHAPE_C = COSHAPE(C) ALLOCATE ( D[COSHAPE_C(1),*] )

16.9.65

COSPI (X)

26

1 Description. Circular cosine function.

27

2 Class. Elemental function.

28

3 Argument. X shall be of type real.

29

4 Result Characteristics. Same as X.

30 31

5 Result Value. The result has a value equal to a processor-dependent approximation to the cosine of X, which

32

6 Example. COSPI (1.0) has the value −1.0 (approximately).

33

is regarded as a value in half-revolutions; thus COSPI (X) is approximately equal to COS (X×π).

16.9.66

COUNT (MASK [, DIM, KIND])

34

1 Description. Array reduced by counting true values.

35

2 Class. Transformational function.

36

3 Arguments.

378

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

MASK

2 3 4

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK. The corresponding actual argument shall not be an optional dummy argument, a disassociated pointer, or an unallocated allocatable.

5

KIND (optional) shall be a scalar integer constant expression.

6 7 8 9 10

shall be a logical array.

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

KIND; otherwise the kind type parameter is that of default integer type. The result is scalar if DIM is absent or n = 1; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of MASK. 5 Result Value.

11 12

Case (i):

13 14 15

Case (ii):

16

6 Examples.

17

Case (i):

18

Case (ii):

The value of COUNT ([.TRUE., .FALSE., .TRUE.]) is 2.    1 3 5 0 3 If B is the array and C is the array 2 4 6 7 4 [2, 0, 1] and COUNT (B /= C, DIM = 2) is [1, 2].

16.9.67

CPU_TIME (TIME)

19 20

If DIM is absent or MASK has rank one, the result has a value equal to the number of true elements of MASK or has the value zero if MASK has size zero. If DIM is present and MASK has rank n > 1, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to the number of true elements of MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ).

5 8

 , COUNT (B /= C, DIM = 1) is

21

1 Description. Processor time used.

22

2 Class. Subroutine.

23 24 25 26

3 Argument. TIME shall be a real scalar. It is an INTENT (OUT) argument. If the processor cannot provide

27 28 29 30 31 32 33 34 35

a meaningful value for the time, it is assigned a processor-dependent negative value; otherwise, it is assigned a processor-dependent approximation to the processor time in seconds. Whether the value assigned is an approximation to the amount of time used by the invoking image, or the amount of time used by the whole program, is processor dependent. 4 Example.

REAL T1, T2 ... CALL CPU_TIME(T1) . . . Code to be timed. CALL CPU_TIME(T2) WRITE (*,*) ’Time taken by code was ’, T2-T1, ’ seconds’ writes the processor time taken by a piece of code. NOTE 1 A processor for which a single result is inadequate (for example, a parallel processor) might choose to provide an additional version for which time is an array. The exact definition of time is left imprecise because of the variability in what different processors are able to provide. The primary purpose is to compare different algorithms on the same processor or discover which parts of a calculation are the most expensive.

ISO/IEC JTC 1/SC 22/WG5/N2184

379

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) The start time is left imprecise because the purpose is to time sections of code, as in the example. Most computer systems have multiple concepts of time. One common concept is that of time expended by the processor for a given program. This might or might not include system overhead, and has no obvious connection to elapsed “wall clock” time. 1

16.9.68

CSHIFT (ARRAY, SHIFT [, DIM])

2

1 Description. Circular shift of an array.

3

2 Class. Transformational function.

4

3 Arguments.

5

ARRAY

may be of any type. It shall be an array.

6 7 8

SHIFT

shall be of type integer and shall be scalar if ARRAY has rank one; otherwise, it shall be scalar or of rank n − 1 and of shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

9 10

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY. If DIM is absent, it is as if it were present with the value 1.

11

4 Result Characteristics. The result is of the type and type parameters of ARRAY, and has the shape of

12 13

ARRAY. 5 Result Value.

14 15

Case (i):

16 17 18

Case (ii):

19

6 Examples.

20 21 22

Case (i):

23

Case (ii):

If ARRAY has rank one, element i of the result is ARRAY (1 + MODULO (i + SHIFT − 1, SIZE (ARRAY))). If ARRAY has rank greater than one, section (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . ., sn ) of the result has a value equal to CSHIFT (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . ., sn ), sh, 1), where sh is SHIFT or SHIFT (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ).

If V is the array [1, 2, 3, 4, 5, 6], the effect of shifting V circularly to the left by two positions is achieved by CSHIFT (V, SHIFT = 2) which has the value [3, 4, 5, 6, 1, 2]; CSHIFT (V, SHIFT = −2) achieves a circular shift to the right by two positions and has the value [5, 6, 1, 2, 3, 4]. The rows of an array  of ranktwo may all be shifted by the same amount or by different amounts. 1 2 3 If M is the array  4 5 6 , the value of 7 8 9   3 1 2 CSHIFT (M, SHIFT = −1, DIM = 2) is  6 4 5 , and the value of 9 7 8   3 1 2 CSHIFT (M, SHIFT = [−1, 1, 0], DIM = 2) is  5 6 4 . 7 8 9

24

25

26

27

16.9.69

DATE_AND_TIME ([DATE, TIME, ZONE, VALUES])

28

1 Description. Date and time.

29

2 Class. Subroutine.

30

3 Arguments.

380

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3 4

DATE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned a value of the form YYYYMMDD, where YYYY is the year in the Gregorian calendar, MM is the month within the year, and DD is the day within the month. The characters of this value shall all be decimal digits. If there is no date available, DATE is assigned all blanks.

5 6

TIME (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned a value of the form hhmmss.sss, where hh is the hour of the day, mm is the minutes of the hour, and ss.sss is the seconds and milliseconds of the minute. Except for the decimal point, the characters of this value shall all be decimal digits. If there is no clock available, TIME is assigned all blanks.

7 8

15 16

ZONE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned a value of the form +hhmm or -hhmm, where hh and mm are the time difference with respect to Coordinated Universal Time (UTC) in hours and minutes, respectively. The characters of this value following the sign character shall all be decimal digits. If this information is not available, ZONE is assigned all blanks. VALUES (optional) shall be a rank-one array of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. Its size shall be at least 8. The values assigned to VALUES are as follows:

17 18

VALUES (1) the year, including the century (for example, 2008), or −HUGE (VALUES) if there is no date available;

19

VALUES (2) the month of the year, or −HUGE (VALUES) if there is no date available;

20

VALUES (3) the day of the month, or −HUGE (VALUES) if there is no date available;

21 22

VALUES (4) the time difference from Coordinated Universal Time (UTC) in minutes, or −HUGE (VALUES) if this information is not available;

23

VALUES (5) the hour of the day, in the range of 0 to 23, or −HUGE (VALUES) if there is no clock;

24

VALUES (6) the minutes of the hour, in the range 0 to 59, or −HUGE (VALUES) if there is no clock;

25

VALUES (7) the seconds of the minute, in the range 0 to 60, or −HUGE (VALUES) if there is no clock;

26

VALUES (8) the milliseconds of the second, in the range 0 to 999, or −HUGE (VALUES) if there is no clock.

27 28 29

4 The date, clock, and time zone information might be available on some images and not others. If the date, clock,

30

5 Example. If run in Geneva, Switzerland on April 12, 2008 at 15:27:35.5 with a system configured for the

31 32

local time zone, this example would have assigned the value 20080412 to BIG_BEN (1), the value 152735.500 to BIG_BEN (2), the value +0100 to BIG_BEN (3), and the value [2008, 4, 12, 60, 15, 27, 35, 500] to DATE_TIME.

9 10 11 12 13 14

33 34 35

or time zone information is available on more than one image, it is processor dependent whether or not those images share the same information.

INTEGER DATE_TIME (8) CHARACTER (LEN = 10) BIG_BEN (3) CALL DATE_AND_TIME (BIG_BEN (1), BIG_BEN (2), BIG_BEN (3), DATE_TIME) NOTE 1 These forms are compatible with the representations defined in ISO 8601:2004. UTC is established by the International Bureau of Weights and Measures (BIPM, i.e. Bureau International des Poids et Mesures) and the International Earth Rotation Service (IERS).

36

16.9.70

DBLE (A)

37

1 Description. Conversion to double precision real.

38

2 Class. Elemental function.

39

3 Argument. A shall be of type integer, real, complex, or a boz-literal-constant.

40

4 Result Characteristics. Double precision real.

ISO/IEC JTC 1/SC 22/WG5/N2184

381

J3/21-007r1

WD 1539-1

1

5 Result Value. The result has the value REAL (A, KIND (0.0D0)).

2

6 Example. DBLE (−3) has the value −3.0D0.

3

16.9.71

2021-05-21

DIGITS (X)

4

1 Description. Significant digits in numeric model.

5

2 Class. Inquiry function.

6

3 Argument. X shall be of type integer or real. It may be a scalar or an array.

7

4 Result Characteristics. Default integer scalar.

8 9

5 Result Value. The result has the value q if X is of type integer and p if X is of type real, where q and p are as

10

6 Example. DIGITS (X) has the value 24 for real X whose model is as in 16.4, NOTE 1.

11

defined in 16.4 for the model representing numbers of the same type and kind type parameter as X.

16.9.72

DIM (X, Y)

12

1 Description. Maximum of X − Y and zero.

13

2 Class. Elemental function.

14

3 Arguments.

15

X

shall be of type integer or real.

16

Y

shall be of the same type and kind type parameter as X.

17

4 Result Characteristics. Same as X.

18

5 Result Value. The value of the result is the maximum of X − Y and zero.

19

6 Example. DIM (−3.0, 2.0) has the value 0.0.

20

16.9.73

DOT_PRODUCT (VECTOR_A, VECTOR_B)

21

1 Description. Dot product of two vectors.

22

2 Class. Transformational function.

23

3 Arguments.

24

VECTOR_A shall be of numeric type (integer, real, or complex) or of logical type. It shall be a rank-one array.

25 26

VECTOR_B shall be of numeric type if VECTOR_A is of numeric type or of type logical if VECTOR_A is of type logical. It shall be a rank-one array. It shall be of the same size as VECTOR_A.

27 28 29 30

4 Result Characteristics. If the arguments are of numeric type, the type and kind type parameter of the result

31

5 Result Value.

are those of the expression VECTOR_A * VECTOR_B determined by the types and kinds of the arguments according to 10.1.9.3. If the arguments are of type logical, the result is of type logical with the kind type parameter of the expression VECTOR_A .AND. VECTOR_B according to 10.1.9.3. The result is scalar.

32 33

Case (i):

34 35

Case (ii):

36 37

Case (iii):

382

If VECTOR_A is of type integer or real, the result has the value SUM (VECTOR_A*VECTOR_B). If the vectors have size zero, the result has the value zero. If VECTOR_A is of type complex, the result has the value SUM (CONJG (VECTOR_A)*VECTOR_B). If the vectors have size zero, the result has the value zero. If VECTOR_A is of type logical, the result has the value ANY (VECTOR_A .AND. VECTOR_B). If the vectors have size zero, the result has the value false.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

6 Example. DOT_PRODUCT ([1, 2, 3], [2, 3, 4]) has the value 20.

16.9.74

DPROD (X, Y)

3

1 Description. Double precision real product.

4

2 Class. Elemental function.

5

3 Arguments.

6

X

shall be default real.

7

Y

shall be default real.

8

4 Result Characteristics. Double precision real.

9 10

5 Result Value. The result has a value equal to a processor-dependent approximation to the product of X and

11

6 Example. DPROD (−3.0, 2.0) has the value −6.0D0.

12

Y. DPROD (X, Y) should have the same value as DBLE (X) * DBLE (Y).

16.9.75

DSHIFTL (I, J, SHIFT)

13

1 Description. Combined left shift.

14

2 Class. Elemental function.

15

3 Arguments.

16

I

shall be of type integer or a boz-literal-constant.

17 18

J

shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have the same kind type parameter. I and J shall not both be boz-literal-constants.

19

SHIFT

shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I) if I is of type integer; otherwise, it shall be less than or equal to BIT_SIZE (J).

20 21

4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.

22 23 24 25 26

5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to

27 28

6 Examples. DSHIFTL (1, 2**30, 2) has the value 5 if default integer has 32 bits. DSHIFTL (I, I, SHIFT) has

29

type integer with the kind type parameter of the other. The rightmost SHIFT bits of the result value are the same as the leftmost bits of J, and the remaining bits of the result value are the same as the rightmost bits of I. This is equal to IOR (SHIFTL (I, SHIFT), SHIFTR (J, BIT_SIZE (J)−SHIFT)). The model for the interpretation of an integer value as a sequence of bits is in 16.3. the same result value as ISHFTC (I, SHIFT).

16.9.76

DSHIFTR (I, J, SHIFT)

30

1 Description. Combined right shift.

31

2 Class. Elemental function.

32

3 Arguments.

33

I

shall be of type integer or a boz-literal-constant.

34 35

J

shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have the same kind type parameter. I and J shall not both be boz-literal-constants.

36 37

SHIFT

shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I) if I is of type integer; otherwise, it shall be less than or equal to BIT_SIZE (J).

38

4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.

ISO/IEC JTC 1/SC 22/WG5/N2184

383

J3/21-007r1

1 2 3 4 5 6 7 8

WD 1539-1

2021-05-21

5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to

type integer with the kind type parameter of the other. The leftmost SHIFT bits of the result value are the same as the rightmost bits of I, and the remaining bits of the result value are the same as the leftmost bits of J. This is equal to IOR (SHIFTL (I, BIT_SIZE (I)−SHIFT), SHIFTR (J, SHIFT)). The model for the interpretation of an integer value as a sequence of bits is in 16.3. 6 Examples. DSHIFTR (1, 16, 3) has the value 229 + 2 if default integer has 32 bits. DSHIFTR (I, I, SHIFT) has

the same result value as ISHFTC (I,−SHIFT).

16.9.77

EOSHIFT (ARRAY, SHIFT [, BOUNDARY, DIM])

9

1 Description. End-off shift of the elements of an array.

10

2 Class. Transformational function.

11

3 Arguments.

12

ARRAY

shall be an array be of any type.

13 14 15

SHIFT

shall be of type integer and shall be scalar if ARRAY has rank one; otherwise, it shall be scalar or of rank n − 1 and of shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

16 17 18 19

BOUNDARY (optional) shall be of the same type and type parameters as ARRAY and shall be scalar if ARRAY has rank one; otherwise, it shall be either scalar or of rank n − 1 and of shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ]. BOUNDARY is permitted to be absent only for the types in Table 16.4, and in this case it is as if it were present with the scalar value shown, converted if necessary to the kind type parameter value of ARRAY.

20

Table 16.4: Default BOUNDARY values for EOSHIFT Type of ARRAY Integer Real Complex Logical Character (len) 21 22

Value of BOUNDARY 0 0.0 (0.0, 0.0) .FALSE. len blanks

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY. If DIM is absent, it is as if it were present with the value 1.

23

4 Result Characteristics. The result has the type, type parameters, and shape of ARRAY.

24 25

5 Result Value. Element (s1 , s2 , . . . , sn ) of the result has the value ARRAY (s1 , s2 , . . . , sDIM−1 , sDIM + sh,

26 27

sDIM+1 , . . . , sn ) where sh is SHIFT or SHIFT (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) provided the inequality LBOUND (ARRAY, DIM) ≤ sDIM + sh ≤ UBOUND (ARRAY, DIM) holds and is otherwise BOUNDARY or BOUNDARY (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ).

28

6 Examples.

29 30 31 32

Case (i):

33

Case (ii):

34

384

If V is the array [1, 2, 3, 4, 5, 6], the effect of shifting V end-off to the left by 3 positions is achieved by EOSHIFT (V, SHIFT = 3), which has the value [4, 5, 6, 0, 0, 0]; EOSHIFT (V, SHIFT = −2, BOUNDARY = 99) achieves an end-off shift to the right by 2 positions with the boundary value of 99 and has the value [99, 99, 1, 2, 3, 4]. The rows of an array of rank two may all be shifted by the same amountor by different  amounts A B C and the boundary elements can be the same or different. If M is the array  D E F , then the G H I

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1 

 B E , and the value H   * A B of EOSHIFT (M, SHIFT = [−1, 1, 0], BOUNDARY = [’*’, ’/’, ’?’], DIM = 2) is  E F / . G H I

* value of EOSHIFT (M, SHIFT = −1, BOUNDARY = ’*’, DIM = 2) is  * ∗

1

2

3

16.9.78

A D G

EPSILON (X)

4

1 Description. Model number that is small compared to 1.

5

2 Class. Inquiry function.

6

3 Argument. X shall be of type real. It may be a scalar or an array.

7

4 Result Characteristics. Scalar of the same type and kind type parameter as X.

8 9

5 Result Value. The result has the value b1−p where b and p are as defined in 16.4 for the model representing

10

6 Example. EPSILON (X) has the value 2−23 for real X whose model is as in 16.4, NOTE 1.

11

numbers of the same type and kind type parameter as X.

16.9.79

ERF (X)

12

1 Description. Error function.

13

2 Class. Elemental function.

14

3 Argument. X shall be of type real.

15

4 Result Characteristics. Same as X.

16

5 Result Value. The result has a value equal to a processor-dependent approximation to the error function of X,

17 18 19

√2 π

RX 0

exp(−t2 ) dt.

6 Example. ERF (1.0) has the value 0.843 (approximately).

16.9.80

ERFC (X)

20

1 Description. Complementary error function.

21

2 Class. Elemental function.

22

3 Argument. X shall be of type real.

23

4 Result Characteristics. Same as X.

24 25

5 Result Value. The result has a value equal to a processor-dependent approximation to the complementary error R

26

6 Example. ERFC (1.0) has the value 0.157 (approximately).

27

function of X, 1 − ERF (X); this is equivalent to √2π

16.9.81

∞ exp(−t2 )dt. X

ERFC_SCALED (X)

28

1 Description. Scaled complementary error function.

29

2 Class. Elemental function.

30

3 Argument. X shall be of type real.

ISO/IEC JTC 1/SC 22/WG5/N2184

385

J3/21-007r1

WD 1539-1

2021-05-21

1

4 Result Characteristics. Same as X.

2 3

5 Result Value. The result has a value equal to aR processor-dependent approximation to the exponentially-scaled

4

6 Example. ERFC_SCALED (20.0) has the value 0.02817434874 (approximately).

complementary error function of X, exp(X 2 ) √2π

∞ exp(−t2 ) dt. X

NOTE 1

√ The complementary error function is asymptotic to exp(−X 2 )/(X π). As such it underflows for X >≈ 9 when using ISO/IEC/IEEE 60559:2011 single precision arithmetic. The exponentially-scaled complement√ √ ary error function is asymptotic to 1/(X π). As such it does not underflow until X > HUGE (X)/ π.

5

16.9.82

EVENT_QUERY (EVENT, COUNT [, STAT])

6

1 Description. Query event count.

7

2 Class. Subroutine.

8

3 Arguments.

9 10

EVENT

shall be an event variable (16.10.2.10). It shall not be coindexed. It is an INTENT (IN) argument. The EVENT argument is accessed atomically with respect to the execution of EVENT POST statements in unordered segments, in exact analogy to atomic subroutines.

12 13 14

COUNT

shall be an integer scalar with a decimal exponent range no smaller than that of default integer. It is an INTENT (OUT) argument. If no error condition occurs, COUNT is assigned the value of the count of EVENT; otherwise, it is assigned the value −1.

15 16 17 18

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If the STAT argument is present, it is assigned a processor-dependent positive value if an error condition occurs; otherwise it is assigned the value zero. If the STAT argument is not present and an error condition occurs, error termination is initiated.

19

4 Example. If EVENT is an event variable for which there have been no successful posts or waits in preceding

11

20

segments, and for which there are no posts or waits in an unordered segment, after execution of CALL EVENT_QUERY (EVENT, COUNT)

21 22 23 24

the integer variable COUNT will have the value zero. If there have been ten successful posts to EVENT and two successful waits without an UNTIL_COUNT= specifier in preceding segments, and for which there are no posts or waits in an unordered segment, after execution of

25

CALL EVENT_QUERY (EVENT, COUNT)

26

the variable COUNT will have the value eight. NOTE 1 Execution of EVENT_QUERY does not imply any synchronization.

27

16.9.83

EXECUTE_COMMAND_LINE (COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG ])

28

1 Description. Execute a command line.

29

2 Class. Subroutine.

30

3 Arguments.

31 32

COMMAND shall be a default character scalar. It is an INTENT (IN) argument. Its value is the command line to be executed. The interpretation is processor dependent.

386

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

WAIT (optional) shall be a logical scalar. It is an INTENT (IN) argument. If WAIT is present with the value false, and the processor supports asynchronous execution of the command, the command is executed asynchronously; otherwise it is executed synchronously.

4 5 6

EXITSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least nine. It is an INTENT (INOUT) argument. If the command is executed synchronously, it is assigned the value of the processor-dependent exit status. Otherwise, the value of EXITSTAT is unchanged.

7 8 9 10 11

CMDSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned the value −1 if the processor does not support command line execution, a processor-dependent positive value if an error condition occurs, or the value −2 if no error condition occurs but WAIT is present with the value false and the processor does not support asynchronous execution. Otherwise it is assigned the value 0.

12 13

CMDMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. If an error condition occurs, it is assigned a processor-dependent explanatory message. Otherwise, it is unchanged.

14 15

4 If the processor supports command line execution, it shall support synchronous and may support asynchronous

16 17

5 When the command is executed synchronously, EXECUTE_COMMAND_LINE returns after the command line

18 19

6 If a condition occurs that would assign a nonzero value to CMDSTAT but the CMDSTAT variable is not present,

20

execution of the command line. has completed execution. Otherwise, EXECUTE_COMMAND_LINE returns without waiting. error termination is initiated.

16.9.84

EXP (X)

21

1 Description. Exponential function.

22

2 Class. Elemental function.

23

3 Argument. X shall be of type real or complex.

24

4 Result Characteristics. Same as X.

25 26

5 Result Value. The result has a value equal to a processor-dependent approximation to eX . If X is of type

27

6 Example. EXP (1.0) has the value 2.7182818 (approximately).

28

complex, its imaginary part is regarded as a value in radians.

16.9.85

EXPONENT (X)

29

1 Description. Exponent of floating-point number.

30

2 Class. Elemental function.

31

3 Argument. X shall be of type real.

32

4 Result Characteristics. Default integer.

33

5 Result Value. The result has a value equal to the exponent e of the representation for the value of X in the

34 35 36

extended real model for the kind of X (16.4), provided X is nonzero and e is within the range for default integers. If X has the value zero, the result has the value zero. If X is an IEEE infinity or NaN, the result has the value HUGE (0).

37 38

6 Examples. EXPONENT (1.0) has the value 1 and EXPONENT (4.1) has the value 3 for reals whose model is

as in 16.4, NOTE 1.

ISO/IEC JTC 1/SC 22/WG5/N2184

387

J3/21-007r1

1

16.9.86

WD 1539-1

2021-05-21

EXTENDS_TYPE_OF (A, MOLD)

2

1 Description. Dynamic type extension inquiry.

3

2 Class. Inquiry function.

4

3 Arguments.

5 6

A

shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.

7 8

MOLD

shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.

9

4 Result Characteristics. Default logical scalar.

10 11 12

5 Result Value. If MOLD is unlimited polymorphic and is either a disassociated pointer or unallocated allocatable

13 14

variable, the result is true; otherwise if A is unlimited polymorphic and is either a disassociated pointer or unallocated allocatable variable, the result is false; otherwise if the dynamic type of A or MOLD is extensible, the result is true if and only if the dynamic type of A is an extension type of the dynamic type of MOLD; otherwise the result is processor dependent. NOTE 1 The dynamic type of a disassociated pointer or unallocated allocatable variable is its declared type. NOTE 2 The test performed by EXTENDS_TYPE_OF is not the same as the test performed by the type guard CLASS IS. The test performed by EXTENDS_TYPE_OF does not consider kind type parameters.

15

6 Example. Given the declarations and assignments

16

TYPE T1 REAL C END TYPE TYPE, EXTENDS(T1) :: T2 END TYPE CLASS(T1), POINTER :: P, Q ALLOCATE (P) ALLOCATE (T2 :: Q)

17 18 19 20 21 22 23 24 25

the result of EXTENDS_TYPE_OF (P, Q) will be false, and the result of EXTENDS_TYPE_OF (Q, P) will be true.

26

16.9.87

FAILED_IMAGES ([TEAM, KIND])

27

1 Description. Indices of failed images.

28

2 Class. Transformational function.

29

3 Arguments.

31 32

TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV. Its value shall be that of the current or an ancestor team. If TEAM is absent, the team specified is the current team.

33

KIND (optional) shall be a scalar integer constant expression.

30

34 35

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value

of KIND; otherwise, the kind type parameter is that of default integer type. The result is an array of rank one

388

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

whose size is equal to the number of images in the specified team that are known by the invoking image to have failed.

3 4

5 Result Value. The elements of the result are the values of the image indices of the known failed images in the

5 6 7 8 9 10

specified team, in numerically increasing order. If the executing image has previously executed an image control statement whose STAT= specifier assigned the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV, or referenced a collective subroutine whose STAT argument was set to STAT_FAILED_IMAGE, at least one image in the set of images participating in that image control statement or collective subroutine reference shall be known to have failed. 6 Examples. If image 3 is the only image in the current team that is known by the invoking image to have failed,

11

FAILED_IMAGES() will have the value [3]. If there are no images in the current team that are known by the invoking image to have failed, the value of FAILED_IMAGES() will be a zero-sized array.

12

16.9.88

FINDLOC (ARRAY, VALUE, DIM [, MASK, KIND, BACK]) or FINDLOC (ARRAY, VALUE [, MASK, KIND, BACK])

13

1 Description. Location(s) of a specified value.

14

2 Class. Transformational function.

15

3 Arguments.

16

ARRAY

shall be an array of intrinsic type.

17 18

VALUE

shall be scalar and in type conformance with ARRAY, as specified in Table 10.2 for the operator == or the operator .EQV..

19

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

20

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

21

KIND (optional) shall be a scalar integer constant expression.

22

BACK (optional) shall be a logical scalar.

23 24 25 26 27 28 29

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

KIND; otherwise the kind type parameter is that of default integer type. If DIM does not appear, the result is an array of rank one and of size equal to the rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where [d1 , d2 , . . . , dn ] is the shape of ARRAY. 5 Result Value.

Case (i):

30 31 32 33 34 35 36 37

Case (ii):

38 39

Case (iii):

40 41 42 43 44 45

The result of FINDLOC (ARRAY, VALUE) is a rank-one array whose element values are the values of the subscripts of an element of ARRAY whose value matches VALUE. If there is such a value, the ith element value is in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If no elements match VALUE or ARRAY has size zero, all elements of the result are zero. The result of FINDLOC (ARRAY, VALUE, MASK = MASK) is a rank-one array whose element values are the values of the subscripts of an element of ARRAY, corresponding to a true element of MASK, whose value matches VALUE. If there is such a value, the ith element value is in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If no elements match VALUE, ARRAY has size zero, or every element of MASK has the value false, all elements of the result are zero. If ARRAY has rank one, the result of FINDLOC (ARRAY, VALUE, DIM=DIM [, MASK = MASK]) is a scalar whose value is equal to that of the first element of FINDLOC (ARRAY, VALUE [, MASK = MASK]). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to FINDLOC (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), VALUE, DIM=1 [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).

6 If both ARRAY and VALUE are of type logical, the comparison is performed with the .EQV. operator; otherwise,

the comparison is performed with the == operator. If the value of the comparison is true, that element of ARRAY

ISO/IEC JTC 1/SC 22/WG5/N2184

389

J3/21-007r1

1 2 3 4 5

7 If DIM is not present, more than one element matches VALUE, and BACK is absent or present with the value

false, the value returned indicates the first such element, taken in array element order. If DIM is not present and BACK is present with the value true, the value returned indicates the last such element, taken in array element order. 8 Examples.

7 8

Case (i):

9

Case (ii):

The value of FINDLOC ([2, 6, 4, 6], VALUE = 6) is [2], and the value of FINDLOC ([2, 6, 4, 6], VALUE = 6, BACK = .TRUE.) is [4].     0 −5 7 7 T T F T If A has the value  3 4 −1 2 , and M has the value  T T F T , FINDLOC (A, 7, 1 5 6 7 T T F T MASK = M) has the value [1, 4] and FINDLOC (A, 7, MASK = M, BACK = .TRUE.) has the value [3, 4]. This is independent of the declared lower bounds for A. The value of FINDLOC ([2, 6, 4], VALUE = 6, DIM = 1) is 2. If B has the value   1 2 −9 , FINDLOC (B, VALUE = 2, DIM = 1) has the value [2, 1, 0] and FINDLOC (B, 2 2 6 VALUE = 2, DIM = 2) has the value [2, 1]. This is independent of the declared lower bounds for B.

10 11

Case (iii):

13 14 15

2021-05-21

matches VALUE.

6

12

WD 1539-1

16.9.89

FLOOR (A [, KIND])

16

1 Description. Greatest integer less than or equal to A.

17

2 Class. Elemental function.

18

3 Arguments.

19

A

20

KIND (optional) shall be a scalar integer constant expression.

shall be of type real.

21 22

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

23

5 Result Value. The result has a value equal to the greatest integer less than or equal to A.

24

6 Examples. FLOOR (3.7) has the value 3. FLOOR (−3.7) has the value −4.

25

KIND; otherwise, the kind type parameter is that of default integer type.

16.9.90

FRACTION (X)

26

1 Description. Fractional part of number.

27

2 Class. Elemental function.

28

3 Argument. X shall be of type real.

29

4 Result Characteristics. Same as X.

30 31 32

5 Result Value. The result has the value X × b−e , where b and e are as defined in 16.4 for the representation of

33

6 Example. FRACTION (3.0) has the value 0.75 for reals whose model is as in 16.4, NOTE 1.

34

X in the extended real model for the kind of X. If X has the value zero, the result is zero. If X is an IEEE NaN, the result is that NaN. If X is an IEEE infinity, the result is an IEEE NaN.

16.9.91

GAMMA (X)

35

1 Description. Gamma function.

36

2 Class. Elemental function.

390

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

3 Argument. X shall be of type real. Its value shall not be a negative integer or zero.

2

4 Result Characteristics. Same as X.

J3/21-007r1

5 Result Value. The result has a value equal to a processor-dependent approximation to the gamma function of

X,  R ∞ X−1 exp(−t) dt   0 t Γ(X) =   R k   ∞ tX−1 exp(−t) − Pn (−t) dt k=0 k! 0 3 4

X>0 −n − 1 < X < −n, n an integer ≥ 0

6 Example. GAMMA (1.0) has the value 1.000 (approximately).

16.9.92

GET_COMMAND ([COMMAND, LENGTH, STATUS, ERRMSG])

5

1 Description. Get program invocation command.

6

2 Class. Subroutine.

7

3 Arguments.

8 9 10

COMMAND (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned the entire command by which the program was invoked. If the command cannot be determined, COMMAND is assigned all blanks.

11 12 13 14 15 16

LENGTH (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned the significant length of the command by which the program was invoked. The significant length may include trailing blanks if the processor allows commands with significant trailing blanks. This length does not consider any possible truncation or padding in assigning the command to the COMMAND argument; in fact the COMMAND argument need not even be present. If the command length cannot be determined, a length of 0 is assigned.

17 18 19 20

STATUS (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned the value −1 if the COMMAND argument is present and has a length less than the significant length of the command. It is assigned a processor-dependent positive value if the command retrieval fails. Otherwise it is assigned the value 0.

21 22

ERRMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. It is assigned a processor-dependent explanatory message if the command retrieval fails. Otherwise, it is unchanged.

23

4 Example. If the program below is invoked with the command “example” on a processor that supports command

24 25 26 27 28 29

30

retrieval, it will display “Hello example”. PROGRAM hello CHARACTER(:), ALLOCATABLE :: cmd CALL GET_COMMAND(cmd) PRINT *, ’Hello ’, cmd END PROGRAM

16.9.93

GET_COMMAND_ARGUMENT (NUMBER [, VALUE, LENGTH, STATUS, ERRMSG])

31

1 Description. Get program invocation argument.

32

2 Class. Subroutine.

33

3 Arguments.

ISO/IEC JTC 1/SC 22/WG5/N2184

391

J3/21-007r1

WD 1539-1

2021-05-21

1 2

NUMBER

3 4 5

Command argument 0 always exists, and is the command name by which the program was invoked if the processor has such a concept; otherwise, the value of command argument 0 is processor dependent. The remaining command arguments are numbered consecutively from 1 to the argument count in an order determined by the processor. VALUE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. If the command argument specified by NUMBER exists, its value is assigned to VALUE; otherwise, VALUE is assigned all blanks.

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

LENGTH (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If the command argument specified by NUMBER exists, its significant length is assigned to LENGTH; otherwise, LENGTH is assigned the value zero. It is processor dependent whether the significant length includes trailing blanks. This length does not consider any possible truncation or padding in assigning the command argument value to the VALUE argument; in fact the VALUE argument need not even be present. STATUS (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If NUMBER is less than zero or greater than the argument count that would be returned by the intrinsic function COMMAND_ARGUMENT_COUNT, or command retrieval fails, STATUS is assigned a processor-dependent positive value. Otherwise, if VALUE is present and has a length less than the significant length of the specified command argument, it is assigned the value −1. Otherwise it is assigned the value 0. ERRMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. It is assigned a processor-dependent explanatory message if the optional argument STATUS is, or would be if present, assigned a positive value. Otherwise, it is unchanged. 4 Example. On a processor that supports command arguments, the following program displays the arguments of

the command by which it was invoked. PROGRAM show_arguments INTEGER :: i CHARACTER :: command*32, arg*128 CALL get_command_argument(0, command) WRITE (*,*) "Command name is: ", command DO i = 1, command_argument_count() CALL get_command_argument(i, arg) WRITE (*,*) "Argument ", i, " is ", arg END DO END PROGRAM show_arguments

27 28 29 30 31 32 33 34 35 36

37

shall be an integer scalar. It is an INTENT (IN) argument that specifies the number of the command argument that the other arguments give information about.

16.9.94

GET_ENVIRONMENT_VARIABLE (NAME [, VALUE, LENGTH, STATUS, TRIM_NAME, ERRMSG])

38

1 Description. Get environment variable.

39

2 Class. Subroutine.

40

3 Arguments.

41 42

NAME

43 44

VALUE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned the value of the environment variable specified by NAME. VALUE is assigned all blanks if the environment

392

shall be a default character scalar. It is an INTENT (IN) argument. The interpretation of case is processor dependent.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

variable does not exist or does not have a value, or if the processor does not support environment variables.

3 4 5

LENGTH (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If the specified environment variable exists and has a value, LENGTH is assigned the value of its length. Otherwise LENGTH is assigned the value zero.

6 7

STATUS (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If the environment variable exists and either has no value, its value is successfully assigned to VALUE, or the VALUE argument is not present, STATUS is assigned the value zero. STATUS is assigned the value −1 if the VALUE argument is present and has a length less than the significant length of the environment variable. It is assigned the value 1 if the specified environment variable does not exist, or 2 if the processor does not support environment variables. Processor-dependent values greater than 2 may be assigned for other error conditions.

8 9 10 11 12

15 16

TRIM_NAME (optional) shall be a logical scalar. It is an INTENT (IN) argument. If TRIM_NAME is present with the value false then trailing blanks in NAME are considered significant if the processor supports trailing blanks in environment variable names. Otherwise trailing blanks in NAME are not considered part of the environment variable’s name.

17 18 19

ERRMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. It is assigned a processor-dependent explanatory message if the optional argument STATUS is, or would be if present, assigned a positive value. Otherwise, it is unchanged.

20 21

4 It is processor dependent whether an environment variable that exists on an image also exists on another image,

22

5 Example. If the value of the environment variable DATAFILE is datafile.dat, executing the statement sequence

13 14

23 24 25

26

and if it does exist on both images, whether the values are the same or different. below will assign the value ’datafile.dat’ to FILENAME. CHARACTER(:),ALLOCATABLE :: FILENAME CALL GET_ENVIRONMENT_VARIABLE("DATAFILE", FILENAME)

16.9.95

GET_TEAM ([LEVEL])

27

1 Description. Team.

28

2 Class. Transformational function.

29 30

3 Argument. LEVEL (optional) shall be a scalar integer whose value is equal to one of the named constants

31

4 Result Characteristics. Scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.

32

5 Result Value. The result is a TEAM_TYPE value that identifies the current team if LEVEL is not present,

33 34 35

present with the value CURRENT_TEAM, or if the current team is the initial team. Otherwise, the result identifies the parent team if LEVEL is present with the value PARENT_TEAM, and identifies the initial team if LEVEL is present with the value INITIAL_TEAM.

36 37 38 39

INITIAL_TEAM, PARENT_TEAM, or CURRENT_TEAM from the intrinsic module ISO_FORTRAN_ENV.

6 Examples.

PROGRAM EXAMPLE1 USE,INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE TYPE(TEAM_TYPE) :: WORLD_TEAM, TEAM2

40 41 42 43

! Define a team variable representing the initial team WORLD_TEAM = GET_TEAM() END PROGRAM

ISO/IEC JTC 1/SC 22/WG5/N2184

393

J3/21-007r1

WD 1539-1

2021-05-21

1

SUBROUTINE EXAMPLE2 (A) USE,INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE REAL A[*] TYPE(TEAM_TYPE) :: NEW_TEAM, PARENT_TEAM

2 3 4 5 6

... ! Form NEW_TEAM

7 8

PARENT_TEAM = GET_TEAM ()

9 10

CHANGE TEAM (NEW_TEAM)

11 12

! Reference image 1 in parent’s team A [1,TEAM=PARENT_TEAM] = 4.2

13 14 15

! Reference image 1 in current team A [1] = 9.0 END TEAM END SUBROUTINE EXAMPLE2

16 17 18 19

NOTE 1 Because the result of GET_TEAM is of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, a program unit that assigns the result of a reference to GET_TEAM to a local variable will also need access to the definition of TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV. 20

16.9.96

HUGE (X)

21

1 Description. Largest model value.

22

2 Class. Inquiry function.

23

3 Argument. X shall be of type integer or real, or of enumeration type. It may be a scalar or an array.

24

4 Result Characteristics. Scalar of the same type and kind type parameter as X.

25

5 Result Value. The result has the value r q − 1 if X is of type integer and (1 − b−p )bemax if X is of type real,

26 27 28

where r, q, b, p, and emax are as defined in 16.4 for the model representing numbers of the same type and kind type parameter as X. If X is of enumeration type, the result has the value of the last enumerator in the type definition.

29 30

6 Example. HUGE (X) has the value (1 − 2−24 ) × 2127 for real X whose model is as in 16.4, NOTE 1.

16.9.97

HYPOT (X, Y)

31

1 Description. Euclidean distance function.

32

2 Class. Elemental function.

33

3 Arguments.

34

X

shall be of type real.

35

Y

shall be of type real with the same kind type parameter as X.

394

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

4 Result Characteristics. Same as X.

2

5 Result Value. The result has a value equal to a processor-dependent approximation to the Euclidean distance, p

3 4 5

X2 + Y2 , without undue overflow or underflow.

6 Example. HYPOT (3.0, 4.0) has the value 5.0 (approximately).

16.9.98

IACHAR (C [, KIND])

6

1 Description. ASCII code value for character.

7

2 Class. Elemental function.

8

3 Arguments.

9

C

10

KIND (optional) shall be a scalar integer constant expression.

shall be of type character and of length one.

11 12

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

13 14 15 16 17

5 Result Value. If C is in the collating sequence defined by the codes specified in ISO/IEC 646:1991 (International

18

6 Example. IACHAR (’X’) has the value 88.

19

KIND; otherwise, the kind type parameter is that of default integer type. Reference Version), the result is the position of C in that sequence; it is nonnegative and less than or equal to 127. The value of the result is processor dependent if C is not in the ASCII collating sequence. The results are consistent with the LGE, LGT, LLE, and LLT comparison functions. For example, if LLE (C, D) is true, IACHAR (C) <= IACHAR (D) is true where C and D are any two characters representable by the processor.

16.9.99

IALL (ARRAY, DIM [, MASK]) or IALL (ARRAY [, MASK])

20

1 Description. Array reduced by IAND function.

21

2 Class. Transformational function.

22

3 Arguments.

23

ARRAY

shall be an array of type integer.

24

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

25

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

26 27 28

4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar if

29

5 Result Value.

DIM does not appear or if ARRAY has rank one; otherwise, the result is an array of rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

30 31

Case (i):

32 33

Case (ii):

34 35

Case (iii):

36 37 38 39

If ARRAY has size zero the result value is equal to NOT (INT (0, KIND (ARRAY))). Otherwise, the result of IALL (ARRAY) has a value equal to the bitwise AND of all the elements of ARRAY. The result of IALL (ARRAY, MASK=MASK) has a value equal to IALL (PACK (ARRAY, MASK)). The result of IALL (ARRAY, DIM=DIM [ , MASK=MASK]) has a value equal to that of IALL (ARRAY [ , MASK=MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to IALL (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).

6 Examples. IALL ([14, 13, 11]) has the value 8. IALL ([14, 13, 11], MASK=[.true., .false., .true.]) has the value

10.

ISO/IEC JTC 1/SC 22/WG5/N2184

395

J3/21-007r1

1

16.9.100 IAND (I, J)

2

1 Description. Bitwise AND.

3

2 Class. Elemental function.

4

3 Arguments.

WD 1539-1

2021-05-21

5

I

shall be of type integer or a boz-literal-constant.

6 7

J

shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have the same kind type parameter. I and J shall not both be boz-literal-constants.

8

4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.

9 10 11

5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to

type integer with the kind type parameter of the other. The result has the value obtained by combining I and J bit-by-bit according to the following table: I 1 1 0 0

J 1 0 1 0

IAND (I, J) 1 0 0 0

12

6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.

13

7 Example. IAND (1, 3) has the value 1.

14

16.9.101 IANY (ARRAY, DIM [, MASK]) or IANY (ARRAY [, MASK])

15

1 Description. Reduce array with bitwise OR operation.

16

2 Class. Transformational function.

17

3 Arguments.

18

ARRAY

shall be of type integer. It shall be an array.

19

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

20

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

21 22 23

4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar if

24

5 Result Value.

DIM does not appear or if ARRAY has rank one; otherwise, the result is an array of rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

25 26

Case (i):

27 28

Case (ii):

29 30 31

Case (iii):

32 33 34

The result of IANY (ARRAY) is the bitwise OR of all the elements of ARRAY. If ARRAY has size zero the result value is equal to zero. The result of IANY (ARRAY, MASK=MASK) has a value equal to IANY (PACK (ARRAY, MASK)). The result of IANY (ARRAY, DIM=DIM [, MASK=MASK]) has a value equal to that of IANY (ARRAY [, MASK=MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to IANY (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).

6 Examples. IANY ([14, 13, 8]) has the value 15. IANY ([14, 13, 8], MASK=[.true., .false., .true.]) has the value

14.

396

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

16.9.102 IBCLR (I, POS)

2

1 Description. I with bit POS replaced by zero.

3

2 Class. Elemental function.

4

3 Arguments.

5

I

shall be of type integer.

6

POS

shall be of type integer. It shall be nonnegative and less than BIT_SIZE (I).

7

4 Result Characteristics. Same as I.

8 9

5 Result Value. The result has the value of the sequence of bits of I, except that bit POS is zero. The model for

10 11

6 Examples. IBCLR (14, 1) has the value 12. If V has the value [1, 2, 3, 4], the value of IBCLR (POS = V, I = 31)

the interpretation of an integer value as a sequence of bits is in 16.3. is [29, 27, 23, 15].

12

16.9.103 IBITS (I, POS, LEN)

13

1 Description. Specified sequence of bits.

14

2 Class. Elemental function.

15

3 Arguments.

16

I

shall be of type integer.

17 18

POS

shall be of type integer. It shall be nonnegative and POS + LEN shall be less than or equal to BIT_SIZE (I).

19

LEN

shall be of type integer and nonnegative.

20

4 Result Characteristics. Same as I.

21 22

5 Result Value. The result has the value of the sequence of LEN bits in I beginning at bit POS, right-adjusted

23

6 Example. IBITS (14, 1, 3) has the value 7.

24

and with all other bits zero. The model for the interpretation of an integer value as a sequence of bits is in 16.3.

16.9.104 IBSET (I, POS)

25

1 Description. I with bit POS replaced by one.

26

2 Class. Elemental function.

27

3 Arguments.

28

I

shall be of type integer.

29

POS

shall be of type integer. It shall be nonnegative and less than BIT_SIZE (I).

30

4 Result Characteristics. Same as I.

31 32

5 Result Value. The result has the value of the sequence of bits of I, except that bit POS is one. The model for

33

6 Examples. IBSET (12, 1) has the value 14. If V has the value [1, 2, 3, 4], the value of IBSET (POS = V, I = 0)

34

the interpretation of an integer value as a sequence of bits is in 16.3. is [2, 4, 8, 16].

ISO/IEC JTC 1/SC 22/WG5/N2184

397

J3/21-007r1

WD 1539-1

1

16.9.105 ICHAR (C [, KIND])

2

1 Description. Code value for character.

3

2 Class. Elemental function.

4

3 Arguments.

5 6

C

7

KIND (optional) shall be a scalar integer constant expression.

2021-05-21

shall be of type character and of length one. Its value shall be that of a character capable of representation in the processor.

8 9

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

10 11 12

5 Result Value. The result is the position of C in the processor collating sequence associated with the kind type

KIND; otherwise, the kind type parameter is that of default integer type.

13 14

parameter of C; it is nonnegative and less than n, where n is the number of characters in the collating sequence. The kind type parameter of the result shall specify an integer kind that is capable of representing n. For any characters C and D capable of representation in the processor, C <= D is true if and only if ICHAR (C) <= ICHAR (D) is true and C == D is true if and only if ICHAR (C) == ICHAR (D) is true.

15

6 Example. ICHAR (’X’) has the value 88 on a processor using the ASCII collating sequence for default characters.

16

16.9.106 IEOR (I, J)

17

1 Description. Bitwise exclusive OR.

18

2 Class. Elemental function.

19

3 Arguments.

20 21

I J

22

shall be of type integer or a boz-literal-constant. shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have the same kind type parameter. I and J shall not both be boz-literal-constants.

23

4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.

24 25 26

5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to

type integer with the kind type parameter of the other. The result has the value obtained by combining I and J bit-by-bit according to the following table: I 1 1 0 0

J 1 0 1 0

IEOR (I, J) 0 1 1 0

27

6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.

28

7 Example. IEOR (1, 3) has the value 2.

29

16.9.107 IMAGE_INDEX (COARRAY, SUB) or (COARRAY, SUB, TEAM) or (COARRAY, SUB, TEAM_NUMBER)

30

1 Description. Image index from cosubscripts.

31

2 Class. Transformational function.

398

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

3 Arguments.

2 3 4 5

COARRAY shall be a coarray of any type. If its designator has more than one part-ref , the rightmost part-ref shall have nonzero corank. If TEAM_NUMBER appears and the current team is not the initial team, it shall be established in an ancestor of the current team. Otherwise, if TEAM appears, it shall be established in that team. Otherwise, it shall be established in the current team.

6

SUB

shall be a rank-one integer array of size equal to the corank of COARRAY.

7 8

TEAM

shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, with a value that identifies the current or an ancestor team.

9

TEAM_NUMBER shall be an integer scalar. It shall identify the initial team or a sibling team of the current team.

10 11

4 Result Characteristics. Default integer scalar.

12 13 14

5 Result Value. If the value of SUB is a valid sequence of cosubscripts for COARRAY in the team specified by

15 16 17

6 Examples. If A and B are declared as A [0:*] and B (10, 20) [10, 0:9, 0:*] respectively, IMAGE_INDEX (A, [0])

18

TEAM or TEAM_NUMBER, or the current team if neither TEAM nor TEAM_NUMBER appears, the result is the index of the corresponding image in that team. Otherwise, the result is zero. has the value 1 and IMAGE_INDEX (B, [3, 1, 2]) has the value 213 (on any image, provided the number of images is at least 213).

16.9.108 IMAGE_STATUS (IMAGE [, TEAM])

19

1 Description. Image execution state.

20

2 Class. Elemental function.

21

3 Arguments.

22 23

IMAGE

24 25

TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV. Its value shall represent the current or an ancestor team. If TEAM is absent, the team specified is the current team.

26

shall be of type integer. Its value shall be positive and less than or equal to the number of images in the specified team.

27

4 Result Characteristics. Default integer.

28 29 30

5 Result Value. The result value is STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV

31 32

6 Example. If image 3 of the current team has failed, IMAGE_STATUS (3) has the value STAT_FAILED_-

33

if the specified image has failed, STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV if that image has initiated normal termination, and zero otherwise. IMAGE.

16.9.109 INDEX (STRING, SUBSTRING [, BACK, KIND])

34

1 Description. Character string search.

35

2 Class. Elemental function.

36

3 Arguments.

37

STRING

38

SUBSTRING shall be of type character with the same kind type parameter as STRING.

39

BACK (optional) shall be of type logical.

40

KIND (optional) shall be a scalar integer constant expression.

shall be of type character.

ISO/IEC JTC 1/SC 22/WG5/N2184

399

J3/21-007r1

WD 1539-1

2021-05-21

1 2

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

3

5 Result Value.

4 5 6 7 8 9 10 11 12

KIND; otherwise the kind type parameter is that of default integer type.

Case (i): Case (ii):

Case (iii):

If STRING % LEN < SUBSTRING % LEN, the result has the value zero. Otherwise, if there is an integer I in the range 1 ≤ I ≤ STRING % LEN − SUBSTRING % LEN + 1, such that STRING(I : I + SUBSTRING % LEN − 1) is equal to SUBSTRING, the result has the value of the smallest such I if BACK is absent or present with the value false, and the greatest such I if BACK is present with the value true. Otherwise, the result has the value zero.

6 Examples. INDEX (’FORTRAN’, ’R’) has the value 3.

INDEX (’FORTRAN’, ’R’, BACK = .TRUE.) has the value 5.

16.9.110 INT (A [, KIND])

13

1 Description. Conversion to integer type.

14

2 Class. Elemental function.

15

3 Arguments.

16

A

shall be of type integer, real, complex, or enumeration type, or a boz-literal-constant.

17

KIND (optional) shall be a scalar integer constant expression.

18 19

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

20

5 Result Value.

21 22

KIND; otherwise, the kind type parameter is that of default integer type.

Case (i): Case (ii):

23 24 25 26 27 28 29 30 31

Case (iii): Case (iv): Case (v):

If A is of type integer, INT (A) = A. If A is of type real, there are two cases: if |A| < 1, INT (A) has the value 0; if |A| ≥ 1, INT (A) is the integer whose magnitude is the largest integer that does not exceed the magnitude of A and whose sign is the same as the sign of A. If A is of type complex, INT (A) = INT (REAL (A, KIND (A))). If A is of enumeration type, INT (A) has the value of the ordinal position of A. If A is a boz-literal-constant, the value of the result is the value whose bit sequence according to the model in 16.3 is the same as that of A as modified by padding or truncation according to 16.3.3. The interpretation of a bit sequence whose most significant bit is 1 is processor dependent.

6 Example. INT (−3.7) has the value −3.

16.9.111 IOR (I, J)

32

1 Description. Bitwise inclusive OR.

33

2 Class. Elemental function.

34

3 Arguments.

35

I

shall be of type integer or a boz-literal-constant.

36 37

J

shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have the same kind type parameter. I and J shall not both be boz-literal-constants.

38

4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.

39 40 41

5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to

type integer with the kind type parameter of the other. The result has the value obtained by combining I and J bit-by-bit according to the following table:

400

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

I 1 1 0 0

J 1 0 1 0

IOR (I, J) 1 1 1 0

1

6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.

2

7 Example. IOR (5, 3) has the value 7.

3

J3/21-007r1

16.9.112 IPARITY (ARRAY, DIM [, MASK]) or IPARITY (ARRAY [, MASK])

4

1 Description. Array reduced by IEOR function.

5

2 Class. Transformational function.

6

3 Arguments.

7

ARRAY

shall be of type integer. It shall be an array.

8

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

9

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

10 11 12

4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar if

13

5 Result Value.

DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

14 15

Case (i):

16 17

Case (ii):

18 19 20 21

Case (iii):

22 23 24

The result of IPARITY (ARRAY) has a value equal to the bitwise exclusive OR of all the elements of ARRAY. If ARRAY has size zero the result has the value zero. The result of IPARITY (ARRAY, MASK=MASK) has a value equal to that of IPARITY (PACK (ARRAY, MASK)). The result of IPARITY (ARRAY, DIM=DIM [, MASK=MASK]) has a value equal to that of IPARITY (ARRAY [, MASK=MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to IPARITY (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).

6 Examples. IPARITY ([14, 13, 8]) has the value 11. IPARITY ([14, 13, 8], MASK=[.true., .false., .true.]) has

the value 6.

16.9.113 ISHFT (I, SHIFT)

25

1 Description. Logical shift.

26

2 Class. Elemental function.

27

3 Arguments.

28

I

shall be of type integer.

29

SHIFT

shall be of type integer. The absolute value of SHIFT shall be less than or equal to BIT_SIZE (I).

30

4 Result Characteristics. Same as I.

31

5 Result Value. The result has the value obtained by shifting the bits of I by SHIFT positions. If SHIFT is

32 33 34

positive, the shift is to the left; if SHIFT is negative, the shift is to the right; if SHIFT is zero, no shift is performed. Bits shifted out from the left or from the right, as appropriate, are lost. Zeros are shifted in from the opposite end. The model for the interpretation of an integer value as a sequence of bits is in 16.3.

ISO/IEC JTC 1/SC 22/WG5/N2184

401

J3/21-007r1

1

WD 1539-1

6 Example. ISHFT (3, 1) has the value 6.

2

16.9.114 ISHFTC (I, SHIFT [, SIZE])

3

1 Description. Circular shift of the rightmost bits.

4

2 Class. Elemental function.

5

3 Arguments.

6 7 8 9

2021-05-21

I SHIFT

shall be of type integer. shall be of type integer. The absolute value of SHIFT shall be less than or equal to SIZE.

SIZE (optional) shall be of type integer. The value of SIZE shall be positive and shall not exceed BIT_SIZE (I). If SIZE is absent, it is as if it were present with the value of BIT_SIZE (I).

10

4 Result Characteristics. Same as I.

11 12 13 14

5 Result Value. The result has the value obtained by shifting the SIZE rightmost bits of I circularly by SHIFT

15

6 Example. ISHFTC (3, 2, 3) has the value 5.

16

positions. If SHIFT is positive, the shift is to the left; if SHIFT is negative, the shift is to the right; and if SHIFT is zero, no shift is performed. No bits are lost. The unshifted bits are unaltered. The model for the interpretation of an integer value as a sequence of bits is in 16.3.

16.9.115 IS_CONTIGUOUS (ARRAY)

17

1 Description. Array contiguity test (8.5.7).

18

2 Class. Inquiry function.

19 20

3 Argument. ARRAY may be of any type. It shall be assumed-rank or an array. If it is a pointer it shall be

21

4 Result Characteristics. Default logical scalar.

22

5 Result Value. The result has the value true if ARRAY has rank zero or is contiguous, and false otherwise.

23 24

6 Example. After the pointer assignment AP => TARGET (1:10:2), IS_CONTIGUOUS (AP) has the value

25

associated.

false.

16.9.116 IS_IOSTAT_END (I)

26

1 Description. IOSTAT value test for end of file.

27

2 Class. Elemental function.

28

3 Argument. I shall be of type integer.

29

4 Result Characteristics. Default logical.

30 31

5 Result Value. The result has the value true if and only if I is a value for the stat-variable in an IOSTAT=

32

specifier (12.11.5) that would indicate an end-of-file condition.

16.9.117 IS_IOSTAT_EOR (I)

33

1 Description. IOSTAT value test for end of record.

34

2 Class. Elemental function.

35

3 Argument. I shall be of type integer.

402

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

4 Result Characteristics. Default logical.

2 3

5 Result Value. The result has the value true if and only if I is a value for the stat-variable in an IOSTAT=

4

specifier (12.11.5) that would indicate an end-of-record condition.

16.9.118 KIND (X)

5

1 Description. Value of the kind type parameter of X.

6

2 Class. Inquiry function.

7

3 Argument. X may be of any intrinsic type. It may be a scalar or an array.

8

4 Result Characteristics. Default integer scalar.

9

5 Result Value. The result has a value equal to the kind type parameter value of X.

10

6 Example. KIND (0.0) has the kind type parameter value of default real.

11

16.9.119 LBOUND (ARRAY [, DIM, KIND])

12

1 Description. Lower bound(s).

13

2 Class. Inquiry function.

14

3 Arguments.

15 16

ARRAY

17 18 19

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY. The corresponding actual argument shall not be an optional dummy argument, a disassociated pointer, or an unallocated allocatable.

20

KIND (optional) shall be a scalar integer constant expression.

shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer that is not associated.

21

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

22 23

KIND; otherwise the kind type parameter is that of default integer type. The result is scalar if DIM is present; otherwise, the result is an array of rank one and size n, where n is the rank of ARRAY.

24

5 Result Value.

25 26 27

Case (i):

28 29 30 31

Case (ii):

If DIM is present, ARRAY is a whole array, and either ARRAY is an assumed-size array of rank DIM or dimension DIM of ARRAY has nonzero extent, the result has a value equal to the lower bound for subscript DIM of ARRAY. Otherwise, if DIM is present, the result value is 1. LBOUND (ARRAY) has a value whose ith element is equal to LBOUND (ARRAY, i), for i = 1, 2, . . . , n, where n is the rank of ARRAY. LBOUND (ARRAY, KIND=KIND) has a value whose ith element is equal to LBOUND (ARRAY, i, KIND), for i = 1, 2, . . . , n, where n is the rank of ARRAY.

NOTE 1 If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement 1 ≤ DIM ≤ 0. 32 33 34

6 Examples. If A is declared by the statement

REAL A (2:3, 7:10) then LBOUND (A) is [2, 7] and LBOUND (A, DIM=2) is 7.

ISO/IEC JTC 1/SC 22/WG5/N2184

403

J3/21-007r1

1

WD 1539-1

2021-05-21

16.9.120 LCOBOUND (COARRAY [, DIM, KIND])

2

1 Description. Lower cobound(s) of a coarray.

3

2 Class. Inquiry function.

4

3 Arguments.

5 6 7

COARRAY shall be a coarray and may be of any type. It may be a scalar or an array. If it is allocatable it shall be allocated. If its designator has more than one part-ref , the rightmost part-ref shall have nonzero corank.

8 9 10

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the corank of COARRAY. The corresponding actual argument shall not be an optional dummy argument, a disassociated pointer, or an unallocated allocatable.

11

KIND (optional) shall be a scalar integer constant expression.

12 13 14

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

15

5 Result Value.

KIND; otherwise, the kind type parameter is that of default integer type. The result is scalar if DIM is present; otherwise, the result is an array of rank one and size n, where n is the corank of COARRAY.

16 17

Case (i):

18 19

Case (ii):

20 21 22

If DIM is present, the result has a value equal to the lower cobound for codimension DIM of COARRAY. If DIM is absent, the result has a value whose ith element is equal to the lower cobound for codimension i of COARRAY, for i = 1, 2,. . . , n, where n is the corank of COARRAY.

6 Examples. If A is allocated by the statement ALLOCATE (A [2:3, 7:*]) then LCOBOUND (A) is [2, 7] and

LCOBOUND (A, DIM=2) is 7.

16.9.121 LEADZ (I)

23

1 Description. Number of leading zero bits.

24

2 Class. Elemental function.

25

3 Argument. I shall be of type integer.

26

4 Result Characteristics. Default integer.

27 28 29

5 Result Value. If all of the bits of I are zero, the result has the value BIT_SIZE (I). Otherwise, the result has

30

6 Examples. LEADZ (1) has the value 31 if BIT_SIZE (1) has the value 32.

31

the value BIT_SIZE (I) − 1 − k, where k is the position of the leftmost 1 bit in I. The model for the interpretation of an integer value as a sequence of bits is in 16.3.

16.9.122 LEN (STRING [, KIND])

32

1 Description. Length of a character entity.

33

2 Class. Inquiry function.

34

3 Arguments.

35 36

STRING

37

KIND (optional) shall be a scalar integer constant expression.

38 39

shall be of type character. If it is an unallocated allocatable variable or a pointer that is not associated, its length type parameter shall not be deferred.

4 Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by the

value of KIND; otherwise the kind type parameter is that of default integer type.

404

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

5 Result Value. The result has a value equal to the number of characters in STRING if it is scalar or in an

3

6 Example. If C is declared by the statement

4

7

5

8 LEN (C) has the value 11.

6

element of STRING if it is an array.

CHARACTER (11) C (100)

16.9.123 LEN_TRIM (STRING [, KIND])

7

1 Description. Length without trailing blanks.

8

2 Class. Elemental function.

9

3 Arguments.

10

STRING

11

KIND (optional) shall be a scalar integer constant expression.

shall be of type character.

12 13

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

14 15

5 Result Value. The result has a value equal to the number of characters remaining after any trailing blanks in

16

6 Examples. LEN_TRIM (’ A B ’) has the value 4 and LEN_TRIM (’

17

KIND; otherwise the kind type parameter is that of default integer type. STRING are removed. If the argument contains no nonblank characters, the result is zero. ’) has the value 0.

16.9.124 LGE (STRING_A, STRING_B)

18

1 Description. ASCII greater than or equal.

19

2 Class. Elemental function.

20

3 Arguments.

21

STRING_A shall be default character or ASCII character.

22

STRING_B shall be of type character with the same kind type parameter as STRING_A.

23

4 Result Characteristics. Default logical.

24 25

5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended

26 27

on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII character set, the result is processor dependent. The result is true if the strings are equal or if STRING_A follows STRING_B in the ASCII collating sequence; otherwise, the result is false. NOTE 1 The result is true if both STRING_A and STRING_B are of zero length.

28

6 Example. LGE (’ONE’, ’TWO’) has the value false.

29

16.9.125 LGT (STRING_A, STRING_B)

30

1 Description. ASCII greater than.

31

2 Class. Elemental function.

32

3 Arguments.

33

STRING_A shall be default character or ASCII character.

ISO/IEC JTC 1/SC 22/WG5/N2184

405

J3/21-007r1

1

WD 1539-1

2021-05-21

STRING_B shall be of type character with the same kind type parameter as STRING_A.

2

4 Result Characteristics. Default logical.

3 4 5 6

5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended

on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII character set, the result is processor dependent. The result is true if STRING_A follows STRING_B in the ASCII collating sequence; otherwise, the result is false. NOTE 1 The result is false if both STRING_A and STRING_B are of zero length.

7

6 Example. LGT (’ONE’, ’TWO’) has the value false.

8

16.9.126 LLE (STRING_A, STRING_B)

9

1 Description. ASCII less than or equal.

10

2 Class. Elemental function.

11

3 Arguments.

12

STRING_A shall be default character or ASCII character.

13

STRING_B shall be of type character with the same kind type parameter as STRING_A.

14

4 Result Characteristics. Default logical.

15 16

5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended

17 18

on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII character set, the result is processor dependent. The result is true if the strings are equal or if STRING_A precedes STRING_B in the ASCII collating sequence; otherwise, the result is false. NOTE 1 The result is true if both STRING_A and STRING_B are of zero length.

19

6 Example. LLE (’ONE’, ’TWO’) has the value true.

20

16.9.127 LLT (STRING_A, STRING_B)

21

1 Description. ASCII less than.

22

2 Class. Elemental function.

23

3 Arguments.

24

STRING_A shall be default character or ASCII character.

25

STRING_B shall be of type character with the same kind type parameter as STRING_A.

26

4 Result Characteristics. Default logical.

27 28 29 30

5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended

on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII character set, the result is processor dependent. The result is true if STRING_A precedes STRING_B in the ASCII collating sequence; otherwise, the result is false. NOTE 1 The result is false if both STRING_A and STRING_B are of zero length.

406

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

6 Example. LLT (’ONE’, ’TWO’) has the value true.

16.9.128 LOG (X)

3

1 Description. Natural logarithm.

4

2 Class. Elemental function.

5 6

3 Argument. X shall be of type real or complex. If X is real, its value shall be greater than zero. If X is complex,

7

4 Result Characteristics. Same as X.

8 9 10

5 Result Value. The result has a value equal to a processor-dependent approximation to loge X. A result of type

11 12 13 14

its value shall not be zero.

complex is the principal value with imaginary part ω in the range −π ≤ ω ≤ π. If the real part of X is less than zero and the imaginary part of X is zero, then the imaginary part of the result is approximately π if the imaginary part of X is positive real zero or the processor does not distinguish between positive and negative real zero, and approximately −π if the imaginary part of X is negative real zero. 6 Example. LOG (10.0) has the value 2.3025851 (approximately).

16.9.129 LOG_GAMMA (X)

15

1 Description. Logarithm of the absolute value of the gamma function.

16

2 Class. Elemental function.

17

3 Argument. X shall be of type real. Its value shall not be a negative integer or zero.

18

4 Result Characteristics. Same as X.

19 20

5 Result Value. The result has a value equal to a processor-dependent approximation to the natural logarithm

21

6 Example. LOG_GAMMA (3.0) has the value 0.693 (approximately).

22

of the absolute value of the gamma function of X.

16.9.130 LOG10 (X)

23

1 Description. Common logarithm.

24

2 Class. Elemental function.

25

3 Argument. X shall be of type real. The value of X shall be greater than zero.

26

4 Result Characteristics. Same as X.

27

5 Result Value. The result has a value equal to a processor-dependent approximation to log10 X.

28

6 Example. LOG10 (10.0) has the value 1.0 (approximately).

29

16.9.131 LOGICAL (L [, KIND])

30

1 Description. Conversion between kinds of logical.

31

2 Class. Elemental function.

32

3 Arguments.

33

L

34

KIND (optional) shall be a scalar integer constant expression.

shall be of type logical.

ISO/IEC JTC 1/SC 22/WG5/N2184

407

J3/21-007r1

WD 1539-1

2021-05-21

1 2

4 Result Characteristics. Logical. If KIND is present, the kind type parameter is that specified by the value of

3

5 Result Value. The value is that of L.

4

6 Example. LOGICAL (L .OR. .NOT. L) has the value true and is default logical, regardless of the kind type

KIND; otherwise, the kind type parameter is that of default logical.

5

parameter of the logical variable L.

6

16.9.132 MASKL (I [, KIND])

7

1 Description. Left justified mask.

8

2 Class. Elemental function.

9

3 Arguments.

12

shall be of type integer. It shall be nonnegative and less than or equal to the number of bits z of the model integer defined for bit manipulation contexts in 16.3 for the kind of the result. KIND (optional) shall be a scalar integer constant expression.

13

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

10 11

14

I

KIND; otherwise, the kind type parameter is that of default integer type.

15 16

5 Result Value. The result value has its leftmost I bits set to 1 and the remaining bits set to 0. The model for

17

6 Example. MASKL (3) has the value SHIFTL (7, BIT_SIZE (0) − 3).

18

the interpretation of an integer value as a sequence of bits is in 16.3.

16.9.133 MASKR (I [, KIND])

19

1 Description. Right justified mask.

20

2 Class. Elemental function.

21

3 Arguments.

shall be of type integer. It shall be nonnegative and less than or equal to the number of bits z of the model integer defined for bit manipulation contexts in 16.3 for the kind of the result.

22 23

I

24

KIND (optional) shall be a scalar integer constant expression.

25 26

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

27

5 Result Value. The result value has its rightmost I bits set to 1 and the remaining bits set to 0. The model for

28 29 30

KIND; otherwise, the kind type parameter is that of default integer type. the interpretation of an integer value as a sequence of bits is in 16.3. 6 Example. MASKR (3) has the value 7.

16.9.134 MATMUL (MATRIX_A, MATRIX_B)

31

1 Description. Matrix multiplication.

32

2 Class. Transformational function.

33

3 Arguments.

34

MATRIX_A shall be a rank-one or rank-two array of numeric type or logical type.

35 36 37 38

MATRIX_B shall be of numeric type if MATRIX_A is of numeric type and of logical type if MATRIX_A is of logical type. It shall be an array of rank one or two. MATRIX_A and MATRIX_B shall not both have rank one. The size of the first (or only) dimension of MATRIX_B shall equal the size of the last (or only) dimension of MATRIX_A.

408

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

WD 1539-1

J3/21-007r1

4 Result Characteristics. If the arguments are of numeric type, the type and kind type parameter of the result

are determined by the types of the arguments as specified in 10.1.9.3 for the * operator. If the arguments are of type logical, the result is of type logical with the kind type parameter of the arguments as specified in 10.1.9.3 for the .AND. operator. The shape of the result depends on the shapes of the arguments as follows: If MATRIX_A has shape [n, m] and MATRIX_B has shape [m, k], the result has shape [n, k]. If MATRIX_A has shape [m] and MATRIX_B has shape [m, k], the result has shape [k]. If MATRIX_A has shape [n, m] and MATRIX_B has shape [m], the result has shape [n].

7

Case (i): Case (ii): Case (iii):

8

5 Result Value.

9 10 11

Element (i, j) of the result has the value SUM (MATRIX_A (i, :) * MATRIX_B (:, j)) if the arguments are of numeric type and has the value ANY (MATRIX_A (i, :) .AND. MATRIX_B (:, j)) if the arguments are of logical type. Case (ii): Element (j) of the result has the value SUM (MATRIX_A (:) * MATRIX_B (:, j)) if the arguments are of numeric type and has the value ANY (MATRIX_A (:) .AND. MATRIX_B (:, j)) if the arguments are of logical type. Case (iii): Element (i) of the result has the value SUM (MATRIX_A (i, :) * MATRIX_B (:)) if the arguments are of numeric type and has the value ANY (MATRIX_A (i, :) .AND. MATRIX_B (:)) if the arguments are of logical type.     1 2 1 2 3 6 Examples. Let A and B be the matrices and  2 3 ; let X and Y be the vectors [1, 2] and 2 3 4 3 4 [1, 2, 3].   14 20 Case (i): The result of MATMUL (A, B) is the matrix-matrix product AB with the value . 20 29 Case (ii): The result of MATMUL (X, A) is the vector-matrix product XA with the value [5, 8, 11]. Case (iii): The result of MATMUL (A, Y) is the matrix-vector product AY with the value [14, 20].

5 6

12 13 14 15 16 17

18 19 20 21 22 23

Case (i):

16.9.135 MAX (A1, A2 [, A3, ...])

24

1 Description. Maximum value.

25

2 Class. Elemental function.

26 27

3 Arguments. The arguments shall all have the same type which shall be integer, real, or character and they shall

28 29

4 Result Characteristics. The type and kind type parameter of the result are the same as those of the arguments.

30 31

5 Result Value. The value of the result is that of the largest argument. For arguments of character type, the

32 33 34 35 36 37

all have the same kind type parameter. For arguments of character type, the length of the result is the length of the longest argument. result is the value that would be selected by application of intrinsic relational operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied. If the selected argument is shorter than the longest argument, the result is extended with blanks on the right to the length of the longest argument. 6 Examples. MAX (−9.0, 7.0, 2.0) has the value 7.0, MAX (’Z’, ’BB’) has the value ’Z ’, and MAX ([’A’, ’Z’],

[’BB’, ’Y ’]) has the value [’BB’, ’Z ’].

16.9.136 MAXEXPONENT (X)

38

1 Description. Maximum exponent of a real model.

39

2 Class. Inquiry function.

40

3 Argument. X shall be of type real. It may be a scalar or an array.

ISO/IEC JTC 1/SC 22/WG5/N2184

409

J3/21-007r1

WD 1539-1

2021-05-21

1

4 Result Characteristics. Default integer scalar.

2 3

5 Result Value. The result has the value emax , as defined in 16.4 for the model representing numbers of the same

4

6 Example. MAXEXPONENT (X) has the value 127 for real X whose model is as in 16.4, NOTE 1.

5

type and kind type parameter as X.

16.9.137 MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or MAXLOC (ARRAY [, MASK, KIND, BACK])

6

1 Description. Location(s) of maximum value.

7

2 Class. Transformational function.

8

3 Arguments.

9

ARRAY

shall be an array of type integer, real, or character.

10

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

11

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

12

KIND (optional) shall be a scalar integer constant expression.

13

BACK (optional) shall be a logical scalar.

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

31

32 33 34 35

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

KIND; otherwise the kind type parameter is that of default integer type. If DIM does not appear, the result is an array of rank one and of size equal to the rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where [d1 , d2 , . . . , dn ] is the shape of ARRAY. 5 Result Value.

Case (i):

If DIM does not appear and MASK is absent, the result is a rank-one array whose element values are the values of the subscripts of an element of ARRAY whose value equals the maximum value of all of the elements of ARRAY. The ith subscript returned lies in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If ARRAY has size zero, all elements of the result are zero. Case (ii): If DIM does not appear and MASK is present, the result is a rank-one array whose element values are the values of the subscripts of an element of ARRAY, corresponding to a true element of MASK, whose value equals the maximum value of all such elements of ARRAY. The ith subscript returned lies in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If ARRAY has size zero or every element of MASK has the value false, all elements of the result are zero. Case (iii): If ARRAY has rank one and DIM is specified, the result has a value equal to that of the first element of MAXLOC (ARRAY [, MASK = MASK, KIND = KIND, BACK = BACK]). Otherwise, if DIM is specified, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to MAXLOC (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), DIM = 1 [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), KIND = KIND, BACK = BACK] ). 6 If only one element has the maximum value, that element’s subscripts are returned. Otherwise, if more than one element has the maximum value and BACK is absent or present with the value false, the element whose subscripts are returned is the first such element, taken in array element order. If BACK is present with the value true, the element whose subscripts are returned is the last such element, taken in array element order.

36 37

7 If ARRAY has type character, the result is the value that would be selected by application of intrinsic relational

38

8 Examples.

39 40

Case (i):

operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.

410

The value of MAXLOC ([2, 6, 4, 6]) is [2] and the value of MAXLOC ([2, 6, 4, 6], BACK=.TRUE.) is [4].

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

Case (ii):

2 3

Case (iii):

4 5 6

 0 −5 8 −3 If A has the value  3 4 −1 2 , MAXLOC (A, MASK = A < 6) has the value [3, 2]. This 1 5 6 −4 is independent of the declared lower bounds for A.   1 3 −9 The value of MAXLOC ([5, −9, 3], DIM = 1) is 1. If B has the value , MAXLOC 2 2 6 (B, DIM = 1) is [2, 1, 2] and MAXLOC (B, DIM = 2) is [2, 3]. This is independent of the declared lower bounds for B.

16.9.138 MAXVAL (ARRAY, DIM [, MASK]) or MAXVAL (ARRAY [, MASK])

7

1 Description. Maximum value(s) of array.

8

2 Class. Transformational function.

9

3 Arguments.

10

ARRAY

shall be an array of type integer, real, or character.

11

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

12

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

13 14 15

4 Result Characteristics. The result is of the same type and type parameters as ARRAY. It is scalar if DIM

16

5 Result Value.

17 18

does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

Case (i):

19 20 21 22 23 24

Case (ii):

25 26 27

Case (iii):

The result of MAXVAL (ARRAY) has a value equal to the maximum value of all the elements of ARRAY if the size of ARRAY is not zero. If ARRAY has size zero and type integer or real, the result has the value of the negative number of the largest magnitude supported by the processor for numbers of the type and kind type parameter of ARRAY. If ARRAY has size zero and type character, the result has the value of a string of characters of length LEN (ARRAY), with each character equal to CHAR (0, KIND (ARRAY)). The result of MAXVAL (ARRAY, MASK = MASK) has a value equal to that of MAXVAL (PACK (ARRAY, MASK)). The result of MAXVAL (ARRAY, DIM = DIM [,MASK = MASK]) has a value equal to that of MAXVAL (ARRAY [,MASK = MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to MAXVAL (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).

28 29 30 31

6 If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relational

32

7 Examples.

33 34

Case (i): Case (ii):

35

Case (iii):

36 37

operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.

The value of MAXVAL ([1, 2, 3]) is 3. MAXVAL (C, MASK = C < 0.0) is the maximum of the negative elements of C.   1 3 5 If B is the array , MAXVAL (B, DIM = 1) is [2, 7, 6] and MAXVAL (B, DIM = 2) is 2 7 6 [5, 7].

16.9.139 MERGE (TSOURCE, FSOURCE, MASK)

38

1 Description. Expression value selection.

39

2 Class. Elemental function.

ISO/IEC JTC 1/SC 22/WG5/N2184

411

J3/21-007r1

WD 1539-1

1

3 Arguments.

2

TSOURCE

may be of any type.

3

FSOURCE

shall be of the same type and type parameters as TSOURCE.

4

MASK

shall be of type logical.

2021-05-21

5 6 7

4 Result Characteristics. Same type and type parameters as TSOURCE. Because TSOURCE and FSOURCE

8

5 Result Value. The result is TSOURCE if MASK is true and FSOURCE otherwise.

are required to have the same type and type parameters (for both the declared and dynamic types), the result is polymorphic if and only if both TSOURCE and FSOURCE are polymorphic.

 9

6 Examples. If TSOURCE is the array

1 2

6 4

5 6

  0 , FSOURCE is the array 7

3 4

2 8



and MASK is the  T . T array , where “T” represents true and “.” represents false, then MERGE (TSOURCE, FSOURCE, . . T   1 3 5 MASK) is . The value of MERGE (1.0, 0.0, K > 0) is 1.0 for K = 5 and 0.0 for K = −2. 7 4 6 

10 11

12

16.9.140 MERGE_BITS (I, J, MASK)

13

1 Description. Merge of bits under mask.

14

2 Class. Elemental function.

15

3 Arguments.

16

I

shall be of type integer or a boz-literal-constant.

17

J

shall be of type integer or a boz-literal-constant. If both I and J are of type integer they shall have the same kind type parameter. I and J shall not both be boz-literal-constants. shall be of type integer or a boz-literal-constant. If MASK is of type integer, it shall have the same kind type parameter as each other argument of type integer.

18 19

MASK

20 21

4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.

22 23 24

5 Result Value. If any argument is a boz-literal-constant, it is first converted as if by the intrinsic function

25

6 Example. MERGE_BITS (13, 18, 22) has the value 4.

26

INT to the type and kind type parameter of the result. The result has the value of IOR (IAND (I, MASK), IAND (J, NOT (MASK))).

16.9.141 MIN (A1, A2 [, A3, ...])

27

1 Description. Minimum value.

28

2 Class. Elemental function.

29 30

3 Arguments. The arguments shall all be of the same type which shall be integer, real, or character and they

31 32

4 Result Characteristics. The type and kind type parameter of the result are the same as those of the arguments.

33 34 35 36 37

5 Result Value. The value of the result is that of the smallest argument. For arguments of character type, the

shall all have the same kind type parameter. For arguments of character type, the length of the result is the length of the longest argument. result is the value that would be selected by application of intrinsic relational operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied. If the selected argument is shorter than the longest argument, the result is extended with blanks on the right to the length of the longest argument.

412

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

6 Examples. MIN (−9.0, 7.0, 2.0) has the value −9.0, MIN (’A’, ’YY’) has the value ’A ’, and

MIN ([’Z’, ’A’], [’YY’, ’B ’]) has the value [’YY’, ’A ’].

16.9.142 MINEXPONENT (X)

4

1 Description. Minimum exponent of a real model.

5

2 Class. Inquiry function.

6

3 Argument. X shall be of type real. It may be a scalar or an array.

7

4 Result Characteristics. Default integer scalar.

8 9

5 Result Value. The result has the value emin , as defined in 16.4 for the model representing numbers of the same

10

6 Example. MINEXPONENT (X) has the value −126 for real X whose model is as in 16.4, NOTE 1.

11

type and kind type parameter as X.

16.9.143 MINLOC (ARRAY, DIM [, MASK, KIND, BACK]) or MINLOC (ARRAY [, MASK, KIND, BACK])

12

1 Description. Location(s) of minimum value.

13

2 Class. Transformational function.

14

3 Arguments.

15

ARRAY

shall be an array of type integer, real, or character.

16

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

17

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

18

KIND (optional) shall be a scalar integer constant expression.

19

BACK (optional) shall be a logical scalar.

20 21 22 23

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

24

5 Result Value.

25

KIND; otherwise the kind type parameter is that of default integer type. If DIM does not appear, the result is an array of rank one and of size equal to the rank of ARRAY; otherwise, the result is of rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

Case (i):

26 27 28 29 30 31 32 33

Case (ii):

34 35

Case (iii):

36

37

If DIM does not appear and MASK is absent the result is a rank-one array whose element values are the values of the subscripts of an element of ARRAY whose value equals the minimum value of all the elements of ARRAY. The ith subscript returned lies in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If ARRAY has size zero, all elements of the result are zero. If DIM does not appear and MASK is present, the result is a rank-one array whose element values are the values of the subscripts of an element of ARRAY, corresponding to a true element of MASK, whose value equals the minimum value of all such elements of ARRAY. The ith subscript returned lies in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If ARRAY has size zero or every element of MASK has the value false, all elements of the result are zero. If ARRAY has rank one and DIM is specified, the result has a value equal to that of the first element of MINLOC (ARRAY [, MASK = MASK, KIND = KIND, BACK = BACK]). Otherwise, if DIM is specified, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to MINLOC (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), DIM = 1 [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), KIND = KIND, BACK = BACK] ).

ISO/IEC JTC 1/SC 22/WG5/N2184

413

J3/21-007r1

1 2 3 4

WD 1539-1

2021-05-21

6 If only one element has the minimum value, that element’s subscripts are returned. Otherwise, if more than one

element has the minimum value and BACK is absent or present with the value false, the element whose subscripts are returned is the first such element, taken in array element order. If BACK is present with the value true, the element whose subscripts are returned is the last such element, taken in array element order.

5 6

7 If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relational

7

8 Examples.

8 9

Case (i):

10

Case (ii):

operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.

11 12

Case (iii):

13 14 15

The value of MINLOC ([4, 3, 6, 3]) is [2] and the value of MINLOC ([4, 3, 6, 3], BACK = .TRUE.) is [4].   0 −5 8 −3 If A has the value  3 4 −1 2 , MINLOC (A, MASK = A > −4) has the value [1, 4]. 1 5 6 −4 This is independent of the declared lower bounds for A.   1 3 −9 The value of MINLOC ([5, −9, 3], DIM = 1) is 2. If B has the value , MIN2 2 6 LOC (B, DIM = 1) is [1, 2, 1] and MINLOC (B, DIM = 2) is [3, 1]. This is independent of the declared lower bounds for B.

16.9.144 MINVAL (ARRAY, DIM [, MASK]) or MINVAL (ARRAY [, MASK])

16

1 Description. Minimum value(s) of array.

17

2 Class. Transformational function.

18

3 Arguments.

19

ARRAY

shall be an array of type integer, real, or character.

20

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

21

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

22 23 24

4 Result Characteristics. The result is of the same type and type parameters as ARRAY. It is scalar if DIM

25

5 Result Value.

26 27 28 29

does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

Case (i):

30 31 32 33 34

Case (ii):

35 36 37

Case (iii):

The result of MINVAL (ARRAY) has a value equal to the minimum value of all the elements of ARRAY if the size of ARRAY is not zero. If ARRAY has size zero and type integer or real, the result has the value of the positive number of the largest magnitude supported by the processor for numbers of the type and kind type parameter of ARRAY. If ARRAY has size zero and type character, the result has the value of a string of characters of length LEN (ARRAY), with each character equal to CHAR (n − 1, KIND (ARRAY)), where n is the number of characters in the collating sequence for characters with the kind type parameter of ARRAY. The result of MINVAL (ARRAY, MASK = MASK) has a value equal to that of MINVAL (PACK (ARRAY, MASK)). The result of MINVAL (ARRAY, DIM = DIM [, MASK = MASK]) has a value equal to that of MINVAL (ARRAY [, MASK = MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to MINVAL (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK= MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).

38 39

414

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

6 If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relational

3

7 Examples.

4 5

Case (i): Case (ii):

6

Case (iii):

operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.

7 8

The value of MINVAL ([1, 2, 3]) is 1. MINVAL (C, MASK = C > 0.0) is the minimum of the positive elements of C.   1 3 5 If B is the array , MINVAL (B, DIM = 1) is [1, 3, 5] and MINVAL (B, DIM = 2) is 2 4 6 [1, 2].

16.9.145 MOD (A, P)

9

1 Description. Remainder function.

10

2 Class. Elemental function.

11

3 Arguments.

12

A

shall be of type integer or real.

13

P

shall be of the same type and kind type parameter as A. P shall not be zero.

14

4 Result Characteristics. Same as A.

15

5 Result Value. The value of the result is A − INT (A/P) * P.

16 17

6 Examples. MOD (3.0, 2.0) has the value 1.0 (approximately). MOD (8, 5) has the value 3. MOD (−8, 5) has

18

the value −3. MOD (8, −5) has the value 3. MOD (−8, −5) has the value −3.

16.9.146 MODULO (A, P)

19

1 Description. Modulo function.

20

2 Class. Elemental function.

21

3 Arguments.

22

A

shall be of type integer or real.

23

P

shall be of the same type and kind type parameter as A. P shall not be zero.

24

4 Result Characteristics. Same as A.

25

5 Result Value.

26 27

Case (i):

28

Case (ii):

29 30 31

A is of type integer. MODULO (A, P) has the value R such that A = Q × P + R, where Q is an integer, the inequalities 0 ≤ R < P hold if P > 0, and P < R ≤ 0 hold if P < 0. A is of type real. The value of the result is A − FLOOR (A / P) * P.

6 Examples. MODULO (8, 5) has the value 3. MODULO (−8, 5) has the value 2. MODULO (8, −5) has the

value −2. MODULO (−8, −5) has the value −3.

16.9.147 MOVE_ALLOC (FROM, TO [, STAT, ERRMSG])

32

1 Description. Move an allocation.

33

2 Class. Subroutine, simple if and only if FROM is not a coarray.

34

3 Arguments.

35 36

FROM

may be of any type, rank, and corank. It shall be allocatable and shall not be a coindexed object. It is an INTENT (INOUT) argument.

ISO/IEC JTC 1/SC 22/WG5/N2184

415

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

TO

5 6

STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument.

7

ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.

8

shall be type compatible (7.3.3) with FROM and have the same rank and corank. It shall be allocatable and shall not be a coindexed object. It shall be polymorphic if FROM is polymorphic. It is an INTENT (OUT) argument. Each nondeferred parameter of the declared type of TO shall have the same value as the corresponding parameter of the declared type of FROM.

4 If execution of MOVE_ALLOC is successful, or if STAT_FAILED_IMAGE is assigned to STAT,

17

• On invocation of MOVE_ALLOC, if the allocation status of TO is allocated, it is deallocated. Then, if FROM has an allocation status of allocated on entry to MOVE_ALLOC, TO becomes allocated with dynamic type, type parameters, bounds, cobounds, and value identical to those that FROM had on entry to MOVE_ALLOC. Note that if FROM and TO are the same variable, it shall be unallocated when MOVE_ALLOC is invoked. • If TO has the TARGET attribute, any pointer associated with FROM on entry to MOVE_ALLOC becomes correspondingly associated with TO. If TO does not have the TARGET attribute, the pointer association status of any pointer associated with FROM on entry becomes undefined. • The allocation status of FROM becomes unallocated.

18

5 When a reference to MOVE_ALLOC is executed for which the FROM argument is a coarray, there is an implicit

19 20 21 22

synchronization of all active images of the current team. On those images, execution of the segment (11.7.2) following the CALL statement is delayed until all other active images of the current team have executed the same statement the same number of times. When such a reference is executed, if any image of the current team has stopped or failed, an error condition occurs.

9 10 11 12 13 14 15 16

23

6 If STAT is present and execution is successful, it is assigned the value zero.

24

7 If an error condition occurs,

25 26 27 28 29 30 31 32

• if STAT is absent, error termination is initiated; • otherwise, if FROM is a coarray and the current team contains a stopped image, STAT is assigned the value STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV; • otherwise, if FROM is a coarray and the current team contains a failed image, and no other error condition occurs, STAT is assigned the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV; • otherwise, STAT is assigned a processor-dependent positive value that differs from that of STAT_STOPPED_IMAGE or STAT_FAILED_IMAGE.

33 34

8 If the ERRMSG argument is present and an error condition occurs, it is assigned an explanatory message. If no

35 36

9 Example. The example below demonstrates reallocation of GRID to twice its previous size, with its previous

error condition occurs, the definition status and value of ERRMSG are unchanged. contents evenly distributed over the new elements so that intermediate points can be inserted. REAL,ALLOCATABLE :: GRID(:),TEMPGRID(:) ... ALLOCATE(GRID(-N:N)) ! initial allocation of GRID ... ALLOCATE(TEMPGRID(-2*N:2*N)) ! allocate bigger grid TEMPGRID(::2)=GRID ! distribute values to new locations CALL MOVE_ALLOC(TO=GRID,FROM=TEMPGRID)

37 38 39 40 41 42 43 44

The old grid is deallocated because TO is INTENT (OUT), and GRID then takes over the new grid allocation.

416

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 It is expected that the implementation of allocatable objects will typically involve descriptors to locate the allocated storage; MOVE_ALLOC could then be implemented by transferring the contents of the descriptor for FROM to the descriptor for TO and clearing the descriptor for FROM. 1

16.9.148 MVBITS (FROM, FROMPOS, LEN, TO, TOPOS)

2

1 Description. Copy a sequence of bits.

3

2 Class. Simple elemental subroutine.

4

3 Arguments.

5

FROM

6 7 9

FROMPOS shall be of type integer and nonnegative. It is an INTENT (IN) argument. FROMPOS + LEN shall be less than or equal to BIT_SIZE (FROM). The model for the interpretation of an integer value as a sequence of bits is in 16.3. LEN shall be of type integer and nonnegative. It is an INTENT (IN) argument.

10

TO

shall be a variable of the same type and kind type parameter value as FROM and may be associated with FROM (15.9.3). It is an INTENT (INOUT) argument. TO is defined by copying the sequence of bits of length LEN, starting at position FROMPOS of FROM to position TOPOS of TO. No other bits of TO are altered. On return, the LEN bits of TO starting at TOPOS are equal to the value that the LEN bits of FROM starting at FROMPOS had on entry. The model for the interpretation of an integer value as a sequence of bits is in 16.3.

TOPOS

shall be of type integer and nonnegative. It is an INTENT (IN) argument. TOPOS + LEN shall be less than or equal to BIT_SIZE (TO).

8

11 12 13 14 15 16 17 18 19

shall be of type integer. It is an INTENT (IN) argument.

4 Example. If TO has the initial value 6, its value after the statement CALL MVBITS (7, 2, 2, TO, 0) is 5.

16.9.149 NEAREST (X, S)

20

1 Description. Adjacent machine number.

21

2 Class. Elemental function.

22

3 Arguments.

23

X

shall be of type real.

24

S

shall be of type real and not equal to zero.

25

4 Result Characteristics. Same as X.

26 27

5 Result Value. The result has a value equal to the machine-representable number distinct from X and nearest

28

6 Example. NEAREST (3.0, 2.0) has the value 3 + 2−22 on a machine whose representation for default real is

29

to it in the direction of the ∞ with the same sign as S. that of the model in 16.4, NOTE 1. NOTE 1 Unlike other floating-point manipulation functions, NEAREST operates on machine-representable numbers rather than model numbers. On many systems there are machine-representable numbers that lie between adjacent model numbers.

ISO/IEC JTC 1/SC 22/WG5/N2184

417

J3/21-007r1

WD 1539-1

2021-05-21

1

16.9.150 NEW_LINE (A)

2

1 Description. Newline character.

3

2 Class. Inquiry function.

4

3 Argument. A shall be of type character. It may be a scalar or an array.

5

4 Result Characteristics. Character scalar of length one with the same kind type parameter as A.

6

5 Result Value.

7 8

Case (i):

9

Case (ii): Case (iii):

10 11 12 13 14

Case (iv):

If A is default character and the character in position 10 of the ASCII collating sequence is representable in the default character set, then the result is ACHAR (10). If A is ASCII character or ISO 10646 character, then the result is CHAR (10, KIND (A)). Otherwise, the result is a processor-dependent character that represents a newline in output to files connected for formatted stream output if there is such a character. Otherwise, the result is the blank character.

6 Example. If there is a suitable newline character, and unit 10 is connected for formatted stream output, the

statement

15

WRITE (10, ’(A)’) ’New’//NEW_LINE(’a’)//’Line’

16

will write a record containing “New” and then a record containing “Line”.

17

16.9.151 NEXT (A [, STAT])

18

1 Description. Next enumeration value.

19

2 Class. Elemental function.

20

3 Arguments.

21

A

22 23 24 25

STAT (optional) shall be an integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If A is equal to the last enumerator of its type, it is assigned a processor-dependent positive value; otherwise, it is assigned the value zero. If STAT would have been assigned a nonzero value but is not present, error termination is initiated.

shall be of enumeration type.

26

4 Result Characteristics. Same as A.

27 28

5 Result Value. If A is equal to the last enumerator of its type, the value of the result is that of A. Otherwise,

29 30

6 Example. If the enumerators of an enumeration type are EN1, EN2, EN3, and EN4, NEXT (EN1) is equal to

31

the value of the result is the next enumerator following the value of A. EN2, and NEXT (EN4, ISTAT) is equal to EN4 and a positive value is assigned to ISTAT.

16.9.152 NINT (A [, KIND])

32

1 Description. Nearest integer.

33

2 Class. Elemental function.

34

3 Arguments.

35

A

36

KIND (optional) shall be a scalar integer constant expression.

37 38

shall be of type real.

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

KIND; otherwise, the kind type parameter is that of default integer type.

418

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

5 Result Value. The result is the integer nearest A, or if there are two integers equally near A, the result is

3

6 Example. NINT (2.783) has the value 3.

4

whichever such integer has the greater magnitude.

16.9.153 NORM2 (X) or NORM2 (X, DIM)

5

1 Description. L2 norm of an array.

6

2 Class. Transformational function.

7

3 Arguments.

8

X

shall be a real array.

9

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of X.

10 11 12

4 Result Characteristics. The result is of the same type and type parameters as X. It is scalar if DIM does not

13

5 Result Value.

appear; otherwise the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where n is the rank of X and [d1 , d2 , . . . , dn ] is the shape of X.

14 15 16

Case (i):

17 18 19

Case (ii):

20

The result of NORM2 (X) has a value equal to a processor-dependent approximation to the generalized L2 norm of X, which is the square root of the sum of the squares of the elements of X. If X has size zero, the result has the value zero. The result of NORM2 (X, DIM=DIM) has a value equal to that of NORM2 (X) if X has rank one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . sn ) of the result is equal to NORM2 (X(s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . sn )).

6 It is recommended that the processor compute the result without undue overflow or underflow.



21 22 23 24

 1.0 2.0 7 Example. The value of NORM2 ([3.0, 4.0]) is 5.0 (approximately). If X has the value then the 3.0 4.0 value of NORM2 (X, DIM=1) is [3.162, 4.472] (approximately) and the value of NORM2 (X, DIM=2) is [2.236, 5.0] (approximately).

16.9.154 NOT (I)

25

1 Description. Bitwise complement.

26

2 Class. Elemental function.

27

3 Argument. I shall be of type integer.

28

4 Result Characteristics. Same as I.

29

5 Result Value. The result has the value obtained by complementing I bit-by-bit according to the following table:

I 1 0

NOT (I) 0 1

30

6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.

31

7 Example. If I is represented by the string of bits 01010101, NOT (I) has the binary value 10101010.

ISO/IEC JTC 1/SC 22/WG5/N2184

419

J3/21-007r1

1

WD 1539-1

2021-05-21

16.9.155 NULL ([MOLD])

2

1 Description. Disassociated pointer or unallocated allocatable entity.

3

2 Class. Transformational function.

4 5 6

3 Argument. MOLD shall be a pointer or allocatable. It may be of any type or may be a procedure pointer.

7 8

4 Result Characteristics. If MOLD is present, the characteristics are the same as MOLD. If MOLD has deferred

If MOLD is a pointer its pointer association status may be undefined, disassociated, or associated. If MOLD is allocatable its allocation status may be allocated or unallocated. It need not be defined with a value. type parameters, those type parameters of the result are deferred.

9

5 If MOLD is absent, the characteristics of the result are determined by the entity with which the reference is

10 11 12

associated. See Table 16.5. MOLD shall not be absent in any other context. If any type parameters of the contextual entity are deferred, those type parameters of the result are deferred. If any type parameters of the contextual entity are assumed, MOLD shall be present.

13 14

6 If the context of the reference to NULL is an actual argument in a generic procedure reference, MOLD shall be

present if the type, type parameters, or rank are required to resolve the generic reference. Table 16.5: Characteristics of the result of NULL ( ) Appearance of NULL ( )

Type, type parameters, and rank of result:

right side of a pointer assignment initialization for an object in a declaration default initialization for a component in a structure constructor as an actual argument in a DATA statement

pointer on the left side the object the component the corresponding component the corresponding dummy argument the corresponding pointer object

15

7 Result. The result is a disassociated pointer or an unallocated allocatable entity.

16

8 Examples.

17 18

Case (i):

19

Case (ii):

20 21 22 23 24 25 26 27 28 29 30 31

420

REAL, POINTER, DIMENSION (:) :: VEC => NULL ( ) defines the initial association status of VEC to be disassociated. The MOLD argument is required in the following: INTERFACE GEN SUBROUTINE S1 (J, PI) INTEGER J INTEGER, POINTER :: PI END SUBROUTINE S1 SUBROUTINE S2 (K, PR) INTEGER K REAL, POINTER :: PR END SUBROUTINE S2 END INTERFACE REAL, POINTER :: REAL_PTR CALL GEN (7, NULL (REAL_PTR) ) ! Invokes S2

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

16.9.156 NUM_IMAGES ( ) or NUM_IMAGES (TEAM) or NUM_IMAGES (TEAM_NUMBER)

2

1 Description. Number of images.

3

2 Class. Transformational function.

4

3 Arguments.

5 6

TEAM

shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, with a value that identifies the current or an ancestor team.

7 8

TEAM_NUMBER shall be an integer scalar. It shall identify the initial team or a sibling team of the current team.

9

4 Result Characteristics. Default integer scalar.

10

5 Result Value. The number of images in the specified team, or in the current team if no team is specified.

11

6 Example. The following code uses image 1 to read data and broadcast it to other images.

REAL :: P[*] IF (THIS_IMAGE()==1) THEN READ (6,*) P DO I = 2, NUM_IMAGES() P[I] = P END DO END IF SYNC ALL

12 13 14 15 16 17 18 19

20

16.9.157 OUT_OF_RANGE (X, MOLD [, ROUND])

21

1 Description. Whether a value cannot be converted safely.

22

2 Class. Elemental function.

23

3 Arguments.

24

X

shall be of type integer or real.

25

MOLD

shall be an integer or real scalar. If it is a variable, it need not be defined.

26 27

ROUND (optional) shall be a logical scalar. ROUND shall be present only if X is of type real and MOLD is of type integer.

28

4 Result Characteristics. Default logical.

29

5 Result Value.

30 31 32 33

Case (i):

34 35

Case (ii):

36 37 38 39

Case (iii):

If MOLD is of type integer, and ROUND is absent or present with the value false, the result is true if and only if the value of X is an IEEE infinity or NaN, or if the integer with largest magnitude that lies between zero and X inclusive is not representable by objects with the type and kind of MOLD. If MOLD is of type integer, and ROUND is present with the value true, the result is true if and only if the value of X is an IEEE infinity or NaN, or if the integer nearest X, or the integer of greater magnitude if two integers are equally near to X, is not representable by objects with the type and kind of MOLD. Otherwise, the result is true if and only if the value of X is an IEEE infinity or NaN that is not supported by objects of the type and kind of MOLD, or if X is a finite number and the result of

ISO/IEC JTC 1/SC 22/WG5/N2184

421

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

rounding the value of X (according to the IEEE rounding mode if appropriate) to the extended model for the kind of MOLD has magnitude larger than that of the largest finite number with the same sign as X that is representable by objects with the type and kind of MOLD.

4 5

6 Examples. If INT8 is the kind value for an 8-bit binary integer type, OUT_OF_RANGE (−128.5, 0_INT8)

will have the value false and OUT_OF_RANGE (−128.5, 0_INT8, .TRUE.) will have the value true. NOTE 1 MOLD is required to be a scalar because the only information taken from it is its type and kind. Allowing an array MOLD would require that it be conformable with X. ROUND is scalar because allowing an array rounding mode would have severe performance difficulties on many processors.

6

16.9.158 PACK (ARRAY, MASK [, VECTOR])

7

1 Description. Array packed into a vector.

8

2 Class. Transformational function.

9

3 Arguments.

10

ARRAY

shall be an array of any type.

11

MASK

shall be of type logical and shall be conformable with ARRAY.

12 13

VECTOR (optional) shall be of the same type and type parameters as ARRAY and shall have rank one. VECTOR shall have at least as many elements as there are true elements in MASK. If MASK is scalar with the value true, VECTOR shall have at least as many elements as there are in ARRAY.

14 15 16 17 18

4 Result Characteristics.

19 20

5 Result Value. Element i of the result is the element of ARRAY that corresponds to the ith true element of

21

22 23 24 25

The result is an array of rank one with the same type and type parameters as ARRAY. If VECTOR is present, the result size is that of VECTOR; otherwise, the result size is the number t of true elements in MASK unless MASK is scalar with the value true, in which case the result size is the size of ARRAY.

MASK, taking elements in array element order, for i = 1, 2, . . . , t. If VECTOR is present and has size n > t, element i of the result has the value VECTOR (i), for i = t + 1, . . . , n.   0 0 0 6 Examples. The nonzero elements of an array M with the value  9 0 0  can be “gathered” by the func0 0 7 tion PACK. The result of PACK (M, MASK = M /= 0) is [9, 7] and the result of PACK (M, M /= 0, VECTOR = [2, 4, 6, 8, 10, 12]) is [9, 7, 6, 8, 10, 12].

16.9.159 PARITY (MASK) or PARITY (MASK, DIM)

26

1 Description. Array reduced by .NEQV. operation.

27

2 Class. Transformational function.

28

3 Arguments.

29

MASK

shall be a logical array.

30

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.

31 32 33 34

4 Result Characteristics. The result is of type logical with the same kind type parameter as MASK. It is scalar

if DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of MASK. 5 Result Value.

422

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

Case (i):

3 4 5

Case (ii):

6

6 Examples.

7

Case (i):

8

Case (ii):

9

WD 1539-1

J3/21-007r1

The result of PARITY (MASK) has the value true if an odd number of the elements of MASK are true, and false otherwise. If MASK has rank one, PARITY (MASK, DIM) is equal to PARITY (MASK). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of PARITY (MASK, DIM) is equal to PARITY (MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )).

The value of PARITY ([T, T, T, F]) is true if T has the value true and F has the value false.   T T F If B is the array , where T has the value true and F has the value false, then T T T PARITY (B, DIM=1) has the value [F, F, T] and PARITY (B, DIM=2) has the value [F, T].

10

16.9.160 POPCNT (I)

11

1 Description. Number of one bits.

12

2 Class. Elemental function.

13

3 Argument. I shall be of type integer.

14

4 Result Characteristics. Default integer.

15

5 Result Value. The result value is equal to the number of one bits in the sequence of bits of I. The model for

16

the interpretation of an integer value as a sequence of bits is in 16.3.

17

6 Examples. POPCNT ([1, 2, 3, 4, 5, 6]) has the value [1, 1, 2, 1, 2, 2].

18

16.9.161 POPPAR (I)

19

1 Description. Parity expressed as 0 or 1.

20

2 Class. Elemental function.

21

3 Argument. I shall be of type integer.

22

4 Result Characteristics. Default integer.

23

5 Result Value. POPPAR (I) has the value 1 if POPCNT (I) is odd, and 0 if POPCNT (I) is even.

24

6 Examples. POPPAR ([1, 2, 3, 4, 5, 6]) has the value [1, 1, 0, 1, 0, 0].

25

16.9.162 PRECISION (X)

26

1 Description. Decimal precision of a real model.

27

2 Class. Inquiry function.

28

3 Argument. X shall be of type real or complex. It may be a scalar or an array.

29

4 Result Characteristics. Default integer scalar.

30 31 32

5 Result Value. The result has the value INT ((p − 1) * LOG10 (b)) + k, where b and p are as defined in 16.4

33

6 Example. PRECISION (X) has the value INT (23 * LOG10 (2.)) = INT (6.92. . . ) = 6 for real X whose model

34

for the model representing real numbers with the same value for the kind type parameter as X, and where k is 1 if b is an integral power of 10 and 0 otherwise. is as in 16.4, NOTE 1.

ISO/IEC JTC 1/SC 22/WG5/N2184

423

J3/21-007r1

1

WD 1539-1

2021-05-21

16.9.163 PRESENT (A)

2

1 Description. Presence of optional argument.

3

2 Class. Inquiry function.

4 5

3 Argument. A shall be the name of an optional dummy argument that is accessible in the subprogram in which

6

4 Result Characteristics. Default logical scalar.

7

5 Result Value. The result has the value true if A is present (15.5.2.12) and otherwise has the value false.

8

the PRESENT function reference appears. There are no other requirements on A.

16.9.164 PREVIOUS (A [, STAT])

9

1 Description. Previous enumeration value.

10

2 Class. Elemental function.

11

3 Arguments.

12

A

shall be of enumeration type.

13 14 15 16

STAT (optional) shall be an integer scalar with a decimal exponent range of at least four. It is an INTENT (OUT) argument. If A is equal to the first enumerator of its type, it is assigned a processor-dependent positive value; otherwise, it is assigned the value zero. If STAT would have been assigned a nonzero value but is not present, error termination is initiated.

17

4 Result Characteristics. Same as A.

18 19

5 Result Value. If A is equal to the first enumerator of its type, the value of the result is that of A. Otherwise,

20 21

6 Example. If the enumerators of an enumeration type are EN1, EN2, EN3, and EN4, PREVIOUS (EN3) is equal

22

the value of the result is the enumerator preceding the value of A. to EN2, and PREVIOUS (EN1, ISTAT) is equal to EN1 and a positive value is assigned to ISTAT.

16.9.165 PRODUCT (ARRAY, DIM [, MASK]) or PRODUCT (ARRAY [, MASK])

23

1 Description. Array reduced by multiplication.

24

2 Class. Transformational function.

25

3 Arguments.

26

ARRAY

shall be an array of numeric type.

27

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

28

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

29 30 31

4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar if

32

5 Result Value.

DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

33 34

Case (i):

35 36

Case (ii):

37

424

The result of PRODUCT (ARRAY) has a value equal to a processor-dependent approximation to the product of all the elements of ARRAY or has the value one if ARRAY has size zero. The result of PRODUCT (ARRAY, MASK = MASK) has a value equal to a processor-dependent approximation to the product of the elements of ARRAY corresponding to the true elements of MASK or has the value one if there are no true elements.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

Case (iii):

J3/21-007r1

If ARRAY has rank one, PRODUCT (ARRAY, DIM = DIM [, MASK = MASK]) has a value equal to that of PRODUCT (ARRAY [, MASK = MASK ]). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of PRODUCT (ARRAY, DIM = DIM [, MASK = MASK]) is equal to PRODUCT (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).

4 5 6

6 Examples.

7 8

Case (i): Case (ii):

9

Case (iii):

10 11

WD 1539-1

The value of PRODUCT ([1, 2, 3]) is 6. PRODUCT (C, MASK = C > 0.0) forms the product of the positive elements of C.   1 3 5 If B is the array , PRODUCT (B, DIM = 1) is [2, 12, 30] and PRODUCT (B, DIM = 2) 2 4 6 is [15, 48].

16.9.166 RADIX (X)

12

1 Description. Base of a numeric model.

13

2 Class. Inquiry function.

14

3 Argument. X shall be of type integer or real. It may be a scalar or an array.

15

4 Result Characteristics. Default integer scalar.

16 17

5 Result Value. The result has the value r if X is of type integer and the value b if X is of type real, where r and

18

6 Example. RADIX (X) has the value 2 for real X whose model is as in 16.4, NOTE 1.

19

16.9.167 RANDOM_INIT (REPEATABLE, IMAGE_DISTINCT)

b are as defined in 16.4 for the model representing numbers of the same type and kind type parameter as X.

20

1 Description. Initialize pseudorandom number generator.

21

2 Class. Subroutine.

22

3 Arguments.

23

REPEATABLE shall be a logical scalar. It is an INTENT (IN) argument.

24

IMAGE_DISTINCT shall be a logical scalar. It is an INTENT (IN) argument.

25 26

4 The effect of calling RANDOM_INIT depends on the values of the REPEATABLE and IMAGE_DISTINCT

27 28 29 30

CALL RANDOM_INIT (REPEATABLE=true, IMAGE_DISTINCT=true) is equivalent to invoking RANDOM_SEED with a processor-dependent value for PUT that is different on every invoking image. In each execution of the program with the same execution environment, if the invoking image index value in the initial team is the same, the value for PUT shall be the same. CALL RANDOM_INIT(REPEATABLE=true, IMAGE_DISTINCT=false) is equivalent to invoking RANDOM_SEED with a processor-dependent value for PUT that is the same on every invoking image. In each execution of the program with the same execution environment, the value for PUT shall be the same. CALL RANDOM_INIT(REPEATABLE=false, IMAGE_DISTINCT=true) is equivalent to invoking RANDOM_SEED with a processor-dependent value for PUT that is different on every invoking image. Different values for PUT shall be used for subsequent invocations, and for each execution of the program. CALL RANDOM_INIT(REPEATABLE=false, IMAGE_DISTINCT=false) is equivalent to invoking RANDOM_SEED with a processor-dependent value for PUT that is the same on every invoking image. Different values for PUT shall be used for subsequent invocations, and for each execution of the program.

arguments: Case (i):

31 32 33 34

Case (ii):

35 36 37

Case (iii):

38 39 40 41 42

Case (iv):

ISO/IEC JTC 1/SC 22/WG5/N2184

425

J3/21-007r1

WD 1539-1

2021-05-21

1 2

5 In each of these cases, a different processor-dependent value for PUT shall result in a different sequence of

3 4

6 Example. The following statement initializes the pseudorandom number generator of the invoking image so that

5

pseudorandom numbers. the pseudorandom number sequence will differ from that of other images that execute a similar statement, and will be different on subsequent execution of the program. CALL RANDOM_INIT (REPEATABLE=.FALSE., IMAGE_DISTINCT=.TRUE.)

6

7

16.9.168 RANDOM_NUMBER (HARVEST)

8

1 Description. Generate pseudorandom number(s).

9

2 Class. Subroutine.

10 11

3 Argument. HARVEST shall be of type real. It is an INTENT (OUT) argument. It may be a scalar or an array.

12

4 Example.

It is assigned pseudorandom numbers from the uniform distribution in the interval 0 ≤ x < 1.

REAL X, Y (10, 10) ! Initialize X with a pseudorandom number CALL RANDOM_NUMBER (HARVEST = X) CALL RANDOM_NUMBER (Y) ! X and Y contain uniformly distributed random numbers

13 14 15 16 17

18

16.9.169 RANDOM_SEED ([SIZE, PUT, GET])

19

1 Description. Pseudorandom number generator control.

20

2 Class. Subroutine.

21

3 Arguments. There shall either be exactly one or no arguments present.

23

SIZE (optional) shall be a default integer scalar. It is an INTENT (OUT) argument. It is assigned the number N of integers that the processor uses to hold the value of the seed.

24 25 26

PUT (optional) shall be a default integer array of rank one and size ≥ N . It is an INTENT (IN) argument. It is used in a processor-dependent manner to compute the seed value accessed by the pseudorandom number generator.

27 28

GET (optional) shall be a default integer array of rank one and size ≥ N . It is an INTENT (OUT) argument. It is assigned the value of the seed.

22

29

4 If no argument is present, the processor assigns a processor-dependent value to the seed.

30 31

5 The pseudorandom number generator used by RANDOM_NUMBER maintains a seed on each image that is

32 33 34

updated during the execution of RANDOM_NUMBER and that can be retrieved or changed by RANDOM_INIT or RANDOM_SEED1 . Computation of the seed from the argument PUT is performed in a processor-dependent manner. The value assigned to GET need not be the same as the value of PUT in an immediately preceding reference to RANDOM_SEED. For example, following execution of the statements CALL RANDOM_SEED (PUT=SEED1) CALL RANDOM_SEED (GET=SEED2)

35 36 37 38 39

SEED2 need not equal SEED1. When the values differ, the use of either value as the PUT argument in a subsequent call to RANDOM_SEED shall result in the same sequence of pseudorandom numbers being generated. For example, after execution of the statements 1 These three procedures only affect the value of the seed on the invoking image.

426

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2 3 4 5

7

X2 equals X1. 6 Examples.

CALL RANDOM_SEED ! Processor-dependent initialization CALL RANDOM_SEED (SIZE = K) ! Puts size of seed in K CALL RANDOM_SEED (PUT = SEED (1 : K)) ! Define seed CALL RANDOM_SEED (GET = OLD (1 : K)) ! Read current seed

8 9 10 11

12

16.9.170 RANGE (X)

13

1 Description. Decimal exponent range of a numeric model (16.4).

14

2 Class. Inquiry function.

15

3 Argument. X shall be of type integer, real, or complex. It may be a scalar or an array.

16

4 Result Characteristics. Default integer scalar.

17

5 Result Value.

18

Case (i): Case (ii): Case (iii):

19 20 21 22 23

J3/21-007r1

CALL RANDOM_SEED (PUT=SEED1) CALL RANDOM_SEED (GET=SEED2) CALL RANDOM_NUMBER (X1) CALL RANDOM_SEED (PUT=SEED2) CALL RANDOM_NUMBER (X2)

1

6

WD 1539-1

If X is of type integer, the result has the value INT (LOG10 (HUGE (X))). If X is of type real, the result has the value INT (MIN (LOG10 (HUGE (X)), −LOG10 (TINY (X)))). If X is of type complex, the result has the value RANGE (REAL (X)).

6 Examples. RANGE (X) has the value 38 for real X whose model is as in 16.4, NOTE 1, because in this case

HUGE (X) = (1 − 2−24 ) × 2127 and TINY (X) = 2−127 .

16.9.171 RANK (A)

24

1 Description. Rank of a data object.

25

2 Class. Inquiry function.

26

3 Argument. A shall be a data object of any type.

27

4 Result Characteristics. Default integer scalar.

28

5 Result Value. The value of the result is the rank of A.

29 30

6 Example. If X is an assumed-rank dummy argument and its associated effective argument is an array of rank

3, RANK(X) has the value 3.

31

16.9.172 REAL (A [, KIND])

32

1 Description. Conversion to real type.

33

2 Class. Elemental function.

34

3 Arguments.

35

A

shall be of type integer, real, or complex, or a boz-literal-constant.

ISO/IEC JTC 1/SC 22/WG5/N2184

427

J3/21-007r1

1 2

4 Result Characteristics. Real.

Case (i):

6 7 8

Case (ii):

9 10

Case (iii):

11

13 14 15 16 17 18 19 20 21

2021-05-21

KIND (optional) shall be a scalar integer constant expression.

3 4 5

12

WD 1539-1

If A is of type integer or real and KIND is present, the kind type parameter is that specified by the value of KIND. If A is of type integer or real and KIND is not present, the kind type parameter is that of default real kind. If A is of type complex and KIND is present, the kind type parameter is that specified by the value of KIND. If A is of type complex and KIND is not present, the kind type parameter is the kind type parameter of A. If A is a boz-literal-constant and KIND is present, the kind type parameter is that specified by the value of KIND. If A is a boz-literal-constant and KIND is not present, the kind type parameter is that of default real kind.

5 Result Value.

Case (i): Case (ii): Case (iii):

If A is of type integer or real, the result is equal to a processor-dependent approximation to A. If A is of type complex, the result is equal to a processor-dependent approximation to the real part of A. If A is a boz-literal-constant, the value of the result is the value whose internal representation as a bit sequence is the same as that of A as modified by padding or truncation according to 16.3.3. The interpretation of the bit sequence is processor dependent.

6 Examples. REAL (−3) has the value −3.0. REAL (Z) has the same kind type parameter and the same value

as the real part of the complex variable Z.

16.9.173 REDUCE (ARRAY, OPERATION [, MASK, IDENTITY, ORDERED]) or REDUCE (ARRAY, OPERATION, DIM [, MASK, IDENTITY, ORDERED])

22

1 Description. General reduction of array.

23

2 Class. Transformational function.

24

3 Arguments.

25

ARRAY

26 27 28 29 30 31

OPERATION shall be a pure function with exactly two arguments; each argument shall be a scalar, nonallocatable, nonpointer, nonpolymorphic, nonoptional dummy data object with the same declared type and type parameters as ARRAY. If one argument has the ASYNCHRONOUS, TARGET, or VALUE attribute, the other shall have that attribute. Its result shall be a nonpolymorphic scalar and have the same declared type and type parameters as ARRAY. OPERATION should implement a mathematically associative operation. It need not be commutative.

32

DIM

33

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

34

IDENTITY (optional) shall be scalar with the same declared type and type parameters as ARRAY.

35

ORDERED (optional) shall be a logical scalar.

shall be an array of any type.

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

36 37 38

4 Result Characteristics. The result is of the same declared type and type parameters as ARRAY. It is scalar

39

5 Result Value.

40 41 42

if DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

Case (i):

428

The result of REDUCE (ARRAY, OPERATION [, IDENTITY = IDENTITY, ORDERED = ORDERED]) over the sequence of values in ARRAY is the result of an iterative process. The initial order of the sequence is array element order. While the sequence has more than one element,

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9

Case (ii):

10 11 12 13 14

Case (iii):

15

16

17 18 19 20

J3/21-007r1

each iteration involves the execution of r = OPERATION(x, y) for adjacent x and y in the sequence, with x immediately preceding y, and the subsequent replacement of x and y with r; if ORDERED is present with the value true, x and y shall be the first two elements of the sequence. The process continues until the sequence has only one element which is the value of the reduction. If the initial sequence is empty, the result has the value IDENTITY if IDENTITY is present, and otherwise, error termination is initiated. The result of REDUCE (ARRAY, OPERATION, MASK = MASK [, IDENTITY = IDENTITY, ORDERED = ORDERED]) is as for Case (i) except that the initial sequence is only those elements of ARRAY for which the corresponding elements of MASK are true. If ARRAY has rank one, REDUCE (ARRAY, OPERATION, DIM = DIM [, MASK = MASK, IDENTITY = IDENTITY, ORDERED = ORDERED]) has a value equal to that of REDUCE (ARRAY, OPERATION [, MASK = MASK, IDENTITY = IDENTITY, ORDERED = ORDERED]). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of REDUCE (ARRAY, OPERATION, DIM = DIM [, MASK = MASK, IDENTITY = IDENTITY, ORDERED = ORDERED]) is equal to REDUCE (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), OPERATION = OPERATION, DIM=1 [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), IDENTITY = IDENTITY, ORDERED = ORDERED] ).

6 Examples. The following examples all use the function MY_MULT, which returns the product of its two integer

arguments. Case (i): Case (ii):

21 22

WD 1539-1

Case (iii):

23

The value of REDUCE ([1, 2, 3], MY_MULT) is 6. REDUCE (C, MY_MULT, MASK= C > 0, IDENTITY=1) forms the product of the positive elements of C.   1 3 5 If B is the array , REDUCE (B, MY_MULT, DIM = 1) is [2, 12, 30] and REDUCE (B, 2 4 6 MY_MULT, DIM = 2) is [15, 48].

NOTE 1 If OPERATION is not computationally associative, REDUCE without ORDERED=.TRUE. with the same argument values might not always produce the same result, as the processor can apply the associative law to the evaluation. 24

16.9.174 REPEAT (STRING, NCOPIES)

25

1 Description. Repetitive string concatenation.

26

2 Class. Transformational function.

27

3 Arguments.

28

STRING

shall be a character scalar.

29

NCOPIES

shall be an integer scalar. Its value shall not be negative.

30 31

4 Result Characteristics. Character scalar of length NCOPIES times that of STRING, with the same kind type

32

5 Result Value. The value of the result is the concatenation of NCOPIES copies of STRING.

33

6 Examples. REPEAT (’H’, 2) has the value HH. REPEAT (’XYZ’, 0) has the value of a zero-length string.

parameter as STRING.

ISO/IEC JTC 1/SC 22/WG5/N2184

429

J3/21-007r1

1

WD 1539-1

2021-05-21

16.9.175 RESHAPE (SOURCE, SHAPE [, PAD, ORDER])

2

1 Description. Arbitrary shape array construction.

3

2 Class. Transformational function.

4

3 Arguments.

5 6 7

SOURCE

shall be an array of any type. If PAD is absent or of size zero, the size of SOURCE shall be greater than or equal to PRODUCT (SHAPE). The size of the result is the product of the values of the elements of SHAPE.

8 9 10

SHAPE

shall be a rank-one integer array. SIZE (x), where x is the actual argument corresponding to SHAPE, shall be a constant expression whose value is positive and less than 16. It shall not have an element whose value is negative.

11

PAD (optional) shall be an array of the same type and type parameters as SOURCE.

12 13 14

ORDER (optional) shall be of type integer, shall have the same shape as SHAPE, and its value shall be a permutation of (1, 2, . . . , n), where n is the size of SHAPE. If absent, it is as if it were present with value (1, 2, . . . , n).

15

4 Result Characteristics. The result is an array of shape SHAPE (that is, SHAPE (RESHAPE (SOURCE,

16 17 18 19 20 21

22

SHAPE, PAD, ORDER)) is equal to SHAPE) with the same type and type parameters as SOURCE. 5 Result Value. The elements of the result, taken in permuted subscript order ORDER (1), . . . , ORDER (n), are

those of SOURCE in normal array element order followed if necessary by those of PAD in array element order, followed if necessary by additional copies of PAD in array element order.   1 3 5 6 Examples. RESHAPE ([1, 2, 3, 4, 5, 6], [2, 3]) has the value . 2 4 6   1 2 3 4 RESHAPE ([1, 2, 3, 4, 5, 6], [2, 4], [0, 0], [2, 1]) has the value . 5 6 0 0

16.9.176 RRSPACING (X)

23

1 Description. Reciprocal of relative spacing of model numbers.

24

2 Class. Elemental function.

25

3 Argument. X shall be of type real.

26

4 Result Characteristics. Same as X.

27 28 29

5 Result Value. The result has the value |Y × b−e | × bp = ABS (FRACTION (Y)) * RADIX (X) / EPSILON (X),

30 31 32

where b, e, and p are as defined in 16.4 for Y, the value nearest to X in the model for real values whose kind type parameter is that of X; if there are two such values, the value of greater absolute value is taken. If X is an IEEE infinity, the result is an IEEE NaN. If X is an IEEE NaN, the result is that NaN. 6 Example. RRSPACING (−3.0) has the value 0.75 × 224 for reals whose model is as in 16.4, NOTE 1.

16.9.177 SAME_TYPE_AS (A, B)

33

1 Description. Dynamic type equality test.

34

2 Class. Inquiry function.

35

3 Arguments.

36 37

A

shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.

38

B

shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic

430

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

pointer, it shall not have an undefined association status.

1 2

4 Result Characteristics. Default logical scalar.

3 4 5

5 Result Value. If the dynamic type of A or B is extensible, the result is true if and only if the dynamic type of

A is the same as the dynamic type of B. If neither A nor B has extensible dynamic type, the result is processor dependent. NOTE 1 The dynamic type of a disassociated pointer or unallocated allocatable variable is its declared type. An unlimited polymorphic entity has no declared type. NOTE 2 The test performed by SAME_TYPE_AS is not the same as the test performed by the type guard TYPE IS. The test performed by SAME_TYPE_AS does not consider kind type parameters.

6

6 Example. Given the declarations and assignments

TYPE T1 REAL C END TYPE TYPE, EXTENDS(T1) :: T2 END TYPE CLASS(T1), POINTER :: P, Q, R ALLOCATE(P, Q) ALLOCATE(T2 :: R)

7 8 9 10 11 12 13 14 15

the value of SAME_TYPE_AS (P, Q) will be true, and the value of SAME_TYPE_AS (P, R) will be false.

16

16.9.178 SCALE (X, I)

17

1 Description. Real number scaled by radix power.

18

2 Class. Elemental function.

19

3 Arguments.

20

X

shall be of type real.

21

I

shall be of type integer.

22

4 Result Characteristics. Same as X.

23 24

5 Result Value. The result has the value X × bI , where b is defined in 16.4 for model numbers representing values

25

6 Example. SCALE (3.0, 2) has the value 12.0 for reals whose model is as in 16.4, NOTE 1.

26

of X, provided this result is representable; if not, the result is processor dependent.

16.9.179 SCAN (STRING, SET [, BACK, KIND])

27

1 Description. Character set membership search.

28

2 Class. Elemental function.

29

3 Arguments.

30

STRING

shall be of type character.

31

SET

shall be of type character with the same kind type parameter as STRING.

ISO/IEC JTC 1/SC 22/WG5/N2184

431

J3/21-007r1

WD 1539-1

1

BACK (optional) shall be of type logical.

2

KIND (optional) shall be a scalar integer constant expression.

2021-05-21

3 4

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

5

5 Result Value.

6

KIND; otherwise the kind type parameter is that of default integer type.

Case (i):

If BACK is absent or is present with the value false and if STRING contains at least one character that is in SET, the value of the result is the position of the leftmost character of STRING that is in SET. If BACK is present with the value true and if STRING contains at least one character that is in SET, the value of the result is the position of the rightmost character of STRING that is in SET. The value of the result is zero if no character of STRING is in SET or if the length of STRING or SET is zero.

7 8 9 10

Case (ii):

11 12

Case (iii):

13

6 Examples.

14

16

Case (i): Case (ii): Case (iii):

17

16.9.180 SELECTED_CHAR_KIND (NAME)

15

SCAN (’FORTRAN’, ’TR’) has the value 3. SCAN (’FORTRAN’, ’TR’, BACK = .TRUE.) has the value 5. SCAN (’FORTRAN’, ’BCD’) has the value 0.

18

1 Description. Character kind selection.

19

2 Class. Transformational function.

20

3 Argument. NAME shall be default character scalar.

21

4 Result Characteristics. Default integer scalar.

22 23 24 25 26 27

5 Result Value. If NAME has the value DEFAULT, then the result has a value equal to that of the kind type

28 29 30 31 32

parameter of default character. If NAME has the value ASCII, then the result has a value equal to that of the kind type parameter of ASCII character if the processor supports such a kind; otherwise the result has the value −1. If NAME has the value ISO_10646, then the result has a value equal to that of the kind type parameter of the ISO 10646 character kind (corresponding to UCS-4 as specified in ISO/IEC 10646) if the processor supports such a kind; otherwise the result has the value −1. If NAME is a processor-defined name of some other character kind supported by the processor, then the result has a value equal to that kind type parameter value. If NAME is not the name of a supported character type, then the result has the value −1. The NAME is interpreted without respect to case or trailing blanks. 6 Examples. SELECTED_CHAR_KIND (’ASCII’) has the value 1 on a processor that uses 1 as the kind type

parameter for the ASCII character set. The following subroutine produces a Japanese date stamp. SUBROUTINE create_date_string(string) INTRINSIC date_and_time,selected_char_kind INTEGER,PARAMETER :: ucs4 = selected_char_kind("ISO_10646") CHARACTER(1,UCS4),PARAMETER :: nen=CHAR(INT(Z’5e74’),UCS4), & !year gatsu=CHAR(INT(Z’6708’),UCS4), & !month nichi=CHAR(INT(Z’65e5’),UCS4) !day CHARACTER(len= *, kind= ucs4) string INTEGER values(8) CALL date_and_time(values=values) WRITE(string,1) values(1),nen,values(2),gatsu,values(3),nichi 1 FORMAT(I0,A,I0,A,I0,A)

33 34 35 36 37 38 39 40 41 42 43

432

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

2

WD 1539-1

J3/21-007r1

END SUBROUTINE

16.9.181 SELECTED_INT_KIND (R)

3

1 Description. Integer kind selection.

4

2 Class. Transformational function.

5

3 Argument. R shall be an integer scalar.

6

4 Result Characteristics. Default integer scalar.

7

5 Result Value. The result has a value equal to the value of the kind type parameter of an integer type that

8 9 10 11

represents all values n in the range −10R < n < 10R , or if no such kind type parameter is available on the processor, the result is −1. If more than one kind type parameter meets the criterion, the value returned is the one with the smallest decimal exponent range, unless there are several such values, in which case the smallest of these kind values is returned.

12 13

6 Example. Assume a processor supports two integer kinds, 32 with representation method r = 2 and q = 31,

14

and 64 with representation method r = 2 and q = 63. On this processor SELECTED_INT_KIND (9) has the value 32 and SELECTED_INT_KIND (10) has the value 64.

15

16.9.182 SELECTED_LOGICAL_KIND (BITS)

16

1 Description. Logical kind selection.

17

2 Class. Transformational function.

18

3 Argument. BITS shall be an integer scalar.

19

4 Result Characteristics. Default integer scalar.

20 21 22 23

5 Result Value. The result has a value equal to the value of the kind type parameter of a logical type whose

24 25

6 Example. Assume a processor supports four logical kinds with kind type parameter values 8, 16, 32, and 64 for

storage size in bits is at least BITS, or if no such kind type parameter is available on the processor, the result is −1. If more than one kind type parameter meets the criterion, the value returned is the one with the smallest storage size, unless there are several such values, in which case the smallest of these kind values is returned.

26 27

representations with those storage sizes. On this processor, SELECTED_LOGICAL_KIND (1) has the value 8, SELECTED_LOGICAL_KIND (12) has the value 16, and SELECTED_LOGICAL_KIND (128) has the value −1.

28

16.9.183 SELECTED_REAL_KIND ([P, R, RADIX])

29

1 Description. Real kind selection.

30

2 Class. Transformational function.

31

3 Arguments. At least one argument shall be present.

32

P (optional) shall be an integer scalar.

33

R (optional) shall be an integer scalar.

34

RADIX (optional) shall be an integer scalar.

35

4 Result Characteristics. Default integer scalar.

36

5 Result Value. If P or R is absent, the result value is the same as if it were present with the value zero. If

37

RADIX is absent, there is no requirement on the radix of the selected kind.

ISO/IEC JTC 1/SC 22/WG5/N2184

433

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

6 The result has a value equal to a value of the kind type parameter of a real type with decimal precision, as

5 6 7 8 9 10

7 Otherwise, the result is −1 if the processor supports a real type with radix RADIX and exponent range of at least

11 12

8 If more than one kind type parameter value meets the criteria, the value returned is the one with the smallest

13 14 15

9 Example. SELECTED_REAL_KIND (6, 70) has the value KIND (0.0) on a machine that supports a default

returned by the function PRECISION, of at least P digits, a decimal exponent range, as returned by the function RANGE, of at least R, and a radix, as returned by the function RADIX, of RADIX, if such a kind type parameter is available on the processor. R but not with precision of at least P, −2 if the processor supports a real type with radix RADIX and precision of at least P but not with exponent range of at least R, −3 if the processor supports a real type with radix RADIX but with neither precision of at least P nor exponent range of at least R, −4 if the processor supports a real type with radix RADIX and either precision of at least P or exponent range of at least R but not both together, and −5 if the processor supports no real type with radix RADIX. decimal precision, unless there are several such values, in which case the smallest of these kind values is returned. real approximation method with b = 16, p = 6, emin = −64, and emax = 63 and does not have a less precise approximation method.

16

16.9.184 SET_EXPONENT (X, I)

17

1 Description. Real value with specified exponent.

18

2 Class. Elemental function.

19

3 Arguments.

20

X

shall be of type real.

21

I

shall be of type integer.

22

4 Result Characteristics. Same as X.

23 24 25 26

5 Result Value. If X has the value zero, the result has the same value as X. If X is an IEEE infinity, the result is

27

6 Example. SET_EXPONENT (3.0, 1) has the value 1.5 for reals whose model is as in 16.4, NOTE 1.

28

an IEEE NaN. If X is an IEEE NaN, the result is the same NaN. Otherwise, the result has the value X × bI−e , where b and e are as defined in 16.4 for the representation for the value of X in the extended real model for the kind of X.

16.9.185 SHAPE (SOURCE [, KIND])

29

1 Description. Shape of an array or a scalar.

30

2 Class. Inquiry function.

31

3 Arguments.

32 33

SOURCE

34

KIND (optional) shall be a scalar integer constant expression.

shall be a scalar or array of any type. It shall not be an unallocated allocatable variable or a pointer that is not associated. It shall not be an assumed-size array.

35 36 37

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value

38 39 40

5 Result Value. The result has a value whose ith element is equal to the extent of dimension i of SOURCE,

41

6 Examples. The value of SHAPE (A (2:5, −1:1) ) is [4, 3]. The value of SHAPE (3) is the rank-one array of size

of KIND; otherwise the kind type parameter is that of default integer type. The result is an array of rank one whose size is equal to the rank of SOURCE. except that if SOURCE is assumed-rank, and associated with an assumed-size array, the last element is equal to −1.

434

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

zero.

2

16.9.186 SHIFTA (I, SHIFT)

3

1 Description. Right shift with fill.

4

2 Class. Elemental function.

5

3 Arguments.

6 7

I SHIFT

J3/21-007r1

shall be of type integer. shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I).

8

4 Result Characteristics. Same as I.

9 10

5 Result Value. The result has the value obtained by shifting the bits of I to the right SHIFT bits and replicating

11 12

6 If SHIFT is zero the result is I. Bits shifted out from the right are lost. The model for the interpretation of an

13

7 Example. SHIFTA (IBSET (0, BIT_SIZE (0) − 1), 2) is equal to SHIFTL (7, BIT_SIZE (0) − 3).

14

the leftmost bit of I in the left SHIFT bits. integer value as a sequence of bits is in 16.3.

16.9.187 SHIFTL (I, SHIFT)

15

1 Description. Left shift.

16

2 Class. Elemental function.

17

3 Arguments.

18

I

shall be of type integer.

19

SHIFT

shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I).

20

4 Result Characteristics. Same as I.

21

5 Result Value. The value of the result is ISHFT (I, SHIFT).

22

6 Examples. SHIFTL (3, 1) has the value 6.

23

16.9.188 SHIFTR (I, SHIFT)

24

1 Description. Right shift.

25

2 Class. Elemental function.

26

3 Arguments.

27

I

shall be of type integer.

28

SHIFT

shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I).

29

4 Result Characteristics. Same as I.

30

5 Result Value. The value of the result is ISHFT (I, −SHIFT).

31

6 Examples. SHIFTR (3, 1) has the value 1.

ISO/IEC JTC 1/SC 22/WG5/N2184

435

J3/21-007r1

1

WD 1539-1

16.9.189 SIGN (A, B)

2

1 Description. Magnitude of A with the sign of B.

3

2 Class. Elemental function.

4

3 Arguments.

5

A

shall be of type integer or real.

6

B

shall be of the same type as A.

7

4 Result Characteristics. Same as A.

8

5 Result Value.

9

Case (i): Case (ii): Case (iii): Case (iv):

10 11 12

If B > 0, the value of the result is |A|. If B < 0, the value of the result is -|A|. If B is of type integer and B=0, the value of the result is |A|. If B is of type real and is zero, then: • if the processor does not distinguish between positive and negative real zero, or if B is positive real zero, the value of the result is |A|; • if the processor distinguishes between positive and negative real zero, and B is negative real zero, the value of the result is -|A|.

13 14 15 16 17

2021-05-21

6 Example. SIGN (−3.0, 2.0) has the value 3.0.

18

16.9.190 SIN (X)

19

1 Description. Sine function.

20

2 Class. Elemental function.

21

3 Argument. X shall be of type real or complex.

22

4 Result Characteristics. Same as X.

23 24

5 Result Value. The result has a value equal to a processor-dependent approximation to sin(X). If X is of type

25

6 Example. SIN (1.0) has the value 0.84147098 (approximately).

26

real, it is regarded as a value in radians. If X is of type complex, its real part is regarded as a value in radians.

16.9.191 SIND (X)

27

1 Description. Degree sine function.

28

2 Class. Elemental function.

29

3 Argument. X shall be of type real.

30

4 Result Characteristics. Same as X.

31 32

5 Result Value. The result has a value equal to a processor-dependent approximation to the sine of X, which is

33

6 Example. SIND (180.0) has the value 0.0 (approximately).

regarded as a value in degrees.

436

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

16.9.192 SINH (X)

2

1 Description. Hyperbolic sine function.

3

2 Class. Elemental function.

4

3 Argument. X shall be of type real or complex.

5

4 Result Characteristics. Same as X.

6 7

5 Result Value. The result has a value equal to a processor-dependent approximation to sinh(X). If X is of type

8

6 Example. SINH (1.0) has the value 1.1752012 (approximately).

9

complex its imaginary part is regarded as a value in radians.

16.9.193 SINPI (X)

10

1 Description. Circular sine function.

11

2 Class. Elemental function.

12

3 Argument. X shall be of type real.

13

4 Result Characteristics. Same as X.

14 15

5 Result Value. The result has a value equal to a processor-dependent approximation to the sine of X, which is

16

6 Example. SINPI (1.0) has the value 0.0 (approximately).

17

regarded as a value in half-revolutions; thus, SINPI (X) is approximately equal to SIN (X×π).

16.9.194 SIZE (ARRAY [, DIM, KIND])

18

1 Description. Size of an array or one extent.

19

2 Class. Inquiry function.

20

3 Arguments.

21 22

ARRAY

23

shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer that is not associated. If ARRAY is an assumed-size array, DIM shall be present with a value less than the rank of ARRAY.

25

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY. KIND (optional) shall be a scalar integer constant expression.

26

4 Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by the

24

27

value of KIND; otherwise the kind type parameter is that of default integer type.

28 29 30

5 Result Value. If DIM is present, the result has a value equal to the extent of dimension DIM of ARRAY, except

31 32

6 If DIM is absent and ARRAY is assumed-rank, the result has a value equal to PRODUCT(SHAPE(ARRAY,

33

7 Examples. The value of SIZE (A (2:5, −1:1), DIM=2) is 3. The value of SIZE (A (2:5, −1:1)) is 12.

that if ARRAY is assumed-rank and associated with an assumed-size array and DIM is present with a value equal to the rank of ARRAY, the value is −1. KIND)). Otherwise, the result has a value equal to the total number of elements of ARRAY.

NOTE 1 If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement 1 ≤ DIM ≤ 0.

ISO/IEC JTC 1/SC 22/WG5/N2184

437

J3/21-007r1

1

WD 1539-1

2021-05-21

16.9.195 SPACING (X)

2

1 Description. Spacing of model numbers.

3

2 Class. Elemental function.

4

3 Argument. X shall be of type real.

5

4 Result Characteristics. Same as X.

6 7 8 9

5 Result Value. If X does not have the value zero and is not an IEEE infinity or NaN, the result has the value

10 11 12 13

be−p , where b, e, and p are as defined in 16.4 for the value nearest to X in the model for real values whose kind type parameter is that of X, provided this result is representable; otherwise, the result is the same as that of TINY (X). If there are two extended model values equally near to X, the value of greater absolute value is taken. If X has the value zero, the result is the same as that of TINY (X). If X is an IEEE infinity, the result is an IEEE NaN. If X is an IEEE NaN, the result is that NaN. 6 Example. SPACING (3.0) has the value 2−22 for reals whose model is as in 16.4, NOTE 1.

16.9.196 SPLIT (STRING, SET, POS [, BACK])

14

1 Description. Parse a string into tokens, one at a time.

15

2 Class. Simple subroutine.

16

3 Arguments.

17

STRING

shall be a scalar of type character. It is an INTENT (IN) argument.

18 19 20 21 22

SET

shall be a scalar of type character with the same kind type parameter as STRING. It is an INTENT (IN) argument. Each character in SET is a token delimiter. A sequence of zero or more characters in STRING delimited by any token delimiter, or the beginning or end of STRING, comprise a token. Thus, two consecutive token delimiters in STRING, or a token delimiter in the first or last character of STRING, indicate a token with zero length.

23 24

POS

shall be an integer scalar. It is an INTENT (INOUT) argument. If BACK is present with the value true, the value of POS shall be in the range 0 < POS ≤ LEN (STRING) + 1; otherwise it shall be in the range 0 ≤ POS ≤ LEN (STRING).

25

30

If BACK is absent or is present with the value false, POS is assigned the position of the leftmost token delimiter in STRING whose position is greater than POS, or if there is no such character, it is assigned a value one greater than the length of STRING. This identifies a token with starting position one greater than the value of POS on invocation, and ending position one less than the value of POS on return.

31 32 33 34

If BACK is present with the value true, POS is assigned the position of the rightmost token delimiter in STRING whose position is less than POS, or if there is no such character, it is assigned the value zero. This identifies a token with ending position one less than the value of POS on invocation, and starting position one greater than the value of POS on return.

35

If SPLIT is invoked with a value for POS in the range 1 ≤ POS ≤ LEN (STRING), and the value of STRING (POS:POS) is not equal to any character in SET, the token identified by SPLIT will not comprise a complete token as described in the description of the SET argument, but rather a partial token.

26 27 28 29

36 37 38 39 40 41

BACK (optional) shall be a logical scalar. It is an INTENT (IN) argument. 4 Example.

Execution of CHARACTER (LEN=:), ALLOCATABLE :: INPUT CHARACTER (LEN=2) :: SET = ’, ’

42 43

438

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11

J3/21-007r1

INTEGER P INPUT = "one,last example" P = 0 DO IF (P > LEN (INPUT)) EXIT ISTART = P + 1 CALL SPLIT (INPUT, SET, P) IEND = P - 1 PRINT ’(T7,A)’, INPUT (ISTART:IEND) END DO will print one last example

12 13 14

15

WD 1539-1

16.9.197 SPREAD (SOURCE, DIM, NCOPIES)

16

1 Description. Value replicated in a new dimension.

17

2 Class. Transformational function.

18

3 Arguments.

19

SOURCE

shall be a scalar or array of any type. The rank of SOURCE shall be less than 15.

20

DIM

shall be an integer scalar with value in the range 1 ≤ DIM ≤ n + 1, where n is the rank of SOURCE.

21

NCOPIES

shall be an integer scalar.

22 23 24 25 26 27 28 29 30

31 32

4 Result Characteristics. The result is an array of the same type and type parameters as SOURCE and of rank

n + 1, where n is the rank of SOURCE. Case (i): Case (ii):

If SOURCE is scalar, the shape of the result is (MAX (NCOPIES, 0)). If SOURCE is an array with shape [d1 , d2 , . . . , dn ], the shape of the result is [d1 , d2 , . . . , dDIM−1 , MAX (NCOPIES, 0), dDIM , . . . , dn ].

5 Result Value.

Case (i): Case (ii):

If SOURCE is scalar, each element of the result has a value equal to SOURCE. If SOURCE is an array, the element of the result with subscripts (r1 , r2 , . . . , rn+1 ) has the value SOURCE (r1 , r2 , . . . , rDIM−1 , rDIM+1 , . . . , rn+1 ).   2 3 4 6 Examples. If A is the array [2, 3, 4], SPREAD (A, DIM=1, NCOPIES=NC) is the array  2 3 4  if NC 2 3 4 has the value 3 and is a zero-sized array if NC has the value 0.

33

16.9.198 SQRT (X)

34

1 Description. Square root.

35

2 Class. Elemental function.

36

3 Argument. X shall be of type real or complex. If X is real, its value shall be greater than or equal to zero.

37

4 Result Characteristics. Same as X.

ISO/IEC JTC 1/SC 22/WG5/N2184

439

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

5 Result Value. The result has a value equal to a processor-dependent approximation to the square root of X. A

4

6 Example. SQRT (4.0) has the value 2.0 (approximately).

5

result of type complex is the principal value with the real part greater than or equal to zero. When the real part of the result is zero, the imaginary part has the same sign as the imaginary part of X.

16.9.199 STOPPED_IMAGES ([TEAM, KIND])

6

1 Description. Indices of stopped images.

7

2 Class. Transformational function.

8

3 Arguments.

9 10 11

TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, whose value identifies the current or an ancestor team. If TEAM is absent the team specified is the current team.

12

KIND (optional) shall be a scalar integer constant expression.

13 14 15 16 17 18 19 20 21 22 23 24 25

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value

of KIND; otherwise, the kind type parameter is that of default integer type. The result is an array of rank one whose size is equal to the number of images in the specified team that have initiated normal termination. 5 Result Value. The elements of the result are the values of the indices of the images that are known to have

initiated normal termination in the specified team, in numerically increasing order. If the executing image has previously executed an image control statement whose STAT= specifier assigned the value STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV or invoked a collective subroutine whose STAT argument was assigned STAT_STOPPED_IMAGE, at least one of the images participating in that image control statement or collective invocation shall be known to have initiated normal termination. 6 Examples. If image 3 is the only image in the current team that is known to have initiated normal termination,

STOPPED_IMAGES() will have the value [3]. If there are no images in the current team that have initiated normal termination, the value of STOPPED_IMAGES() will be a zero-sized array.

16.9.200 STORAGE_SIZE (A [, KIND])

26

1 Description. Storage size in bits.

27

2 Class. Inquiry function.

28

3 Arguments.

29 30 31

A

shall be a data object of any type. If it is polymorphic it shall not be an undefined pointer. If it is unlimited polymorphic or has any deferred type parameters, it shall not be an unallocated allocatable variable or a disassociated or undefined pointer.

32

KIND (optional) shall be a scalar integer constant expression.

33 34

4 Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by the

35

5 Result Value. The result value is the size expressed in bits for an element of an array that has the dynamic

36 37

type and type parameters of A. If the type and type parameters are such that storage association (19.5.3) applies, the result is consistent with the named constants defined in the intrinsic module ISO_FORTRAN_ENV.

value of KIND; otherwise, the kind type parameter is that of default integer type.

NOTE 1 An array element might take more bits to store than an isolated scalar, since any hardware-imposed alignment requirements for array elements might not apply to a simple scalar variable.

440

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 This is intended to be the size in memory that an object takes when it is stored; this might differ from the size it takes during expression handling (which might be the native register size) or when stored in a file. If an object is never stored in memory but only in a register, this function nonetheless returns the size it would take if it were stored in memory. 1 2 3

6 Example. STORAGE_SIZE (1.0) has the same value as the named constant NUMERIC_STORAGE_SIZE in

the intrinsic module ISO_FORTRAN_ENV.

16.9.201 SUM (ARRAY, DIM [, MASK]) or SUM (ARRAY [, MASK])

4

1 Description. Array reduced by addition.

5

2 Class. Transformational function.

6

3 Arguments.

7

ARRAY

shall be an array of numeric type.

8

DIM

shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.

9

MASK (optional) shall be of type logical and shall be conformable with ARRAY.

10 11 12

4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar if

13

5 Result Value.

DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.

14 15

Case (i):

16 17 18

Case (ii):

19 20 21

Case (iii):

The result of SUM (ARRAY) has a value equal to a processor-dependent approximation to the sum of all the elements of ARRAY or has the value zero if ARRAY has size zero. The result of SUM (ARRAY, MASK = MASK) has a value equal to a processor-dependent approximation to the sum of the elements of ARRAY corresponding to the true elements of MASK or has the value zero if there are no true elements. If ARRAY has rank one, SUM (ARRAY, DIM = DIM [, MASK = MASK]) has a value equal to that of SUM (ARRAY [,MASK = MASK ]). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of SUM (ARRAY, DIM = DIM [ , MASK = MASK]) is equal to SUM (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK= MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).

22 23 24

6 Examples.

25 26

Case (i): Case (ii):

27

Case (iii):

28

16.9.202 SYSTEM_CLOCK ([COUNT, COUNT_RATE, COUNT_MAX])

The value of SUM ([1, 2, 3]) is 6. SUM (C, MASK= C > 0.0) forms the sum of the positive elements of C.   1 3 5 If B is the array , SUM (B, DIM = 1) is [3, 7, 11] and SUM (B, DIM = 2) is [9, 12]. 2 4 6

29

1 Description. Query system clock.

30

2 Class. Subroutine.

31

3 Arguments.

32 33 34

COUNT (optional) shall be an integer scalar with a decimal exponent range no smaller than that of default integer. It is an INTENT (OUT) argument. It is assigned a processor-dependent value based on the value of a processor clock, or −HUGE (COUNT) if there is no clock for the invoking image. The

ISO/IEC JTC 1/SC 22/WG5/N2184

441

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

processor-dependent value is incremented by one for each clock count until the value COUNT_MAX is reached and is reset to zero at the next count. It lies in the range 0 to COUNT_MAX if there is a clock.

4 5 6 7

COUNT_RATE (optional) shall be an integer or real scalar. If it is of type integer, it shall have a decimal exponent range no smaller than that of default integer It is an INTENT (OUT) argument. It is assigned a processor-dependent approximation to the number of processor clock counts per second, or zero if there is no clock for the invoking image.

8 9 10

COUNT_MAX (optional) shall be an integer scalar with a decimal exponent range no smaller than that of default integer. It is an INTENT (OUT) argument. It is assigned the maximum value that COUNT can have, or zero if there is no clock for the invoking image.

11

4 In a reference to SYSTEM_CLOCK, all integer arguments shall have the same kind type parameter.

12 13

5 Whether an image has no clock, has one or more clocks of its own, or shares a clock with another image, is

14

6 If more than one clock is available, the types and kinds of the arguments to SYSTEM_CLOCK determine which

15 16

clock is accessed. The processor should document the relationship between the clock selection and the argument characteristics.

17 18

7 Different invocations of SYSTEM_CLOCK should use the same types and kinds for the arguments, to ensure

19 20

8 It it recommended that all references to SYSTEM_CLOCK use integer arguments with a decimal exponent range

21 22 23 24 25 26 27

processor dependent.

that any timing calculations are based on the same clock. of at least 18. This lets the processor select the most accurate clock available while minimizing how often the COUNT value resets to zero. 9 Example. If the processor clock is a 24-hour clock that registers time at approximately 18.20648193 ticks per

second, at 11:30 A.M. the reference CALL SYSTEM_CLOCK (COUNT = C, COUNT_RATE = R, COUNT_MAX = M) defines C = (11×3600+30×60)×18.20648193 = 753748, R = 18.20648193, and M = 24×3600×18.20648193−1 = 1573039.

16.9.203 TAN (X)

28

1 Description. Tangent function.

29

2 Class. Elemental function.

30

3 Argument. X shall be of type real or complex.

31

4 Result Characteristics. Same as X.

32

5 Result Value. The result has a value equal to a processor-dependent approximation to tan(X). If X is of type

33

real, it is regarded as a value in radians. If X is of type complex, its real part is regarded as a value in radians.

34 35

6 Example. TAN (1.0) has the value 1.5574077 (approximately).

16.9.204 TAND (X)

36

1 Description. Degree tangent function.

37

2 Class. Elemental function.

38

3 Argument. X shall be of type real.

39

4 Result Characteristics. Same as X.

40

5 Result Value. The result has a value equal to a processor-dependent approximation to the tangent of X, which

442

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

is regarded as a value in degrees. 6 Example. TAND (180.0) has the value 0.0 (approximately).

16.9.205 TANH (X)

4

1 Description. Hyperbolic tangent function.

5

2 Class. Elemental function.

6

3 Argument. X shall be of type real or complex.

7

4 Result Characteristics. Same as X.

8 9

5 Result Value. The result has a value equal to a processor-dependent approximation to tanh(X). If X is of type

10

6 Example. TANH (1.0) has the value 0.76159416 (approximately).

11

complex its imaginary part is regarded as a value in radians.

16.9.206 TANPI (X)

12

1 Description. Circular tangent function.

13

2 Class. Elemental function.

14

3 Argument. X shall be of type real.

15

4 Result Characteristics. Same as X.

16 17

5 Result Value. The result has a value equal to a processor-dependent approximation to the tangent of X, which

18

6 Example. TAND (1.0) has the value 0.0 (approximately).

19

is regarded as a value in half-revolutions; thus, TANPI (X) is approximately equal to TAN (X×π).

16.9.207 TEAM_NUMBER ([TEAM])

20

1 Description. Team number.

21

2 Class. Transformational function.

22

3 Argument. TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FOR-

23 24

TRAN_ENV, whose value identifies the current or an ancestor team. If TEAM is absent, the team specified is the current team.

25

4 Result Characteristics. Default integer scalar.

26 27

5 Result Value. The result has the value −1 if the specified team is the initial team; otherwise, the result value

28

6 Example. The team number can be used to control which statements get executed, for example:

29

TYPE(TEAM_TYPE) :: ODD_EVEN ... FORM TEAM (2-MOD(ME,2), ODD_EVEN) ... CHANGE TEAM (ODD_EVEN) SELECT CASE (TEAM_NUMBER()) CASE (1) ! Case for images with odd image indices in the parent team.

30 31 32 33 34 35 36

is equal to the positive integer that identifies the specified team among its sibling teams.

ISO/IEC JTC 1/SC 22/WG5/N2184

443

J3/21-007r1

2021-05-21

CASE (2) ! Case for images with even image indices in the parent team. END SELECT END TEAM

1 2 3 4

5

WD 1539-1

16.9.208 THIS_IMAGE ([TEAM]) or THIS_IMAGE (COARRAY [, TEAM]) or THIS_IMAGE (COARRAY, DIM [, TEAM])

6

1 Description. Cosubscript(s) for this image.

7

2 Class. Transformational function.

8

3 Arguments.

9 10

COARRAY shall be a coarray of any type. If it is allocatable it shall be allocated. If its designator has more than one part-ref , the rightmost part-ref shall have nonzero corank.

11

DIM

12

shall be an integer scalar. Its value shall be in the range 1 ≤ DIM ≤ n, where n is the corank of COARRAY.

13 14 15

TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, whose value identifies the current or an ancestor team. If COARRAY appears, it shall be established in that team.

16 17

4 Result Characteristics. Default integer. It is scalar if COARRAY does not appear or DIM appears; otherwise,

18

5 Result Value.

the result has rank one and its size is equal to the corank of COARRAY.

19 20

Case (i):

21 22 23

Case (ii):

24 25 26

Case (iii):

27 28 29 30 31 32 33 34

35

The result of THIS_IMAGE ([TEAM]) is a scalar with a value equal to the index of the invoking image in the team specified by TEAM, if present, or in the current team if absent. The result of THIS_IMAGE (COARRAY [, TEAM = TEAM]) is the sequence of cosubscript values for COARRAY that would specify the invoking image in the team specified by TEAM, if present, or in the current team if absent. The result of THIS_IMAGE (COARRAY, DIM [, TEAM = TEAM]) is the value of cosubscript DIM in the sequence of cosubscript values for COARRAY that would specify the invoking image in the team specified by TEAM, if present, or in the current team if absent.

6 Examples. If A is declared by the statement

REAL A (10, 20) [10, 0:9, 0:*] then on image 5, THIS_IMAGE ( ) has the value 5 and THIS_IMAGE (A) has the value [5, 0, 0]. For the same coarray on image 213, THIS_IMAGE (A) has the value [3, 1, 2]. 7 The following code uses image 1 to read data. The other images then copy the data.

IF (THIS_IMAGE()==1) READ (*,*) P SYNC ALL P = P[1]

16.9.209 TINY (X)

36

1 Description. Smallest positive model number.

37

2 Class. Inquiry function.

38

3 Argument. X shall be a real scalar or array.

39

4 Result Characteristics. Scalar with the same type and kind type parameter as X.

444

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

5 Result Value. The result has the value bemin −1 where b and emin are as defined in 16.4 for the model representing

3

6 Example. TINY (X) has the value 2−127 for real X whose model is as in 16.4, NOTE 1.

4

16.9.210 TOKENIZE (STRING, SET, TOKENS [, SEPARATOR]) or TOKENIZE (STRING, SET, FIRST, LAST)

numbers of the same type and kind type parameter as X.

5

1 Description. Parse a string into tokens.

6

2 Class. Simple subroutine.

7

3 Arguments.

8

STRING

shall be a scalar of type character. It is an INTENT (IN) argument.

9 10

SET

shall be a scalar of type character with the same kind type parameter as STRING. It is an INTENT (IN) argument. Each character in SET is a token delimiter. A sequence of zero or more characters in STRING delimited by any token delimiter, or the beginning or end of STRING, comprise a token. Thus, two consecutive token delimiters in STRING, or a token delimiter in the first or last character of STRING, indicate a token with zero length.

TOKENS

18

shall be of type character with the same kind type parameter as STRING. It is an INTENT (OUT) argument. It shall not be a coarray or a coindexed object. It shall be an allocatable array of rank one with deferred length. It is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in STRING, and with character length equal to the length of the longest token.

19 20

The tokens in STRING are assigned by intrinsic assignment, in the order found, to the elements of TOKENS, in array element order.

21 22 23 24

SEPARATOR (optional) shall be of type character with the same kind type parameter as STRING. It is an INTENT (OUT) argument. It shall not be a coarray or a coindexed object. It shall be an allocatable array of rank one with deferred length. It is allocated with the lower bound equal to one and the upper bound equal to one less than the number of tokens in STRING, and with character length equal to one. Each element SEPARATOR(i) is assigned the value of the ith token delimiter in STRING.

11 12 13 14 15 16 17

25 26 27 28 29 30 31

FIRST

shall be an allocatable array of type integer and rank one. It is an INTENT (OUT) argument. It shall not be a coarray or a coindexed object. It is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in STRING. Each element is assigned, in array element order, the starting position of each token in STRING, in the order found. If a token has zero length, the starting position is equal to one if the token is at the beginning of STRING, and one greater than the position of the preceding delimitor otherwise.

LAST

shall be an allocatable array of type integer and rank one. It is an INTENT (OUT) argument. It shall not be a coarray or a coindexed object. It is allocated with the lower bound equal to one and the upper bound equal to the number of tokens in STRING. Each element is assigned, in array element order, the ending position of each token in STRING, in the order found. If a token has zero length, the ending position is one less than the starting position.

32 33 34 35 36 37 38

4 Examples.

39

Execution of

40

CHARACTER (LEN=:), ALLOCATABLE :: STRING CHARACTER (LEN=:), ALLOCATABLE, DIMENSION(:) :: TOKENS CHARACTER (LEN=2) :: SET = ’,;’ STRING = ’first,second,third’ CALL SPLIT (STRING, TOKENS, SET) will assign the value [ ’first ’, ’second’, ’third ’ ] to TOKENS.

41 42 43 44 45

ISO/IEC JTC 1/SC 22/WG5/N2184

445

J3/21-007r1

WD 1539-1

6 7

Execution of CHARACTER (LEN=:), ALLOCATABLE :: STRING CHARACTER (LEN=2) :: SET = ’,;’ INTEGER, DIMENSION(:):: FIRST, LAST STRING = ’first,second,,forth’ CALL SPLIT (STRING, SET, FIRST, LAST) will assign the value [ 1, 7, 14, 15 ] to FIRST, and the value [ 5, 12, 13, 19 ] to LAST.

8

16.9.211 TRAILZ (I)

1 2 3 4 5

2021-05-21

9

1 Description. Number of trailing zero bits.

10

2 Class. Elemental function.

11

3 Argument. I shall be of type integer.

12

4 Result Characteristics. Default integer.

13 14 15

5 Result Value. If all of the bits of I are zero, the result value is BIT_SIZE (I). Otherwise, the result value is the

16

6 Examples. TRAILZ (8) has the value 3.

17

position of the rightmost 1 bit in I. The model for the interpretation of an integer value as a sequence of bits is in 16.3.

16.9.212 TRANSFER (SOURCE, MOLD [, SIZE])

18

1 Description. Transfer physical representation.

19

2 Class. Transformational function.

20

3 Arguments.

21

SOURCE

shall be a scalar or array of any type.

22 23 24

MOLD

shall be a scalar or array of any type. If it is a variable, it need not be defined. If the storage size of SOURCE is greater than zero and MOLD is an array, a scalar with the type and type parameters of MOLD shall not have a storage size equal to zero.

25 26

SIZE (optional) shall be an integer scalar. The corresponding actual argument shall not be an optional dummy argument.

27 28 29 30 31 32 33 34 35 36 37 38 39

4 Result Characteristics. The result is of the same type and type parameters as MOLD.

Case (i): Case (ii): Case (iii):

If MOLD is a scalar and SIZE is absent, the result is a scalar. If MOLD is an array and SIZE is absent, the result is an array and of rank one. Its size is as small as possible such that its physical representation is not shorter than that of SOURCE. If SIZE is present, the result is an array of rank one and size SIZE.

5 Result Value. If the physical representation of the result has the same length as that of SOURCE, the physical

representation of the result is that of SOURCE. If the physical representation of the result is longer than that of SOURCE, the physical representation of the leading part is that of SOURCE and the remainder is processor dependent. If the physical representation of the result is shorter than that of SOURCE, the physical representation of the result is the leading part of SOURCE. If D and E are scalar variables such that the physical representation of D is as long as or longer than that of E, the value of TRANSFER (TRANSFER (E, D), E) shall be the value of E. IF D is an array and E is an array of rank one, the value of TRANSFER (TRANSFER (E, D), E, SIZE (E)) shall be the value of E.

40

6 Examples.

41 42

Case (i):

446

TRANSFER (1082130432, 0.0) has the value 4.0 on a processor that represents the values 4.0 and 1082130432 as the string of binary digits 0100 0000 1000 0000 0000 0000 0000 0000.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

Case (ii):

4 5

Case (iii):

6

16.9.213 TRANSPOSE (MATRIX)

7

1 Description. Transpose of an array of rank two.

8

2 Class. Transformational function.

9

3 Argument. MATRIX shall be a rank-two array of any type.

10 11

4 Result Characteristics. The result is an array of the same type and type parameters as MATRIX and with

12 13

5 Result Value. Element (i, j) of the result has the value MATRIX (j + LBOUND (MATRIX, 1) − 1, i +

14

15

TRANSFER ([1.1, 2.2, 3.3], [(0.0, 0.0)])) is a complex rank-one array of length two whose first element has the value (1.1, 2.2) and whose second element has a real part with the value 3.3. The imaginary part of the second element is processor dependent. TRANSFER ([1.1, 2.2, 3.3], [(0.0, 0.0)], 1) is a complex rank-one array of length one whose only element has the value (1.1, 2.2).

rank two and shape [n, m] where [m, n] is the shape of MATRIX. LBOUND (MATRIX, 2) − 1). 

1 6 Example. If A is the array  4 7

2 5 8

  3 1 6 , then TRANSPOSE (A) has the value  2 9 3

4 5 6

 7 8 . 9

16.9.214 TRIM (STRING)

16

1 Description. String without trailing blanks.

17

2 Class. Transformational function.

18

3 Argument. STRING shall be a character scalar.

19 20 21

4 Result Characteristics. Character with the same kind type parameter value as STRING and with a length

22

5 Result Value. The value of the result is the same as STRING except any trailing blanks are removed.

23

6 Example. TRIM (’ A B ’) has the value ’ A B’.

24

that is the length of STRING less the number of trailing blanks in STRING. If STRING contains no nonblank characters, the result has zero length.

16.9.215 UBOUND (ARRAY [, DIM, KIND])

25

1 Description. Upper bound(s).

26

2 Class. Inquiry function.

27

3 Arguments.

28

ARRAY

29 30

shall be assumed-rank or an array. It shall not be an unallocated allocatable array or a pointer that is not associated. If ARRAY is an assumed-size array, DIM shall be present with a value less than the rank of ARRAY.

31 32 33

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY. The corresponding actual argument shall not be an optional dummy argument, a disassociated pointer, or an unallocated allocatable.

34

KIND (optional) shall be a scalar integer constant expression.

35 36 37

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

KIND; otherwise the kind type parameter is that of default integer type. The result is scalar if DIM is present; otherwise, the result is an array of rank one and size n, where n is the rank of ARRAY.

ISO/IEC JTC 1/SC 22/WG5/N2184

447

J3/21-007r1

1 2 3 4 5 6

Case (i):

Case (ii):

9 10 11 12 13 14 15

2021-05-21

5 Result Value.

7 8

WD 1539-1

If DIM is present, ARRAY is a whole array, and dimension DIM of ARRAY has nonzero extent, the result has a value equal to the upper bound for subscript DIM of ARRAY. Otherwise, if DIM is present and ARRAY is assumed-rank, the value of the result is as if ARRAY were a whole array, with the extent of the final dimension of ARRAY when ARRAY is associated with an assumed-size array being considered to be −1. Otherwise, if DIM is present, the result has a value equal to the number of elements in dimension DIM of ARRAY. If ARRAY has rank zero, UBOUND (ARRAY) has a value that is a zero-sized array. Otherwise, UBOUND (ARRAY) has a value whose ith element is equal to UBOUND (ARRAY, i), for i = 1, 2, . . . , n, where n is the rank of ARRAY. UBOUND (ARRAY, KIND=KIND) has a value whose ith element is equal to UBOUND (ARRAY, i, KIND=KIND), for i = 1, 2, . . . , n, where n is the rank of ARRAY.

6 Examples. If A is declared by the statement

REAL A (2:3, 7:10) then UBOUND (A) is [3, 10] and UBOUND (A, DIM = 2) is 10. NOTE 1 If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement 1 ≤ DIM ≤ 0.

16

16.9.216 UCOBOUND (COARRAY [, DIM, KIND])

17

1 Description. Upper cobound(s) of a coarray.

18

2 Class. Inquiry function.

19

3 Arguments.

20 21

COARRAY shall be a coarray of any type. It may be a scalar or an array. If it is allocatable it shall be allocated. If its designator has more than one part-ref , the rightmost part-ref shall have nonzero corank.

22 23 24

DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the corank of COARRAY. The corresponding actual argument shall not be an optional dummy argument, a disassociated pointer, or an unallocated allocatable.

25

KIND (optional) shall be a scalar integer constant expression.

26 27 28

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

29 30

5 Result Value. The final upper cobound is the final cosubscript in the cosubscript list for the coarray that selects

KIND; otherwise, the kind type parameter is that of default integer type. The result is scalar if DIM is present; otherwise, the result is an array of rank one and size n, where n is the corank of COARRAY. the image whose index is equal to the number of images in the current team.

31 32

Case (i):

33 34

Case (ii):

35 36 37 38

If DIM is present, the result has a value equal to the upper cobound for codimension DIM of COARRAY. If DIM is absent, the result has a value whose ith element is equal to the upper cobound for codimension i of COARRAY, for i = 1, 2,. . . , n, where n is the corank of COARRAY.

6 Examples. If NUM_IMAGES( ) has the value 30 and A is allocated by the statement

ALLOCATE (A [2:3, 0:7, *]) then UCOBOUND (A) is [3, 7, 2] and UCOBOUND (A, DIM=2) is 7. Note that the cosubscripts [3, 7, 2] do not correspond to an actual image.

448

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

16.9.217 UNPACK (VECTOR, MASK, FIELD)

2

1 Description. Vector unpacked into an array.

3

2 Class. Transformational function.

4

3 Arguments.

5 6

VECTOR

shall be a rank-one array of any type. Its size shall be at least t where t is the number of true elements in MASK.

7

MASK

shall be a logical array.

8

FIELD

shall be of the same type and type parameters as VECTOR and shall be conformable with MASK.

9 10

4 Result Characteristics. The result is an array of the same type and type parameters as VECTOR and the

11 12 13

5 Result Value. The element of the result that corresponds to the ith true element of MASK, in array element

14

6 Examples. Particular values can be “scattered” to particular positionsin an array by    using UNPACK. If M is the

15

16

17

18

same shape as MASK. order, has the value VECTOR (i) for i = 1, 2, . . . , t, where t is the number of true values in MASK. Each other element has a value equal to FIELD if FIELD is scalar or to the corresponding element of FIELD if it is an array. 1 array  0 0

0 1 0

0 . T 0 , V is the array [1, 2, 3], and Q is the logical mask  T . 1 . .

. . , where “T” represents true T   1 2 0 and “.” represents false, then the result of UNPACK (V, MASK = Q, FIELD = M) has the value  1 1 0  0 0 3   0 2 0 and the result of UNPACK (V, MASK = Q, FIELD = 0) has the value  1 0 0 . 0 0 3

16.9.218 VERIFY (STRING, SET [, BACK, KIND])

19

1 Description. Character set non-membership search.

20

2 Class. Elemental function.

21

3 Arguments.

22

STRING

shall be of type character.

23

SET

shall be of type character with the same kind type parameter as STRING.

24

BACK (optional) shall be of type logical.

25

KIND (optional) shall be a scalar integer constant expression.

26 27

4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

28

5 Result Value.

KIND; otherwise the kind type parameter is that of default integer type.

29 30 31

Case (i):

32 33 34

Case (ii):

35

Case (iii):

36

6 Examples.

If BACK is absent or has the value false and if STRING contains at least one character that is not in SET, the value of the result is the position of the leftmost character of STRING that is not in SET. If BACK is present with the value true and if STRING contains at least one character that is not in SET, the value of the result is the position of the rightmost character of STRING that is not in SET. The value of the result is zero if each character in STRING is in SET or if STRING has zero length.

ISO/IEC JTC 1/SC 22/WG5/N2184

449

J3/21-007r1

WD 1539-1

3

Case (i): Case (ii): Case (iii):

4

16.10

Standard intrinsic modules

5

16.10.1

General

1 2

2021-05-21

VERIFY (’ABBA’, ’A’) has the value 2. VERIFY (’ABBA’, ’A’, BACK = .TRUE.) has the value 3. VERIFY (’ABBA’, ’AB’) has the value 0.

6 7 8

1 This document defines five standard intrinsic modules: a Fortran environment module, a set of three modules

9 10 11

2 The intrinsic modules IEEE_EXCEPTIONS, IEEE_ARITHMETIC, and IEEE_FEATURES are described in

to support floating-point exceptions and IEEE arithmetic, and a module to support interoperability with the C programming language. Clause 17. The intrinsic module ISO_C_BINDING is described in Clause 18. The module procedures described in 16.10.2 are simple. NOTE 1 The types and procedures defined in standard intrinsic modules are not themselves intrinsic.

12

3 A processor may extend the standard intrinsic modules to provide public entities in them in addition to those

13

specified in this document.

14

16.10.2

The ISO_FORTRAN_ENV intrinsic module

15

16.10.2.1

General

16

1 The intrinsic module ISO_FORTRAN_ENV provides public entities relating to the Fortran environment.

17 18

2 The processor shall provide the named constants, derived types, and procedures described in 16.10.2. In the

19 20 21 22 23 24 25 26 27

detailed descriptions below, procedure names are generic and not specific. 16.10.2.2

ATOMIC_INT_KIND

1 The value of the default integer scalar constant ATOMIC_INT_KIND is the kind type parameter value of type

integer variables for which the processor supports atomic operations specified by atomic subroutines. 16.10.2.3

ATOMIC_LOGICAL_KIND

1 The value of the default integer scalar constant ATOMIC_LOGICAL_KIND is the kind type parameter value

of type logical variables for which the processor supports atomic operations specified by atomic subroutines. 16.10.2.4

CHARACTER_KINDS

1 The values of the elements of the default integer array constant CHARACTER_KINDS are the kind values

28

supported by the processor for variables of type character. The order of the values is processor dependent. The rank of the array is one, its lower bound is one, and its size is the number of character kinds supported.

29

16.10.2.5

30 31

CHARACTER_STORAGE_SIZE

1 The value of the default integer scalar constant CHARACTER_STORAGE_SIZE is the size expressed in bits

of the character storage unit (19.5.3.2).

450

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

16.10.2.6

WD 1539-1

J3/21-007r1

COMPILER_OPTIONS ( )

2

1 Description. Processor-dependent string describing the options that controlled the program translation phase.

3

2 Class. Transformational function.

4

3 Argument. None.

5

4 Result Characteristics. Default character scalar with processor-dependent length.

6 7 8

5 Result Value. A processor-dependent value which describes the options that controlled the translation phase of

9

6 Example. COMPILER_OPTIONS ( ) might have the value ’/OPTIMIZE /FLOAT=IEEE’.

10

program execution. This value should include relevant information that could be useful for diagnosing problems at a later date.

16.10.2.7

COMPILER_VERSION ( )

11

1 Description. Processor-dependent string identifying the program translation phase.

12

2 Class. Transformational function.

13

3 Argument. None.

14

4 Result Characteristics. Default character scalar with processor-dependent length.

15

5 Result Value. A processor-dependent value that identifies the name and version of the program translation

16 17

phase of the processor. This value should include relevant information that could be useful for diagnosing problems at a later date.

18

6 Example. COMPILER_VERSION ( ) might have the value ’Fast KL-10 Compiler Version 7’.

NOTE 1 Relevant information that could be useful for diagnosing problems at a later date might include compiler release and patch level, default compiler arguments, environment variable values, and run time library requirements. A processor might include this information in an object file automatically, without the user needing to save the result of this function in a variable. 19 20 21 22

16.10.2.8

CURRENT_TEAM

1 The value of the default integer scalar constant CURRENT_TEAM identifies the current team when it is used

as the LEVEL argument to GET_TEAM. 16.10.2.9

ERROR_UNIT

23

1 The value of the default integer scalar constant ERROR_UNIT identifies the processor-dependent preconnected

24 25

external unit used for the purpose of error reporting (12.5). This unit may be the same as OUTPUT_UNIT. The value shall not be −1.

26

16.10.2.10

EVENT_TYPE

27 28

1 EVENT_TYPE is a derived type with private components. It is an extensible type with no type parameters.

29

2 A scalar variable of type EVENT_TYPE is an event variable. The value of an event variable includes its event

30 31 32

count, which is updated by execution of a sequence of EVENT POST or EVENT WAIT statements. The effect of each change is as if the intrinsic subroutine ATOMIC_ADD were executed with a variable that stores the event count as its ATOM argument. A coarray that is of type EVENT_TYPE may be referenced or defined

Each nonallocatable component is fully default-initialized.

ISO/IEC JTC 1/SC 22/WG5/N2184

451

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3

during execution of a segment that is unordered relative to the execution of another segment in which that coarray is defined. The event count is of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. The initial value of the event count of an event variable is zero.

4 5 6

C1603 A named entity with declared type EVENT_TYPE, or which has a noncoarray potential subobject component with declared type EVENT_TYPE, shall be a variable. A component that is of such a type shall be a data component.

7 8

C1604 A named variable with declared type EVENT_TYPE shall be a coarray. A named variable with a noncoarray potential subobject component of type EVENT_TYPE shall be a coarray.

9 10 11

C1605 An event variable shall not appear in a variable definition context except as the event-variable in an EVENT POST or EVENT WAIT statement, as an allocate-object, or as an actual argument in a reference to a procedure with an explicit interface if the corresponding dummy argument has INTENT (INOUT).

12 13 14 15

C1606 A variable with a nonpointer subobject of type EVENT_TYPE shall not appear in a variable definition context except as an allocate-object in an ALLOCATE statement without a SOURCE= specifier, as an allocate-object in a DEALLOCATE statement, or as an actual argument in a reference to a procedure with an explicit interface if the corresponding dummy argument has INTENT (INOUT). NOTE 1 The restrictions against changing an event variable except via EVENT POST and EVENT WAIT statements ensure the integrity of its value and facilitate efficient implementation, particularly when special synchronization is needed for correct event handling. NOTE 2 Updates to variables via atomic subroutines are coherent but not necessarily consistent, so a processor might have to use extra synchronization to obtain the consistency required for the segments ordered by EVENT POST and EVENT WAIT statements.

16 17 18 19 20 21 22 23 24

16.10.2.11

FILE_STORAGE_SIZE

1 The value of the default integer scalar constant FILE_STORAGE_SIZE is the size expressed in bits of the file

storage unit (12.3.5). 16.10.2.12

INITIAL_TEAM

1 The value of the default integer scalar constant INITIAL_TEAM identifies the initial team when it is used as

the LEVEL argument to GET_TEAM. 16.10.2.13

INPUT_UNIT

1 The value of the default integer scalar constant INPUT_UNIT identifies the same processor-dependent external

25 26 27

unit as the one identified by an asterisk in a READ statement; this unit is the one used for a READ statement that does not contain an input/output control list (12.6.4.3). This unit is preconnected for sequential formatted input on image one in the initial team only, and is not preconnected on any other image. The value shall not be −1.

28

16.10.2.14

29 30 31 32 33

INT8, INT16, INT32, and INT64

1 The values of these default integer scalar named constants shall be those of the kind type parameters that specify

an INTEGER type whose storage size expressed in bits is 8, 16, 32, and 64 respectively. If, for any of these constants, the processor supports more than one kind of that size, it is processor dependent which kind value is provided. If the processor supports no kind of a particular size, that constant shall be equal to −2 if the processor supports a kind with larger size and −1 otherwise.

452

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

16.10.2.15

WD 1539-1

J3/21-007r1

INTEGER_KINDS

1 The values of the elements of the default integer array constant INTEGER_KINDS are the kind values supported

4

by the processor for variables of type integer. The order of the values is processor dependent. The rank of the array is one, its lower bound is one, and its size is the number of integer kinds supported.

5

16.10.2.16

6 7 8 9 10 11 12 13

IOSTAT_END

1 The value of the default integer scalar constant IOSTAT_END is assigned to the variable specified in an IOSTAT=

specifier (12.11.5) if an end-of-file condition occurs during execution of an input statement and no error condition occurs. This value shall be negative. 16.10.2.17

IOSTAT_EOR

1 The value of the default integer scalar constant IOSTAT_EOR is assigned to the variable specified in an IOSTAT=

specifier (12.11.5) if an end-of-record condition occurs during execution of an input statement and no end-of-file or error condition occurs. This value shall be negative and different from the value of IOSTAT_END. 16.10.2.18

IOSTAT_INQUIRE_INTERNAL_UNIT

14

1 The value of the default integer scalar constant IOSTAT_INQUIRE_INTERNAL_UNIT is assigned to the

15 16

variable specified in an IOSTAT= specifier in an INQUIRE statement (12.10) if a file-unit-number identifies an internal unit in that statement. NOTE 1 This can only occur when a defined input/output procedure is called by the processor as the result of executing a parent data transfer statement (12.6.4.8.3) for an internal unit.

17

16.10.2.19

LOCK_TYPE

18 19

1 LOCK_TYPE is a derived type with private components; no component is allocatable or a pointer. It is an

20 21

2 A scalar variable of type LOCK_TYPE is a lock variable. A lock variable can have one of two states: locked and

extensible type with no type parameters. All components have default initialization.

22 23

unlocked. The unlocked state is represented by the one value that is the default value of a LOCK_TYPE variable; this is the value specified by the structure constructor LOCK_TYPE ( ). The locked state is represented by all other values. The value of a lock variable can be changed with the LOCK and UNLOCK statements (11.7.10).

24 25 26

C1607 A named entity with declared type LOCK_TYPE, or which has a noncoarray potential subobject component with declared type LOCK_TYPE, shall be a variable. A component that is of such a type shall be a data component.

27 28

C1608 A named variable with declared type LOCK_TYPE shall be a coarray. A named variable with a noncoarray potential subobject component of type LOCK_TYPE shall be a coarray.

29 30 31

C1609 A lock variable shall not appear in a variable definition context except as the lock-variable in a LOCK or UNLOCK statement, as an allocate-object, or as an actual argument in a reference to a procedure with an explicit interface where the corresponding dummy argument has INTENT (INOUT).

32 33

C1610 A variable with a subobject of type LOCK_TYPE shall not appear in a variable definition context except as an allocate-object or as an actual argument in a reference to a procedure with an explicit interface where the corresponding dummy argument has INTENT (INOUT).

34

ISO/IEC JTC 1/SC 22/WG5/N2184

453

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 The restrictions against changing a lock variable except via the LOCK and UNLOCK statements ensure the integrity of its value and facilitate efficient implementation, particularly when special synchronization is needed for correct lock operation. 1 2 3 4 5 6 7 8 9

16.10.2.20

LOGICAL_KINDS

1 The values of the elements of the default integer array constant LOGICAL_KINDS are the kind values supported

by the processor for variables of type logical. The order of the values is processor dependent. The rank of the array is one, its lower bound is one, and its size is the number of logical kinds supported. 16.10.2.21

LOGICAL8, LOGICAL16, LOGICAL32, and LOGICAL64

1 The values of these default integer scalar named constants shall be those of the kind type parameters that specify

10

a LOGICAL type whose storage size expressed in bits is 8, 16, 32, and 64 respectively. If, for any of these constants, the processor supports more than one kind of that size, it is processor dependent which kind value is provided. If the processor supports no kind of a particular size, that constant shall be equal to −2 if the processor supports a kind with larger size and −1 otherwise.

11

16.10.2.22

NOTIFY_TYPE

12 13

1 NOTIFY_TYPE is a derived type with private components. It is an extensible type with no type parameters.

14 15

2 A scalar variable of type NOTIFY_TYPE is a notify variable. The value of a notify variable includes its notify

16

Each nonallocatable component is fully default-initialized. count, which is updated by execution of assignment statements that have a NOTIFY= specifier and NOTIFY WAIT statements.

17 18 19 20 21

3 The effect of each update is as if the intrinsic subroutine ATOMIC_ADD were executed with a variable that

22 23 24

C1611 A named entity with declared type NOTIFY_TYPE, or which has a noncoarray potential subobject component with declared type NOTIFY_TYPE, shall be a variable. A component that is of such a type shall be a data component.

25 26

C1612 A named variable with declared type NOTIFY_TYPE shall be a coarray. A named variable with a potential subobject component of type NOTIFY_TYPE shall be a coarray.

27

C1613 A notify variable shall not appear in a variable definition context except as the notify-variable of a NOTIFY= specifier or NOTIFY WAIT statement, as an allocate-object, or as an actual argument in a reference to a procedure with an explicit interface if the corresponding dummy argument has INTENT (INOUT).

28 29 30 31 32 33 34

stores the notify count as its ATOM argument. A coarray that is of type NOTIFY_TYPE may be referenced or defined during execution of a segment that is unordered relative to the execution of another segment in which that coarray is defined. The notify count is of type integer with kind ATOMIC_INT_KIND from the intrinsic module ISO_FORTRAN_ENV. The initial value of the notify count of a notify variable is zero.

C1614 A variable with a nonpointer subobject of type NOTIFY_TYPE shall not appear in a variable definition context except as an allocate-object in an ALLOCATE statement without a SOURCE= specifier, as an allocate-object in a DEALLOCATE statement, or as an actual argument in a reference to a procedure with an explicit interface if the corresponding dummy argument has INTENT (INOUT). NOTE 1 The restrictions on changing a notify variable ensure the integrity of its value and facilitate efficient implementation, particularly when special synchronization is needed for correct notify handling.

454

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11

16.10.2.23

WD 1539-1

J3/21-007r1

NUMERIC_STORAGE_SIZE

1 The value of the default integer scalar constant NUMERIC_STORAGE_SIZE is the size expressed in bits of the

numeric storage unit (19.5.3.2). 16.10.2.24

OUTPUT_UNIT

1 The value of the default integer scalar constant OUTPUT_UNIT identifies the same processor-dependent external

unit preconnected for sequential formatted output as the one identified by an asterisk in a WRITE statement (12.6.4.3). The value shall not be −1. 16.10.2.25

PARENT_TEAM

1 The value of the default integer scalar constant PARENT_TEAM identifies the parent team when it is used as

the LEVEL argument to GET_TEAM. 16.10.2.26

REAL_KINDS

12

1 The values of the elements of the default integer array constant REAL_KINDS are the kind values supported by

13 14

the processor for variables of type real. The order of the values is processor dependent. The rank of the array is one, its lower bound is one, and its size is the number of real kinds supported.

15

16.10.2.27

16 17 18 19

REAL16, REAL32, REAL64, and REAL128

1 The values of these default integer scalar named constants shall be those of the kind type parameters that specify

20

a REAL type whose storage size expressed in bits is 16, 32, 64, and 128 respectively. If, for any of these constants, the processor supports more than one kind of that size, it is processor dependent which kind value is provided. If the processor supports no kind of a particular size, that constant shall be equal to −2 if the processor supports kinds of a larger size and −1 otherwise.

21

16.10.2.28

22 23 24 25 26

STAT_FAILED_IMAGE

1 If the processor has the ability to detect that an image has failed, the value of the default integer scalar constant

27

STAT_FAILED_IMAGE is positive; otherwise, the value of STAT_FAILED_IMAGE is negative. If an image involved in execution of an image control statement, a reference to a coindexed object, or execution of a collective or atomic subroutine has failed, and no other error condition occurs, the value of STAT_FAILED_IMAGE is assigned to the variable specified in a STAT= specifier in the execution of an image control statement or reference to a coindexed object, or to the STAT argument in an invocation of a collective or atomic subroutine.

28

16.10.2.29

29 30 31 32 33 34

STAT_LOCKED

1 The value of the default integer scalar constant STAT_LOCKED is assigned to the variable specified in a STAT=

specifier (11.7.11) of a LOCK statement if the lock variable is locked by the executing image. 16.10.2.30

STAT_LOCKED_OTHER_IMAGE

1 The value of the default integer scalar constant STAT_LOCKED_OTHER_IMAGE is assigned to the variable

specified in a STAT= specifier (11.7.11) of an UNLOCK statement if the lock variable is locked by another image. 16.10.2.31

STAT_STOPPED_IMAGE

35

1 The value of the default integer scalar constant STAT_STOPPED_IMAGE is assigned to the variable specified

36 37 38 39

in a STAT= specifier (9.7.4, 11.7.11), if execution of the statement with that specifier requires synchronization with an image that has initiated normal termination. It is assigned to a STAT argument in a reference to a collective subroutine if any image of the current team has initiated normal termination. This value shall be positive.

ISO/IEC JTC 1/SC 22/WG5/N2184

455

J3/21-007r1

1 2 3 4 5 6 7 8

16.10.2.32

WD 1539-1

2021-05-21

STAT_UNLOCKED

1 The value of the default integer scalar constant STAT_UNLOCKED is assigned to the variable specified in a

STAT= specifier (11.7.11) of an UNLOCK statement if the lock variable is unlocked. 16.10.2.33

STAT_UNLOCKED_FAILED_IMAGE

1 The value of the default integer scalar constant STAT_UNLOCKED_FAILED_IMAGE is assigned to the vari-

able specified in a STAT= specifier (11.7.11) of a LOCK statement if the lock variable is unlocked because of the failure of the image that locked it. 16.10.2.34

TEAM_TYPE

9 10

1 TEAM_TYPE is a derived type with private components. It is an extensible type with no type parameters.

11 12

2 A scalar variable of type TEAM_TYPE is a team variable, and can identify a team. The default initial value of

13

Each nonallocatable component is fully default-initialized. a team variable does not identify any team. 16.10.2.35

Uniqueness of named constant values

14

1 The values of these named constants shall be distinct:

15

IOSTAT_INQUIRE_INTERNAL_UNIT STAT_FAILED_IMAGE STAT_LOCKED STAT_LOCKED_OTHER_IMAGE

456

STAT_STOPPED_IMAGE STAT_UNLOCKED STAT_UNLOCKED_FAILED_IMAGE

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

17 Exceptions and IEEE arithmetic

2

17.1

3 4 5 6 7

J3/21-007r1

Overview of IEEE arithmetic support

1 The intrinsic modules IEEE_EXCEPTIONS, IEEE_ARITHMETIC, and IEEE_FEATURES provide support

for the facilities defined by ISO/IEC 60559:2020∗ . Whether the modules are provided is processor dependent. If the module IEEE_FEATURES is provided, which of the named constants defined in this document are included is processor dependent. The module IEEE_ARITHMETIC behaves as if it contained a USE statement for IEEE_EXCEPTIONS; everything that is public in IEEE_EXCEPTIONS is public in IEEE_ARITHMETIC. NOTE 1 The types and procedures defined in these modules are not themselves intrinsic.

8 9 10 11 12 13 14 15 16 17 18

2 If IEEE_EXCEPTIONS or IEEE_ARITHMETIC is accessible in a scoping unit, the exceptions IEEE_OVER-

FLOW and IEEE_DIVIDE_BY_ZERO are supported in the scoping unit for all kinds of real and complex IEEE floating-point data. Which other exceptions are supported in the scoping unit can be determined by the function IEEE_SUPPORT_FLAG (17.11.55); whether control of halting is supported can be determined by the function IEEE_SUPPORT_HALTING. The extent of support of the other exceptions can be influenced by the accessibility of the named constants IEEE_INEXACT_FLAG, IEEE_INVALID_FLAG, and IEEE_UNDERFLOW_FLAG of the module IEEE_FEATURES. If IEEE_UNDERFLOW_FLAG is accessible, within the scoping unit the processor shall support underflow for at least one kind of real. Similarly, if IEEE_INEXACT_FLAG or IEEE_INVALID_FLAG is accessible, within the scoping unit the processor shall support the exception for at least one kind of real. If IEEE_HALTING is accessible, within the scoping unit the processor shall support control of halting. NOTE 2 IEEE_INVALID is not required to be supported whenever IEEE_EXCEPTIONS is accessed. This is to allow a processor whose arithmetic does not conform to ISO/IEC 60559:2020 to provide support for overflow and divide_by_zero. On a processor which does support ISO/IEC 60559:2020, invalid is an equally serious condition.

19 20 21 22

3 If a scoping unit does not access IEEE_FEATURES, IEEE_EXCEPTIONS, or IEEE_ARITHMETIC, the level

23 24 25 26 27 28

4 Additional ISO/IEC/IEEE 60559:2011 facilities are available from the module IEEE_ARITHMETIC. The extent

of support is processor dependent, and need not include support for any exceptions. If a flag is signaling on entry to such a scoping unit, the processor ensures that it is signaling on exit. If a flag is quiet on entry to such a scoping unit, whether it is signaling on exit is processor dependent.

29 30 31 32

of support can be influenced by the accessibility of the named constants of the module IEEE_FEATURES. If IEEE_DATATYPE of IEEE_FEATURES is accessible, within the scoping unit the processor shall support IEEE arithmetic for at least one kind of real. Similarly, if IEEE_DENORMAL, IEEE_DIVIDE, IEEE_INF, IEEE_NAN, IEEE_ROUNDING, IEEE_SQRT, or IEEE_SUBNORMAL is accessible, within the scoping unit the processor shall support the feature for at least one kind of real. In the case of IEEE_ROUNDING, it shall support the rounding modes IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, and IEEE_DOWN; support for IEEE_AWAY is also required if there is at least one kind of real X for which IEEE_SUPPORT_DATATYPE (X) is true and RADIX (X) is equal to ten. Note that the effect of IEEE_DENORMAL is the same as that of IEEE_SUBNORMAL.

33

5 Execution might be slowed on some processors by the support of some features. If IEEE_EXCEPTIONS or ∗ Because ISO/IEC 60559:2020 was originally an IEEE standard, its facilities are widely known as “IEEE arithmetic”, and this

terminology is used by this document.

ISO/IEC JTC 1/SC 22/WG5/N2184

457

J3/21-007r1

1 2

WD 1539-1

2021-05-21

IEEE_ARITHMETIC is accessed but IEEE_FEATURES is not accessed, the supported subset of features is processor dependent. The processor’s fullest support is provided when all of IEEE_FEATURES is accessed as in USE, INTRINSIC :: IEEE_ARITHMETIC; USE, INTRINSIC :: IEEE_FEATURES

3 4

but execution might then be slowed by the presence of a feature that is not needed.

5

17.2

Derived types, constants, and operators defined in the modules

6 7

1 The modules IEEE_EXCEPTIONS, IEEE_ARITHMETIC, and IEEE_FEATURES define derived types whose

8

2 The module IEEE_EXCEPTIONS defines the following types and constants.

9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

31 32 33 34 35 36

37 38 39 40 41

components are all private. No direct component of any of these types is allocatable or a pointer.

• IEEE_FLAG_TYPE is for identifying a particular exception flag. Its only possible values are those of named constants defined in the module: IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, and IEEE_INEXACT. The module also defines the array named constants IEEE_USUAL = [ IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_INVALID ] and IEEE_ALL = [ IEEE_USUAL, IEEE_UNDERFLOW, IEEE_INEXACT ]. • IEEE_MODES_TYPE is for representing the floating-point modes. • IEEE_STATUS_TYPE is for representing the floating-point status. 3 The module IEEE_ARITHMETIC defines the following types, constants, and operators.

• The type IEEE_CLASS_TYPE, for identifying a class of floating-point values. Its only possible values are those of named constants defined in the module: IEEE_SIGNALING_NAN, IEEE_QUIET_NAN, IEEE_NEGATIVE_INF, IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_DENORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, IEEE_POSITIVE_SUBNORMAL, IEEE_POSITIVE_NORMAL, IEEE_POSITIVE_INF, and IEEE_OTHER_VALUE. The named constants IEEE_NEGATIVE_DENORMAL and IEEE_POSITIVE_DENORMAL are defined with the same value as IEEE_NEGATIVE_SUBNORMAL and IEEE_POSITIVE_SUBNORMAL respectively. • The type IEEE_ROUND_TYPE, for identifying a particular rounding mode. Its only possible values are those of named constants defined in the module: IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, IEEE_AWAY and IEEE_OTHER for the rounding modes specified in this document. • The simple elemental operator == for two values of one of these types to return true if the values are the same and false otherwise. • The simple elemental operator /= for two values of one of these types to return true if the values differ and false otherwise. 4 The module IEEE_FEATURES defines the following types and constants.

• The type IEEE_FEATURES_TYPE, for expressing the need for particular ISO/IEC/IEEE 60559:2011 features. Its only possible values are those of named constants defined in the module: IEEE_DATATYPE, IEEE_DENORMAL, IEEE_DIVIDE, IEEE_HALTING, IEEE_INEXACT_FLAG, IEEE_INF, IEEE_INVALID_FLAG, IEEE_NAN, IEEE_ROUNDING, IEEE_SQRT, IEEE_SUBNORMAL, and IEEE_UNDERFLOW_FLAG.

17.3

The exceptions

1 The exceptions are the following.

• IEEE_OVERFLOW occurs in an intrinsic real addition, subtraction, multiplication, division, or conversion by the intrinsic function REAL, as specified by ISO/IEC/IEEE 60559:2011 if IEEE_SUPPORT_DATATYPE is true for the operands of the operation or conversion, and as determined by the processor otherwise.

458

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

16 17 18 19 20 21 22

WD 1539-1

J3/21-007r1

It occurs in an intrinsic real exponentiation as determined by the processor. It occurs in a complex operation, or conversion by the intrinsic function CMPLX, if it is caused by the calculation of the real or imaginary part of the result. • IEEE_DIVIDE_BY_ZERO occurs in a real division as specified by ISO/IEC/IEEE 60559:2011 if IEEE_SUPPORT_DATATYPE is true for the operands of the division, and as determined by the processor otherwise. It is processor-dependent whether it occurs in a real exponentiation with a negative exponent. It occurs in a complex division if it is caused by the calculation of the real or imaginary part of the result. • IEEE_INVALID occurs when a real or complex operation or assignment is invalid; possible examples are SQRT (X) when X is real and has a nonzero negative value, and conversion to an integer (by assignment, an intrinsic procedure, or a procedure defined in an intrinsic module) when the result is too large to be representable. IEEE_INVALID occurs for numeric relational intrinsic operations as specified below. • IEEE_UNDERFLOW occurs when the result for an intrinsic real operation or assignment has an absolute value less than a processor-dependent limit, or the real or imaginary part of the result for an intrinsic complex operation or assignment has an absolute value less than a processor-dependent limit. • IEEE_INEXACT occurs when the result of a real or complex operation or assignment is not exact. 2 Each exception has a flag whose value is either quiet or signaling. The value can be determined by the subroutine

IEEE_GET_FLAG. Its initial value is quiet. It is set to signaling when the associated exception occurs, except that the flag for IEEE_UNDERFLOW is not set if the result of the operation that caused the exception was exact and default ISO/IEC/IEEE 60559:2011 exception handling is in effect for IEEE_UNDERFLOW. Its status can also be changed by the subroutine IEEE_SET_FLAG or the subroutine IEEE_SET_STATUS. Once signaling within a procedure, it remains signaling unless set quiet by an invocation of the subroutine IEEE_SET_FLAG or the subroutine IEEE_SET_STATUS.

23 24 25

3 If a flag is signaling on entry to a procedure other than IEEE_GET_FLAG or IEEE_GET_STATUS, the

26

4 Evaluation of a specification expression might cause an exception to signal.

27

5 In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC, if an intrinsic procedure

28 29 30 31 32

or a procedure defined in an intrinsic module executes normally, the values of the flags IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, and IEEE_INVALID shall be as on entry to the procedure, even if one or more of them signals during the calculation. If a real or complex result is too large for the procedure to handle, IEEE_OVERFLOW may signal. If a real or complex result is a NaN because of an invalid operation (for example, LOG (−1.0)), IEEE_INVALID may signal. Similar rules apply to format processing and to intrinsic operations: no signaling flag shall be set quiet and no quiet flag shall be set signaling because of an intermediate calculation that does not affect the result.

33 34 35 36 37 38 39 40

processor will set it to quiet on entry and restore it to signaling on return. If a flag signals during execution of a procedure, the processor shall not set it to quiet on return.

6 In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC, if x1 and x2 are numeric

entities, the type of x1 + x2 is real, and IEEE_SUPPORT_NAN (x1 + x2 ) is true, the relational intrinsic operation x1 rel-op x2 shall signal IEEE_INVALID as specified for the conditional predicate of ISO/IEC 60559:2020 corresponding to rel-op indicated by Table 17.1. If the types or kind type parameters of x1 or x2 differ, the conversions (10.1.5.5.1) might signal exceptions instead of or in addition to an IEEE_INVALID exception signaled by the comparison. NOTE 1 Each comparison predicate defined by ISO/IEC 60559:2020 is either unordered signaling or unordered quiet. An unordered signaling predicate signals an invalid operation exception if and only if one of the values being compared is a NaN. An unordered quiet predicate signals an invalid operation exception if and only if one of the values being compared is a signaling NaN. The comparison predicates do not signal any other exceptions.

ISO/IEC JTC 1/SC 22/WG5/N2184

459

J3/21-007r1

WD 1539-1

2021-05-21

Table 17.1: IEEE relational operator correspondence Operator ISO/IEC/IEEE 60559:2011 comparison predicate .LT. or < .LE. or <= .GT. or > .GE. or >= .EQ. or == .NE. or /=

compareSignalingLess compareSignalingLessEqual compareSignalingGreater compareSignalingGreaterEqual compareQuietEqual compareQuietNotEqual

1

7 In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC, if x1 or x2 are numeric

2 3 4 5 6

entities, the type of x1 + x2 is complex, and IEEE_SUPPORT_NAN (REAL (x1 + x2 )) is true, the intrinsic equality or inequality operation between x1 and x2 may signal IEEE_INVALID if the value of the real or imaginary part of either operand is a signaling NaN. If any conversions are done before the values are compared, those conversions might signal exceptions instead of or in addition to an IEEE_INVALID exception signaled by the comparison.

7

8 In a sequence of statements that has no invocations of IEEE_GET_FLAG, IEEE_SET_FLAG, IEEE_GET_-

8 9 10 11

STATUS, IEEE_SET_HALTING_MODE, or IEEE_SET_STATUS, if the execution of an operation would cause an exception to signal but after execution of the sequence no value of a variable depends on the operation, whether the exception is signaling is processor dependent. For example, when Y has the value zero, whether the code X = 1.0/Y X = 3.0

12 13 14

signals IEEE_DIVIDE_BY_ZERO is processor dependent. Another example is the following: REAL, PARAMETER :: X=0.0, Y=6.0 IF (1.0/X == Y) PRINT *,’Hello world’

15 16 17 18

where the processor is permitted to discard the IF statement because the logical expression can never be true and no value of a variable depends on it.

19 20

9 An exception shall not signal if this could arise only during execution of an operation beyond those required or

permitted by the standard. For example, the statement IF (F (X) > 0.0) Y = 1.0/Z

21 22

shall not signal IEEE_DIVIDE_BY_ZERO when both F (X) and Z are zero and the statement WHERE (A > 0.0) A = 1.0/A

23 24 25

shall not signal IEEE_DIVIDE_BY_ZERO. On the other hand, when X has the value 1.0 and Y has the value 0.0, the expression X>0.00001 .OR. X/Y>0.00001

26 27 28 29

is permitted to cause the signaling of IEEE_DIVIDE_BY_ZERO. 10 The processor need not support IEEE_INVALID, IEEE_UNDERFLOW, and IEEE_INEXACT. If an exception

is not supported, its flag is always quiet.

460

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6

17.4

WD 1539-1

J3/21-007r1

The rounding modes

1 This document specifies a binary rounding mode that affects floating-point arithmetic with radix two, and a

decimal rounding mode that affects floating-point arithmetic with radix ten. Unqualified references to the rounding mode with respect to a particular arithmetic operation or operands refers to the mode for the radix of the operation or operands, and other unqualified references to the rounding mode refers to both binary and decimal rounding modes.

7 8 9 10 11

2 ISO/IEC 60559:2020 specifies five possible rounding-direction attributes: roundTiesToEven, roundTowardZero,

12 13

3 The subroutine IEEE_GET_ROUNDING_MODE can be used to get the rounding modes. The initial rounding

14 15

4 If the processor supports the alteration of the rounding modes during execution, the subroutine IEEE_SET_-

16 17

5 In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS, the processor shall not

18

roundTowardPositive, roundTowardNegative, and roundTiesToAway. These correspond to the rounding modes IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, and IEEE_AWAY respectively. The rounding mode IEEE_OTHER does not correspond to any ISO/IEC/IEEE 60559:2011 rounding-direction attribute; if supported, the effect of this rounding mode is processor dependent. modes are processor dependent. ROUNDING_MODE can be used to alter them. change the rounding modes on entry, and on return shall ensure that the rounding modes are the same as they were on entry. NOTE 1 ISO/IEC 60559:2020 requires support for roundTiesToAway only for decimal floating-point. NOTE 2 ISO/IEC 60559:2020 requires that there is a language-defined means to specify a constant value for the rounding-direction attribute for all standard operations in a block. The means provided by this document are a CALL to IEEE_GET_ROUNDING_MODE at the beginning of the block followed by a CALL to IEEE_SET_ROUNDING_MODE with constant arguments, together with another CALL to IEEE_SET_ROUNDING_MODE at the end of the block to restore the rounding mode. NOTE 3 Within a program, all literal constants that have the same form have the same value (7.1.4). Therefore, the value of a literal constant is not affected by the rounding modes.

19

17.5

Underflow mode

20 21 22 23

1 Some processors allow control during program execution of whether underflow produces a subnormal number in

24 25

2 Control over the underflow mode is exercised by invocation of IEEE_SET_UNDERFLOW_MODE. The sub-

26 27 28 29 30 31

conformance with ISO/IEC 60559:2020 (gradual underflow) or produces zero instead (abrupt underflow). On some processors, floating-point performance is typically better in abrupt underflow mode than in gradual underflow mode. routine IEEE_GET_UNDERFLOW_MODE can be used to get the underflow mode. The inquiry function IEEE_SUPPORT_UNDERFLOW_CONTROL can be used to inquire whether this facility is available. The initial underflow mode is processor dependent. In a procedure other than IEEE_SET_UNDERFLOW_MODE or IEEE_SET_STATUS, the processor shall not change the underflow mode on entry, and on return shall ensure that the underflow mode is the same as it was on entry. 3 The underflow mode affects only floating-point calculations whose type is that of an X for which IEEE_SUP-

PORT_UNDERFLOW_CONTROL returns true.

ISO/IEC JTC 1/SC 22/WG5/N2184

461

J3/21-007r1

1 2 3 4 5

17.6

WD 1539-1

2021-05-21

Halting

1 Some processors allow control during program execution of whether to abort or continue execution after an

6 7

exception. Such control is exercised by invocation of the subroutine IEEE_SET_HALTING_MODE. Halting is not precise and may occur any time after the exception has occurred. The initial halting mode is processor dependent. In a procedure other than IEEE_SET_HALTING_MODE or IEEE_SET_STATUS, the processor shall not change the halting mode on entry, and on return shall ensure that the halting mode is the same as it was on entry.

8

17.7

9 10 11 12 13 14 15

The floating-point modes and status

1 The values of the rounding modes, underflow mode, and halting mode are collectively called the floating-point

modes. The values of all the supported flags for exceptions and the floating-point modes are collectively called the floating-point status. The floating-point modes can be stored in a scalar variable of type IEEE_MODES_TYPE with the subroutine IEEE_GET_MODES and restored with the subroutine IEEE_SET_MODES. The floatingpoint status can be stored in a scalar variable of type IEEE_STATUS_TYPE with the subroutine IEEE_GET_STATUS and restored with the subroutine IEEE_SET_STATUS. There are no facilities for finding the values of particular flags represented by such a variable. NOTE 1 Each image has its own floating-point status (5.3.4). NOTE 2 Some processors hold all these flags and modes in one or two status registers that can be obtained and set as a whole faster than all individual flags and modes can be obtained and set. These procedures are provided to exploit this feature. NOTE 3 The processor is required to ensure that a call to a Fortran procedure does not change the floating-point status other than by setting exception flags to signaling.

16 17 18 19 20

17.8

Exceptional values

1 ISO/IEC 60559:2020 specifies the following exceptional floating-point values.

• Subnormal values have very small absolute values and reduced precision. • Infinite values (+infinity and −infinity) are created by overflow or division by zero. • Not-a-Number ( NaN) values are undefined values or values created by an invalid operation.

21

2 A value that does not fall into the above classes is called a normal number.

22 23

3 The functions IEEE_IS_FINITE, IEEE_IS_NAN, IEEE_IS_NEGATIVE, and IEEE_IS_NORMAL are

24 25 26

provided to test whether a value is finite, NaN, negative, or normal. The function IEEE_VALUE is provided to generate an IEEE number of any class, including an infinity or a NaN. The inquiry functions IEEE_SUPPORT_SUBNORMAL, IEEE_SUPPORT_INF, and IEEE_SUPPORT_NAN are provided to determine whether these facilities are available for a particular kind of real.

27

17.9

28 29

IEEE arithmetic

1 The inquiry function IEEE_SUPPORT_DATATYPE can be used to inquire whether IEEE arithmetic is sup-

ported for a particular kind of real. Complete conformance with ISO/IEC 60559:2020 is not required, but

462

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8

WD 1539-1

J3/21-007r1

• the normal numbers shall be exactly those of an ISO/IEC/IEEE 60559:2011 floating-point format, • for at least one rounding mode, the intrinsic operations of addition, subtraction and multiplication shall conform whenever the operands and result specified by ISO/IEC 60559:2020 are normal numbers, • the IEEE function abs shall be provided by the intrinsic function ABS, • the IEEE operation remainder shall be provided by the function IEEE_REM, and • the IEEE functions copySign, logB, and compareQuietUnordered shall be provided by the functions IEEE_COPY_SIGN, IEEE_LOGB, and IEEE_UNORDERED, respectively, for that kind of real.

9 10 11 12

2 The inquiry function IEEE_SUPPORT_NAN is provided to inquire whether the processor supports IEEE NaNs.

13 14 15 16

3 The inquiry function IEEE_SUPPORT_INF is provided to inquire whether the processor supports IEEE infinit-

17 18

4 The inquiry function IEEE_SUPPORT_SUBNORMAL is provided to inquire whether the processor supports

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

Where these are supported, the result of the intrinsic operations +, −, and *, and the functions IEEE_REM and IEEE_RINT from the intrinsic module IEEE_ARITHMETIC, shall conform to ISO/IEC 60559:2020 when the result is an IEEE NaN. ies. Where these are supported, the result of the intrinsic operations +, −, and *, and the functions IEEE_REM and IEEE_RINT from the intrinsic module IEEE_ARITHMETIC, shall conform to ISO/IEC 60559:2020 when exactly one operand or the result specified by ISO/IEC 60559:2020 is an IEEE infinity. subnormal numbers. Where these are supported, the result of the intrinsic operations +, −, and *, and the functions IEEE_REM and IEEE_RINT from the intrinsic module IEEE_ARITHMETIC, shall conform to ISO/IEC 60559:2020 when the result specified by ISO/IEC 60559:2020 is subnormal, or any operand is subnormal and either the result is not an IEEE infinity or IEEE_SUPPORT_INF is true. 5 The inquiry function IEEE_SUPPORT_DIVIDE is provided to inquire whether, on kinds of real for which

IEEE_SUPPORT_DATATYPE returns true, the intrinsic division operation conforms to ISO/IEC 60559:2020 when both operands and the result specified by ISO/IEC 60559:2020 are normal numbers. If IEEE_SUPPORT_NAN is also true for a particular kind of real, the intrinsic division operation on that kind conforms to ISO/IEC 60559:2020 when the result specified by ISO/IEC 60559:2020 is a NaN. If IEEE_SUPPORT_INF is also true for a particular kind of real, the intrinsic division operation on that kind conforms to ISO/IEC 60559:2020 when one operand or the result specified by ISO/IEC 60559:2020 is an IEEE infinity. If IEEE_SUPPORT_SUBNORMAL is also true for a particular kind of real, the intrinsic division operation on that kind conforms to ISO/IEC 60559:2020 when the result specified by ISO/IEC 60559:2020 is subnormal, or when any operand is subnormal and either the result specified by ISO/IEC 60559:2020 is not an infinity or IEEE_SUPPORT_INF is true. 6 ISO/IEC 60559:2020 specifies a square root function that returns negative real zero for the square root of neg-

36 37 38 39 40

ative real zero and has certain accuracy requirements. The inquiry function IEEE_SUPPORT_SQRT can be used to inquire whether the intrinsic function SQRT conforms to ISO/IEC 60559:2020 for a particular kind of real. If IEEE_SUPPORT_NAN is also true for a particular kind of real, the intrinsic function SQRT on that kind conforms to ISO/IEC 60559:2020 when the result specified by ISO/IEC 60559:2020 is a NaN. If IEEE_SUPPORT_INF is also true for a particular kind of real, the intrinsic function SQRT on that kind conforms to ISO/IEC 60559:2020 when the result specified by ISO/IEC 60559:2020 is an IEEE infinity. If IEEE_SUPPORT_SUBNORMAL is also true for a particular kind of real, the intrinsic function SQRT on that kind conforms to ISO/IEC 60559:2020 when the argument is subnormal.

41

7 The inquiry function IEEE_SUPPORT_STANDARD is provided to inquire whether the processor supports all

42

the ISO/IEC/IEEE 60559:2011 facilities defined in this document for a particular kind of real.

43

17.10

Summary of the procedures

44 45

1 For all of the procedures defined in the modules, the arguments shown are the names that shall be used for

46

2 A procedure classified in 17.10 as an inquiry function depends on the properties of one or more of its arguments

argument keywords if the keyword form is used for the actual arguments.

ISO/IEC JTC 1/SC 22/WG5/N2184

463

J3/21-007r1

1 2 3 4 5 6 7 8 9 10 11

WD 1539-1

2021-05-21

instead of their values; in fact, these argument values may be undefined. Unless the description of one of these inquiry functions states otherwise, these arguments are permitted to be unallocated allocatable variables or pointers that are undefined or disassociated. A procedure that is classified as a transformational function is neither an inquiry function nor elemental. 3 In the Class column of Tables 17.2 and 17.3,

E indicates that the procedure is an elemental function, ES indicates that the procedure is a simple elemental subroutine, I indicates that the procedure is an inquiry function, S indicates that the procedure is an impure subroutine, SS indicates that the procedure is a simple subroutine, and T indicates that the procedure in a transformational function. Table 17.2: IEEE_ARITHMETIC module procedure summary Procedure (arguments) Class Description IEEE_CLASS (X) E Classify number. IEEE_COPY_SIGN (X, Y) E Copy sign. IEEE_FMA (A, B, C) E Fused multiply-add operation. IEEE_GET_ROUNDING_MODE (ROUND_VALUE S Get rounding mode. [, RADIX]) IEEE_GET_UNDERFLOW_MODE (GRADUAL) S Get underflow mode. IEEE_INT (A, ROUND [, KIND]) E Conversion to integer type. IEEE_IS_FINITE (X) E Whether a value is finite. IEEE_IS_NAN (X) E Whether a value is an IEEE NaN. IEEE_IS_NEGATIVE (X) E Whether a value is negative. IEEE_IS_NORMAL (X) E Whether a value is a normal number. IEEE_LOGB (X) E Exponent. IEEE_MAX (X, Y) E Maximum value. IEEE_MAX_MAG (X, Y) E Maximum magnitude value. IEEE_MAX_NUM (X, Y) E Maximum numeric value. IEEE_MAX_NUM_MAG (X, Y) E Maximum magnitude numeric value. IEEE_MIN (X, Y) E Minimum value. IEEE_MIN_MAG (X, Y) E Minimum magnitude value. IEEE_MIN_NUM (X, Y) E Minimum numeric value. IEEE_MIN_NUM_MAG (X, Y) E Minimum magnitude numeric value. IEEE_NEXT_AFTER (X, Y) E Adjacent machine number. IEEE_NEXT_DOWN (X) E Adjacent lower machine number. IEEE_NEXT_UP (X) E Adjacent higher machine number. IEEE_QUIET_EQ (A, B) E Quiet compares equal. IEEE_QUIET_GE (A, B) E Quiet compares greater than or equal. IEEE_QUIET_GT (A, B) E Quiet compares greater than. IEEE_QUIET_LE (A, B) E Quiet compares less than or equal. IEEE_QUIET_LT (A, B) E Quiet compares less than. IEEE_QUIET_NE (A, B) E Quiet compares not equal. IEEE_REAL (A [, KIND]) E Conversion to real type. IEEE_REM (X, Y) E Exact remainder. IEEE_RINT (X) E Round to integer. IEEE_SCALB (X, I) E X × 2I . IEEE_SELECTED_REAL_KIND ([P, R, RADIX]) T IEEE kind type parameter value. IEEE_SET_ROUNDING_MODE (ROUND_VALUE S Set rounding mode. [, RADIX]) IEEE_SET_UNDERFLOW_MODE (GRADUAL) S Set underflow mode. IEEE_SIGNALING_EQ (A, B) E Signaling compares equal. IEEE_SIGNALING_GE (A, B) E Signaling compares greater than or equal. IEEE_SIGNALING_GT (A, B) E Signaling compares greater than.

464

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Table 17.2: IEEE_ARITHMETIC module procedure summary (cont.) Procedure (arguments) Class Description IEEE_SIGNALING_LE (A, B) E Signaling compares less than or equal. IEEE_SIGNALING_LT (A, B) E Signaling compares less than. IEEE_SIGNALING_NE (A, B) E Signaling compares not equal. IEEE_SIGNBIT (X) E Test sign bit. IEEE_SUPPORT_DATATYPE ([X]) I Query IEEE arithmetic support. IEEE_SUPPORT_DENORMAL ([X]) I Query subnormal number support. IEEE_SUPPORT_DIVIDE ([X]) I Query IEEE division support. IEEE_SUPPORT_INF ([X]) I Query IEEE infinity support. IEEE_SUPPORT_IO ([X]) I Query IEEE formatting support. IEEE_SUPPORT_NAN ([X]) I Query IEEE NaN support. IEEE_SUPPORT_ROUNDING (ROUND_VALUE [, X]) T Query IEEE rounding support. IEEE_SUPPORT_SQRT ([X]) I Query IEEE square root support. IEEE_SUPPORT_SUBNORMAL ([X]) I Query subnormal number support. IEEE_SUPPORT_STANDARD ([X]) I Query IEEE standard support. IEEE_SUPPORT_UNDERFLOW_CONTROL ([X]) I Query underflow control support. IEEE_UNORDERED (X, Y) E Whether two values are unordered. IEEE_VALUE (X, CLASS) E Return number in a class.

Table 17.3: IEEE_EXCEPTIONS module procedure summary Procedure (arguments) Class Description IEEE_GET_FLAG (FLAG, FLAG_VALUE) ES Get an exception flag. IEEE_GET_HALTING_MODE (FLAG, HALTING) ES Get a halting mode. IEEE_GET_MODES (MODES) S Get floating-point modes. IEEE_GET_STATUS (STATUS_VALUE) S Get floating-point status. IEEE_SET_FLAG (FLAG, FLAG_VALUE) SS Set an exception flag. IEEE_SET_HALTING_MODE (FLAG, HALTING) SS Set a halting mode. IEEE_SET_MODES (MODES) S Set floating-point modes. IEEE_SET_STATUS (STATUS_VALUE) S Restore floating-point status. IEEE_SUPPORT_FLAG (FLAG [, X]) T Query exception support. IEEE_SUPPORT_HALTING (FLAG) T Query halting mode support.

1

4 In the intrinsic module IEEE_ARITHMETIC, the elemental functions listed are provided for all reals X and Y.

2

17.11

Specifications of the procedures

3

17.11.1

General

4

1 In the detailed descriptions in 17.11, procedure names are generic and are not specific. All the functions are

5 6 7

simple and all the subroutines are impure unless otherwise stated. All dummy arguments have INTENT (IN) if the intent is not stated explicitly. In the examples, it is assumed that the processor supports IEEE arithmetic for default real.

8 9

2 For the elemental functions of IEEE_ARITHMETIC that return a floating-point result, if X or Y has a value

10 11 12 13

that is an infinity or a NaN, the result shall be consistent with the general rules in 6.1 and 6.2 of ISO/IEC 60559:2020. For example, the result for an infinity shall be constructed as the limiting case of the result with a value of arbitrarily large magnitude, if such a limit exists. 3 A program may contain statements that, if executed, would violate the requirements listed in a Restriction

paragraph.

ISO/IEC JTC 1/SC 22/WG5/N2184

465

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 A program can avoid violating those requirements by using IF constructs to check whether particular features are supported. For example, IF (IEEE_SUPPORT_DATATYPE (X)) THEN C = IEEE_CLASS (X) ELSE ... END IF avoids invoking IEEE_CLASS except on a processor which supports that facility. 1

17.11.2

IEEE_CLASS (X)

2

1 Description. Classify number.

3

2 Class. Elemental function.

4

3 Argument. X shall be of type real.

5

4 Restriction. IEEE_CLASS (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

6

5 Result Characteristics. IEEE_CLASS_TYPE.

7 8

6 Result Value. The result value shall be IEEE_SIGNALING_NAN or IEEE_QUIET_NAN if IEEE_SUP-

9 10 11 12 13 14 15 16

PORT_NAN (X) has the value true and the value of X is a signaling or quiet NaN, respectively. The result value shall be IEEE_NEGATIVE_INF or IEEE_POSITIVE_INF if IEEE_SUPPORT_INF (X) has the value true and the value of X is negative or positive infinity, respectively. The result value shall be IEEE_NEGATIVE_SUBNORMAL or IEEE_POSITIVE_SUBNORMAL if IEEE_SUPPORT_SUBNORMAL (X) has the value true and the value of X is a negative or positive subnormal value, respectively. The result value shall be IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, or IEEE_POSITIVE_NORMAL if the value of X is negative normal, negative zero, positive zero, or positive normal, respectively. Otherwise, the result value shall be IEEE_OTHER_VALUE. 7 Example. IEEE_CLASS (−1.0) has the value IEEE_NEGATIVE_NORMAL.

NOTE 1 The result value IEEE_OTHER_VALUE is useful on systems that are almost IEEE-compatible, but do not implement all of it. For example, if a subnormal value is encountered on a system that does not support them. 17

17.11.3

IEEE_COPY_SIGN (X, Y)

18

1 Description. Copy sign.

19

2 Class. Elemental function.

20

3 Arguments. The arguments shall be of type real.

21 22

4 Restriction.

23

5 Result Characteristics. Same as X.

24 25

6 Result Value. The result has the absolute value of X with the sign of Y. This is true even for IEEE special

26

7 Example. The value of IEEE_COPY_SIGN (X, 1.0) is ABS (X) even when X is a NaN.

IEEE_COPY_SIGN (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or IEEE_SUPPORT_DATATYPE (Y) has the value false.

values, such as a NaN or an infinity (on processors supporting such values).

466

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

17.11.4

WD 1539-1

IEEE_FMA (A, B, C)

2

1 Description. Fused multiply-add operation.

3

2 Class. Elemental function.

4

3 Arguments.

5

A

shall be of type real.

6

B C

shall be of the same type and kind type parameter as A. shall be of the same type and kind type parameter as A.

7 8 9

J3/21-007r1

4 Restriction. IEEE_FMA (A, B, C) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the value

false.

10

5 Result Characteristics. Same as A.

11 12 13 14

6 Result Value. The result has the value specified by ISO/IEC 60559:2020 for the fusedMultiplyAdd operation;

15

that is, when the result is in range, its value is equal to the mathematical value of (A × B) + C rounded to the representation method of A according to the rounding mode. IEEE_OVERFLOW, IEEE_UNDERFLOW, and IEEE_INEXACT shall be signaled according to the final step in the calculation and not by any intermediate calculation.

16 17

7 Example.

18

17.11.5

The value of IEEE_FMA (TINY (0.0), TINY (0.0), 1.0), when the rounding mode is IEEE_NEAREST, is equal to 1.0; only the IEEE_INEXACT exception is signaled.

IEEE_GET_FLAG (FLAG, FLAG_VALUE)

19

1 Description. Get an exception flag.

20

2 Class. Elemental subroutine.

21

3 Arguments.

22

FLAG

23 24 25 26

FLAG_VALUE shall be of type logical. It is an INTENT (OUT) argument. If the value of FLAG is IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT, FLAG_VALUE is assigned the value true if the corresponding exception flag is signaling and is assigned the value false otherwise.

27 28

4 Example. Following CALL IEEE_GET_FLAG (IEEE_OVERFLOW, FLAG_VALUE), FLAG_VALUE is

29

shall be of type IEEE_FLAG_TYPE. It specifies the exception flag to be obtained.

true if the IEEE_OVERFLOW flag is signaling and is false if it is quiet.

17.11.6

IEEE_GET_HALTING_MODE (FLAG, HALTING)

30

1 Description. Get a halting mode.

31

2 Class. Elemental subroutine.

32

3 Arguments.

33 34 35

FLAG

shall be of type IEEE_FLAG_TYPE. It specifies the exception flag. It shall have one of the values IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT.

36 37

HALTING

shall be of type logical. It is an INTENT (OUT) argument. It is assigned the value true if the exception specified by FLAG will cause halting. Otherwise, it is assigned the value false.

38 39

4 Example. To store the halting mode for IEEE_OVERFLOW, do a calculation without halting, and restore the

halting mode later:

ISO/IEC JTC 1/SC 22/WG5/N2184

467

J3/21-007r1

2021-05-21

USE, INTRINSIC :: IEEE_ARITHMETIC LOGICAL HALTING ... CALL IEEE_GET_HALTING_MODE (IEEE_OVERFLOW, HALTING) ! Store halting mode CALL IEEE_SET_HALTING_MODE (IEEE_OVERFLOW, .FALSE.) ! No halting . . . ! calculation without halting CALL IEEE_SET_HALTING_MODE (IEEE_OVERFLOW, HALTING) ! Restore halting mode

1 2 3 4 5 6 7

8

WD 1539-1

17.11.7

IEEE_GET_MODES (MODES)

9

1 Description. Get floating-point modes.

10

2 Class. Subroutine.

11

3 Argument. MODES shall be a scalar of type IEEE_MODES_TYPE. It is an INTENT (OUT) argument that

12 13 14

is assigned the value of the floating-point modes. 4 Example. To save the floating-point modes, do a calculation with specific rounding and underflow modes, and

restore them later: USE, INTRINSIC :: IEEE_ARITHMETIC TYPE (IEEE_MODES_TYPE) SAVE_MODES ... CALL IEEE_GET_MODES (SAVE_MODES) ! Save all modes. CALL IEEE_SET_ROUNDING_MODE (IEEE_TO_ZERO) CALL IEEE_SET_UNDERFLOW_MODE (GRADUAL=.FALSE.) . . . ! calculation with abrupt round-to-zero. CALL IEEE_SET_MODES (SAVE_MODES) ! Restore all modes.

15 16 17 18 19 20 21 22

23

17.11.8

IEEE_GET_ROUNDING_MODE (ROUND_VALUE [, RADIX])

24

1 Description. Get rounding mode.

25

2 Class. Subroutine.

26

3 Arguments.

27 28 29

ROUND_VALUE shall be a scalar of type IEEE_ROUND_TYPE. It is an INTENT (OUT) argument. It is assigned the value IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, or IEEE_AWAY if the corresponding rounding mode is in operation and IEEE_OTHER otherwise.

30 31

RADIX (optional) shall be an integer scalar with the value two or ten. If RADIX is present with the value ten, the rounding mode queried is the decimal rounding mode, otherwise it is the binary rounding mode.

32

4 Example. To save the binary rounding mode, do a calculation with round to nearest, and restore the rounding

33

mode later: USE, INTRINSIC :: IEEE_ARITHMETIC TYPE (IEEE_ROUND_TYPE) ROUND_VALUE ... CALL IEEE_GET_ROUNDING_MODE (ROUND_VALUE) ! Store the rounding mode CALL IEEE_SET_ROUNDING_MODE (IEEE_NEAREST) . . . ! calculation with round to nearest CALL IEEE_SET_ROUNDING_MODE (ROUND_VALUE) ! Restore the rounding mode

34 35 36 37 38 39 40

468

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

17.11.9

WD 1539-1

J3/21-007r1

IEEE_GET_STATUS (STATUS_VALUE)

2

1 Description. Get floating-point status.

3

2 Class. Subroutine.

4 5

3 Argument. STATUS_VALUE shall be a scalar of type IEEE_STATUS_TYPE. It is an INTENT (OUT)

6

4 Example. To store all the exception flags, do a calculation involving exception handling, and restore them later:

argument. It is assigned the value of the floating-point status.

USE, INTRINSIC :: IEEE_ARITHMETIC TYPE (IEEE_STATUS_TYPE) STATUS_VALUE ... CALL IEEE_GET_STATUS (STATUS_VALUE) ! Get the flags CALL IEEE_SET_FLAG (IEEE_ALL, .FALSE.) ! Set the flags quiet. . . . ! calculation involving exception handling CALL IEEE_SET_STATUS (STATUS_VALUE) ! Restore the flags

7 8 9 10 11 12 13

14

17.11.10 IEEE_GET_UNDERFLOW_MODE (GRADUAL)

15

1 Description. Get underflow mode.

16

2 Class. Subroutine.

17 18

3 Argument. GRADUAL shall be a logical scalar. It is an INTENT (OUT) argument. It is assigned the value

19

4 Restriction. IEEE_GET_UNDERFLOW_MODE shall not be invoked unless IEEE_SUPPORT_UNDER-

20 21 22 23

true if the underflow mode is gradual underflow, and false if the underflow mode is abrupt underflow. FLOW_CONTROL (X) is true for some X. 5 Example. After CALL IEEE_SET_UNDERFLOW_MODE (.FALSE.), a subsequent CALL IEEE_GET_-

UNDERFLOW_MODE (GRADUAL) will set GRADUAL to false.

17.11.11 IEEE_INT (A, ROUND [, KIND])

24

1 Description. Conversion to integer type.

25

2 Class. Elemental function.

26

3 Arguments.

27

A

28

ROUND shall be of type IEEE_ROUND_TYPE. KIND (optional) shall be a scalar integer constant expression.

29 30 31

shall be of type real.

4 Restriction. IEEE_INT (A, ROUND, KIND) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

the value false.

32 33

5 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of

34 35 36

6 Result Value. The result has the value specified by ISO/IEC 60559:2020 for the convertToInteger{round} or

37 38

KIND; otherwise, the kind type parameter is that of default integer. the convertToIntegerExact{round} operation; the processor shall consistently choose which operation it provides. That is, the value of A is converted to an integer according to the rounding mode specified by ROUND; if this value is representable in the representation method of the result, the result has this value, otherwise IEEE_INVALID is signaled and the result is processor dependent. If the processor provides the convertToIntegerExact

ISO/IEC JTC 1/SC 22/WG5/N2184

469

J3/21-007r1

WD 1539-1

2021-05-21

1 2

operation, IEEE_INVALID did not signal, and the value of the result differs from that of A, IEEE_INEXACT will be signaled.

3 4

7 Example. The value of IEEE_INT (12.5, IEEE_UP) is 13; IEEE_INEXACT will be signaled if the processor

provides the convertToIntegerExact operation.

5

17.11.12 IEEE_IS_FINITE (X)

6

1 Description. Whether a value is finite.

7

2 Class. Elemental function.

8

3 Argument. X shall be of type real.

9 10

4 Restriction. IEEE_IS_FINITE (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value

11

5 Result Characteristics. Default logical.

12 13 14 15

6 Result Value. The result has the value true if the value of X is finite, that is, IEEE_CLASS (X) has one

16

7 Example. IEEE_IS_FINITE (1.0) has the value true.

17

false.

of the values IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_SUBNORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, IEEE_POSITIVE_SUBNORMAL, or IEEE_POSITIVE_NORMAL; otherwise, the result has the value false.

17.11.13 IEEE_IS_NAN (X)

18

1 Description. Whether a value is an IEEE NaN.

19

2 Class. Elemental function.

20

3 Argument. X shall be of type real.

21

4 Restriction. IEEE_IS_NAN (X) shall not be invoked if IEEE_SUPPORT_NAN (X) has the value false.

22

5 Result Characteristics. Default logical.

23

6 Result Value. The result has the value true if the value of X is an IEEE NaN; otherwise, it has the value false.

24 25

7 Example. IEEE_IS_NAN (SQRT (−1.0)) has the value true if IEEE_SUPPORT_SQRT (1.0) has the value

26

true.

17.11.14 IEEE_IS_NEGATIVE (X)

27

1 Description. Whether a value is negative.

28

2 Class. Elemental function.

29

3 Argument. X shall be of type real.

30 31

4 Restriction. IEEE_IS_NEGATIVE (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the

32

5 Result Characteristics. Default logical.

33 34

6 Result Value. The result has the value true if IEEE_CLASS (X) has one of the values IEEE_NEGATIVE_-

35

value false.

NORMAL, IEEE_NEGATIVE_SUBNORMAL, IEEE_NEGATIVE_ZERO or IEEE_NEGATIVE_INF; otherwise, the result has the value false.

470

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

7 Example. IEEE_IS_NEGATIVE (0.0) has the value false.

17.11.15 IEEE_IS_NORMAL (X)

3

1 Description. Whether a value is a normal number.

4

2 Class. Elemental function.

5

3 Argument. X shall be of type real.

6 7

4 Restriction. IEEE_IS_NORMAL (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the

8

5 Result Characteristics. Default logical.

9 10 11

6 Result Value. The result has the value true if IEEE_CLASS (X) has one of the values IEEE_NEGATIVE_-

12 13

7 Example. IEEE_IS_NORMAL (SQRT (−1.0) has the value false if IEEE_SUPPORT_SQRT (1.0) has the

14

value false.

NORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO or IEEE_POSITIVE_NORMAL; otherwise, the result has the value false. value true.

17.11.16 IEEE_LOGB (X)

15

1 Description. Exponent.

16

2 Class. Elemental function.

17

3 Argument. X shall be of type real.

18

4 Restriction. IEEE_LOGB (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

19

5 Result Characteristics. Same as X.

20

6 Result Value.

21 22

Case (i):

23 24

Case (ii):

25

Case (iii): Case (iv):

26 27 28

If the value of X is neither zero, infinity, nor NaN, the result has the value of the unbiased exponent of X. Note: this value is equal to EXPONENT (X)− 1. If X==0, the result is −infinity if IEEE_SUPPORT_INF (X) is true and −HUGE (X) otherwise; IEEE_DIVIDE_BY_ZERO signals. If IEEE_SUPPORT_INF (X) is true and X is infinite, the result is +infinity. If IEEE_SUPPORT_NAN (X) is true and X is a NaN, the result is a NaN.

7 Example. IEEE_LOGB (−1.1) has the value 0.0.

17.11.17 IEEE_MAX (X, Y)

29

1 Description. Maximum value.

30

2 Class. Elemental function.

31

3 Arguments.

32

X

shall be of type real.

33

Y

shall be of the same type and kind type parameter as X.

34

4 Restriction. IEEE_MAX shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

35

5 Result Characteristics. Same as X.

36

6 Result Value.

ISO/IEC JTC 1/SC 22/WG5/N2184

471

J3/21-007r1

1

WD 1539-1

2021-05-21

7 The result has the value specified for the maximum operation in ISO/IEC 60559:2020; that is,

6

• if X > Y the result has the value of X; • if Y > X the result has the value of Y; • if either operand is a NaN, the result is a quiet Nan; • if X = Y and the signs are the same, the result is the value of either X or Y; • otherwise (one argument is negative zero and the other is positive zero), the result is positive zero.

7

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals; otherwise, no exception is signaled.

2 3 4 5

8 9

8 Example. The value of IEEE_MAX (1.5, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) is a quiet NaN.

17.11.18 IEEE_MAX_MAG (X, Y)

10

1 Description. Maximum magnitude value.

11

2 Class. Elemental function.

12

3 Arguments.

13

X

shall be of type real.

14

Y

shall be of the same type and kind type parameter as X.

15 16

4 Restriction. IEEE_MAX_MAG shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value

17

5 Result Characteristics. Same as X.

18

6 Result Value.

19

7 The result has the value specified for the maximumMagnitude operation in ISO/IEC 60559:2020; that is,

false.

• if |X| > |Y| the result has the value of X; • if |Y| > |X| the result has the value of Y; • otherwise, the result has the value of IEEE_MAX (X, Y).

20 21 22 23 24 25

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals; otherwise, no exception is signaled. 8 Example. The value of IEEE_MAX_MAG (1.5, −2.5) is −2.5.

17.11.19 IEEE_MAX_NUM (X, Y)

26

1 Description. Maximum numeric value.

27

2 Class. Elemental function.

28

3 Arguments.

29

X

shall be of type real.

30

Y

shall be of the same type and kind type parameter as X.

31 32

4 Restriction. IEEE_MAX_NUM shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value

33

5 Result Characteristics. Same as X.

34 35

6 Result Value. The result has the value specified for the maximumNumber operation in ISO/IEC 60559:2020;

36 37 38

false.

that is, • if X > Y the result has the value of X; • if Y > X the result has the value of Y; • if exactly one of X and Y is a NaN the result has the value of the other argument;

472

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2 3

5 6 7

J3/21-007r1

• if both X and Y are NaNs, the result is a quiet NaN; • if X = Y and the signs are the same, the result is either X or Y; • otherwise (one argument is negative zero and the other is positive zero), the result is positive zero.

1

4

WD 1539-1

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals, but unless X and Y are both signaling NaNs, the signaling NaN is otherwise ignored and not converted to a quiet NaN. No other exceptions are signaled. 7 Example. The value of IEEE_MAX_NUM (1.5, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) is 1.5.

17.11.20 IEEE_MAX_NUM_MAG (X, Y)

8

1 Description. Maximum magnitude numeric value.

9

2 Class. Elemental function.

10

3 Arguments.

11

X

shall be of type real.

12

Y

shall be of the same type and kind type parameter as X.

13 14

4 Restriction. IEEE_MAX_NUM_MAG shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the

15

5 Result Characteristics. Same as X.

16 17

6 Result Value.

value false.

20

The result has the value specified for the maximumMagnitudeNumber operation in ISO/IEC 60559:2020; that is, • if |X| > |Y| the result has the value of X; • if |Y| > |X| the result has the value of Y; • otherwise, the result has the value of IEEE_MAX_NUM (X, Y).

21 22

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals, but unless X and Y are both signaling NaNs, the signaling NaN is otherwise ignored and not converted to a quiet NaN. No other exceptions are signaled.

18 19

23 24

7 Example. The value of IEEE_MAX_NUM_MAG (1.5, −2.5) is −2.5.

17.11.21 IEEE_MIN (X, Y)

25

1 Description. Minimum value.

26

2 Class. Elemental function.

27

3 Arguments.

28 29

X Y

shall be of type real. shall be of the same type and kind type parameter as X.

30

4 Restriction. IEEE_MIN shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

31

5 Result Characteristics. Same as X.

32

6 Result Value.

33

7 The result has the value specified for the minimum operation in ISO/IEC 60559:2020; that is,

34 35 36 37 38

• if X < Y the result has the value of X; • if Y < X the result has the value of Y; • if either operand is a NaN, the result is a quiet NaN; • if X = Y and the signs are the same, the result is the value of either X or Y; • otherwise (one argument is negative zero and the other is positive zero), the result is negative zero.

ISO/IEC JTC 1/SC 22/WG5/N2184

473

J3/21-007r1

1 2 3

WD 1539-1

2021-05-21

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals; otherwise, no exception is signaled. 8 Example. The value of IEEE_MIN (1.5, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) is a quiet NaN.

17.11.22 IEEE_MIN_MAG (X, Y)

4

1 Description. Minimum magnitude value.

5

2 Class. Elemental function.

6

3 Arguments.

7

X

shall be of type real.

8

Y

shall be of the same type and kind type parameter as X.

9

4 Restriction. IEEE_MIN_MAG shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

10

5 Result Characteristics. Same as X.

11

6 Result Value.

12

7 The result has the value specified for the minimumMagnitude operation in ISO/IEC 60559:2020; that is,

• if |X| < |Y| the result has the value of X; • if |Y| < |X| the result has the value of Y; • otherwise, the result has the value of IEEE_MIN (X, Y).

13 14 15 16 17 18

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals; otherwise, no exception is signaled. 8 Example. The value of IEEE_MIN_MAG (1.5, −2.5) is 1.5.

17.11.23 IEEE_MIN_NUM (X, Y)

19

1 Description. Minimum numeric value.

20

2 Class. Elemental function.

21

3 Arguments.

22

X

shall be of type real.

23

Y

shall be of the same type and kind type parameter as X.

24

4 Restriction. IEEE_MIN_NUM shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

25

5 Result Characteristics. Same as X.

26 27

6 Result Value.

33

The result has the value specified for the minimumNumber operation in ISO/IEC 60559:2020; that is, • if X < Y the result has the value of X; • if Y < X the result has the value of Y; • if exactly one of X and Y is a NaN the result has the value of the other argument; • if both X and Y are NaNs, the result is a quiet NaN; • if X = Y and the signs are the same, the result is either X or Y; • otherwise (one argument is negative zero and the other is positive zero), the result is positive zero.

34 35

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals, but unless X and Y are both signaling NaNs, the signaling NaN is otherwise ignored and not converted to a quiet NaN. No other exceptions are signaled.

28 29 30 31 32

36

7 Example. The value of IEEE_MIN_NUM (1.5, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) is 1.5.

474

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

17.11.24 IEEE_MIN_NUM_MAG (X, Y)

2

1 Description. Minimum magnitude numeric value.

3

2 Class. Elemental function.

4

3 Arguments.

5

X

shall be of type real.

6

Y

shall be of the same type and kind type parameter as X.

7 8

J3/21-007r1

4 Restriction. IEEE_MIN_NUM_MAG shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the

value false.

9

5 Result Characteristics. Same as X.

10 11

6 Result Value.

14

The result has the value specified for the minimumMagnitudeNumber operation in ISO/IEC 60559:2020; that is, • if |X| < |Y| the result has the value of X; • if |Y| < |X| the result has the value of Y; • otherwise, the result has the value of IEEE_MIN_NUM (X, Y).

15 16

If one or both of X and Y are signaling NaNs, IEEE_INVALID signals, but unless X and Y are both signaling NaNs, the signaling NaN is otherwise ignored and not converted to a quiet NaN. No other exceptions are signaled.

12 13

17 18

7 Example. The value of IEEE_MIN_NUM_MAG (1.5, −2.5) is 1.5.

17.11.25 IEEE_NEXT_AFTER (X, Y)

19

1 Description. Adjacent machine number.

20

2 Class. Elemental function.

21

3 Arguments. The arguments shall be of type real.

22 23

4 Restriction. IEEE_NEXT_AFTER (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or

24

5 Result Characteristics. Same as X.

25

6 Result Value.

26 27 28 29 30 31

IEEE_SUPPORT_DATATYPE (Y) has the value false.

Case (i): Case (ii):

If X == Y, the result is X and no exception is signaled. If X ̸= Y, the result has the value of the next representable neighbor of X in the direction of Y. The neighbors of zero (of either sign) are both nonzero. IEEE_OVERFLOW is signaled when X is finite but IEEE_NEXT_AFTER (X, Y) is infinite; IEEE_UNDERFLOW is signaled when IEEE_NEXT_AFTER (X, Y) is subnormal; in both cases, IEEE_INEXACT signals.

7 Example. The value of IEEE_NEXT_AFTER (1.0, 2.0) is 1.0 + EPSILON (X).

32

17.11.26 IEEE_NEXT_DOWN (X)

33

1 Description. Adjacent lower machine number.

34

2 Class. Elemental function.

35

3 Argument. X shall be of type real.

36 37 38

4 Restriction. IEEE_NEXT_DOWN (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the

value false. IEEE_NEXT_DOWN (−HUGE (X)) shall not be invoked if IEEE_SUPPORT_INF (X) has the value false.

ISO/IEC JTC 1/SC 22/WG5/N2184

475

J3/21-007r1

WD 1539-1

2021-05-21

1

5 Result Characteristics. Same as X.

2 3 4

6 Result Value. The result has the value specified for the nextDown operation in ISO/IEC 60559:2020; that is, it

5 6 7 8

is the greatest value in the representation method of X that compares less than X, except when X is equal to −∞ the result has the value −∞, and when X is a NaN the result is a NaN. If X is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled. 7 Example. If IEEE_SUPPORT_SUBNORMAL (0.0) is true, the value of IEEE_NEXT_DOWN (+0.0) is the

negative subnormal number with least magnitude.

17.11.27 IEEE_NEXT_UP (X)

9

1 Description. Adjacent higher machine number.

10

2 Class. Elemental function.

11

3 Argument. X shall be of type real.

12 13

4 Restriction. IEEE_NEXT_UP (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value

14

5 Result Characteristics. Same as X.

15 16

6 Result Value. The result has the value specified for the nextUp operation in ISO/IEC 60559:2020; that is,

17 18 19 20

false. IEEE_NEXT_UP (HUGE (X)) shall not be invoked if IEEE_SUPPORT_INF (X) has the value false.

it is the least value in the representation method of X that compares greater than X, except when X is equal to +∞ the result has the value +∞, and when X is a NaN the result is a NaN. If X is a signaling NaN, IEEE_INVALID_signals; otherwise, no exception is signaled. 7 Example. If IEEE_SUPPORT_INF (X) is true, the value of IEEE_NEXT_UP (HUGE (X)) is +∞.

17.11.28 IEEE_QUIET_EQ (A, B)

21

1 Description. Quiet compares equal.

22

2 Class. Elemental function.

23

3 Arguments.

24

A

shall be of type real.

25

B

shall have the same type and kind type parameter as A.

26 27

4 Restriction. IEEE_QUIET_EQ (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the

value false.

28

5 Result Characteristics. Default logical.

29 30 31

6 Result Value. The result has the value specified for the compareQuietEqual operation in ISO/IEC 60559:2020;

32

7 Example. IEEE_QUIET_EQ (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and no

that is, it is true if and only if A compares equal to B. If A or B is a NaN, the result will be false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.

33

exception is signaled.

34

17.11.29 IEEE_QUIET_GE (A, B)

35

1 Description. Quiet compares greater than or equal.

36

2 Class. Elemental function.

37

3 Arguments.

476

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

A

shall be of type real.

2

B

shall have the same type and kind type parameter as A.

J3/21-007r1

3 4

4 Restriction. IEEE_QUIET_GE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the

5

5 Result Characteristics. Default logical.

6 7

6 Result Value. The result has the value specified for the compareQuietGreaterEqual operation in ISO/IEC

8 9 10 11

value false.

60559:2020; that is, it is true if and only if A compares greater than or equal to B. If A or B is a NaN, the result will be false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled. 7 Example. IEEE_QUIET_GE (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and no

exception is signaled.

17.11.30 IEEE_QUIET_GT (A, B)

12

1 Description. Quiet compares greater than.

13

2 Class. Elemental function.

14

3 Arguments.

15

A

shall be of type real.

16

B

shall have the same type and kind type parameter as A.

17 18

4 Restriction. IEEE_QUIET_GT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the

19

5 Result Characteristics. Default logical.

20 21 22

6 Result Value. The result has the value specified for the compareQuietGreater operation in ISO/IEC 60559:2020;

23 24

7 Example. IEEE_QUIET_GT (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and no

value false.

that is, it is true if and only if A compares greater than B. If A or B is a NaN, the result will be false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled. exception is signaled.

25

17.11.31 IEEE_QUIET_LE (A, B)

26

1 Description. Quiet compares less than or equal.

27

2 Class. Elemental function.

28

3 Arguments.

29

A

shall be of type real.

30

B

shall have the same type and kind type parameter as A.

31 32

4 Restriction. IEEE_QUIET_LE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the

33

5 Result Characteristics. Default logical.

34 35 36

6 Result Value.

37

7 Example. IEEE_QUIET_LE (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and no

value false.

The result has the value specified for the compareQuietLessEqual operation in ISO/IEC 60559:2020; that is, it is true if and only if A compares less than or equal to B. If A or B is a NaN, the result will be false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.

ISO/IEC JTC 1/SC 22/WG5/N2184

477

J3/21-007r1

WD 1539-1

1

exception is signaled.

2

17.11.32 IEEE_QUIET_LT (A, B)

3

1 Description. Quiet compares less than.

4

2 Class. Elemental function.

5

3 Arguments.

6 7 8 9

A B

2021-05-21

shall be of type real. shall have the same type and kind type parameter as A.

4 Restriction. IEEE_QUIET_LT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the

value false.

10

5 Result Characteristics. Default logical.

11 12 13

6 Result Value. The result has the value specified for the compareQuietLess operation in ISO/IEC 60559:2020;

14

7 Example. IEEE_QUIET_LT (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and no

that is, it is true if and only if A compares less than B. If A or B is a NaN, the result will be false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.

15

exception is signaled.

16

17.11.33 IEEE_QUIET_NE (A, B)

17

1 Description. Quiet compares not equal.

18

2 Class. Elemental function.

19

3 Arguments.

20

A

shall be of type real.

21

B

shall have the same type and kind type parameter as A.

22 23

4 Restriction. IEEE_QUIET_NE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the

24

5 Result Characteristics. Default logical.

25 26 27

6 Result Value.

28 29

7 Example. IEEE_QUIET_NE (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value true and no

30

value false.

The result has the value specified for the compareQuietNotEqual operation in ISO/IEC 60559:2020; that is, it is true if and only if A compares not equal to B. If A or B is a NaN, the result will be true. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled. exception is signaled.

17.11.34 IEEE_REAL (A [, KIND])

31

1 Description. Conversion to real type.

32

2 Class. Elemental function.

33

3 Arguments.

34

A

35

KIND (optional) shall be a scalar integer constant expression.

36 37

shall be of type integer or real.

4 Restriction. IEEE_REAL shall not be invoked if A is of type real and IEEE_SUPPORT_DATATYPE (A)

has the value false, or if IEEE_SUPPORT_DATATYPE (IEEE_REAL (A, KIND)) has the value false.

478

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

5 Result Characteristics. Real. If KIND is present, the kind type parameter is that specified by the value of

3 4

6 Result Value. The result has the same value as A if that value is representable in the representation method

5 6 7 8

KIND; otherwise, the kind type parameter is that of default real. of the result, and is rounded according to the rounding mode otherwise. This shall be consistent with the specification of ISO/IEC 60559:2020 for the convertFromInt operation when A is of type integer, and with the convertFormat operation otherwise. 7 Example. The value of IEEE_REAL (123) is 123.0.

17.11.35 IEEE_REM (X, Y)

9

1 Description. Exact remainder.

10

2 Class. Elemental function.

11

3 Arguments. The arguments shall be of type real and have the same radix.

12 13

4 Restriction. IEEE_REM (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or IEEE_SUP-

14

5 Result Characteristics. Real with the kind type parameter of whichever argument has the greater precision.

15

6 Result Value. This function computes the remainder operation specified in ISO/IEC 60559:2020.

16 17 18

7 The result value when X and Y are finite, and Y is nonzero, regardless of the rounding mode, shall be exactly X

19 20 21

8 When X is finite and Y is infinite, the result value is X. If Y is zero or X is infinite, and neither is a NaN, the

22 23 24 25

PORT_DATATYPE (Y) has the value false.

− Y*N, where N is the integer nearest to the exact value X/Y; whenever |N − X/Y| = 12 , N shall be even. If the result value is zero, the sign shall be that of X. IEEE_INVALID exception shall occur; if IEEE_SUPPORT_NAN(X+Y) is true, the result is a NaN. If X is subnormal and Y is infinite, the IEEE_UNDERFLOW exception shall occur. No exception shall signal if X is finite and normal, and Y is infinite. 9 Examples. The value of IEEE_REM (4.0, 3.0) is 1.0, the value of IEEE_REM (3.0, 2.0) is −1.0, and the value

of IEEE_REM (5.0, 2.0) is 1.0.

17.11.36 IEEE_RINT (X [, ROUND])

26

1 Description. Round to integer.

27

2 Class. Elemental function.

28

3 Arguments.

29

X

shall be of type real.

30

ROUND (optional) shall be of type IEEE_ROUND_TYPE.

31

4 Restriction. IEEE_RINT (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

32

5 Result Characteristics. Same as X.

33 34

6 Result Value. If ROUND is present, the value of the result is the value of X rounded to an integer according

35 36 37 38 39

to the mode specified by ROUND; this is the ISO/IEC/IEEE 60559:2011 operation roundToInteger{rounding}. Otherwise, the value of the result is that specified for the operation roundIntegralToExact in ISO/IEC 60559:2020; this is the value of X rounded to an integer according to the rounding mode. If the result has the value zero, the sign is that of X. 7 Examples. If the rounding mode is round to nearest, the value of IEEE_RINT (1.1) is 1.0. The value of

IEEE_RINT (1.1, IEEE_UP) is 2.0.

ISO/IEC JTC 1/SC 22/WG5/N2184

479

J3/21-007r1

1

WD 1539-1

2021-05-21

17.11.37 IEEE_SCALB (X, I)

2

1 Description. X × 2I .

3

2 Class. Elemental function.

4

3 Arguments.

5

X

shall be of type real.

6

I

shall be of type integer.

7

4 Restriction. IEEE_SCALB (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.

8

5 Result Characteristics. Same as X.

9

6 Result Value.

10 11 12 13

Case (i): Case (ii):

14 15

Case (iii):

16

Case (iv):

17 18

If X × 2I is representable as a normal number, the result has this value. If X is finite and X × 2I is too large, the IEEE_OVERFLOW exception shall occur. If IEEE_SUPPORT_INF (X) is true, the result value is infinity with the sign of X; otherwise, the result value is SIGN (HUGE (X), X). If X × 2I is too small and there is loss of accuracy, the IEEE_UNDERFLOW exception shall occur. The result is the representable number having a magnitude nearest to |2I | and the same sign as X. If X is infinite, the result is the same as X; no exception signals.

7 Example. The value of IEEE_SCALB (1.0, 2) is 4.0.

17.11.38 IEEE_SELECTED_REAL_KIND ([P, R, RADIX])

19

1 Description. IEEE kind type parameter value.

20

2 Class. Transformational function.

21

3 Arguments. At least one argument shall be present.

22

P (optional) shall be an integer scalar.

23

R (optional) shall be an integer scalar.

24

RADIX (optional) shall be an integer scalar.

25

4 Result Characteristics. Default integer scalar.

26

5 Result Value. If P or R is absent, the result value is the same as if it were present with the value zero. If

27 28 29 30 31

RADIX is absent, there is no requirement on the radix of the selected kind. The result has a value equal to a value of the kind type parameter of an ISO/IEC/IEEE 60559:2011 floating-point format with decimal precision, as returned by the intrinsic function PRECISION, of at least P digits, a decimal exponent range, as returned by the intrinsic function RANGE, of at least R, and a radix, as returned by the intrinsic function RADIX, of RADIX, if such a kind type parameter is available on the processor.

32

6 Otherwise, the result is −1 if the processor supports an IEEE real type with radix RADIX and exponent range

33 34 35 36 37

of at least R but not with precision of at least P, −2 if the processor supports an IEEE real type with radix RADIX and precision of at least P but not with exponent range of at least R, −3 if the processor supports an IEEE real type with radix RADIX but with neither precision of at least P nor exponent range of at least R, −4 if the processor supports an IEEE real type with radix RADIX and either precision of at least P or exponent range of at least R but not both together, and −5 if the processor supports no IEEE real type with radix RADIX.

38

7 If more than one kind type parameter value meets the criteria, the value returned is the one with the smallest

39

decimal precision, unless there are several such values, in which case the smallest of these kind values is returned.

40

8 Example. IEEE_SELECTED_REAL_KIND (6, 30) has the value KIND (0.0) on a machine that supports

480

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

ISO/IEC/IEEE 60559:2011 single precision arithmetic for its default real approximation method.

2

17.11.39 IEEE_SET_FLAG (FLAG, FLAG_VALUE)

3

1 Description. Set an exception flag.

4

2 Class. Simple subroutine.

5

3 Arguments.

6 7 8 9

FLAG

10 11

FLAG_VALUE shall be a logical scalar or array. It shall be conformable with FLAG. If an element has the value true, the corresponding flag is set to be signaling; otherwise, the flag is set to be quiet.

12 13

4 Example. CALL IEEE_SET_FLAG (IEEE_OVERFLOW, .TRUE.) sets the IEEE_OVERFLOW flag to be

14

shall be a scalar or array of type IEEE_FLAG_TYPE. If a value of FLAG is IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT, the corresponding exception flag is assigned a value. No two elements of FLAG shall have the same value.

signaling.

17.11.40 IEEE_SET_HALTING_MODE (FLAG, HALTING)

15

1 Description. Set a halting mode.

16

2 Class. Simple subroutine.

17

3 Arguments.

18 19 20

FLAG

shall be a scalar or array of type IEEE_FLAG_TYPE. It shall have only the values IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT. No two elements of FLAG shall have the same value.

21

HALTING

shall be a logical scalar or array. It shall be conformable with FLAG. If an element has the value true, the corresponding exception specified by FLAG will cause halting. Otherwise, execution will continue after this exception.

22 23 24 25

4 Restriction. IEEE_SET_HALTING_MODE (FLAG, HALTING) shall not be invoked if IEEE_SUPPORT_-

26 27

5 Example. CALL IEEE_SET_HALTING_MODE (IEEE_DIVIDE_BY_ZERO, .TRUE.) causes halting after

28

HALTING (FLAG) has the value false. a divide_by_zero exception.

17.11.41 IEEE_SET_MODES (MODES)

29

1 Description. Set floating-point modes.

30

2 Class. Subroutine.

31 32 33

3 Argument. MODES shall be a scalar of type IEEE_MODES_TYPE. Its value shall be one that was assigned

34

4 Example.

35 36 37 38 39 40

by a previous invocation of IEEE_GET_MODES to its MODES argument. The floating-point modes (17.7) are restored to the state at that invocation. To save the floating-point modes, do a calculation with specific rounding and underflow modes, and restore them later: USE, INTRINSIC :: IEEE_ARITHMETIC TYPE (IEEE_MODES_TYPE) SAVE_MODES ... CALL IEEE_GET_MODES (SAVE_MODES) ! Save all modes.

ISO/IEC JTC 1/SC 22/WG5/N2184

481

J3/21-007r1

2021-05-21

CALL IEEE_SET_ROUNDING_MODE (IEEE_TO_ZERO)) CALL IEEE_SET_UNDERFLOW_MODE (GRADUAL=.FALSE.) . . . ! calculation with abrupt round-to-zero. CALL IEEE_SET_MODES (SAVE_MODES) ! Restore all modes.

1 2 3 4

5

WD 1539-1

17.11.42 IEEE_SET_ROUNDING_MODE (ROUND_VALUE [, RADIX])

6

1 Description. Set rounding mode.

7

2 Class. Subroutine.

8

3 Arguments.

9

ROUND_VALUE shall be a scalar of type IEEE_ROUND_TYPE. It specifies the rounding mode to be set.

10 11

RADIX (optional) shall be an integer scalar with the value two or ten. If RADIX is present with the value ten, the rounding mode set is the decimal rounding mode; otherwise it is the binary rounding mode.

12 13 14 15 16

4 Restriction. IEEE_SET_ROUNDING_MODE (ROUND_VALUE) shall not be invoked unless IEEE_SUP-

17 18

5 Example. To save the binary rounding mode, do a calculation with round to nearest, and restore the rounding

PORT_ROUNDING (ROUND_VALUE, X) is true for some X such that IEEE_SUPPORT_DATATYPE (X) is true. IEEE_SET_ROUNDING_MODE (ROUND_VALUE, RADIX) shall not be invoked unless IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X) is true for some X with radix RADIX such that IEEE_SUPPORT_DATATYPE (X) is true. mode later: USE, INTRINSIC :: IEEE_ARITHMETIC TYPE (IEEE_ROUND_TYPE) ROUND_VALUE ... CALL IEEE_GET_ROUNDING_MODE (ROUND_VALUE) ! Store the rounding mode CALL IEEE_SET_ROUNDING_MODE (IEEE_NEAREST) . . . ! calculation with round to nearest CALL IEEE_SET_ROUNDING_MODE (ROUND_VALUE) ! Restore the rounding mode

19 20 21 22 23 24 25

26

17.11.43 IEEE_SET_STATUS (STATUS_VALUE)

27

1 Description. Restore floating-point status.

28

2 Class. Subroutine.

29 30 31

3 Argument. STATUS_VALUE shall be a scalar of type IEEE_STATUS_TYPE. Its value shall be one that was

32 33

4 Example. To store all the exceptions flags, do a calculation involving exception handling, and restore them

assigned by a previous invocation of IEEE_GET_STATUS to its STATUS_VALUE argument. The floatingpoint status (17.7 is restored to the state at that invocation). later: USE, INTRINSIC :: IEEE_EXCEPTIONS TYPE (IEEE_STATUS_TYPE) STATUS_VALUE ... CALL IEEE_GET_STATUS (STATUS_VALUE) ! Store the flags CALL IEEE_SET_FLAG (IEEE_ALL, .FALSE.) ! Set them quiet . . . ! calculation involving exception handling CALL IEEE_SET_STATUS (STATUS_VALUE) ! Restore the flags

34 35 36 37 38 39 40

482

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

17.11.44 IEEE_SET_UNDERFLOW_MODE (GRADUAL)

2

1 Description. Set underflow mode.

3

2 Class. Subroutine.

4 5

3 Argument. GRADUAL shall be a logical scalar. If it is true, the underflow mode is set to gradual underflow.

6 7

4 Restriction. IEEE_SET_UNDERFLOW_MODE shall not be invoked unless IEEE_SUPPORT_UNDER-

8

5 Example. To perform some calculations with abrupt underflow and then restore the previous mode:

If it is false, the underflow mode is set to abrupt underflow. FLOW_CONTROL (X) is true for some X.

USE, INTRINSIC :: IEEE_ARITHMETIC LOGICAL SAVE_UNDERFLOW_MODE ... CALL IEEE_GET_UNDERFLOW_MODE (SAVE_UNDERFLOW_MODE) CALL IEEE_SET_UNDERFLOW_MODE (GRADUAL=.FALSE.) . . . ! Perform some calculations with abrupt underflow CALL IEEE_SET_UNDERFLOW_MODE (SAVE_UNDERFLOW_MODE)

9 10 11 12 13 14 15

16

17.11.45 IEEE_SIGNALING_EQ (A, B)

17

1 Description. Signaling compares equal.

18

2 Class. Elemental function.

19

3 Arguments.

20

A

shall be of type real.

21

B

shall be of the same type and kind type parameter as A.

22 23

4 Restriction. IEEE_SIGNALING_EQ (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

24

5 Result Characteristics. Default logical.

25 26 27

6 Result Value.

28 29

7 Example. IEEE_SIGNALING_EQ (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and

the value false.

The result has the value specified for the compareSignalingEqual operation in ISO/IEC 60559:2020; that is, it is true if and only if A compares equal to B. If A or B is a NaN, the result will be false and IEEE_INVALID signals; otherwise, no exception is signaled.

signals IEEE_INVALID.

30

17.11.46 IEEE_SIGNALING_GE (A, B)

31

1 Description. Signaling compares greater than or equal.

32

2 Class. Elemental function.

33

3 Arguments.

34

A

shall be of type real.

35

B

shall be of the same type and kind type parameter as A.

36 37

4 Restriction. IEEE_SIGNALING_GE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

the value false.

ISO/IEC JTC 1/SC 22/WG5/N2184

483

J3/21-007r1

WD 1539-1

2021-05-21

1

5 Result Characteristics. Default logical.

2 3 4

6 Result Value. The result has the value specified for the compareSignalingGreaterEqual operation in ISO/IEC

5 6

7 Example. IEEE_SIGNALING_GE (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and

7

60559:2020; that is, it is true if and only if A compares greater than or equal to B. If A or B is a NaN, the result will be false and IEEE_INVALID signals; otherwise, no exception is signaled. signals IEEE_INVALID.

17.11.47 IEEE_SIGNALING_GT (A, B)

8

1 Description. Signaling compares greater than.

9

2 Class. Elemental function.

10

3 Arguments.

11

A

shall be of type real.

12

B

shall be of the same type and kind type parameter as A.

13 14

4 Restriction. IEEE_SIGNALING_GT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

15

5 Result Characteristics. Default logical.

16 17 18

6 Result Value.

19 20

7 Example. IEEE_SIGNALING_GT (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and

the value false.

The result has the value specified for the compareSignalingGreater operation in ISO/IEC 60559:2020; that is, it is true if and only if A compares greater than B. If A or B is a NaN, the result will be false and IEEE_INVALID signals; otherwise, no exception is signaled. signals IEEE_INVALID.

21

17.11.48 IEEE_SIGNALING_LE (A, B)

22

1 Description. Signaling compares less than or equal.

23

2 Class. Elemental function.

24

3 Arguments.

25

A

shall be of type real.

26

B

shall be of the same type and kind type parameter as A.

27 28

4 Restriction. IEEE_SIGNALING_LE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

29

5 Result Characteristics. Default logical.

30

6 Result Value. The result has the value specified for the compareSignalingLessEqual operation in ISO/IEC

31 32

60559:2020; that is, it is true if and only if A compares less than or equal to B. If A or B is a NaN, the result will be false and IEEE_INVALID signals; otherwise, no exception is signaled.

33 34

7 Example. IEEE_SIGNALING_LE (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and

35

the value false.

signals IEEE_INVALID.

17.11.49 IEEE_SIGNALING_LT (A, B)

36

1 Description. Signaling compares less than.

37

2 Class. Elemental function.

484

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

3 Arguments.

2

A

shall be of type real.

3

B

shall be of the same type and kind type parameter as A.

4 5

4 Restriction. IEEE_SIGNALING_LT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

6

5 Result Characteristics. Default logical.

7 8

6 Result Value. The result has the value specified for the compareSignalingLess operation in ISO/IEC 60559:2020;

9 10 11 12

the value false.

that is, it is true if and only if A compares less than B. If A or B is a NaN, the result will be false and IEEE_INVALID signals; otherwise, no exception is signaled. 7 Example. IEEE_SIGNALING_LT (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value false and

signals IEEE_INVALID.

17.11.50 IEEE_SIGNALING_NE (A, B)

13

1 Description. Signaling compares not equal.

14

2 Class. Elemental function.

15

3 Arguments.

16

A

shall be of type real.

17

B

shall be of the same type and kind type parameter as A.

18 19

4 Restriction. IEEE_SIGNALING_NE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has

20

5 Result Characteristics. Default logical.

21 22 23

6 Result Value. The result has the value specified for the compareSignalingNotEqual operation in ISO/IEC

24 25

7 Example. IEEE_SIGNALING_NE (1.0, IEEE_VALUE (1.0, IEEE_QUIET_NAN)) has the value true and

26

the value false.

60559:2020; that is, it is true if and only if A compares not equal to B. If A or B is a NaN, the result will be true and IEEE_INVALID signals; otherwise, no exception is signaled. signals IEEE_INVALID.

17.11.51 IEEE_SIGNBIT (X)

27

1 Description. Test sign bit.

28

2 Class. Elemental function.

29

3 Argument. X shall be of type real.

30 31

4 Restriction. IEEE_SIGNBIT (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value

32

5 Result Characteristics. Default logical.

33 34

6 Result Value. The result has the value specified for the isSignMinus operation in ISO/IEC 60559:2020; that is,

35

7 Example. IEEE_SIGNBIT (−1.0) has the value true.

false.

it is true if and only if the sign bit of X is nonzero. No exception is signaled even if X is a signaling NaN.

ISO/IEC JTC 1/SC 22/WG5/N2184

485

J3/21-007r1

1

WD 1539-1

2021-05-21

17.11.52 IEEE_SUPPORT_DATATYPE () or IEEE_SUPPORT_DATATYPE (X)

2

1 Description. Query IEEE arithmetic support.

3

2 Class. Inquiry function.

4

3 Argument. X shall be of type real. It may be a scalar or an array.

5

4 Result Characteristics. Default logical scalar.

6

5 Result Value. The result has the value true if the processor supports IEEE arithmetic for all reals (X does

7 8

not appear) or for real variables of the same kind type parameter as X; otherwise, it has the value false. Here, support is as defined in the first paragraph of 17.9.

9 10

6 Example. If default real kind conforms to ISO/IEC 60559:2020 except that underflow values flush to zero instead

11

of being subnormal, IEEE_SUPPORT_DATATYPE (1.0) has the value true.

17.11.53 IEEE_SUPPORT_DENORMAL () or IEEE_SUPPORT_DENORMAL (X)

12

1 Description. Query subnormal number support.

13

2 Class. Inquiry function.

14

3 Argument. X shall be of type real. It may be a scalar or an array.

15

4 Result Characteristics. Default logical scalar.

16

5 Result Value.

17 18 19 20

Case (i):

21 22

Case (ii):

23 24

IEEE_SUPPORT_DENORMAL (X) has the value true if IEEE_SUPPORT_DATATYPE (X) has the value true and the processor supports arithmetic operations and assignments with subnormal numbers (biased exponent e = 0 and fraction f ̸= 0, see ISO/IEC 60559:2020, 3.2) for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_DENORMAL () has the value true if IEEE_SUPPORT_DENORMAL (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_DENORMAL (X) has the value true if the processor supports subnormal values

for X. NOTE 1 A reference to IEEE_SUPPORT_DENORMAL will have the same result value as a reference to IEEE_SUPPORT_SUBNORMAL with the same argument list.

25

17.11.54 IEEE_SUPPORT_DIVIDE () or IEEE_SUPPORT_DIVIDE (X)

26

1 Description. Query IEEE division support.

27

2 Class. Inquiry function.

28

3 Argument. X shall be of type real. It may be a scalar or an array.

29

4 Result Characteristics. Default logical scalar.

30

5 Result Value.

31 32 33

Case (i):

486

IEEE_SUPPORT_DIVIDE (X) has the value true if the processor supports division with the accuracy specified by ISO/IEC 60559:2020 for real variables of the same kind type parameter as X; otherwise, it has the value false.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5

Case (ii):

WD 1539-1

J3/21-007r1

IEEE_SUPPORT_DIVIDE () has the value true if IEEE_SUPPORT_DIVIDE (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_DIVIDE (X) has the value true if division of operands with the same kind as X

conforms to ISO/IEC 60559:2020.

17.11.55 IEEE_SUPPORT_FLAG (FLAG) or IEEE_SUPPORT_FLAG (FLAG, X)

6

1 Description. Query exception support.

7

2 Class. Transformational function.

8

3 Arguments.

9 10

FLAG

shall be a scalar of type IEEE_FLAG_TYPE. Its value shall be one of IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT.

11

X

shall be of type real. It may be a scalar or an array.

12

4 Result Characteristics. Default logical scalar.

13

5 Result Value.

14

Case (i):

15 16 17 18 19 20 21

Case (ii):

IEEE_SUPPORT_FLAG (FLAG, X) has the value true if the processor supports detection of the specified exception for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_FLAG (FLAG) has the value true if IEEE_SUPPORT_FLAG (FLAG, X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_FLAG (IEEE_INEXACT) has the value true if the processor supports the inexact

exception.

17.11.56 IEEE_SUPPORT_HALTING (FLAG)

22

1 Description. Query halting mode support.

23

2 Class. Transformational function.

24 25

3 Argument. FLAG shall be a scalar of type IEEE_FLAG_TYPE. Its value shall be one of IEEE_INVALID,

26

4 Result Characteristics. Default logical scalar.

27 28 29

5 Result Value. The result has the value true if the processor supports the ability to control during program

30 31

6 Example. IEEE_SUPPORT_HALTING (IEEE_OVERFLOW) has the value true if the processor supports

32

IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT.

execution whether to abort or continue execution after the exception specified by FLAG; otherwise, it has the value false. Support includes the ability to change the mode by CALL IEEE_SET_HALTING_MODE (FLAG). control of halting after an overflow.

17.11.57 IEEE_SUPPORT_INF () or IEEE_SUPPORT_INF (X)

33

1 Description. Query IEEE infinity support.

34

2 Class. Inquiry function.

35

3 Argument. X shall be of type real. It may be a scalar or an array.

36

4 Result Characteristics. Default logical scalar.

37

5 Result Value.

ISO/IEC JTC 1/SC 22/WG5/N2184

487

J3/21-007r1

1 2 3

Case (i):

4 5

Case (ii):

6 7

WD 1539-1

IEEE_SUPPORT_INF (X) has the value true if the processor supports IEEE infinities (positive and negative) for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_INF () has the value true if IEEE_SUPPORT_INF (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_INF (X) has the value true if the processor supports IEEE infinities for X.

17.11.58 IEEE_SUPPORT_IO () or IEEE_SUPPORT_IO (X)

8

1 Description. Query IEEE formatting support.

9

2 Class. Inquiry function.

10

3 Argument. X shall be of type real. It may be a scalar or an array.

11

4 Result Characteristics. Default logical scalar.

12

5 Result Value.

13 14 15

Case (i):

16 17

Case (ii):

18 19 20 21

IEEE_SUPPORT_IO (X) has the value true if base conversion during formatted input/output (12.5.6.17, 12.6.2.14, 13.7.2.3.8) conforms to ISO/IEC 60559:2020 for the modes UP, DOWN, ZERO, and NEAREST for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_IO () has the value true if IEEE_SUPPORT_IO (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_IO (X) has the value true if formatted input/output base conversions conform to

ISO/IEC 60559:2020.

17.11.59 IEEE_SUPPORT_NAN () or IEEE_SUPPORT_NAN (X)

22

1 Description. Query IEEE NaN support.

23

2 Class. Inquiry function.

24

3 Argument. X shall be of type real. It may be a scalar or an array.

25

4 Result Characteristics. Default logical scalar.

26

5 Result Value.

27 28

Case (i):

29 30

Case (ii):

31 32

2021-05-21

IEEE_SUPPORT_NAN (X) has the value true if the processor supports IEEE NaNs for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_NAN () has the value true if IEEE_SUPPORT_NAN (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_NAN (X) has the value true if the processor supports IEEE NaNs for X.

17.11.60 IEEE_SUPPORT_ROUNDING (ROUND_VALUE) or IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X)

33

1 Description. Query IEEE rounding support.

34

2 Class. Transformational function.

35

3 Arguments.

36

ROUND_VALUE shall be of type IEEE_ROUND_TYPE.

37

X

488

shall be of type real. It may be a scalar or an array.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

4 Result Characteristics. Default logical scalar.

2

5 Result Value.

3 4 5 6

Case (i):

7 8

Case (ii):

9 10 11 12

IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X) has the value true if the processor supports the rounding mode defined by ROUND_VALUE for real variables of the same kind type parameter as X; otherwise, it has the value false. Support includes the ability to change the mode by CALL IEEE_SET_ROUNDING_MODE (ROUND_VALUE). IEEE_SUPPORT_ROUNDING (ROUND_VALUE) has the value true if IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_ROUNDING (IEEE_TO_ZERO) has the value true if the processor supports

rounding to zero for all reals.

17.11.61 IEEE_SUPPORT_SQRT () or IEEE_SUPPORT_SQRT (X)

13

1 Description. Query IEEE square root support.

14

2 Class. Inquiry function.

15

3 Argument. X shall be of type real. It may be a scalar or an array.

16

4 Result Characteristics. Default logical scalar.

17

5 Result Value.

18 19 20

Case (i):

21 22

Case (ii):

23 24

IEEE_SUPPORT_SQRT (X) has the value true if the intrinsic function SQRT conforms to ISO/IEC 60559:2020 for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_SQRT () has the value true if IEEE_SUPPORT_SQRT (X) has the value true for all real X; otherwise, it has the value false.

6 Example. If IEEE_SUPPORT_SQRT (1.0) has the value true, SQRT (−0.0) will have the value −0.0.

17.11.62 IEEE_SUPPORT_STANDARD () or IEEE_SUPPORT_STANDARD (X)

25

1 Description. Query IEEE standard support.

26

2 Class. Inquiry function.

27

3 Argument. X shall be of type real. It may be a scalar or an array.

28

4 Result Characteristics. Default logical scalar.

29

5 Result Value.

30

Case (i):

31 32 33 34 35 36 37 38 39

J3/21-007r1

Case (ii):

IEEE_SUPPORT_STANDARD (X) has the value true if the results of all the functions IEEE_SUPPORT_DATATYPE (X), IEEE_SUPPORT_DIVIDE (X), IEEE_SUPPORT_FLAG (FLAG, X) for valid FLAG, IEEE_SUPPORT_HALTING (FLAG) for valid FLAG, IEEE_SUPPORT_INF (X), IEEE_SUPPORT_NAN (X), IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X) for valid ROUND_VALUE, IEEE_SUPPORT_SQRT (X), and IEEE_SUPPORT_SUBNORMAL (X) are all true; otherwise, it has the value false. IEEE_SUPPORT_STANDARD () has the value true if IEEE_SUPPORT_STANDARD (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_STANDARD () has the value false if some but not all kinds of reals conform to

ISO/IEC 60559:2020.

ISO/IEC JTC 1/SC 22/WG5/N2184

489

J3/21-007r1

1

WD 1539-1

17.11.63 IEEE_SUPPORT_SUBNORMAL () or IEEE_SUPPORT_SUBNORMAL (X)

2

1 Description. Query subnormal number support.

3

2 Class. Inquiry function.

4

3 Argument. X shall be of type real. It may be a scalar or an array.

5

4 Result Characteristics. Default logical scalar.

6

5 Result Value.

7 8 9 10

Case (i):

11 12

Case (ii):

13 14

2021-05-21

IEEE_SUPPORT_SUBNORMAL (X) has the value true if IEEE_SUPPORT_DATATYPE (X) has the value true and the processor supports arithmetic operations and assignments with subnormal numbers (biased exponent e = 0 and fraction f ̸= 0, see ISO/IEC 60559:2020, 3.2) for real variables of the same kind type parameter as X; otherwise, it has the value false. IEEE_SUPPORT_SUBNORMAL () has the value true if IEEE_SUPPORT_SUBNORMAL (X) has the value true for all real X; otherwise, it has the value false.

6 Example. IEEE_SUPPORT_SUBNORMAL (X) has the value true if the processor supports subnormal values

for X. NOTE 1 The subnormal numbers are not included in the 16.4 model for real numbers; they satisfy the inequality ABS (X) < TINY (X). They usually occur as a result of an arithmetic operation whose exact result is less than TINY (X). Such an operation causes IEEE_UNDERFLOW to signal unless the result is exact. IEEE_SUPPORT_SUBNORMAL (X) is false if the processor never returns a subnormal number as the result of an arithmetic operation.

15

17.11.64 IEEE_SUPPORT_UNDERFLOW_CONTROL () or IEEE_SUPPORT_UNDERFLOW_CONTROL (X)

16

1 Description. Query underflow control support.

17

2 Class. Inquiry function.

18

3 Argument. X shall be of type real. It may be a scalar or an array.

19

4 Result Characteristics. Default logical scalar.

20

5 Result Value.

21 22 23

Case (i):

24 25

Case (ii):

26 27

IEEE_SUPPORT_UNDERFLOW_CONTROL (X) has the value true if the processor supports control of the underflow mode for floating-point calculations with the same type as X, and false otherwise. IEEE_SUPPORT_UNDERFLOW_CONTROL () has the value true if the processor supports control of the underflow mode for all floating-point calculations, and false otherwise.

6 Example. IEEE_SUPPORT_UNDERFLOW_CONTROL (2.5) has the value true if the processor supports

underflow mode control for default real calculations.

28

17.11.65 IEEE_UNORDERED (X, Y)

29

1 Description. Whether two values are unordered.

30

2 Class. Elemental function.

31

3 Arguments. The arguments shall be of type real.

490

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2

4 Restriction. IEEE_UNORDERED (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or

3

5 Result Characteristics. Default logical.

4

6 Result Value. The result has the value true if X or Y is a NaN or both are NaNs; otherwise, it has the value

5 6 7 8

IEEE_SUPPORT_DATATYPE (Y) has the value false.

false. If X or Y is a signaling NaN, IEEE_INVALID may signal. 7 Example. IEEE_UNORDERED (0.0, SQRT (−1.0)) has the value true if IEEE_SUPPORT_SQRT (1.0) has

the value true.

17.11.66 IEEE_VALUE (X, CLASS)

9

1 Description. Return number in a class.

10

2 Class. Elemental function.

11

3 Arguments.

12 13

X CLASS

14 15 16 17 18

shall be of type real. shall be of type IEEE_CLASS_TYPE. The value is permitted to be: IEEE_SIGNALING_NAN or IEEE_QUIET_NAN if IEEE_SUPPORT_NAN (X) has the value true, IEEE_NEGATIVE_INF or IEEE_POSITIVE_INF if IEEE_SUPPORT_INF (X) has the value true, IEEE_NEGATIVE_SUBNORMAL or IEEE_POSITIVE_SUBNORMAL if IEEE_SUPPORT_SUBNORMAL (X) has the value true, IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO or IEEE_POSITIVE_NORMAL.

19 20

4 Restriction. IEEE_VALUE (X, CLASS) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the

21

5 Result Characteristics. Same as X.

22 23 24

6 Result Value. The result value is an IEEE value as specified by CLASS. Although in most cases the value is

25

7 Example. IEEE_VALUE (1.0, IEEE_NEGATIVE_INF) has the value −infinity.

26

8 Whenever IEEE_VALUE returns a signaling NaN, it is processor dependent whether or not invalid is raised and

27

value false.

processor dependent, the value shall not vary between invocations for any particular X kind type parameter and CLASS value.

processor dependent whether or not the signaling NaN is converted into a quiet NaN. NOTE 1 If the expr in an assignment statement is a reference to the IEEE_VALUE function that returns a signaling NaN and the variable is of the same type and kind as the function result, it is recommended that the signaling NaN be preserved.

28

17.12

Examples

NOTE 1 MODULE DOT ! Module for dot product of two real arrays of rank 1. ! The caller needs to ensure that exceptions do not cause halting. USE, INTRINSIC :: IEEE_EXCEPTIONS LOGICAL :: MATRIX_ERROR = .FALSE.

ISO/IEC JTC 1/SC 22/WG5/N2184

491

J3/21-007r1

WD 1539-1

2021-05-21

NOTE 1 (cont.) INTERFACE OPERATOR(.dot.) MODULE PROCEDURE MULT END INTERFACE CONTAINS REAL FUNCTION MULT (A, B) REAL, INTENT (IN) :: A(:), B(:) INTEGER I LOGICAL OVERFLOW IF (SIZE(A) /= SIZE(B)) THEN MATRIX_ERROR = .TRUE. RETURN END IF ! The processor ensures that IEEE_OVERFLOW is quiet. MULT = 0.0 DO I = 1, SIZE (A) MULT = MULT + A(I)*B(I) END DO CALL IEEE_GET_FLAG (IEEE_OVERFLOW, OVERFLOW) IF (OVERFLOW) MATRIX_ERROR = .TRUE. END FUNCTION MULT END MODULE DOT This module provides a function that computes the dot product of two real arrays of rank 1. If the sizes of the arrays are different, an immediate return occurs with MATRIX_ERROR true. If overflow occurs during the actual calculation, the IEEE_OVERFLOW flag will signal and MATRIX_ERROR will be true. NOTE 2 USE, INTRINSIC :: IEEE_EXCEPTIONS USE, INTRINSIC :: IEEE_FEATURES, ONLY: IEEE_INVALID_FLAG ! The other exceptions of IEEE_USUAL (IEEE_OVERFLOW and ! IEEE_DIVIDE_BY_ZERO) are always available with IEEE_EXCEPTIONS TYPE (IEEE_STATUS_TYPE) STATUS_VALUE LOGICAL, DIMENSION(3) :: FLAG_VALUE ... CALL IEEE_GET_STATUS (STATUS_VALUE) CALL IEEE_SET_HALTING_MODE (IEEE_USUAL, .FALSE.) ! Needed in case the ! default on the processor is to halt on exceptions CALL IEEE_SET_FLAG (IEEE_USUAL, .FALSE.) ! First try the "fast" algorithm for inverting a matrix: MATRIX1 = FAST_INV (MATRIX) ! This shall not alter MATRIX. CALL IEEE_GET_FLAG (IEEE_USUAL, FLAG_VALUE) IF (ANY(FLAG_VALUE)) THEN ! "Fast" algorithm failed; try "slow" one: CALL IEEE_SET_FLAG (IEEE_USUAL, .FALSE.) MATRIX1 = SLOW_INV (MATRIX)

492

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 (cont.) CALL IEEE_GET_FLAG (IEEE_USUAL, FLAG_VALUE) IF (ANY (FLAG_VALUE)) THEN WRITE (*, *) ’Cannot invert matrix’ STOP END IF END IF CALL IEEE_SET_STATUS (STATUS_VALUE) In this example, the function FAST_INV might cause a condition to signal. If it does, another try is made with SLOW_INV. If this still fails, a message is printed and the program stops. Note, also, that it is important to set the flags quiet before the second try. The state of all the flags is stored and restored. NOTE 3 USE, INTRINSIC :: IEEE_EXCEPTIONS LOGICAL FLAG_VALUE ... CALL IEEE_SET_HALTING_MODE (IEEE_OVERFLOW, .FALSE.) ! First try a fast algorithm for inverting a matrix. CALL IEEE_SET_FLAG (IEEE_OVERFLOW, .FALSE.) DO K = 1, N ... CALL IEEE_GET_FLAG (IEEE_OVERFLOW, FLAG_VALUE) IF (FLAG_VALUE) EXIT END DO IF (FLAG_VALUE) THEN ! Alternative code which knows that K-1 steps have executed normally. ... END IF Here the code for matrix inversion is in line and the transfer is made more precise by adding extra tests of the flag.

ISO/IEC JTC 1/SC 22/WG5/N2184

493

J3/21-007r1

WD 1539-1

1

18 Interoperability with C

2

18.1

3 4 5 6 7 8

2021-05-21

General

1 Fortran provides a means of referencing procedures that are defined by means of the C programming language or

procedures that can be described by C prototypes as defined in ISO/IEC 9899:2011, 6.7.6.3, even if they are not actually defined by means of C. Conversely, there is a means of specifying that a procedure defined by a Fortran subprogram can be referenced from a function defined by means of C. In addition, there is a means of declaring global variables that are associated with C variables whose names have external linkage as defined in ISO/IEC 9899:2011, 6.2.2.

9 10 11

2 The ISO_C_BINDING module provides access to named constants that represent kind type parameters of data

12 13 14

3 The source file ISO_Fortran_binding.h provides definitions and prototypes to enable a C function to interoperate

15 16 17

4 The conditions under which a Fortran entity is interoperable are defined in 18.3. If a Fortran entity is interoper-

representations compatible with C types. Fortran also provides facilities for defining derived types (7.5) and interoperable enumerations (7.6.1) that correspond to C types. with a Fortran procedure that has a dummy data object that is allocatable, assumed-shape, assumed-rank, pointer, or is of type character with an assumed length. able, an equivalent entity could be defined by means of C and the Fortran entity would interoperate with the C entity. There does not have to be such an interoperating C entity. NOTE 1 A Fortran entity can be interoperable with more than one C entity.

18

18.2

The ISO_C_BINDING intrinsic module

19

18.2.1

Summary of contents

20 21 22 23 24

25

1 The processor shall provide the intrinsic module ISO_C_BINDING. This module shall make accessible the

following entities: the named constants C_NULL_PTR, C_NULL_FUNPTR, and those with names listed in the first column of Table 18.1 and the second column of Table 18.2, the types C_PTR and C_FUNPTR, and the procedures in 18.2.3. A processor may provide other public entities in the ISO_C_BINDING intrinsic module in addition to those listed here.

18.2.2

Named constants and derived types in the module

26

1 The entities listed in the second column of Table 18.2 shall be default integer named constants.

27 28 29 30

2 A Fortran intrinsic type whose kind type parameter is one of the values in the module shall have the same

31 32 33 34 35

3 The value of C_INT shall be a valid value for an integer kind parameter on the processor. The values of

representation as the C type with which it interoperates, for each value that a variable of that type can have. For C_BOOL, the internal representation of .TRUE._C_BOOL and .FALSE._C_BOOL shall be the same as those of the C values (_Bool)1 and (_Bool)0 respectively. C_SHORT, C_LONG, C_LONG_LONG, C_SIGNED_CHAR, C_SIZE_T, C_INT8_T, C_INT16_T, C_INT32_T, C_INT64_T, C_INT_LEAST8_T, C_INT_LEAST16_T, C_INT_LEAST32_T, C_INT_LEAST64_T, C_INT_FAST8_T, C_INT_FAST16_T, C_INT_FAST32_T, C_INT_FAST64_T, C_INTMAX_T, C_INTPTR_T, and C_PTRDIFF_T shall each be a valid value for an integer kind type parameter on the

494

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1 2 3

processor or shall be −1 if the companion processor (5.5.7) defines the corresponding C type and there is no interoperating Fortran processor kind, or −2 if the companion processor does not define the corresponding C type.

4

4 The values of C_FLOAT, C_DOUBLE, and C_LONG_DOUBLE shall each be a valid value for a real kind

5 6 7 8 9 10

type parameter on the processor or shall be −1 if the companion processor’s type does not have a precision equal to the precision of any of the Fortran processor’s real kinds, −2 if the companion processor’s type does not have a range equal to the range of any of the Fortran processor’s real kinds, −3 if the companion processor’s type has neither the precision nor range of any of the Fortran processor’s real kinds, and equal to −4 if there is no interoperating Fortran processor kind for other reasons. The values of C_FLOAT_COMPLEX, C_DOUBLE_COMPLEX, and C_LONG_DOUBLE_COMPLEX shall be the same as those of C_FLOAT, C_DOUBLE, and C_LONG_DOUBLE, respectively.

11 12

5 The value of C_BOOL shall be a valid value for a logical kind parameter on the processor or shall be −1.

13 14 15

6 The value of C_CHAR shall be a valid value for a character kind type parameter on the processor or shall be −1.

16

7 The following entities shall be named constants of type character with a length parameter of one. The kind

17 18 19 20

parameter value shall be equal to the value of C_CHAR unless C_CHAR = −1, in which case the kind parameter value shall be the same as for default kind. The values of these constants are specified in Table 18.1. In the case that C_CHAR ̸= −1 the value is specified using C syntax. The semantics of these values are explained in ISO/IEC 9899:2011, 5.2.1 and 5.2.2.

If the value of C_CHAR is nonnegative, the character kind specified is the C character kind; otherwise, there is no C character kind.

Name

Table 18.1: Names of C characters with special semantics Value C definition C_CHAR = −1 C_CHAR ̸= −1

C_NULL_CHAR C_ALERT C_BACKSPACE C_FORM_FEED C_NEW_LINE C_CARRIAGE_RETURN C_HORIZONTAL_TAB C_VERTICAL_TAB

null character alert backspace form feed new line carriage return horizontal tab vertical tab

CHAR(0) ACHAR(7) ACHAR(8) ACHAR(12) ACHAR(10) ACHAR(13) ACHAR(9) ACHAR(11)

’\0’ ’\a’ ’\b’ ’\f’ ’\n’ ’\r’ ’\t’ ’\v’

21

8 The entities C_PTR and C_FUNPTR are described in 18.3.2.

22

9 The entity C_NULL_PTR shall be a named constant of type C_PTR. The value of C_NULL_PTR shall be the

23 24

same as the value NULL in C. The entity C_NULL_FUNPTR shall be a named constant of type C_FUNPTR. The value of C_NULL_FUNPTR shall be that of a null pointer to a function in C. NOTE 1 The value of NEW_LINE (C_NEW_LINE) is C_NEW_LINE (16.9.150).

25

18.2.3

Procedures in the module

26

18.2.3.1

General

27 28

1 In the detailed descriptions below, procedure names are generic and not specific. The C_F_POINTER and

C_F_STRPOINTER subroutines are impure; all other procedures in the module are simple.

ISO/IEC JTC 1/SC 22/WG5/N2184

495

J3/21-007r1

1

18.2.3.2

WD 1539-1

C_ASSOCIATED (C_PTR_1 [, C_PTR_2])

2

1 Description. Query C pointer status.

3

2 Class. Transformational function.

4

3 Arguments.

5

C_PTR_1

6

C_PTR_2 (optional) shall be a scalar of the same type as C_PTR_1.

shall be a scalar of type C_PTR or C_FUNPTR.

7

4 Result Characteristics. Default logical scalar.

8

5 Result Value.

9 10 11

2021-05-21

Case (i): Case (ii):

If C_PTR_2 is absent, the result is false if C_PTR_1 is a C null pointer and true otherwise. If C_PTR_2 is present, the result is false if C_PTR_1 is a C null pointer. If C_PTR_1 is not a C null pointer, the result is true if C_PTR_1 compares equal to C_PTR_2 in the sense of ISO/IEC 9899:2011, 6.3.2.3 and 6.5.9, and false otherwise.

12

NOTE 1 The following example illustrates the use of C_LOC and C_ASSOCIATED. USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR, C_FLOAT, C_ASSOCIATED, C_LOC INTERFACE SUBROUTINE FOO(GAMMA) BIND(C) IMPORT C_PTR TYPE(C_PTR), VALUE :: GAMMA END SUBROUTINE FOO END INTERFACE REAL(C_FLOAT), TARGET, DIMENSION(100) :: ALPHA TYPE(C_PTR) :: BETA ... IF (.NOT. C_ASSOCIATED(BETA)) THEN BETA = C_LOC(ALPHA) ENDIF CALL FOO(BETA) 13

18.2.3.3

C_F_POINTER (CPTR, FPTR [, SHAPE, LOWER])

14

1 Description. Associate a data pointer with the target of a C pointer and specify its shape.

15

2 Class. Subroutine.

16

3 Arguments.

17

CPTR

• the C address of an interoperable data entity, • the result of a reference to C_LOC with a noninteroperable argument, or • the C address of a storage sequence that is not in use by any other Fortran entity.

18 19 20

The value of CPTR shall not be the C address of a Fortran variable that does not have the TARGET attribute.

21 22 23 24 25

shall be a scalar of type C_PTR. It is an INTENT (IN) argument. Its value shall be

FPTR

496

shall be a pointer, shall not have a deferred type parameter, and shall not be a coindexed object. It is an INTENT (OUT) argument. If FPTR is an array, its shape is specified by SHAPE; the lower bounds are specified by LOWER if it is present, otherwise each lower bound is equal to 1.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

Case (i):

J3/21-007r1

23

If the value of CPTR is the C address of an interoperable data entity, FPTR shall be a data pointer with type and type parameter values interoperable with the type of the entity. If the target T of CPTR is scalar, FPTR becomes pointer associated with T; if FPTR is an array, SHAPE shall specify a size of 1. If T is an array, and FPTR is scalar, FPTR becomes associated with the first element of T. If both T and FPTR are arrays, SHAPE shall specify a size that is less than or equal to the size of T, and FPTR becomes associated with the first PRODUCT (SHAPE) elements of T (this could be the entirety of T). If the value of CPTR is the result of a reference to C_LOC with a noninteroperable effective argument X, FPTR shall be a nonpolymorphic pointer with the same type and type parameters as X. In this case, X shall not have been deallocated or have become undefined due to execution of a RETURN or END statement since the reference. If X is scalar, FPTR becomes pointer associated with X; if FPTR is an array, SHAPE shall specify a size of 1. If X is an array and FPTR is scalar, FPTR becomes associated with the first element of X. If both X and FPTR are arrays, SHAPE shall specify a size that is less than or equal to the size of X, and FPTR becomes associated with the first PRODUCT (SHAPE) elements of X (this could be the entirety of X). If the value of CPTR is the C address of a storage sequence that is not in use by any other Fortran entity, FPTR becomes associated with that storage sequence. The storage sequence shall be large enough to contain the target object described by FPTR and shall satisfy any other processor-dependent requirement for association.

24 25

SHAPE (optional) shall be a rank-one integer array. It is an INTENT (IN) argument. SHAPE shall be present if and only if FPTR is an array; its size shall be equal to the rank of FPTR.

26 27

LOWER (optional) shall be a rank-one integer array. It is an INTENT (IN) argument. It shall not be present if SHAPE is not present. If LOWER is present, its size shall be equal to the rank of FPTR.

1 2 3 4 5 6 7 8

Case (ii):

9 10 11 12 13 14 15 16 17 18

Case (iii):

19 20 21 22

28

4 Examples.

29

Case (i):

30 31 32 33

extern double c_x; void *address_of_x (void) { return &c_x; }

34

! Assume interface to "address_of_x" is available. Real (C_double), Pointer :: xp Call C_F_Pointer (address_of_x (), xp)

35 36 37 38

Case (ii):

Type t Real, Allocatable :: v(:,:) End Type Type(t), Target :: x(0:2) Type(C_ptr) :: xloc xloc = C_Loc (x) ... Type(t), Pointer :: y(:) Call C_F_Pointer (xloc, y, [3], [0])

Case (iii):

void *getmem (int nbits) { return malloc ((nbits+CHAR_BIT-1)/CHAR_BIT);

39 40 41 42 43 44 45 46 47 48 49

ISO/IEC JTC 1/SC 22/WG5/N2184

497

J3/21-007r1

WD 1539-1

2021-05-21

}

1 2

! Assume interface to "getmem" is available, ! and there is a derived type "mytype" accessible. Type(mytype), Pointer :: x Call C_F_Pointer (getmem (Storage_Size (x)), x) The following statements illustrate the use of C_F_POINTER when the pointer to be set has a deferred type parameter: Character(42), Pointer :: C1 Character(:), Pointer :: C2 Call C_F_Pointer (CPTR, C1) C2 => C1 This will associate C2 with the entity at the C address specified by CPTR, and specify its length to be the same as that of C1.

3 4 5 6 7

Case (iv):

8 9 10 11 12 13 14

NOTE 1 In the case of associating FPTR with a storage sequence, there might be processor-dependent requirements such as alignment of the memory address or placement in memory. 15

18.2.3.4

C_F_PROCPOINTER (CPTR, FPTR)

16

1 Description. Associate a procedure pointer with the target of a C function pointer.

17

2 Class. Simple subroutine.

18

3 Arguments.

19 20

CPTR

shall be a scalar of type C_FUNPTR. It is an INTENT (IN) argument. Its value shall be the C address of a procedure that is interoperable, or the result of a reference to the function C_FUNLOC from the intrinsic module ISO_C_BINDING.

FPTR

shall be a procedure pointer, and shall not be a component of a coindexed object. It is an INTENT (OUT) argument. If the target of CPTR is interoperable, the interface for FPTR shall be interoperable with the prototype that describes the target of CPTR; otherwise, the interface for FPTR shall have the same characteristics as that target. FPTR becomes pointer associated with the target of CPTR.

21 22 23 24 25 26

NOTE 1 The term “target” in the descriptions of C_F_POINTER and C_F_PROCPOINTER denotes the entity referenced by a C pointer, as described in ISO/IEC 9899:2011, 6.2.5. 27

18.2.3.5

C_F_STRPOINTER (CSTRARRAY, FSTRPTR [, NCHARS]) or C_F_STRPOINTER (CSTRPTR, FSTRPTR [, NCHARS])

28

1 Description. Associate a character pointer with a C string.

29

2 Class. Simple subroutine.

30

3 Arguments.

31 32 33 34 35 36

CSTRARRAY shall be a rank one character array of kind C_CHAR, with a length type parameter equal to one. It is an INTENT (IN) argument. Its actual argument shall be simply contiguous and have the TARGET attribute. CSTRPTR

498

shall be a scalar of type C_PTR. It is an INTENT (IN) argument. Its value shall be the C address of a contiguous array S of NCHARS characters. Its value shall not be the C address of a Fortran variable that does not have the TARGET attribute.

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4

FSTRPTR

WD 1539-1

J3/21-007r1

shall be a deferred-length character pointer of kind C_CHAR. It is an INTENT (OUT) argument. FSTRPTR becomes pointer associated with the leftmost characters of the actual argument element sequence (15.5.2.11) of CSTRARRAY if it appears, or with the leftmost characters (in array element order) of the array S if CSTRPTR appears.

5 6 7

The length type parameter of FSTRPTR becomes the largest value for which no C null characters appear in the sequence, and which is less than or equal to NCHARS if present, and the size of CSTRARRAY otherwise.

8 9 10

NCHARS (optional) shall be an integer scalar with a nonnegative value. It is an INTENT (IN) argument. NCHARS shall be present if CSTRARRAY is assumed-size, or if CSTRPTR appears. If CSTRARRAY appears, NCHARS shall not be greater than the size of CSTRARRAY.

11 12

4 If C_CHAR has the value −1, indicating that there is no C character kind, the generic subroutine C_F_-

13

STRPOINTER does not have any specific procedure. 18.2.3.6

C_FUNLOC (X)

14

1 Description. C address of the argument.

15

2 Class. Transformational function.

16 17

3 Argument. X shall be a procedure; if it is a procedure pointer it shall be associated. It shall not be a coindexed

18

4 Result Characteristics. Scalar of type C_FUNPTR.

19 20 21

5 Result Value. The result value is described using the result name FUNPTR. The result is determined as if

22 23 24

6 The result is a value that can be used as an actual CPTR argument in a call to C_F_PROCPOINTER where

25

object.

C_FUNPTR were a derived type containing a procedure pointer component PX with an implicit interface and the pointer assignment FUNPTR%PX => X were executed. the FPTR argument has attributes that would allow the pointer assignment FPTR => X. Such a call to C_F_PROCPOINTER shall have the effect of the pointer assignment FPTR => X. 18.2.3.7

C_LOC (X)

26

1 Description. C address of the argument.

27

2 Class. Transformational function.

28 29 30

3 Argument. X shall have either the POINTER or TARGET attribute. It shall not be a coindexed object. It shall

31

be a variable with interoperable type and kind type parameters, an assumed-type variable, or a nonpolymorphic variable that has no length type parameter. If it is allocatable, it shall be allocated. If it is a pointer, it shall be associated. If it is an array, it shall be contiguous and have nonzero size. It shall not be a zero-length string.

32

4 Result Characteristics. Scalar of type C_PTR.

33

5 Result Value. The result value is described using the result name CPTR.

34 35

6 If X is a scalar data entity, the result is determined as if C_PTR were a derived type containing a scalar pointer

36

7 If X is an array data entity, the result is determined as if C_PTR were a derived type containing a scalar pointer

37 38

component PX of the type and type parameters of X and the pointer assignment of CPTR%PX to the first element of X were executed.

39 40 41

8 If X is a data entity that is interoperable or has interoperable type and type parameters, the result is the value

component PX of the type and type parameters of X and the pointer assignment CPTR%PX => X were executed.

that the C processor returns as the result of applying the unary “&” operator (as defined in ISO/IEC 9899:2011, 6.5.3.2) to the target of CPTR%PX.

ISO/IEC JTC 1/SC 22/WG5/N2184

499

J3/21-007r1

1 2 3

WD 1539-1

2021-05-21

9 The result is a value that can be used as an actual CPTR argument in a call to C_F_POINTER where FPTR

has attributes that would allow the pointer assignment FPTR => X. Such a call to C_F_POINTER shall have the effect of the pointer assignment FPTR => X. NOTE 1 Where the actual argument is of noninteroperable type or type parameters, the result of C_LOC provides an opaque “handle” for it. In an actual implementation, this handle might be the C address of the argument; however, only a C function that treats it as a void (generic) C pointer that cannot be dereferenced (ISO/IEC 9899:2011, 6.5.3.2) is likely to be portable.

4

18.2.3.8

C_SIZEOF (X)

5

1 Description. Size of X in bytes.

6

2 Class. Inquiry function.

7 8

3 Argument. X shall be an interoperable data entity that is not an assumed-size array or an assumed-rank array

9

4 Result Characteristics. Scalar integer of kind C_SIZE_T (18.3.1).

10 11

5 Result Value. If X is scalar, the result value is the value that the companion processor returns as the result of

12 13 14 15 16

that is associated with an assumed-size array.

applying the sizeof operator (ISO/IEC 9899:2011, 6.5.3.4) to an object of a type that interoperates with the type and type parameters of X. 6 If X is an array, the result value is the value that the companion processor returns as the result of applying the

sizeof operator to an object of a type that interoperates with the type and type parameters of X, multiplied by the number of elements in X. 18.2.3.9

F_C_STRING (STRING [, ASIS])

17

1 Description. String with appended null character.

18

2 Class. Transformational function.

19

3 Arguments.

20

STRING

21

ASIS (optional) shall be a logical scalar.

shall be a character scalar of kind C_CHAR.

22 23 24

4 Result Characteristics. The result is of type character with the same kind type parameter as STRING. If

25

5 Result Value.

26

6 The leftmost characters of the result, up to the penultimate character, are equal to the corresponding characters

27 28 29

ASIS is present with the value true, the length type parameter of the result is equal to one plus the length of STRING, otherwise it is equal to one plus the length of STRING without trailing blanks.

of STRING. The final character of the result is equal to C_NULL_CHAR. 7 If C_CHAR has the value −1, indicating that there is no C character kind, the generic function F_C_STRING

has no specific procedure.

500

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

18.3

Interoperability between Fortran and C entities

2

18.3.1

Interoperability of intrinsic types

J3/21-007r1

3

1 Table 18.2 shows the interoperability between Fortran intrinsic types and C types. A Fortran intrinsic type with

4 5 6 7 8

particular type parameter values is interoperable with a C type if the type and kind type parameter value are listed in the table on the same row as that C type. If the type is character, the length type parameter is interoperable if and only if its value is one. A combination of Fortran type and type parameters that is interoperable with a C type listed in the table is also interoperable with any unqualified C type that is compatible with the listed C type.

9

2 The second column of the table refers to the named constants made accessible by the ISO_C_BINDING intrinsic

10 11

module. If the value of any of these named constants is negative, there is no combination of Fortran type and type parameters interoperable with the C type shown in that row.

12 13

3 A combination of intrinsic type and type parameters is interoperable if it is interoperable with a C type. The C

types mentioned in Table 18.2 are defined in ISO/IEC 9899:2011, 6.2.5, 7.19, and 7.20.1.

Fortran type

Table 18.2: Interoperability between Fortran and C types Named constant from the ISO_C_BINDING module C type (kind type parameter if value is positive) C_INT C_SHORT C_LONG C_LONG_LONG C_SIGNED_CHAR

INTEGER

REAL

COMPLEX LOGICAL

C_SIZE_T C_INT8_T C_INT16_T C_INT32_T C_INT64_T C_INT_LEAST8_T C_INT_LEAST16_T C_INT_LEAST32_T C_INT_LEAST64_T C_INT_FAST8_T C_INT_FAST16_T C_INT_FAST32_T C_INT_FAST64_T C_INTMAX_T C_INTPTR_T C_PTRDIFF_T C_FLOAT C_DOUBLE C_LONG_DOUBLE C_FLOAT_COMPLEX C_DOUBLE_COMPLEX C_LONG_DOUBLE_COMPLEX C_BOOL

ISO/IEC JTC 1/SC 22/WG5/N2184

int short int long int long long int signed char unsigned char size_t int8_t int16_t int32_t int64_t int_least8_t int_least16_t int_least32_t int_least64_t int_fast8_t int_fast16_t int_fast32_t int_fast64_t intmax_t intptr_t ptrdiff_t float double long double float _Complex double _Complex long double _Complex _Bool

501

J3/21-007r1

WD 1539-1

2021-05-21

Fortran type

Interoperability between Fortran and C types Named constant from the ISO_C_BINDING module (kind type parameter if value is positive)

C type

CHARACTER

C_CHAR

char

(cont.)

NOTE 1 ISO/IEC 9899:2011 specifies that the representations for nonnegative signed integers are the same as the corresponding values of unsigned integers. Because Fortran does not provide direct support for unsigned kinds of integers, the ISO_C_BINDING module does not make accessible named constants for their kind type parameter values. A user can use the signed kinds of integers to interoperate with the unsigned types and all their qualified versions as well. This has the potentially surprising side effect that the C type unsigned char is interoperable with the type integer with a kind type parameter of C_SIGNED_CHAR.

1

18.3.2

Interoperability with C pointer types

2

1 C_PTR and C_FUNPTR shall be derived types with only private components. No direct component of either

3 4

of these types is allocatable or a pointer. C_PTR is interoperable with any C object pointer type. C_FUNPTR is interoperable with any C function pointer type. NOTE 1 This means that only a C processor with the same representation method for all C object pointer types, and the same representation method for all C function pointer types, can be the target of interoperability of a Fortran processor. ISO/IEC 9899:2011 does not require this to be the case. NOTE 2 The function C_LOC can be used to return a value of type C_PTR that is the C address of an allocated allocatable variable. The function C_FUNLOC can be used to return a value of type C_FUNPTR that is the C address of a procedure. For C_LOC and C_FUNLOC the returned value is of an interoperable type and thus can be used in contexts where the procedure or allocatable variable is not directly allowed. For example, it could be passed as an actual argument to a C function. Similarly, type C_FUNPTR or C_PTR can be used in a dummy argument or structure component and can have a value that is the C address of a procedure or allocatable variable, even in contexts where a procedure or allocatable variable is not directly allowed.

5 6

18.3.3

Interoperability of derived types and C structure types

1 Interoperability between a derived type in Fortran and a structure type in C is provided by the BIND attribute

7

on the Fortran type.

8

C1801 (R726) A derived type with the BIND attribute shall not have the SEQUENCE attribute.

9

C1802 (R726) A derived type with the BIND attribute shall not have type parameters.

10

C1803 (R726) A derived type with the BIND attribute shall not have the EXTENDS attribute.

11 12

C1804 (R726) A derived-type-def that defines a derived type with the BIND attribute shall not have a typebound-procedure-part.

13

C1805 (R726) A derived type with the BIND attribute shall have at least one component.

14 15

C1806 (R726) Each component of a derived type with the BIND attribute shall be a nonpointer, nonallocatable data component with interoperable type and type parameters.

502

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 The syntax rules and their constraints require that a derived type that is interoperable with a C structure type have components that are all data entities that are interoperable. No component is permitted to be allocatable or a pointer, but the value of a component of type C_FUNPTR or C_PTR can be the C address of such an entity. 1 2 3 4 5

2 A derived type is interoperable with a C structure type if and only if the derived type has the BIND attribute

(7.5.2), the derived type and the C structure type have the same number of components, and the components of the derived type would interoperate with corresponding components of the C structure type as described in 18.3.4 and 18.3.5 if the components were variables. A component of a derived type and a component of a C structure type correspond if they are declared in the same relative position in their respective type definitions. NOTE 2 The names of the corresponding components of the derived type and the C structure type need not be the same.

6 7

3 There is no Fortran type that is interoperable with a C structure type that contains a bit field or that contains

a flexible array member. There is no Fortran type that is interoperable with a C union type. NOTE 3 For example, the C type myctype, declared below, is interoperable with the Fortran type myftype, declared below. typedef struct { int m, n; float r; } myctype; USE, INTRINSIC :: ISO_C_BINDING TYPE, BIND(C) :: MYFTYPE INTEGER(C_INT) :: I, J REAL(C_FLOAT) :: S END TYPE MYFTYPE The names of the types and the names of the components are not significant for the purposes of determining whether a Fortran derived type is interoperable with a C structure type. NOTE 4 ISO/IEC 9899:2011 requires the names and component names to be the same in order for the types to be compatible (ISO/IEC 9899:2011, 6.2.7). This is similar to Fortran’s rule describing when different derived type definitions describe the same sequence type. This rule was not extended to determine whether a Fortran derived type is interoperable with a C structure type because the case of identifiers is significant in C but not in Fortran.

8

18.3.4

Interoperability of scalar variables

9 10 11

1 A named scalar Fortran variable is interoperable if and only if its type and type parameters are interoperable, it

12 13

2 An interoperable scalar Fortran variable is interoperable with a scalar C entity if their types and type parameters

is not a coarray, it has neither the ALLOCATABLE nor the POINTER attribute, and if it is of type character its length is not assumed or declared by an expression that is not a constant expression. are interoperable.

ISO/IEC JTC 1/SC 22/WG5/N2184

503

J3/21-007r1

1 2 3 4 5 6

18.3.5

WD 1539-1

2021-05-21

Interoperability of array variables

1 A Fortran variable that is a named array is interoperable if and only if its type and type parameters are interop-

erable, it is not a coarray, it is of explicit shape or assumed size, and if it is of type character its length is not assumed or declared by an expression that is not a constant expression.   2 An explicit-shape or assumed-size array of rank r, with a shape of e1 . . . er is interoperable with a C array if its size is nonzero and (1)

7

either (a) (b)

8 9 10

(2)

11

the array is assumed-size, and the C array does not specify a size, or the array is an explicit-shape array, and the extent of the last dimension (er ) is the same as the size of the C array, and

either

12 13

(a)

14 15 16

(b)

r is equal to one, and an element of the array is interoperable with an element of the C array, or   r is greater than one, and an explicit-shape array with shape of e1 . . . er−1 , with the same type and type parameters as the original array, is interoperable with a C array of a type equal to the element type of the original C array.

NOTE 1 An element of a multi-dimensional C array is an array type, so a Fortran array of rank one is not interoperable with a multidimensional C array. NOTE 2 An allocatable array or array pointer is never interoperable. Such an array does not meet the requirement of being an explicit-shape or assumed-size array. NOTE 3 For example, a Fortran array declared as INTEGER(C_INT) :: A(18, 3:7, *) is interoperable with a C array declared as int b[][5][18];

NOTE 4 The C programming language defines null-terminated strings, which are actually arrays of the C type char that have a C null character in them to indicate the last valid element. A Fortran array of type character with a kind type parameter equal to C_CHAR is interoperable with a C string. Fortran’s rules of sequence association (15.5.2.11) permit a character scalar actual argument to correspond to a dummy argument array. This makes it possible to argument associate a Fortran character string with a C string. 18.3.6, NOTE 4 has an example of interoperation between Fortran and C strings.

17

18.3.6

Interoperability of procedures and procedure interfaces

18 19

1 A Fortran procedure is interoperable if and only if it has the BIND attribute, that is, if its interface is specified

20

2 A Fortran procedure interface is interoperable with a C function prototype if

with a proc-language-binding-spec.

504

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

(1) (2)

(a)

5

(b) (3)

8 9

(4)

10 11

(5)

J3/21-007r1

the interface has the BIND attribute, either

3 4

6 7

WD 1539-1

the interface describes a function whose result is a scalar variable that is interoperable with the result of the prototype or the interface describes a subroutine and the prototype has a result type of void,

the number of dummy arguments of the interface is equal to the number of formal parameters of the prototype, any scalar dummy argument with the VALUE attribute is interoperable with the corresponding formal parameter of the prototype, any dummy argument without the VALUE attribute corresponds to a formal parameter of the prototype that is of a pointer type, and either • the dummy argument is interoperable with an entity of the referenced type (ISO/IEC 9899:2011, 6.2.5, 7.19, and 7.20.1) of the formal parameter, • the dummy argument is a nonallocatable nonpointer variable of type CHARACTER with assumed character length and the formal parameter is a pointer to CFI_cdesc_t, • the dummy argument is allocatable, assumed-shape, assumed-rank, or a pointer without the CONTIGUOUS attribute, and the formal parameter is a pointer to CFI_cdesc_t, or • the dummy argument is assumed-type and not allocatable, assumed-shape, assumed-rank, or a pointer, and the formal parameter is a pointer to void,

12 13 14 15 16 17 18 19 20 21

(6)

22

(7)

each allocatable or pointer dummy argument of type CHARACTER has deferred character length, and the prototype does not have variable arguments as denoted by the ellipsis (...).

NOTE 1 The referenced type of a C pointer type is the C type of the object that the C pointer type points to. For example, the referenced type of the pointer type int * is int. NOTE 2 The C language allows specification of a C function that can take a variable number of arguments (ISO/IEC 9899:2011, 7.16). This document does not provide a mechanism for Fortran procedures to interoperate with such C functions. 23 24

3 A formal parameter of a C function prototype corresponds to a dummy argument of a Fortran interface if they

25 26

4 In a reference from C to a Fortran procedure with an interoperable interface, a C actual argument shall be the

27 28 29 30 31 32 33 34 35

36 37 38 39

are in the same relative positions in the C parameter list and the dummy argument list, respectively. address of a C descriptor for the intended effective argument if the corresponding dummy argument interoperates with a C formal parameter that is a pointer to CFI_cdesc_t. In this C descriptor, the members other than attribute and type shall describe an object with the same characteristics as the intended effective argument. The value of the attribute member of the C descriptor shall be compatible with the characteristics of the dummy argument. The type member shall have a value that depends on the intended effective argument as follows: • if the dynamic type of the intended effective argument is an interoperable type listed in Table 18.4, the corresponding value for that type; • if the dynamic type of the intended effective argument is an intrinsic type for which the processor defines a nonnegative type specifier value not listed in Table 18.4, that type specifier value; • otherwise, CFI_type_other. 5 When an interoperable Fortran procedure that is invoked from C has a dummy argument with the CONTIGU-

OUS attribute or that is an assumed-length CHARACTER explicit-shape or assumed-size array, and the actual argument is the address of a C descriptor for a discontiguous object, the Fortran processor shall handle the difference in contiguity.

ISO/IEC JTC 1/SC 22/WG5/N2184

505

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

6 When an interoperable C procedure whose Fortran interface has a dummy argument with the CONTIGUOUS

5 6 7 8

7 If an interoperable procedure defined by means other than Fortran has an optional dummy argument, and the

attribute or that is an assumed-length CHARACTER explicit-shape or assumed-size array is invoked from Fortran and the effective argument is discontiguous, the Fortran processor shall ensure that the C procedure receives a descriptor for a contiguous object. corresponding actual argument in a reference from Fortran is absent, the procedure is invoked with a null pointer for that argument. If an interoperable procedure defined by means of Fortran is invoked by a C function, an optional dummy argument is absent if and only if the corresponding argument in the invocation is a null pointer. NOTE 3 For example, a Fortran procedure interface described by INTERFACE FUNCTION FUNC(I, J, K, L, M) BIND(C) USE, INTRINSIC :: ISO_C_BINDING INTEGER(C_SHORT) :: FUNC INTEGER(C_INT), VALUE :: I REAL(C_DOUBLE) :: J INTEGER(C_INT) :: K, L(10) TYPE(C_PTR), VALUE :: M END FUNCTION FUNC END INTERFACE is interoperable with the C function prototype short func(int i, double *j, int *k, int l[10], void *m); A C pointer can correspond to a Fortran dummy argument of type C_PTR with the VALUE attribute or to a Fortran scalar that does not have the VALUE attribute. In the above example, the C pointers j and k correspond to the Fortran scalars J and K, respectively, and the C pointer m corresponds to the Fortran dummy argument M of type C_PTR. NOTE 4 The interoperability of Fortran procedure interfaces with C function prototypes is only one part of invocation of a C function from Fortran. There are four pieces to consider in such an invocation: the procedure reference, the Fortran procedure interface, the C function prototype, and the C function. Conversely, the invocation of a Fortran procedure from C involves the function reference, the C function prototype, the Fortran procedure interface, and the Fortran procedure. In order to determine whether a reference is allowed, it is necessary to consider all four pieces. For example, consider a C function that can be described by the C function prototype void copy(char in[], char out[]); Such a function can be invoked from Fortran as follows: USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_NULL_CHAR INTERFACE SUBROUTINE COPY(IN, OUT) BIND(C) IMPORT C_CHAR CHARACTER(KIND=C_CHAR), DIMENSION(*) :: IN, OUT END SUBROUTINE COPY END INTERFACE CHARACTER(LEN=10, KIND=C_CHAR) :: &

506

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 4 (cont.) &

DIGIT_STRING = C_CHAR_’123456789’ // C_NULL_CHAR CHARACTER(KIND=C_CHAR) :: DIGIT_ARR(10) CALL COPY(DIGIT_STRING, DIGIT_ARR) PRINT ’(1X, A1)’, DIGIT_ARR(1:9) END

The procedure reference has character string actual arguments. These correspond to character array dummy arguments in the procedure interface body as allowed by Fortran’s rules of sequence association (15.5.2.11). Those array dummy arguments in the procedure interface are interoperable with the formal parameters of the C function prototype. The C function is not shown here, but is assumed to be compatible with the C function prototype. NOTE 5 If an interoperable C procedure whose Fortran interface has a dummy argument which has the CONTIGUOUS attribute, or is an assumed-length CHARACTER explicit-shape or assumed-size array, is invoked from C, because the invoking routine is responsible for the contents of the C descriptor, it therefore might not describe a contiguous data object.

1

18.4

C descriptors

2

1 A C descriptor is a C structure of type CFI_cdesc_t. Together with library functions that have standard

3 4

prototypes, it provides a means for describing and manipulating Fortran data objects from within a C function. This C structure is defined in the source file ISO_Fortran_binding.h.

5

18.5

The source file ISO_Fortran_binding.h

6

18.5.1

Summary of contents

7 8 9 10 11

1 The source file ISO_Fortran_binding.h shall contain the C structure definitions, typedef declarations, macro

definitions, and function prototypes specified in 18.5.2 to 18.5.5. The definitions and declarations in ISO_Fortran_binding.h can be used by a C function to interpret and manipulate a C descriptor. These provide a means to specify a C prototype that interoperates with a Fortran interface that has a non-interoperable dummy variable (18.3.6).

12 13 14

2 The source file ISO_Fortran_binding.h may be included in any order relative to the standard C headers, and

15

3 A C source file that includes the ISO_Fortran_binding.h header file shall not use any names starting with

16 17 18

CFI_ that are not defined in the header, and shall not define any of the structure names defined in the header as macro names. All names other than structure member names defined in the header begin with CFI_ or an underscore character, or are defined by a standard C header that it includes.

19

18.5.2

may be included more than once in a given scope, with no effect different from being included only once, other than the effect on line numbers.

The CFI_dim_t structure type

20

1 CFI_dim_t is a typedef name for a C structure. It is used to represent lower bound, extent, and memory stride

21 22

information for one dimension of an array. The type CFI_index_t is described in 18.5.4. CFI_dim_t contains at least the following members in any order.

ISO/IEC JTC 1/SC 22/WG5/N2184

507

J3/21-007r1

WD 1539-1

2021-05-21

1 2

CFI_index_t lower_bound; The value is equal to the value of the lower bound for the dimension being described.

3 4

CFI_index_t extent; The value is equal to the number of elements in the dimension being described, or −1 for the final dimension of an assumed-size array.

5 6

CFI_index_t sm; The value is equal to the memory stride for a dimension; this is the difference in bytes between the addresses of successive elements in the dimension being described.

7

18.5.3

The CFI_cdesc_t structure type

8 9 10 11

1 CFI_cdesc_t is a typedef name for a C structure, which contains a flexible array member. It shall contain at least

12

2 The first three members of the structure shall be base_addr, elem_len, and version in that order. The final

13 14

member shall be dim. All other members shall be between version and dim, in any order. The types CFI_attribute_t, CFI_rank_t, and CFI_type_t are described in 18.5.4. The type CFI_dim_t is described in 18.5.2.

15 16 17 18 19

void * base_addr; If the object is an unallocated allocatable variable or a pointer that is disassociated, the value is a null pointer; otherwise, if the object has zero size, the value is not a null pointer but is otherwise processor-dependent. Otherwise, the value is the base address of the object being described. The base address of a scalar is its C address. The base address of an array is the C address of the first element in Fortran array element order.

20 21

size_t elem_len; If the object is scalar, the value is the storage size in bytes of the object; otherwise, the value is the storage size in bytes of an element of the object.

22 23

int version; The value is equal to the value of CFI_VERSION in the source file ISO_Fortran_binding.h that defined the format and meaning of this C descriptor.

24 25

CFI_rank_t rank; The value is equal to the number of dimensions of the Fortran object being described; if the object is scalar, the value is zero.

26 27 28

CFI_type_t type; The value is equal to the specifier for the type of the object. Each interoperable intrinsic C type has a specifier. Specifiers are also provided to indicate that the type of the object is an interoperable structure, or is unknown. The macros listed in Table 18.4 provide values that correspond to each specifier.

29 30 31

CFI_attribute_t attribute; The value is equal to the value of an attribute code that indicates whether the object described is allocatable, a data pointer, or a nonallocatable nonpointer data object. The macros listed in Table 18.3 provide values that correspond to each code.

32 33 34

CFI_dim_t dim; The number of elements in the dim array is equal to the rank of the object. Each element of the array contains the lower bound, extent, and memory stride information for the corresponding dimension of the Fortran object.

35

3 For a C descriptor of an array pointer or allocatable array, the value of the lower_bound member of each element

36 37 38

of the dim member of the descriptor is determined by argument association, allocation, or pointer association. For a C descriptor of a nonallocatable nonpointer object, the value of the lower_bound member of each element of the dim member of the descriptor is zero.

39 40 41

4 There shall be an ordering of the dimensions such that the absolute value of the sm member of the first dimension

42 43 44

the members described in this subclause. The values of these members of a structure of type CFI_cdesc_t that is produced by the functions and macros specified in this document, or received by a C function when invoked by a Fortran procedure, shall have the properties described in this subclause.

is not less than the elem_len member of the C descriptor and the absolute value of the sm member of each subsequent dimension is not less than the absolute value of the sm member of the previous dimension multiplied by the extent of the previous dimension. 5 In a C descriptor of an assumed-size array, the extent member of the last element of the dim member has the

value −1.

508

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 The reason for the restriction on the absolute values of the sm members is to ensure that there is no overlap between the elements of the array that is being described, while allowing for the reordering of subscripts. Within Fortran, such a reordering can be achieved with the intrinsic function TRANSPOSE or the intrinsic function RESHAPE with the optional argument ORDER, and an optimizing compiler can accommodate it without making a copy by constructing the appropriate descriptor whenever it can determine that a copy is not needed. NOTE 2 The value of elem_len for a Fortran CHARACTER object is equal to the character length times the number of bytes of a single character of that kind. If the kind is C_CHAR, this value will be equal to the character length.

1

18.5.4

Macros and typedefs in ISO_Fortran_binding.h

2 3 4

1 Except for CFI_CDESC_T, each macro defined in ISO_Fortran_binding.h expands to an integer constant

5 6

2 CFI_CDESC_T is a function-like macro that takes one argument, which is the rank of the C descriptor to create,

7 8 9

expression that is either a single token or a parenthesized expression that is suitable for use in #if preprocessing directives. and evaluates to an unqualified type of suitable size and alignment for defining a variable to use as a C descriptor of that rank. The argument shall be an integer constant expression with a value that is greater than or equal to zero and less than or equal to CFI_MAX_RANK. A pointer to a variable declared using CFI_CDESC_T can be cast to CFI_cdesc_t *. A variable declared using CFI_CDESC_T shall not have an initializer. NOTE 1 The CFI_CDESC_T macro provides the memory for a C descriptor. The address of an entity declared using the macro is not usable as an actual argument corresponding to a formal parameter of type CFI_cdesc_t * without an explicit cast. For example, the following code uses CFI_CDESC_T to declare a C descriptor of rank 5 and pass it to CFI_deallocate (18.5.5.4). CFI_CDESC_T(5) object; int ind; . . . Code to define and use C descriptor. ind = CFI_deallocate((CFI_cdesc_t *)&object);

10 11

3 CFI_index_t is a typedef name for a standard signed integer type capable of representing the result of subtracting

12 13 14

4 The CFI_MAX_RANK macro has a processor-dependent value equal to the largest rank supported. The value

two pointers. shall be greater than or equal to 15. CFI_rank_t is a typedef name for a standard integer type capable of representing the largest supported rank.

15

5 The CFI_VERSION macro has a processor-dependent value that encodes the version of the ISO_Fortran_-

16 17

binding.h source file containing this macro. This value should be increased if a new version of the source file is incompatible with the previous version.

18 19 20

6 The macros in Table 18.3 are for use as attribute codes. The values shall be nonnegative and distinct. CFI_-

attribute_t is a typedef name for a standard integer type capable of representing the values of the attribute codes.

ISO/IEC JTC 1/SC 22/WG5/N2184

509

J3/21-007r1

WD 1539-1

2021-05-21

Table 18.3: ISO_Fortran_binding.h macros for attribute codes Macro name Attribute CFI_attribute_pointer CFI_attribute_allocatable CFI_attribute_other

data pointer allocatable nonallocatable nonpointer

1 2 3

7 CFI_attribute_pointer specifies a data object with the Fortran POINTER attribute. CFI_attribute_allocatable

4 5 6 7 8

8 The macros in Table 18.4 are for use as type specifiers. The value for CFI_type_other shall be negative and

specifies an object with the Fortran ALLOCATABLE attribute. CFI_attribute_other specifies a nonallocatable nonpointer object. distinct from all other type specifiers. CFI_type_struct specifies a C structure that is interoperable with a Fortran derived type; its value shall be positive and distinct from all other type specifiers. If a C type is not interoperable with a Fortran type and kind supported by the Fortran processor, its macro shall evaluate to a negative value. Otherwise, the value for a macro listed in Table 18.4 shall be positive.

9

9 If the processor supports interoperability of a Fortran intrinsic type with a C type not listed in Table 18.4,

10 11

the processor shall define a type specifier value for that type which is positive and distinct from all other type specifiers.

12 13

10 CFI_type_t is a typedef name for a standard integer type capable of representing the values for the supported

type specifiers. Table 18.4: ISO_Fortran_binding.h macros for type codes Macro name C Type

510

CFI_type_signed_char CFI_type_short CFI_type_int CFI_type_long CFI_type_long_long CFI_type_size_t CFI_type_int8_t CFI_type_int16_t CFI_type_int32_t CFI_type_int64_t CFI_type_int_least8_t CFI_type_int_least16_t CFI_type_int_least32_t CFI_type_int_least64_t CFI_type_int_fast8_t CFI_type_int_fast16_t CFI_type_int_fast32_t CFI_type_int_fast64_t CFI_type_intmax_t CFI_type_intptr_t CFI_type_ptrdiff_t

signed char short int int long int long long int size_t int8_t int16_t int32_t int64_t int_least8_t int_least16_t int_least32_t int_least64_t int_fast8_t int_fast16_t int_fast32_t int_fast64_t intmax_t intptr_t ptrdiff_t

CFI_type_float CFI_type_double CFI_type_long_double

float double long double

CFI_type_float_Complex CFI_type_double_Complex CFI_type_long_double_Complex

float _Complex double _Complex long double _Complex

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

ISO_Fortran_binding.h macros for type codes Macro name C Type CFI_type_Bool CFI_type_char CFI_type_cptr CFI_type_struct CFI_type_other

J3/21-007r1

(cont.)

_Bool char void * interoperable C structure Not otherwise specified

NOTE 2 The values for different C types can be the same; for example, CFI_type_int and CFI_type_int32_t might have the same value. 1

11 The macros in Table 18.5 are for use as error codes. The macro CFI_SUCCESS shall be defined to be the

2 3 4

integer constant zero. The value of each macro other than CFI_SUCCESS shall be nonzero and shall be different from the values of the other macros specified in this subclause. Error conditions other than those listed in this subclause should be indicated by error codes different from the values of the macros named in this subclause.

5

12 The values of the macros in Table 18.5 indicate the error condition described.

Macro name

Table 18.5: ISO_Fortran_binding.h macros for error codes Error condition

CFI_SUCCESS CFI_ERROR_BASE_ADDR_NULL CFI_ERROR_BASE_ADDR_NOT_NULL CFI_INVALID_ELEM_LEN CFI_INVALID_RANK CFI_INVALID_TYPE CFI_INVALID_ATTRIBUTE CFI_INVALID_EXTENT CFI_INVALID_DESCRIPTOR CFI_ERROR_MEM_ALLOCATION CFI_ERROR_OUT_OF_BOUNDS

No error detected. The base address member of a C descriptor is a null pointer in a context that requires a non-null pointer value. In a context that requires a null pointer value, the base address member of a C descriptor is not a null pointer. The value supplied for the element length member of a C descriptor is not valid. The value supplied for the rank member of a C descriptor is not valid. The value supplied for the type member of a C descriptor is not valid. The value supplied for the attribute member of a C descriptor is not valid. The value supplied for the extent member of a CFI_dim_t structure is not valid. A C descriptor is invalid in some way. Memory allocation failed. A reference is out of bounds.

6

18.5.5

Functions declared in ISO_Fortran_binding.h

7

18.5.5.1

Arguments and results of the functions

8 9 10 11 12 13

1 Some of the functions described in 18.5.5 return an error indicator; this is an integer value that indicates whether

an error condition was detected. The value zero indicates that no error condition was detected, and a nonzero value indicates which error condition was detected. Table 18.5 lists standard error conditions and macro names for their corresponding error codes. A processor is permitted to detect other error conditions. If an invocation of a function defined in 18.5.5 could detect more than one error condition and an error condition is detected, which error condition is detected is processor dependent.

ISO/IEC JTC 1/SC 22/WG5/N2184

511

J3/21-007r1

WD 1539-1

2021-05-21

1 2

2 In function arguments representing subscripts, bounds, extents, or strides, the ordering of the elements is the

3 4

3 Prototypes for these functions, or equivalent macros, are provided in the ISO_Fortran_binding.h file as described

5

same as the ordering of the elements of the dim member of a C descriptor. in 18.5.5. It is unspecified whether the functions defined by this header are macros or identifiers declared with external linkage. If a macro definition is suppressed in order to access an actual function, the behavior is undefined. NOTE 1 These functions are allowed to be macros to provide extra implementation flexibility. For example, CFI_establish could include the value of CFI_VERSION in the header used to compile the call to CFI_establish as an extra argument of the actual function used to establish the C descriptor.

6 7 8

9

18.5.5.2

The CFI_address function

1 Synopsis. C address of an object described by a C descriptor.

void *CFI_address(const CFI_cdesc_t *dv, const CFI_index_t subscripts[]); 2 Formal Parameters.

shall be the address of a C descriptor describing the object. The object shall not be an unallocated allocatable variable or a pointer that is not associated.

10 11

dv

12 13 14

subscripts shall be a null pointer or the address of an array of type CFI_index_t. If the object is an array, subscripts shall be the address of an array of CFI_index_t with at least n elements, where n is the rank of the object. The value of subscripts[i] shall be within the bounds of dimension i specified by the dim member of the C descriptor except for the last dimension of a C descriptor for an assumed-size array. For the C descriptor of an assumed-size array, the value of the subscript for the last dimension shall not be less than the lower bound, and the subscript order value specified by the subscripts shall not exceed the size of the array.

15 16 17 18 19 20 21

3 Result Value. If the object is an array of rank n, the result is the C address of the element of the object that

22

4 Example. If dv is the address of a C descriptor for the Fortran array A declared as

the first n elements of the subscripts argument would specify if used as subscripts. If the object is scalar, the result is its C address.

23

REAL(C_FLOAT) :: A(100, 100)

24

the following code calculates the C address of A(5, 10): CFI_index_t subscripts[2]; float *address; subscripts[0] = 4; subscripts[1] = 9; address = (float *) CFI_address(dv, subscripts );

25 26 27 28 29

30 31 32 33

34

18.5.5.3

The CFI_allocate function

1 Synopsis. Allocate memory for an object described by a C descriptor.

int CFI_allocate(CFI_cdesc_t *dv, const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[], size_t elem_len); 2 Formal Parameters.

512

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

shall be the address of a C descriptor specifying the rank and type of the object. The base_addr member of the C descriptor shall be a null pointer. If the type is not a character type, the elem_len member shall specify the element length. The attribute member shall have a value of CFI_attribute_allocatable or CFI_attribute_pointer.

1 2 3 4

dv

5

lower_bounds shall be the address of an array with at least dv->rank elements, if dv->rank>0.

6

upper_bounds shall be the address of an array with at least dv->rank elements, if dv->rank>0.

7 8

elem_len

9

3 Description.

If the type specified in the C descriptor type is a Fortran character type, the value of elem_len shall be the storage size in bytes of an element of the object; otherwise, elem_len is ignored.

16

Successful execution of CFI_allocate allocates memory for the object described by the C descriptor with the address dv using the same mechanism as the Fortran ALLOCATE statement, and assigns the address of that memory to dv->base_addr. The first dv->rank elements of the lower_bounds and upper_bounds arguments provide the lower and upper Fortran bounds, respectively, for each corresponding dimension of the object. The supplied lower and upper bounds override any current dimension information in the C descriptor. If the rank is zero, the lower_bounds and upper_bounds arguments are ignored. If the type specified in the C descriptor is a character type, the supplied element length overrides the current element-length information in the descriptor.

17

If an error is detected, the C descriptor is not modified.

10 11 12 13 14 15

18

4 Result Value. The result is an error indicator.

19

5 Example. If dv is the address of a C descriptor for the Fortran array A declared as

REAL, ALLOCATABLE :: A(:, :)

20 21

and the array is not allocated, the following code allocates it to be of shape [100, 500]: CFI_index_t lower[2], upper[2]; int ind; lower[0] = 1; lower[1] = 1; upper[0] = 100; upper[1] = 500; ind = CFI_allocate(dv, lower, upper, 0);

22 23 24 25 26

27 28 29

30 31 32 33 34 35 36 37

18.5.5.4

The CFI_deallocate function

1 Synopsis. Deallocate memory for an object described by a C descriptor.

int CFI_deallocate(CFI_cdesc_t *dv); 2 Formal Parameter. dv shall be the address of a C descriptor describing the object. It shall have been allocated

using the same mechanism as the Fortran ALLOCATE statement. If the object is a pointer, it shall be associated with a target satisfying the conditions for successful deallocation by the Fortran DEALLOCATE statement (9.7.3). 3 Description. Successful execution of CFI_deallocate deallocates memory for the object using the same mech-

anism as the Fortran DEALLOCATE statement, and the base_addr member of the C descriptor becomes a null pointer. If an error is detected, the C descriptor is not modified.

38

4 Result Value. The result is an error indicator.

39

5 Example. If dv is the address of a C descriptor for the Fortran array A declared as

40

REAL, ALLOCATABLE :: A(:, :)

ISO/IEC JTC 1/SC 22/WG5/N2184

513

J3/21-007r1

1

int ind; ind = CFI_deallocate(dv);

3

5 6 7 8

9

2021-05-21

and the array is allocated, the following code deallocates it:

2

4

WD 1539-1

18.5.5.5

The CFI_establish function

1 Synopsis. Establish a C descriptor.

int CFI_establish(CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute, CFI_type_t type, size_t elem_len, CFI_rank_t rank, const CFI_index_t extents[]); 2 Formal Parameters.

10 11 12 13

dv

shall be the address of a data object large enough to hold a C descriptor of the rank specified by rank. It shall not have the same value as either a C formal parameter that corresponds to a Fortran actual argument or a C actual argument that corresponds to a Fortran dummy argument. It shall not be the address of a C descriptor that describes an allocated allocatable object.

14 15

base_addr

shall be a null pointer or the base address of the object to be described. If it is not a null pointer, it shall be the address of a storage sequence that is appropriately aligned (ISO/IEC 9899:2011, 3.2) for an object of the type specified by type.

17 18

attribute

shall be one of the attribute codes in Table 18.3. If it is CFI_attribute_allocatable, base_addr shall be a null pointer.

19 20

type

shall have the value of one of the type codes in Table 18.4, or have a positive value corresponding to an interoperable C type.

21 22 23

elem_len

If type is equal to CFI_type_struct, CFI_type_other, or a Fortran character type code, elem_len shall be greater than zero and equal to the storage size in bytes of an element of the object. Otherwise, elem_len will be ignored.

24

rank

shall have a value in the range 0 ≤ rank ≤ CFI_MAX_RANK. It specifies the rank of the object.

25 26 27

extents

is ignored if rank is equal to zero or if base_addr is a null pointer. Otherwise, it shall be the address of an array with rank elements; the value of each element shall be nonnegative, and extents[i] specifies the extent of dimension i of the object.

16

28

3 Description. Successful execution of CFI_establish updates the object with the address dv to be an established

29 30 31 32 33 34 35 36

C descriptor for a nonallocatable nonpointer data object of known shape, an unallocated allocatable object, or a data pointer. If base_addr is not a null pointer, it is for a nonallocatable entity that is a scalar or a contiguous array; if the attribute argument has the value CFI_attribute_pointer, the lower bounds of the object described by dv are set to zero. If base_addr is a null pointer, the established C descriptor is for an unallocated allocatable, a disassociated pointer, or is a C descriptor that has the attribute CFI_attribute_other but does not describe a data object. If base_addr is the C address of a Fortran data object, the type and elem_len arguments shall be consistent with the type and type parameters of the Fortran data object. The remaining properties of the object are given by the other arguments.

37

If an error is detected, the object with the address dv is not modified.

38

4 Result Value. The result is an error indicator.

NOTE 1 CFI_establish is used to initialize a C descriptor declared in C with CFI_CDESC_T before passing it to any other functions as an actual argument, in order to set the rank, attribute, type and element length.

514

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 A C descriptor with attribute CFI_attribute_other and base_addr a null pointer can be used as the argument result in calls to CFI_section or CFI_select_part, which will produce a C descriptor for a nonallocatable nonpointer data object. 1

5 Examples.

2 3

Case (i):

4 5 6 7 8 9 10

Case (ii):

11 12 13 14 15 16 17 18 19 20 21 22

The following code fragment establishes a C descriptor for an unallocated rank-one allocatable array that can be passed to Fortran for allocation there. CFI_rank_t rank; CFI_CDESC_T(1) field; int ind; rank = 1; ind = CFI_establish((CFI_cdesc_t *)&field, NULL, CFI_attribute_allocatable, CFI_type_double, 0, rank, NULL); Given the Fortran type definition TYPE, BIND(C) :: T REAL(C_DOUBLE) :: X COMPLEX(C_DOUBLE_COMPLEX) :: Y END TYPE and a Fortran subprogram that has an assumed-shape dummy argument of type T, the following code fragment creates a descriptor a_fortran for an array of size 100 that can be used as the actual argument in an invocation of the subprogram from C: typedef struct {double x; double _Complex y;} t; t a_c[100]; CFI_CDESC_T(1) a_fortran; int ind; CFI_index_t extent[1];

23

extent[0] = 100; ind = CFI_establish((CFI_cdesc_t *)&a_fortran, a_c, CFI_attribute_other, CFI_type_struct, sizeof(t), 1, extent);

24 25 26 27 28 29

18.5.5.6

The CFI_is_contiguous function

1 Synopsis. Test contiguity of an array.

int CFI_is_contiguous(const CFI_cdesc_t * dv);

30 31

2 Formal Parameter. dv shall be the address of a C descriptor describing an array. The base_addr member of

32

3 Result Value. The value of the result is 1 if the array described by dv is contiguous, and 0 otherwise.

the C descriptor shall not be a null pointer.

NOTE 1 Assumed-size and allocatable arrays are always contiguous, and therefore the result of CFI_is_contiguous on a C descriptor for such an array will be equal to 1.

ISO/IEC JTC 1/SC 22/WG5/N2184

515

J3/21-007r1

1 2 3 4 5

6

18.5.5.7

WD 1539-1

2021-05-21

The CFI_section function

1 Synopsis. Update a C descriptor for an array section for which each element is an element of a given array.

int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source, const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[], const CFI_index_t strides[]); 2 Formal Parameters.

result

shall be the address of a C descriptor with rank equal to the rank of source minus the number of zero strides. The attribute member shall have the value CFI_attribute_other or CFI_attribute_pointer. If the value of result is the same as either a C formal parameter that corresponds to a Fortran actual argument or a C actual argument that corresponds to a Fortran dummy argument, the attribute member shall have the value CFI_attribute_pointer.

12 13 14

source

shall be the address of a C descriptor that describes a nonallocatable nonpointer array, an allocated allocatable array, or an associated array pointer. The elem_len and type members of source shall have the same values as the corresponding members of result.

15 16 17

lower_bounds shall be a null pointer or the address of an array with at least source->rank elements. If it is not a null pointer, and stridei is zero or (upperi − lower_bounds[i] + stridei )/stridei > 0, the value of lower_bounds[i] shall be within the bounds of dimension i of SOURCE.

18 19 20 21

upper_bounds shall be a null pointer or the address of an array with at least source->rank elements. If source describes an assumed-size array, upper_bounds shall not be a null pointer. If it is not a null pointer and stridei is zero or (upper_bounds[i] − loweri + stridei )/stridei > 0, the value of upper_bounds[i] shall be within the bounds of dimension i of SOURCE.

22

strides

7 8 9 10 11

shall be a null pointer or the address of an array with at least source->rank elements.

23 24 25

3 Description. Successful execution of CFI_section updates the base_addr and dim members of the C descriptor

26 27 28 29 30 31 32

The array section is equivalent to the Fortran array section SOURCE(sectsub1 , sectsub2 , ... sectsubn ), where SOURCE is the array described by source, n is the rank of that array, and sectsubi is the subscript loweri if stridei is zero, and the section subscript loweri : upperi : stridei otherwise. The value of loweri is the lower bound of dimension i of SOURCE if lower_bounds is a null pointer and lower_bounds[i] otherwise. The value of upperi is the upper bound of dimension i of SOURCE if upper_bounds is a null pointer and upper_bounds[i] otherwise. The value of stridei is 1 if strides is a null pointer and strides[i] otherwise. If stridei has the value zero, loweri shall have the same value as upperi .

33

If an error is detected, the C descriptor with the address result is not modified.

with the address result to describe the array section determined by source, lower_bounds, upper_bounds, and strides, as follows.

34

4 Result Value. The result is an error indicator.

35

5 Examples.

36 37 38 39

Case (i):

40 41 42 43 44 45

516

If source is already the address of a C descriptor for the rank-one Fortran array A, the lower bounds of A are equal to 1, and the lower bounds in the C descriptor are equal to 0, the following code fragment establishes a new C descriptor section and updates it to describe the array section A(3::5): CFI_index_t lower[1], strides[1]; CFI_CDESC_T(1) section; int ind; lower[0] = 2; strides[0] = 5; ind = CFI_establish((CFI_cdesc_t *)&section, NULL, CFI_attribute_other,

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5

Case (ii):

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

22

18.5.5.8

WD 1539-1

J3/21-007r1

CFI_type_float, 0, 1, NULL); ind = CFI_section((CFI_cdesc_t *)&section, source, lower, NULL, strides); If source is already the address of a C descriptor for a rank-two Fortran assumed-shape array A with lower bounds equal to 1, the following code fragment establishes a C descriptor and updates it to describe the rank-one array section A(:, 42). CFI_index_t lower[2], upper[2], strides[2]; CFI_CDESC_T(1) section; int ind; lower[0] = source->dim[0].lower_bound; upper[0] = source->dim[0].lower_bound + source->dim[0].extent - 1; strides[0] = 1; lower[1] = upper[1] = source->dim[1].lower_bound + 41; strides[1] = 0; ind = CFI_establish((CFI_cdesc_t *)&section, NULL, CFI_attribute_other, CFI_type_float, 0, 1, NULL); ind = CFI_section((CFI_cdesc_t *)&section, source, lower, upper, strides); The CFI_select_part function

1 Synopsis. Update a C descriptor for an array section for which each element is a part of the corresponding

element of an array. int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source, size_t displacement, size_t elem_len); 2 Formal Parameters.

result

shall be the address of a C descriptor; result->rank shall have the same value as source->rank and result->attribute shall have the value CFI_attribute_other or CFI_attribute_pointer. If the address specified by result is the value of a C formal parameter that corresponds to a Fortran actual argument or of a C actual argument that corresponds to a Fortran dummy argument, result->attribute shall have the value CFI_attribute_pointer. The value of result->type specifies the type of the array section.

29 30

source

shall be the address of a C descriptor for an allocated allocatable array, an associated array pointer, or a nonallocatable nonpointer array that is not assumed-size.

31 32 33

displacement shall have a value 0 ≤ displacement ≤ source->elem_len −1, and the sum of the displacement and the size in bytes of an element of the array section shall be less than or equal to source->elem_len. The address displacement bytes greater than the value of source->base_addr is the base of the array section and shall be appropriately aligned (ISO/IEC 9899:2011, 3.2) for an object of the type of the array section.

23 24 25 26 27 28

34 35 36 37 38 39 40 41 42

elem_len

shall have a value equal to the storage size in bytes of an element of the array section if result->type specifies a Fortran character type; otherwise, elem_len is ignored.

3 Description. Successful execution of CFI_select_part updates the base_addr, dim, and elem_len members of

the C descriptor with the address result for an array section for which each element is a part of the corresponding element of the array described by the C descriptor with the address source. The part shall be a component of a structure, a substring, or the real or imaginary part of a complex value. If an error is detected, the C descriptor with the address result is not modified.

43

4 Result Value. The result is an error indicator.

44

5 Example. If source is already the address of a C descriptor for the Fortran array A declared with

ISO/IEC JTC 1/SC 22/WG5/N2184

517

J3/21-007r1

2 3 4 5

the following code fragment establishes a C descriptor for the array A%Y: typedef struct { double x; double _Complex y; } t; CFI_CDESC_T(1) component; CFI_cdesc_t * comp_cdesc = (CFI_cdesc_t *)&component; CFI_index_t extent[] = { 100 }; (void)CFI_establish(comp_cdesc, NULL, CFI_attribute_other, CFI_type_double_Complex, sizeof(double _Complex), 1, extent); (void)CFI_select_part(comp_cdesc, source, offsetof(t,y), 0);

7 8 9 10 11 12 13 14 15

16 17 18 19 20

21

2021-05-21

TYPE, BIND(C) :: T REAL(C_DOUBLE) :: X COMPLEX(C_DOUBLE_COMPLEX) :: Y END TYPE TYPE(T) A(100)

1

6

WD 1539-1

18.5.5.9

The CFI_setpointer function

1 Synopsis. Update a C descriptor for a Fortran pointer to be associated with the whole of a given object or to

be disassociated. int CFI_setpointer(CFI_cdesc_t *result, CFI_cdesc_t *source, const CFI_index_t lower_bounds[]); 2 Formal Parameters.

22 23

result

shall be the address of a C descriptor for a Fortran pointer. It is updated using information from the source and lower_bounds arguments.

24

source

25 26 27

shall be a null pointer or the address of a C descriptor for an allocated allocatable object, a data pointer object, or a nonallocatable nonpointer data object that is not an assumed-size array. If source is not a null pointer, the corresponding values of the elem_len, rank, and type members shall be the same in the C descriptors with the addresses source and result.

28 29

lower_bounds If source is not a null pointer and source->rank is nonzero, lower_bounds shall be a null pointer or the address of an array with at least source->rank elements.

30 31 32 33 34 35 36 37

38

3 Description.

Successful execution of CFI_setpointer updates the base_addr and dim members of the C descriptor with the address result as follows: • if source is a null pointer or the address of a C descriptor for a disassociated pointer, the updated C descriptor describes a disassociated pointer; • otherwise, the C descriptor with the address result becomes a C descriptor for the object described by the C descriptor with the address source, except that if source->rank is nonzero and lower_bounds is not a null pointer, the lower bounds are replaced by the values of the first source->rank elements of the lower_bounds array.

If an error is detected, the C descriptor with the address result is not modified.

39

4 Result Value. The result is an error indicator.

40 41

5 Example.

If ptr is already the address of a C descriptor for an array pointer of rank 1, the following code updates it to be a C descriptor for a pointer to the same array with lower bound 0.

518

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

J3/21-007r1

CFI_index_t lower_bounds[1]; int ind; lower_bounds[0] = 0; ind = CFI_setpointer(ptr, ptr, lower_bounds);

1 2 3 4

5

WD 1539-1

18.6

Restrictions on C descriptors

6

1 A C descriptor shall not be initialized, updated, or copied other than by calling the functions specified in 18.5.5.

7 8

2 If the address of a C descriptor is a formal parameter that corresponds to a Fortran actual argument or a C

9 10 11 12

actual argument that corresponds to a Fortran dummy argument, • the C descriptor shall not be modified if either the corresponding dummy argument in the Fortran interface has the INTENT (IN) attribute or the C descriptor is for a nonallocatable nonpointer object, and • the base_addr member of the C descriptor shall not be accessed before it is given a value if the corresponding dummy argument in the Fortran interface has the POINTER and INTENT (OUT) attributes. NOTE 1 In this context, modification refers to any change to the location or contents of the C descriptor, including establishment and update. The intent of these restrictions is that C descriptors remain intact at all times they are accessible to an active Fortran procedure, so that the Fortran code is not required to copy them.

13 14

15

3 If the address of a C descriptor is a C actual argument that corresponds to an assumed-shape Fortran dummy

argument, that descriptor shall not be for an assumed-size array.

18.7

Restrictions on formal parameters

16 17 18

1 Within a C function, an allocatable object shall be allocated or deallocated only by execution of the CFI_-

19 20

2 Calling CFI_allocate or CFI_deallocate for a C descriptor changes the allocation status of the Fortran variable

21

3 If the address of an object is the value of a formal parameter that corresponds to a nonpointer dummy argument

22 23 24 25 26

27 28 29

30 31 32 33

allocate and CFI_deallocate functions. A Fortran pointer can become associated with a target by execution of the CFI_allocate function. it describes. in an interface with the BIND attribute, then • if the dummy argument has the INTENT (IN) attribute, the object shall not be defined or become undefined, and • if the dummy argument has the INTENT (OUT) attribute, the object shall not be referenced before it is defined. 4 If a formal parameter that is a pointer to CFI_cdesc_t corresponds to a dummy argument in an interoperable

procedure interface, a pointer based on the base_addr in that C descriptor shall not be used to access memory that is not part of the object described by the C descriptor.

18.8

Restrictions on lifetimes

1 A C descriptor of, or C pointer to, any part of a Fortran object becomes undefined under the same conditions

that the association status of a Fortran pointer associated with that object would become undefined, and any further use of it is undefined behavior (ISO/IEC 9899:2011, 3.4.3).

ISO/IEC JTC 1/SC 22/WG5/N2184

519

J3/21-007r1

WD 1539-1

2021-05-21

1 2 3 4

2 A C descriptor whose address is a formal parameter that corresponds to a Fortran dummy argument becomes

5 6 7 8

3 If the address of a C descriptor is passed as an actual argument to a Fortran procedure, the lifetime (ISO/IEC

9 10

4 If the lifetime of a C descriptor for an allocatable object that was established by C ends before the program exits,

11 12

5 If a Fortran pointer becomes associated with a data object defined by the companion processor, the association

undefined on return from a call to the function from Fortran. If the dummy argument does not have either the TARGET or ASYNCHRONOUS attribute, all C pointers to any part of the object described by the C descriptor become undefined on return from the call, and any further use of them is undefined behavior. 9899:2011, 6.2.4) of the C descriptor shall not end before the return from the procedure call. If an object is passed to a Fortran procedure as a nonallocatable, nonpointer dummy argument, its lifetime shall not end before the return from the procedure call. the object shall be unallocated at that time. status of the Fortran pointer becomes undefined when the lifetime of that data object ends. NOTE 1 The following example illustrates how a C descriptor becomes undefined upon returning from a call to a C function. REAL, TARGET :: X(1000), B INTERFACE REAL FUNCTION CFUN(ARRAY) BIND(C, NAME="Cfun") REAL ARRAY(:) END FUNCTION END INTERFACE B = CFUN(X) Cfun is a C function. Before or during the invocation of Cfun, the processor will create a C descriptor for the array x. On return from Cfun, that C descriptor will become undefined. In addition, because the dummy argument ARRAY does not have the TARGET or ASYNCHRONOUS attribute, a C pointer whose value was set during execution of Cfun to be the address of any part of X will become undefined.

13

18.9

Interoperation with C global variables

14

18.9.1

General

15 16

1 A C variable whose name has external linkage may interoperate with a common block or with a variable declared in

17

2 At most one variable that is associated with a particular C variable whose name has external linkage is permitted

18 19

to be declared within all the Fortran program units of a program. A variable shall not be initially defined by more than one processor.

20 21 22

3 If a common block is specified in a BIND statement, it shall be specified in a BIND statement with the same binding label in each

23 24

• the C variable is of a structure type and the variables that are members of the common block are interoperable with corresponding components of the structure type, or

25

• the common block contains a single variable, and the variable is interoperable with the C variable.

26

4 There does not have to be an associated C entity for a Fortran entity with the BIND attribute.

the scope of a module. The common block or variable shall be specified to have the BIND attribute.

scoping unit in which it is declared. A C variable whose name has external linkage interoperates with a common block that has been specified in a BIND statement if

520

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 1 The following are examples of the usage of the BIND attribute for variables and for a common block. The Fortran variables, C_EXTERN and C2, interoperate with the C variables, c_extern and myVariable, respectively. The Fortran common blocks, COM and SINGLE, interoperate with the C variables, com and single, respectively. MODULE LINK_TO_C_VARS USE, INTRINSIC :: ISO_C_BINDING INTEGER(C_INT), BIND(C) :: C_EXTERN INTEGER(C_LONG) :: C2 BIND(C, NAME=’myVariable’) :: C2 COMMON /COM/ R, S

REAL(C_FLOAT) :: R, S, T BIND(C) :: /COM/, /SINGLE/

COMMON /SINGLE/ T END MODULE LINK_TO_C_VARS /* Global variables. */ int c_extern; long myVariable; struct { float r, s; } com; float single;

1

18.9.2

Binding labels for common blocks and variables

2 3

1 The binding label of a variable or common block is a default character value that specifies the name by which the

4 5 6

2 If a variable or common block has the BIND attribute with the NAME= specifier and the value of its expression,

7 8 9 10 11

variable or common block is known to the companion processor. after discarding leading and trailing blanks, has nonzero length, the variable or common block has this as its binding label. The case of letters in the binding label is significant. If a variable or common block has the BIND attribute specified without a NAME= specifier, the binding label is the same as the name of the entity using lower case letters. Otherwise, the variable or common block has no binding label. 3 The binding label of a C variable whose name has external linkage is the same as the name of the C variable. A

Fortran variable or common block with the BIND attribute that has the same binding label as a C variable whose name has external linkage is linkage associated (19.5.1.5) with that variable.

12

18.10

Interoperation with C functions

13

18.10.1

Definition and reference of interoperable procedures

14

1 A procedure that is interoperable may be defined either by means other than Fortran or by means of a Fortran

15 16

subprogram, but not both. A C function that has an inline definition and no external definition is not considered to be defined in this sense.

17 18 19 20 21

2 If the procedure is defined by means other than Fortran,

• it shall be describable by a C prototype that is interoperable with the interface, and • if it is accessed using its binding label, it shall – have a name that has external linkage as defined by ISO/IEC 9899:2011, 6.2.2, and – have the same binding label as the interface.

ISO/IEC JTC 1/SC 22/WG5/N2184

521

J3/21-007r1

WD 1539-1

2021-05-21

1 2

3 A reference to such a procedure causes the function described by the C prototype to be called as specified in

3 4

4 A reference in C to a procedure that has the BIND attribute, has the same binding label, and is defined by means

5

ISO/IEC 9899:2011. of Fortran, causes the Fortran procedure to be invoked. A C function shall not invoke a function pointer whose value is the result of a reference to C_FUNLOC with a noninteroperable argument.

6 7 8 9

5 A procedure defined by means of Fortran shall not invoke setjmp or longjmp (ISO/IEC 9899:2011, 7.13). If a

10

6 If a procedure defined by means of Fortran and a procedure defined by means other than Fortran perform

11 12 13

14

procedure defined by means other than Fortran invokes setjmp or longjmp, that procedure shall not cause any procedure defined by means of Fortran to be invoked. A procedure defined by means of Fortran shall not be invoked as a signal handler (ISO/IEC 9899:2011, 7.14.1). input/output operations on the same external file, the results are processor dependent (12.5.4). 7 If the value of a C function pointer will be the result of a reference to C_FUNLOC with a noninteroperable

argument, it is recommended that the C function pointer be declared to have the type void (*)().

18.10.2

Binding labels for procedures

15 16

1 The binding label of a procedure is a default character value that specifies the name by which a procedure with

17 18 19 20 21 22

2 If a procedure has the BIND attribute with the NAME= specifier and the value of its expression, after discarding

23 24

C1807 A procedure defined in a submodule shall not have a binding label unless its interface is declared in the ancestor module.

25

the BIND attribute is known to the companion processor. leading and trailing blanks, has nonzero length, the procedure has this as its binding label. The case of letters in the binding label is significant. If a procedure has the BIND attribute with no NAME= specifier, and the procedure is not a dummy procedure, internal procedure, or procedure pointer, then the binding label of the procedure is the same as the name of the procedure using lower case letters. Otherwise, the procedure has no binding label.

3 The binding label for a C function whose name has external linkage is the same as the C function name.

NOTE 1 In the following sample, the binding label of C_SUB is c_sub, and the binding label of C_FUNC is C_funC. SUBROUTINE C_SUB() BIND(C) ... END SUBROUTINE C_SUB INTEGER(C_INT) FUNCTION C_FUNC() BIND(C, NAME="C_funC") USE, INTRINSIC :: ISO_C_BINDING ... END FUNCTION C_FUNC ISO/IEC 9899:2011 permits functions to have names that are not permitted as Fortran names; it also distinguishes between names that would be considered as the same name in Fortran. For example, a C name can begin with an underscore, and C names that differ in case are distinct names. The specification of a binding label allows a program to use a Fortran name to refer to a procedure defined by a companion processor.

522

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

18.10.3

WD 1539-1

J3/21-007r1

Exceptions and IEEE arithmetic procedures

2 3

1 A procedure defined by means other than Fortran shall not use signal (ISO/IEC 9899:2011, 7.14.1) to change the

4 5

2 A procedure defined by means other than Fortran shall not alter the floating-point status (17.7) other than by

6 7

3 The values of the floating-point exception flags on entry to a procedure defined by means other than Fortran are

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

handling of any exception that is being handled by the Fortran processor. setting an exception flag to signaling. processor dependent.

18.10.4

Asynchronous communication

1 Asynchronous communication for a Fortran variable with the ASYNCHRONOUS attribute occurs through the

action of procedures defined by means other than Fortran. It is initiated by execution of an asynchronous communication initiation procedure and completed by execution of an asynchronous communication completion procedure. Between the execution of the initiation and completion procedures, any variable of which any part is associated with any part of the asynchronous communication variable is a pending communication affector. Whether a procedure is an asynchronous communication initiation or completion procedure is processor dependent. 2 Asynchronous communication is either input communication or output communication. For input communication,

a pending communication affector shall not be referenced, become defined, become undefined, become associated with a dummy argument that has the VALUE attribute, or have its pointer association status changed. For output communication, a pending communication affector shall not be redefined, become undefined, or have its pointer association status changed. The restrictions for asynchronous input communication are the same as for asynchronous input data transfer. The restrictions for asynchronous output communication are the same as for asynchronous output data transfer. NOTE 1 Asynchronous communication can be used for nonblocking MPI calls such as MPI_IRECV and MPI_ISEND. For example, REAL :: BUF(100, 100) . . . Code that involves BUF. BLOCK ASYNCHRONOUS :: BUF CALL MPI_IRECV(BUF,. . . REQ, . . . ) . . . Code that does not involve BUF. CALL MPI_WAIT(REQ, . . . ) END BLOCK . . . Code that involves BUF. In this example, there is asynchronous input communication and BUF is a pending communication affector between the two calls. MPI_IRECV can return while the communication (reading values into BUF) is still underway. The intent is that the code between MPI_IRECV and MPI_WAIT can execute without waiting for this communication to complete. Similar code with the call of MPI_IRECV replaced by a call of MPI_ISEND is asynchronous output communication.

ISO/IEC JTC 1/SC 22/WG5/N2184

523

J3/21-007r1

WD 1539-1

1

19 Scope, association, and definition

2

19.1

Scopes, identifiers, and entities

3

1 An entity is identified by an identifier.

4

2 The scope of

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

20 21

22

2021-05-21

• a global identifier is a program (5.2.2), • a local identifier is an inclusive scope, • an identifier of a construct entity is that construct (10.2.4, 11.1), and • an identifier of a statement entity is that statement or part of that statement (6.3), excluding any nested scope where the identifier is treated as the identifier of a different entity (19.3, 19.4), or where an IMPORT statement (8.8) makes the identifier inaccessible. 3 An entity may be identified by

• an image index (3.85), • a name (3.103), • a statement label (3.135), • an external input/output unit number (12.5), • an identifier of a pending data transfer operation (12.6.2.9, 12.7), • a submodule identifier (14.2.3), • a generic identifier (3.79), or • a binding label (3.15). 4 By means of association, an entity may be referred to by the same identifier or a different identifier in a different

scope, or by a different identifier in the same scope.

19.2

Global identifiers

23 24 25 26 27

1 Program units, common blocks, external procedures, entities with binding labels, external input/output units,

28

2 The global identifier of an entity shall not be the same as the global identifier of any other entity. Furthermore, a

29 30 31 32

binding label shall not be the same as the global identifier of any other global entity, ignoring differences in case. A processor may assign a global identifier to an entity that is not specified by this document to have a global identifier (such as an intrinsic procedure); in such a case, the processor shall ensure that this assigned global identifier differs from all other global identifiers in the program.

pending data transfer operations, and images are global entities of a program. The name of a common block with no binding label, external procedure with no binding label, or program unit that is not a submodule is a global identifier. The submodule identifier of a submodule is a global identifier. A binding label of an entity of the program is a global identifier. An entity of the program shall not be identified by more than one binding label.

NOTE 1 An intrinsic module is not a program unit, so a global identifier can be the same as the name of an intrinsic module.

524

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 2 Submodule identifiers are global identifiers, but because they consist of a module name and a descendant submodule name, the name of a submodule can be the same as the name of another submodule so long as they do not have the same ancestor module.

1

19.3

Local identifiers

2

19.3.1

Classes of local identifiers

3 4 5

1 Identifiers of entities, other than statement or construct entities (19.4), in the classes

(1)

6 7 8 9 10 11 12 13 14 15 16 17

18 19 20 21

(2) (3) (4)

named variables, named constants, named procedure pointers, named constructs, statement functions, internal procedures, module procedures, dummy procedures, intrinsic procedures, external procedures that have binding labels, intrinsic modules, abstract interfaces, generic interfaces, derived types, namelist groups, external procedures accessed via USE, and statement labels, type parameters, components, and type-bound procedure bindings, in a separate class for each type, argument keywords, in a separate class for each procedure with an explicit interface, and common blocks that have binding labels

are local identifiers. 2 Within its scope, a local identifier of an entity of class (1) or class (4) shall not be the same as a global identifier

used in that scope unless the global identifier • is used only as the use-name of a rename in a USE statement, • is a common block name (19.3.2), • is an external procedure name that is also a generic name, or • is an external function name and the inclusive scope is its defining subprogram (19.3.3). 3 Within its scope, a local identifier of one class shall not be the same as another local identifier of the same class,

except that a generic name may be the same as the name of a procedure as explained in 15.4.3.4 or the same as the name of a derived type (7.5.10). A local identifier of one class may be the same as a local identifier of another class. NOTE 1 An intrinsic procedure is inaccessible by its own name in a scoping unit that uses the same name as a local identifier of class (1) for a different entity. For example, in the program fragment SUBROUTINE SUB ... A = SIN (K) ... CONTAINS FUNCTION SIN (X) ... END FUNCTION SIN END SUBROUTINE SUB any reference to function SIN in subroutine SUB refers to the internal function SIN, not to the intrinsic function of the same name.

22 23

4 A local identifier identifies an entity in a scope and may be used to identify an entity in another scope except in

the following cases.

ISO/IEC JTC 1/SC 22/WG5/N2184

525

J3/21-007r1

1 2 3 4 5 6 7 8 9

10 11 12 13

14

WD 1539-1

2021-05-21

• The name that appears as a subroutine-name in a subroutine-stmt has limited use within the scope established by the subroutine-stmt. It can be used to identify recursive references of the subroutine or to identify a common block (the latter is possible only for internal and module subroutines). • The name that appears as a function-name in a function-stmt has limited use within the scope established by that function-stmt. It can be used to identify the function result, to identify recursive references of the function, or to identify a common block (the latter is possible only for internal and module functions). • The name that appears as an entry-name in an entry-stmt has limited use within the scope of the subprogram in which the entry-stmt appears. It can be used to identify the function result if the subprogram is a function, to identify recursive references, or to identify a common block (the latter is possible only if the entry-stmt is in a module subprogram).

19.3.2

Local identifiers that are the same as common block names

1 A name that identifies a common block in a scoping unit shall not be used to identify a constant or an intrinsic procedure in that scoping unit. If a local identifier of class (1) is also the name of a common block, the appearance of that name in any context other than as a common block name in a BIND, COMMON, or SAVE statement is an appearance of the local identifier.

19.3.3

Function results

15

1 For each FUNCTION statement or ENTRY statement in a function subprogram, there is a function result. A function

16 17

result is either a variable or a procedure pointer, and thus the name of a function result is a local identifier of class (1).

18

19.3.4

Components, type parameters, and bindings

19

1 A component name has the scope of its derived-type definition. Outside the type definition, it may also appear

20 21

within a designator of a component of a structure of that type or as a component keyword in a structure constructor for that type.

22

2 A type parameter name has the scope of its derived-type definition. Outside the derived-type definition, it may

23 24

also appear as a type parameter keyword in a derived-type-spec for the type or as the type-param-name of a type-param-inquiry.

25

3 The binding name (7.5.5) of a type-bound procedure has the scope of its derived-type definition. Outside of the

26 27 28

derived-type definition, it may also appear as the binding-name in a procedure reference. 4 A generic binding for which the generic-spec is not a generic-name has a scope that consists of all scoping units

in which an entity of the type is accessible.

29

5 A component name or binding name may appear only in a scope in which it is accessible.

30

6 The accessibility of components and bindings is specified in 7.5.4.8 and 7.5.5.

31

19.3.5

Argument keywords

32

1 As an argument keyword, a dummy argument name in an internal procedure, module procedure, or an interface

33

body has a scope of the scoping unit of the host of the procedure or interface body. As an argument keyword, the name of a dummy argument of a procedure declared by a procedure declaration statement that specifies an explicit interface has a scope of the scoping unit containing the procedure declaration statement. It may appear only in a procedure reference for the procedure of which it is a dummy argument. If the procedure is accessible in another scoping unit by use or host association (19.5.1.3, 19.5.1.4), the argument keyword is accessible for procedure references for that procedure in that scoping unit.

34 35 36 37 38

526

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

2 A dummy argument name in an intrinsic procedure has a scope as an argument keyword of the scoping unit

2 3

in which the reference to the procedure occurs. As an argument keyword, it may appear only in a procedure reference for the procedure of which it is a dummy argument.

4

19.4

Statement and construct entities

5

1 A variable that appears as a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor,

6

as a dummy argument in a statement function statement, or as an index-name in a FORALL statement is a statement entity.

7 8

Even if the name of a statement entity is the same as another identifier and the statement is in the scope of that identifier, within the scope of the statement entity the name is interpreted as that of the statement entity.

9

2 The name of a statement entity shall not be the same as an accessible global identifier or local identifier of class

10 11

(1) (19.3.1), except for a common block name or a scalar variable name. Within the scope of a statement entity, another statement entity shall not have the same name.

12

3 A variable that appears as an index-name in a FORALL or DO CONCURRENT construct, as an associate-name

13

in an ASSOCIATE, SELECT RANK, SELECT TYPE construct, or as a coarray-name in a codimension-decl in a CHANGE TEAM construct is a construct entity. A variable that has LOCAL or LOCAL_INIT locality in a DO CONCURRENT construct is a construct entity. An entity that is explicitly declared in the specification part of a BLOCK construct, other than only in ASYNCHRONOUS and VOLATILE statements, is a construct entity. A USE statement in a BLOCK construct explicitly declares the entities accessed by use association to be construct entities.

14 15 16 17 18 19

4 Two construct entities of the same construct shall not have the same identifier.

20

5 The name of a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor has a scope

21

27

of its data-implied-do or ac-implied-do. It is a scalar variable. If integer-type-spec appears in data-implied-do or ac-implied-do-control it has the specified type and type parameters; otherwise it has the type and type parameters that it would have if it were the name of a variable in the innermost executable construct or scoping unit that includes the DATA statement or array constructor, and this type shall be integer type. It has no other attributes. The appearance of a name as a data-i-do-variable of an implied DO in a DATA statement or an ac-do-variable in an array constructor is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement.

28

6 The name of a variable that appears as an index-name in a DO CONCURRENT construct, FORALL statement, or

29

FORALL construct has a scope of the statement or construct. It is a scalar variable. If integer-type-spec appears in

30

35

concurrent-header it has the specified type and type parameters; otherwise it has the type and type parameters that it would have if it were the name of a variable in the innermost executable construct or scoping unit that includes the DO CONCURRENT or FORALL, and this type shall be integer type. It has no other attributes. The appearance of a name as an index-name in a DO CONCURRENT construct, FORALL statement, or FORALL construct is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement or construct.

36

7 A variable that has LOCAL or LOCAL_INIT locality in a DO CONCURRENT construct has the scope of that

22 23 24 25 26

31 32 33 34

37

construct. Its attributes are specified in 11.1.7.5.

38

8 If integer-type-spec does not appear in a concurrent-header, an index-name shall not be the same as an accessible

39

global identifier, local identifier, or identifier of an outer construct entity, except for a common block name or

ISO/IEC JTC 1/SC 22/WG5/N2184

527

J3/21-007r1

WD 1539-1

2021-05-21

3

a scalar variable name. An index-name of a contained DO CONCURRENT construct, FORALL statement, or FORALL construct shall not be the same as an index-name of any of its containing DO CONCURRENT or FORALL constructs.

4

9 The associate names of an ASSOCIATE construct have the scope of the block. They have the declared type,

1 2

5 6 7 8 9

dynamic type, type parameters, rank, and bounds specified in 11.1.3.2. 10 The associate names of a CHANGE TEAM construct have the scope of the block. They have the declared type,

dynamic type, type parameters, rank, corank, bounds, and cobounds specified in 11.1.5. 11 The associate name of a SELECT RANK construct has a separate scope for each block of the construct. It has

the attributes specified in 11.1.10.3.

10

12 The associate name of a SELECT TYPE construct has a separate scope for each block of the construct. Within

11

each block, it has the declared type, dynamic type, type parameters, rank, and bounds specified in 11.1.11.2.

12

13 The name of a variable that appears as a dummy argument in a statement function statement has a scope of the statement in which

13

it appears. It is a scalar that has the type and type parameters that it would have if it were the name of a variable in the scoping

14

unit that includes the statement function; it has no other attributes.

15

19.5

Association

16

19.5.1

Name association

17

19.5.1.1

Forms of name association

18

1 There are five forms of name association: argument association, use association, host association, linkage asso-

19 20

ciation, and construct association. Argument, use, and host association provide mechanisms by which entities known in one scope may be accessed in another scope.

21

19.5.1.2

Argument association

22

1 The rules governing argument association are given in Clause 15. As explained in 15.5, execution of a procedure

23

25

reference establishes a correspondence between each actual argument and a dummy argument and thus an association between each present dummy argument and its effective argument. Argument association can be sequence association (15.5.2.11).

26

2 The name of the dummy argument may be different from the name, if any, of its effective argument. The dummy

27

argument name is the name by which the effective argument is known, and by which it may be accessed, in the referenced procedure.

24

28

NOTE 1 An effective argument can be a nameless data entity, such as the result of evaluating an expression that is not simply a variable or constant. 29

3 Upon termination of execution of a procedure reference, all argument associations established by that reference

30

are terminated. A dummy argument of that procedure can be associated with an entirely different effective argument in a subsequent invocation of the procedure.

31

528

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

19.5.1.3

WD 1539-1

J3/21-007r1

Use association

2

1 Use association is the association of names in different scopes specified by a USE statement. The rules governing

3

5

use association are given in 14.2.2. They allow for renaming of entities being accessed. Use association allows access in one scope to entities defined or declared in another scope; it remains in effect throughout the execution of the program.

6

19.5.1.4

4

Host association

7

1 A derived-type definition, interface body, internal subprogram, module subprogram, or submodule has access

8

14

to entities from its host as specified in 8.8. A host-associated variable is considered to have been previously declared; any other host-associated entity is considered to have been previously defined. In the case of an internal subprogram, the access is to the entities in its host instance. The accessed entities are identified by the same identifier and have the same attributes as in the host, except that a local entity may have the ASYNCHRONOUS attribute even if the host entity does not, and a noncoarray local entity may have the VOLATILE attribute even if the host entity does not. The accessed entities are named data objects, derived types, abstract interfaces, procedures, generic identifiers, and namelist groups.

15

2 If an entity that is accessed by use association has the same nongeneric name as a host entity, the host entity is

16

inaccessible by that name. The name of an external procedure that is given the EXTERNAL attribute (8.5.9) within the scoping unit, or a name that appears within the scoping unit as a module-name in a use-stmt is a global identifier; any entity of the host that has this as its nongeneric name is inaccessible by that name. A name that appears in the scoping unit as

9 10 11 12 13

17 18 19

(1)

a function-name in a stmt-function-stmt or in an entity-decl in a type-declaration-stmt, unless it is a global identifier,

(2)

an object-name in an entity-decl in a type-declaration-stmt, in a pointer-stmt, in a save-stmt, in an allocatable-stmt, or in a target-stmt,

24

(3)

a type-param-name in a derived-type-stmt,

25

(4)

a named-constant in a named-constant-def in a parameter-stmt,

26

(5)

a coarray-name in a codimension-stmt,

27

(6)

an array-name in a dimension-stmt,

28

(7)

a variable-name in a common-block-object in a common-stmt,

29

(8)

a procedure pointer given the EXTERNAL attribute in the scoping unit,

30

(9)

the name of a variable that is wholly or partially initialized in a data-stmt,

31

(10) the name of an object that is wholly or partially equivalenced in an equivalence-stmt,

32

(11) a dummy-arg-name in a function-stmt, in a subroutine-stmt, in an entry-stmt, or in a stmt-function-stmt ,

33

(12) a result-name in a function-stmt or in an entry-stmt ,

34

(13) the name of an entity declared by an interface body, unless it is a global identifier,

35

(14) an intrinsic-procedure-name in an intrinsic-stmt,

36

(15) a namelist-group-name in a namelist-stmt,

37

(16) an enum-type-name in an enum-def ,

38

(17) an enumeration-type-name in an enumeration-type-stmt,

39

(18) a generic-name in a generic-spec in an interface-stmt, or

20 21 22 23

40 41

(19) the name of a named construct is a local identifier in the scoping unit and any entity of the host that has this as its nongeneric name is inaccessible

ISO/IEC JTC 1/SC 22/WG5/N2184

529

J3/21-007r1

1 2 3 4

WD 1539-1

2021-05-21

by that name by host association. If a scoping unit is the host of a derived-type definition or a subprogram that does not define a separate module procedure, the name of the derived type or of any procedure defined by the subprogram is a local identifier in the scoping unit; any entity of the host that has this as its nongeneric name is inaccessible by that name. Local identifiers of a subprogram are not accessible to its host. NOTE 1 A name that appears in an ASYNCHRONOUS or VOLATILE statement is not necessarily the name of a local variable. In an internal or module procedure, if a variable that is accessible via host association is specified in an ASYNCHRONOUS or VOLATILE statement, that host variable is given the ASYNCHRONOUS or VOLATILE attribute in the local scope.

5 6 7 8

3 If a host entity is inaccessible only because a local variable with the same name is wholly or partially initialized

in a DATA statement, the local variable shall not be referenced or defined prior to the DATA statement. 4 If a derived-type name of a host is inaccessible, data entities of that type or subobjects of such data entities still

can be accessible. NOTE 2 An interface body that is not a module procedure interface body accesses by host association only those entities made accessible by IMPORT statements.

9

5 If an external or dummy procedure with an implicit interface is accessed via host association, then it shall have

10

14

the EXTERNAL attribute in the host scoping unit; if it is invoked as a function in the inner scoping unit, its type and type parameters shall be established in the host scoping unit. The type and type parameters of a function with the EXTERNAL attribute are established in a scoping unit if that scoping unit explicitly declares them, invokes the function, accesses the function from a module, or accesses the function from its host where its type and type parameters are established.

15

6 If an intrinsic procedure is accessed via host association, then it shall be established to be intrinsic in the host

16

scoping unit. An intrinsic procedure is established to be intrinsic in a scoping unit if that scoping unit explicitly gives it the INTRINSIC attribute, invokes it as an intrinsic procedure, accesses it from a module, or accesses it from its host where it is established to be intrinsic.

11 12 13

17 18

NOTE 3 A host subprogram and an internal subprogram can contain the same and differing use-associated entities, as illustrated in the following example. MODULE B; REAL BX, Q; INTEGER IX, JX; END MODULE B MODULE C; REAL CX; END MODULE C MODULE D; REAL DX, DY, DZ; END MODULE D MODULE E; REAL EX, EY, EZ; END MODULE E MODULE F; REAL FX; END MODULE F MODULE G; USE F; REAL GX; END MODULE G PROGRAM A USE B; USE C; USE D ... CONTAINS SUBROUTINE INNER_PROC (Q) USE C ! Not needed, but prevents CX from being declared locally.

530

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NOTE 3 (cont.) USE B, ONLY: BX

USE D, X => DX

USE E, ONLY: EX

! Entities accessible are BX, and also IX and JX if ! no other IX or JX is accessible to INNER_PROC. ! Q is local to INNER_PROC, because it is a dummy argument. ! Entities accessible are DX, DY, and DZ ! X is local name for DX in INNER_PROC; if no other DX is ! accessible in INNER_PROC, X and DX denote the same entity ! EX is accessible in INNER_PROC, not in program A. ! EY and EZ are not accessible in INNER_PROC or program A. ! FX and GX are accessible in INNER_PROC.

USE G ... END SUBROUTINE INNER_PROC END PROGRAM A

Because program A contains the statement USE B all of the entities in module B, except for Q, are accessible in INNER_PROC, even though INNER_PROC contains the statement USE B, ONLY: BX The USE statement with the ONLY option means that this particular statement brings in only the entity named, not that this is the only variable from the module accessible in this scoping unit. NOTE 4 For more examples of host association, see C.14.2. 1

19.5.1.5

Linkage association

2

1 Linkage association occurs between a module variable that has the BIND attribute and the C variable with which

3 4

it interoperates, or between a Fortran common block and the C variable with which it interoperates (18.9). Such association remains in effect throughout the execution of the program.

5

19.5.1.6

Construct association

6

1 Execution of a SELECT RANK or SELECT TYPE statement establishes an association between the selector and

7

the associate name of the construct. Execution of an ASSOCIATE or CHANGE TEAM statement statement establishes an association between each selector and the corresponding associate name of the construct.

8 9 10 11

2 In an ASSOCIATE or SELECT TYPE construct, the following rules apply.

• If a selector is allocatable, it shall be allocated; the associate name is associated with the data object and does not have the ALLOCATABLE attribute.

13

• If a selector has the POINTER attribute, it shall be associated; the associate name is associated with the target of the pointer and does not have the POINTER attribute.

14

3 If the selector is a variable other than an array section having a vector subscript, the association is with the data

15

object specified by the selector; otherwise, the association is with the value of the selector expression, which is evaluated prior to execution of the block.

12

16

ISO/IEC JTC 1/SC 22/WG5/N2184

531

J3/21-007r1

WD 1539-1

2021-05-21

1

4 Each associate name remains associated with the corresponding selector throughout the execution of the executed

2

block. Within the block, each selector is known by and may be accessed by the corresponding associate name. On completion of execution of the construct, the association is terminated.

3

NOTE 1 The association between the associate name and a data object is established prior to execution of the block and is not affected by subsequent changes to variables that were used in subscripts or substring ranges in the selector.

4

19.5.2

Pointer association

5

19.5.2.1

General

6

1 Pointer association between a pointer and a target allows the target to be referenced by a reference to the pointer.

7

10

At different times during the execution of a program, a pointer may be undefined, associated with different targets on its own image, or be disassociated. The definition status of an associated data pointer is that of its target. If the pointer has deferred type parameters or shape, their values are assumed from the target. If the pointer is polymorphic, its dynamic type is assumed from the dynamic type of the target.

11

19.5.2.2

8 9

Pointer association status

12

1 A pointer has a pointer association status of associated, disassociated, or undefined. Its association status may

13

change during execution of a program. Unless a pointer is initialized (explicitly or by default), it has an initial association status of undefined. A pointer may be initialized to have an association status of disassociated or associated.

14 15

NOTE 1 A pointer from a module program unit might be accessible in a subprogram via use association. Such pointers have a lifetime that is greater than targets that are declared in the subprogram, unless such targets are saved. Therefore, if such a pointer is associated with a local target, there is the possibility that when a procedure defined by the subprogram completes execution, the target will cease to exist, leaving the pointer “dangling”. This document considers such pointers to have an undefined association status. They are neither associated nor disassociated. They cannot be used again in the program until their status has been reestablished. A processor is not required to detect when a pointer target ceases to exist. 16 17

19.5.2.3

Events that cause pointers to become associated

1 A pointer becomes associated when any of the following events occur.

(1)

The pointer is allocated (9.7.1) as the result of the successful execution of an ALLOCATE statement referencing the pointer.

(2)

The pointer is pointer-assigned to a target (10.2.2) that is associated or is specified with the TARGET attribute and, if allocatable, is allocated.

(3)

The pointer is a subobject of an object that is allocated by an ALLOCATE statement in which SOURCE= appears and the corresponding subobject of source-expr is associated.

24

(4)

The pointer is a dummy argument and its corresponding actual argument is not a pointer.

25

(5)

The pointer is a default-initialized subcomponent of an object, the corresponding initializer is not a reference to the intrinsic function NULL, and

18 19 20 21 22 23

26

532

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

(a)

a procedure is invoked with this object as an actual argument corresponding to a nonpointer nonallocatable dummy argument with INTENT (OUT),

3

(b)

a procedure with this object as an unsaved nonpointer nonallocatable local variable is invoked,

4

(c)

a BLOCK construct is entered and this object is an unsaved local nonpointer nonallocatable local variable of the BLOCK construct, or

(d)

this object is allocated other than by an ALLOCATE statement in which SOURCE= appears.

1 2

5 6

7 8

19.5.2.4

Events that cause pointers to become disassociated

1 A pointer becomes disassociated when

9

(1)

the pointer is nullified (9.7.2),

10

(2)

the pointer is deallocated (9.7.3),

11

(3)

the pointer is pointer-assigned (10.2.2) to a disassociated pointer,

12

(4)

the pointer is a subobject of an object that is allocated by an ALLOCATE statement in which SOURCE= appears and the corresponding subobject of source-expr is disassociated, or

(5)

15

the pointer is a default-initialized subcomponent of an object, the corresponding initializer is a reference to the intrinsic function NULL, and

16

(a)

a procedure is invoked with this object as an actual argument corresponding to a nonpointer nonallocatable dummy argument with INTENT (OUT),

18

(b)

a procedure with this object as an unsaved nonpointer nonallocatable local variable is invoked,

19

(c)

a BLOCK construct is entered and this object is an unsaved local nonpointer nonallocatable local variable of the BLOCK construct, or

(d)

this object is allocated other than by an ALLOCATE statement in which SOURCE= appears.

13 14

17

20 21

22 23

19.5.2.5

Events that cause the association status of pointers to become undefined

1 The association status of a pointer becomes undefined when

24

(1)

the pointer is pointer-assigned to a target that has an undefined association status,

25

(2)

the pointer is pointer-assigned to a target on a different image,

26

(3)

the target of the pointer is deallocated other than through the pointer,

27

(4)

the target of the pointer is a data object defined by the companion processor and the lifetime of that data object ends,

(5)

the allocation transfer procedure (16.9.147) is executed, the pointer is associated with the argument FROM, and the argument TO does not have the TARGET attribute,

(6)

completion of execution of an instance of a subprogram causes the pointer’s target to become undefined (item (3) of 19.6.6),

(7)

completion of execution of a BLOCK construct causes the pointer’s target to become undefined (item (23) of 19.6.6),

35

(8)

execution of the host instance of a procedure pointer is completed,

36

(9)

37

execution of an instance of a subprogram completes and the pointer is declared or accessed in the subprogram that defines the procedure if the pointer

38

(a)

does not have the SAVE attribute,

39

(b)

is not in blank common,

28 29 30 31 32 33 34

ISO/IEC JTC 1/SC 22/WG5/N2184

533

J3/21-007r1

WD 1539-1

2021-05-21

1

(c)

is not in a named common block that is declared in any other scoping unit that is in execution,

2

(d)

is not accessed by host association, and

3

(e)

is not the result of a function declared to have the POINTER attribute,

(10) execution of an instance of a subprogram completes, the pointer is associated with a dummy argument of the procedure, and

4 5 6

(a)

the effective argument does not have the TARGET attribute or is an array section with a vector subscript, or

(b)

the dummy argument has the VALUE attribute,

7 8

(11) a BLOCK construct completes execution and the pointer is an unsaved construct entity of that BLOCK construct,

9 10

(12) a DO CONCURRENT construct is terminated and the pointer’s association status was changed in more than one iteration of the construct,

11 12

14

(13) an iteration of a DO CONCURRENT construct completes and the pointer is associated with a variable of that construct that has LOCAL or LOCAL_INIT locality,

15

(14) the pointer is a subcomponent of an object that is allocated and either

13

16

(a)

the pointer is not default-initialized and SOURCE= does not appear, or

17

(b)

SOURCE= appears and the association status of the corresponding subcomponent of sourceexpr is undefined,

18

(15) the pointer is a subcomponent of an object, the pointer is not default-initialized, and a procedure is invoked with this object as an actual argument corresponding to a dummy argument with INTENT (OUT),

19 20 21

(16) a procedure is invoked with the pointer as an actual argument corresponding to a pointer dummy argument with INTENT (OUT), or

22 23

(17) evaluation of an expression containing a function reference that need not be evaluated completes, if execution of that function would change the association status of the pointer.

24 25 26 27 28 29 30 31

19.5.2.6

Other events that change the association status of pointers

1 When a pointer becomes associated with another pointer by argument association, construct association, or host

association, the effects on its association status are specified in 19.5.5. 2 While two pointers are name associated, storage associated, or inheritance associated, if the association status of

one pointer changes, the association status of the other changes accordingly. 3 The association status of a pointer object with the VOLATILE attribute might change by means not specified

32

by the program.

33

19.5.2.7

Pointer definition status

34

1 The definition status of an associated data pointer is that of its target. If a pointer is associated with a definable

35

target, it becomes defined or undefined according to the rules for a variable (19.6). The definition status of a pointer that is not associated is undefined.

36

534

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

19.5.3

Storage association

2

19.5.3.1

General

J3/21-007r1

3

1 Storage sequences are used to describe relationships that exist among variables and common blocks. Storage asso-

4 5

ciation is the association of two or more data objects that occurs when two or more storage sequences share or are aligned with one or more storage units.

6

19.5.3.2

Storage sequence

7

1 A storage sequence is a sequence of storage units. The size of a storage sequence is the number of storage units

8

in the storage sequence. A storage unit is a character storage unit, a numeric storage unit, a file storage unit (12.3.5), or an unspecified storage unit. The sizes of the numeric storage unit, the character storage unit and the file storage unit are the values of constants in the ISO_FORTRAN_ENV intrinsic module (16.10.2).

9 10 11

2 In a storage association context

(1)

a nonpointer scalar object that is default integer, default real, or default logical occupies a single numeric storage unit,

(2)

a nonpointer scalar object that is double precision real or default complex occupies two contiguous numeric storage units,

(3)

a default character nonpointer scalar object of character length len occupies len contiguous character storage units,

(4)

if C character kind is not the same as default character kind a nonpointer scalar object of type character with the C character kind (18.2.2) and character length len occupies len contiguous unspecified storage units,

(5)

a nonpointer scalar object of sequence type occupies a sequence of storage sequences corresponding to the sequence of its ultimate components,

(6)

a nonpointer scalar object of any type not specified in items (1)-(5) occupies a single unspecified storage unit that is different for each case and each set of type parameter values, and that is different from the unspecified storage units of item (4),

(7)

a nonpointer array occupies a sequence of contiguous storage sequences, one for each array element, in array element order (9.5.3.3), and

(8)

31

a data pointer occupies a single unspecified storage unit that is different from that of any nonpointer object and is different for each combination of type, type parameters, and rank. A data pointer that has the CONTIGUOUS attribute occupies a storage unit that is different from that of a data pointer that does not have the CONTIGUOUS attribute.

32

3 A sequence of storage sequences forms a storage sequence. The order of the storage units in such a composite

33

storage sequence is that of the individual storage units in each of the constituent storage sequences taken in succession, ignoring any zero-sized constituent sequences.

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

34 35 36

4 Each common block has a storage sequence (8.10.2.2).

19.5.3.3

Association of storage sequences

37

1 Two nonzero-sized storage sequences s1 and s2 are storage associated if the ith storage unit of s1 is the same as

38

the jth storage unit of s2 . This causes the (i + k)th storage unit of s1 to be the same as the (j + k)th storage

ISO/IEC JTC 1/SC 22/WG5/N2184

535

J3/21-007r1

WD 1539-1

2021-05-21

2

unit of s2 , for each integer k such that 1 ≤ i + k ≤ size of s1 and 1 ≤ j + k ≤ size of s2 where size of measures the number of storage units.

3

2 Storage association also is defined between two zero-sized storage sequences, and between a zero-sized storage

4

8

sequence and a storage unit. A zero-sized storage sequence in a sequence of storage sequences is storage associated with its successor, if any. If the successor is another zero-sized storage sequence, the two sequences are storage associated. If the successor is a nonzero-sized storage sequence, the zero-sized sequence is storage associated with the first storage unit of the successor. Two storage units that are each storage associated with the same zero-sized storage sequence are the same storage unit.

9

19.5.3.4

1

5 6 7

Association of scalar data objects

10

1 Two scalar data objects are storage associated if their storage sequences are storage associated. Two scalar entities

11 12

are totally associated if they have the same storage sequence. Two scalar entities are partially associated if they are associated without being totally associated.

13

2 The definition status and value of a data object affects the definition status and value of any storage associated

14

entity. An EQUIVALENCE statement, a COMMON statement, or an ENTRY statement can cause storage association of storage

15

sequences.

16 17

3 An EQUIVALENCE statement causes storage association of data objects only within one scoping unit, unless one of the equivalenced entities is also in a common block (8.10.1.2, 8.10.2.2).

18

4 COMMON statements cause data objects in one scoping unit to become storage associated with data objects in another scoping unit.

19

5 A common block is permitted to contain a sequence of differing storage units. All scoping units that access named common blocks

20

with the same name shall specify an identical sequence of storage units. Blank common blocks may be declared with differing sizes

21

in different scoping units. For any two blank common blocks, the initial sequence of storage units of the longer blank common block

22

shall be identical to the sequence of storage units of the shorter common block. If two blank common blocks are the same length,

23

they shall have the same sequence of storage units.

24

6 An ENTRY statement in a function subprogram causes storage association of the function results that are variables.

25

7 Partial association shall exist only between

26 27

• an object that is default character or of character sequence type and an object that is default character or of character sequence type, or

30

• an object that is default complex, double precision real, or of numeric sequence type and an object that is default integer, default real, default logical, double precision real, default complex, or of numeric sequence type.

31

8 For noncharacter entities, partial association shall occur only through the use of COMMON, EQUIVALENCE, or ENTRY statements.

32 33

For character entities, partial association shall occur only through argument association or the use of COMMON or EQUIVALENCE statements.

34

9 Partial association of character entities occurs when some, but not all, of the storage units of the entities are the

28 29

35

same.

36

10 A storage unit shall not be explicitly initialized more than once in a program. Explicit initialization overrides

37

default initialization, and default initialization for an object of derived type overrides default initialization for a component of the object (7.5.4.6). Default initialization may be specified for a storage unit that is storage

38

536

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

2

associated provided the objects supplying the default initialization are of the same type and type parameters, and supply the same value for the storage unit.

3

19.5.4

1

Inheritance association

4

1 Inheritance association occurs between components of the parent component and components inherited by type

5 6

extension into an extended type (7.5.7.2). This association is persistent; it is not affected by the accessibility of the inherited components.

7

19.5.5

8 9 10 11

Establishing associations

1 When an association is established between two entities by argument association, host association, or construct

association, certain properties of the associating entity become those of the pre-existing entity. 2 For argument association, the pre-existing entity is the effective argument and the associating entity is the dummy

argument.

12

3 For host association, the associating entity is the entity in the contained scoping unit. When a procedure is

13 14

invoked, the pre-existing entity that participates in the association is the one from its host instance (15.6.2.4). Otherwise the pre-existing entity that participates in the association is the entity in the host scoping unit.

15

4 For construct association, the associating entity is identified by the associate name and the pre-existing entity is

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

the selector. 5 When an association is established by argument association, host association, or construct association, the fol-

lowing applies. • If the entities have the POINTER attribute, the pointer association status of the associating entity becomes the same as that of the pre-existing entity. If the pre-existing entity has a pointer association status of associated, the associating entity becomes pointer associated with the same target and, if they are arrays, the bounds of the associating entity become the same as those of the pre-existing entity. • If the associating entity has the ALLOCATABLE attribute, its allocation status becomes the same as that of the pre-existing entity. If the pre-existing entity is allocated, the bounds (if it is an array), values of deferred type parameters, definition status, and value (if it is defined) become the same as those of the pre-existing entity. If the associating entity is polymorphic and the pre-existing entity is allocated, the dynamic type of the associating entity becomes the same as that of the pre-existing entity. • If the associating entity is neither a pointer nor allocatable, its definition status, value (if it is defined), and dynamic type (if it is polymorphic) become the same as those of the pre-existing entity. If the entities are arrays and the association is not argument association, the bounds of the associating entity become the same as those of the pre-existing entity. • If the associating entity is a pointer dummy argument and the pre-existing entity is a nonpointer actual argument the associating entity becomes pointer associated with the pre-existing entity and, if the entities are arrays, the bounds of the associating entity become the same as those of the pre-existing entity.

ISO/IEC JTC 1/SC 22/WG5/N2184

537

J3/21-007r1

WD 1539-1

1

19.6

Definition and undefinition of variables

2

19.6.1

Definition of objects and subobjects

2021-05-21

3

1 A variable may be defined or may be undefined and its definition status may change during execution of a

4

6

program. An action that causes a variable to become undefined does not imply that the variable was previously defined. An action that causes a variable to become defined does not imply that the variable was previously undefined.

7

2 Arrays, including sections, and variables of derived, character, or complex type are objects that consist of zero

8

or more subobjects. Associations may be established between variables and subobjects and between subobjects of different variables. These subobjects may become defined or undefined.

5

9 10

3 An array is defined if and only if all of its elements are defined.

11

4 A derived-type scalar object is defined if and only if all of its nonpointer components are defined.

12

5 A complex or character scalar object is defined if and only if all of its subobjects are defined.

13

6 If an object is undefined, at least one (but not necessarily all) of its subobjects are undefined.

14 15

16 17

19.6.2

Variables that are always defined

1 Zero-sized arrays and zero-length strings are always defined.

19.6.3

Variables that are initially defined

1 The following variables are initially defined:

18

(1)

variables specified to have initial values by DATA statements;

19

(2)

variables specified to have initial values by type declaration statements;

20

(3)

nonpointer default-initialized subcomponents of saved variables that do not have the ALLOCATABLE or POINTER attribute;

22

(4)

pointers specified to be initially associated with a variable that is initially defined;

23

(5)

variables that are always defined;

24

(6)

variables with the BIND attribute that are initialized by means other than Fortran.

21

NOTE 1 Fortran code: module mod integer, bind(c,name="blivet") :: foo end module mod C code: int blivet = 123; In the above example, the Fortran variable foo is initially defined to have the value 123 by means other than Fortran.

538

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

3 4

19.6.4

WD 1539-1

J3/21-007r1

Variables that are initially undefined

1 Variables that are not initially defined are initially undefined.

19.6.5

Events that cause variables to become defined

1 Variables become defined by the following events.

(1)

Execution of an intrinsic assignment statement other than a masked array assignment or FORALL assignment statement causes the variable that precedes the equals to become defined.

(2)

Execution of a masked array assignment or FORALL assignment statement might cause some or all of the array elements in the assignment statement to become defined (10.2.3).

(3)

As execution of an input statement proceeds, each variable that is assigned a value from the input file becomes defined at the time that data are transferred to it. (See (4) in 19.6.6.) Execution of a WRITE statement whose unit specifier identifies an internal file causes each record that is written to become defined.

13

(4)

Execution of a DO statement causes the DO variable, if any, to become defined.

14

(5)

Beginning of execution of the action specified by an io-implied-do in a synchronous data transfer statement causes the do-variable to become defined.

(6)

A reference to a procedure causes an entire dummy data object to become defined if the dummy data object does not have INTENT (OUT) and the entire effective argument is defined.

5 6 7 8 9 10 11 12

15 16 17

A reference to a procedure causes a subobject of a dummy argument to become defined if the dummy argument does not have INTENT (OUT) and the corresponding subobject of the effective argument is defined.

18 19 20 21

(7)

Execution of an input/output statement containing an IOSTAT= specifier causes the specified integer variable to become defined.

(8)

Execution of a synchronous input statement containing a SIZE= specifier causes the specified integer variable to become defined.

(9)

Execution of a wait operation (12.7.1) corresponding to an asynchronous input statement containing a SIZE= specifier causes the specified integer variable to become defined.

22 23 24 25 26 27 28

(10) Execution of an INQUIRE statement causes any variable that is assigned a value during the execution of the statement to become defined if no error condition exists.

30

(11) If an error, end-of-file, or end-of-record condition occurs during execution of an input/output statement that has an IOMSG= specifier, the iomsg-variable becomes defined.

31

(12) When a character storage unit becomes defined, all associated character storage units become defined.

32

When a numeric storage unit becomes defined, all associated numeric storage units of the same type become defined. When an entity of double precision real type becomes defined, all totally associated entities of double precision real type become defined.

29

33 34 35 36 37 38

When an unspecified storage unit becomes defined, all associated unspecified storage units become defined. (13) When a default complex entity becomes defined, all partially associated default real entities become defined.

40

(14) When both parts of a default complex entity become defined as a result of partially associated default real or default complex entities becoming defined, the default complex entity becomes defined.

41

(15) When all components of a structure of a numeric sequence type or character sequence type become

39

ISO/IEC JTC 1/SC 22/WG5/N2184

539

J3/21-007r1

WD 1539-1

2021-05-21

1

defined as a result of partially associated objects becoming defined, the structure becomes defined.

2

(16) Execution of a statement with a STAT= specifier causes the variable specified by the STAT= specifier to become defined.

3

(17) If an error condition occurs during execution of a statement that has an ERRMSG= specifier, the variable specified by the ERRMSG= specifier becomes defined.

4 5

(18) Allocation of a zero-sized array or zero-length character variable causes the array or variable to become defined.

6 7

(19) Allocation of an object that has a nonpointer default-initialized subcomponent, except by an ALLOCATE statement with a SOURCE= specifier, causes that subcomponent to become defined.

8 9

(20) Successful execution of an ALLOCATE statement with a SOURCE= specifier causes a subobject of the allocated object to become defined if the corresponding subobject of the SOURCE= expression is defined.

10 11 12

14

(21) Invocation of a procedure causes any automatic data object of zero size or zero character length in that procedure to become defined.

15

(22) When a pointer becomes associated with a target that is defined, the pointer becomes defined.

16

(23) Invocation of a procedure that contains an unsaved nonpointer nonallocatable local variable causes all nonpointer default-initialized subcomponents of the object to become defined.

13

17

(24) Invocation of a procedure that has a nonpointer nonallocatable INTENT (OUT) dummy argument causes all nonpointer default-initialized subcomponents of the dummy argument to become defined.

18 19

(25) In a DO CONCURRENT or FORALL construct, the index-name becomes defined when the indexname value set is evaluated.

20 21

(26) In a DO CONCURRENT construct, a variable with LOCAL_INIT locality becomes defined at the beginning of each iteration.

22 23

(27) An object with the VOLATILE attribute that is changed by a means not specified by the program might become defined (see 8.5.20).

24 25

(28) Execution of the BLOCK statement of a BLOCK construct that has an unsaved nonpointer nonallocatable local variable causes all nonpointer default-initialized subcomponents of the variable to become defined.

26 27 28

(29) Execution of an OPEN statement containing a NEWUNIT= specifier causes the specified integer variable to become defined.

29 30

(30) Execution of a LOCK statement containing an ACQUIRED_LOCK= specifier causes the specified logical variable to become defined. If the logical variable becomes defined with the value true, the lock variable in the LOCK statement also becomes defined.

31 32 33

35

(31) Successful execution of a LOCK statement that does not contain an ACQUIRED_LOCK= specifier causes the lock variable to become defined.

36

(32) Successful execution of an UNLOCK statement causes the lock variable to become defined.

37

(33) Failure of an image that locked a lock variable without unlocking it causes the lock variable to become defined.

34

38

40

(34) Successful execution of an EVENT POST or EVENT WAIT statement causes the event variable to become defined.

41

(35) Successful execution of a FORM TEAM statement causes the team variable to become defined.

42

(36) Execution of a FORM TEAM statement with a STAT= specifier that assigns the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV to its stat-variable causes the

39

43

540

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

3

4 5 6

(37) Execution of a NOTIFY WAIT statement or an assignment statement with a NOTIFY= specifier causes the notify variable to become defined.

19.6.6

(1)

When a scalar variable of intrinsic type becomess defined, all totally associated variables of different type become undefined.

When a double precision scalar variable becomes defined, all partially associated scalar variables become undefined. When a scalar variable becomes undefined, all partially associated double precision scalar variables become undefined.

8 9

(2)

If the evaluation of a function would cause a variable to become defined and if a reference to the function appears in an expression in which the value of the function is not needed to determine the value of the expression, the variable becomes undefined when the expression is evaluated.

(3)

When execution of an instance of a subprogram completes,

11 12 13

Events that cause variables to become undefined

1 Variables become undefined by the following events.

7

10

J3/21-007r1

team variable to become defined.

1 2

WD 1539-1

14

(a)

its unsaved local variables become undefined,

15

(b)

unsaved variables in a named common block that appears in the subprogram become undefined if they have been defined or redefined, unless another active scoping unit is referencing the common block, and

16

(c)

17 18 19

(4)

When an error condition or end-of-file condition occurs during execution of an input statement, all of the variables specified by the input list or namelist group of the statement become undefined.

(5)

When an error condition occurs during execution of an output statement in which the unit is an internal file, the internal file becomes undefined.

(6)

When an error condition, end-of-file condition, or end-of-record condition occurs during execution of an input/output statement and the statement contains any io-implied-dos, all of the do-variables in the statement become undefined (12.11).

(7)

Execution of a direct access input statement that specifies a record that has not been written previously causes all of the variables specified by the input list of the statement to become undefined.

(8)

Execution of an INQUIRE statement might cause the NAME=, RECL=, and NEXTREC= variables to become undefined (12.10).

(9)

When a character storage unit becomes undefined, all associated character storage units become undefined.

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

a variable of type C_PTR from the intrinsic module ISO_C_BINDING whose value is the C address of an unsaved local variable of the subprogram becomes undefined.

When a numeric storage unit becomes undefined, all associated numeric storage units become undefined unless the undefinition is a result of defining an associated numeric storage unit of different type (see (1) above). When an entity of double precision real type becomes undefined, all totally associated entities of double precision real type become undefined. When an unspecified storage unit becomes undefined, all associated unspecified storage units become undefined.

39

(10) When an allocatable entity is deallocated, it becomes undefined.

40

(11) When the allocation transfer procedure (16.9.147) causes the allocation status of an allocatable entity to become unallocated, the entity becomes undefined.

41

ISO/IEC JTC 1/SC 22/WG5/N2184

541

J3/21-007r1

WD 1539-1

2021-05-21

(12) Successful execution of an ALLOCATE statement with no SOURCE= specifier causes a subcomponent of an allocated object to become undefined if default initialization has not been specified for that subcomponent.

1 2 3

(13) Successful execution of an ALLOCATE statement with a SOURCE= specifier causes a subobject of the allocated object to become undefined if the corresponding subobject of the SOURCE= expression is undefined.

4 5 6

8

(14) Execution of an INQUIRE statement causes all inquiry specifier variables to become undefined if an error condition exists, except for any variable in an IOSTAT= or IOMSG= specifier.

9

(15) When a procedure is invoked

7

10

(a)

an optional dummy argument that has no corresponding actual argument becomes undefined,

11

(b)

a dummy argument with INTENT (OUT) becomes undefined except for any nonpointer defaultinitialized subcomponents of the argument,

(c)

an actual argument corresponding to a dummy argument with INTENT (OUT) becomes undefined except for any nonpointer default-initialized subcomponents of the argument,

(d)

a subobject of a dummy argument that does not have INTENT (OUT) becomes undefined if the corresponding subobject of the effective argument is undefined, and

(e)

a variable that is the function result of that procedure becomes undefined except for any of its nonpointer default-initialized subcomponents.

12 13 14 15 16 17 18

(16) When the association status of a pointer becomes undefined or disassociated (19.5.2.4, 19.5.2.5), the pointer becomes undefined.

19 20

(17) When a DO CONCURRENT construct terminates, a variable that is defined or becomes undefined during more than one iteration of the construct becomes undefined.

21 22

(18) When execution of an iteration of a DO CONCURRENT construct completes, a construct entity of that construct which has LOCAL or LOCAL_INIT locality becomes undefined.

23 24

(19) Execution of an asynchronous READ statement causes all of the variables specified by the input list or SIZE= specifier to become undefined. Execution of an asynchronous namelist READ statement causes any variable in the namelist group to become undefined if that variable will subsequently be defined during the execution of the READ statement or the corresponding wait operation (12.7.1).

25 26 27 28

(20) When a variable with the TARGET attribute is deallocated, a variable of type C_PTR from the intrinsic module ISO_C_BINDING becomes undefined if its value is the C address of any part of the variable that is deallocated.

29 30 31

(21) When a pointer is deallocated, a variable of type C_PTR from the intrinsic module ISO_C_BINDING becomes undefined if its value is the C address of any part of the target that is deallocated.

32 33

36

(22) Execution of the allocation transfer procedure (16.9.147) where the argument TO does not have the TARGET attribute causes a variable of type C_PTR from the intrinsic module ISO_C_BINDING to become undefined if its value is the C address of any part of the argument FROM.

37

(23) When a BLOCK construct completes execution,

34 35

38

its unsaved local variables become undefined, and

39

a variable of type C_PTR from the intrinsic module ISO_C_BINDING, whose value is the C address of an unsaved local variable of the BLOCK construct, becomes undefined.

40

(24) When execution of the host instance of the target of a variable of type C_FUNPTR from the intrinsic module ISO_C_BINDING is completed by execution of a RETURN or END statement, the variable becomes undefined.

41 42 43

542

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

(25) Execution of an intrinsic assignment of the type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, or of the type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, in which the variable and expr are not on the same image, causes the variable to become undefined.

5

(26) An object with the VOLATILE attribute (8.5.20) might become undefined by means not specified by the program.

6

(27) When a pointer becomes associated with a target that is undefined, the pointer becomes undefined.

7

(28) When an image fails during execution of a segment, a data object on a nonfailed image becomes undefined if it is not a lock variable and it might become undefined by execution of a statement of the segment other than an invocation of an atomic subroutine with the object as an actual argument corresponding to the ATOM dummy argument.

4

8 9 10 11 12 13 14 15 16 17 18 19

(29) Execution of a FORM TEAM statement with a STAT= specifier that assigns a nonzero value other than that of STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV to the statvariable causes the team variable to become undefined. (30) When the STAT argument in a reference to a collective subroutine is assigned a nonzero value, the A argument becomes undefined. (31) When an image which references a collective subroutine with a present RESULT_IMAGE argument is not the image identified by RESULT_IMAGE, the A argument on that image becomes undefined. (32) When an error condition occurs during execution of an atomic subroutine whose STAT argument is present, any other argument that is not INTENT (IN) becomes undefined. NOTE 1 Execution of a defined assignment statement could leave all or part of the variable undefined.

20

19.6.7

Variable definition context

21

1 Some variables are prohibited from appearing in a syntactic context that would imply definition or undefinition

22

of the variable (8.5.10, 8.5.15, 15.7). The following are the contexts in which the appearance of a variable implies such definition or undefinition of the variable:

23 24

(1)

the variable of an assignment-stmt;

25

(2)

a do-variable in a do-stmt or io-implied-do;

26

(3)

an input-item in a read-stmt;

27

(4)

a variable-name in a namelist-stmt if the namelist-group-name appears in a NML= specifier in a read-stmt;

29

(5)

an internal-file-variable in a write-stmt;

30

(6)

a SIZE= or IOMSG= specifier in an input/output statement;

31

(7)

a specifier in an INQUIRE statement other than FILE=, ID=, and UNIT=;

32

(8)

a NEWUNIT= specifier in an OPEN statement;

33

(9)

an allocate-object, errmsg-variable, notify-variable, or stat-variable;

34

(10) an actual argument in a reference to a procedure with an explicit interface if the corresponding dummy argument is not a pointer and has INTENT (OUT) or INTENT (INOUT);

28

35

38

(11) a variable that is a selector in an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT TYPE construct if the corresponding associate name or any subobject thereof appears in a variable definition context;

39

(12) an event-variable in an EVENT POST or EVENT WAIT statement;

36 37

ISO/IEC JTC 1/SC 22/WG5/N2184

543

J3/21-007r1

WD 1539-1

1

(13) a lock-variable in a LOCK or UNLOCK statement;

2

(14) a scalar-logical-variable in an ACQUIRED_LOCK= specifier;

3

(15) a team-variable in a FORM TEAM statement.

2021-05-21

4

2 If a reference to a function appears in a variable definition context the result of the function reference shall be a

5

pointer that is associated with a definable target. That target is the variable that becomes defined or undefined.

6

19.6.8

Pointer association context

7

1 Some pointers are prohibited from appearing in a syntactic context that would imply alteration of the pointer

8

association status (19.5.2.2, 8.5.10, 8.5.15, 15.7). The following are the contexts in which the appearance of a pointer implies such alteration of its pointer association status:

9 10

• a pointer-object in a nullify-stmt;

11

• a data-pointer-object or proc-pointer-object in a pointer-assignment-stmt;

12

• an allocate-object in an allocate-stmt or deallocate-stmt;

13

• an actual argument in a reference to a procedure if the corresponding dummy argument is a pointer with the INTENT (OUT) or INTENT (INOUT) attribute.

14

544

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

Annex A

2

(Informative)

3

Processor dependencies

4 5

A.1

J3/21-007r1

Unspecified items

1 This document does not specify the following:

6

• the properties excluded in 1;

7

• a processor’s error detection capabilities beyond those listed in 4.2;

8

• which additional intrinsic procedures or modules a processor provides (4.2);

9

• the number and kind of companion processors (5.5.7);

10

• the number of representation methods and associated kind type parameter values of the intrinsic types (7.4), except that there shall be at least two representation methods for type real, and a representation method of type complex that corresponds to each representation method for type real.

11 12

13 14

A.2

Processor dependencies

1 According to this document, the following are processor dependent:

16

• the order of evaluation of the specification expressions within the specification part of an invoked Fortran procedure (5.3.5);

17

• how soon an image terminates if another image initiates error termination (5.3.5);

18

• the value of a reference to a coindexed object on a failed image (5.3.6);

19

• the conditions that cause an image to fail (5.3.6);

20

• whether the processor has the ability to detect that an image has failed (5.3.6);

21

• whether the processor supports a concept of process exit status, and if so, the process exit status on program termination (5.3.7);

15

22

24

• the mechanism of a companion processor, and the means of selecting between multiple companion processors (5.5.7);

25

• the processor character set (6.1);

26

• the means for specifying the source form of a program unit (6.3);

27 28

• in fixed source form, the maximum number of characters allowed on a source line containing characters not of default kind (6.3.3);

29

• the maximum depth of nesting of include lines (6.4);

30

• the interpretation of the char-literal-constant in the include line (6.4);

31

• the set of values supported by an intrinsic type, other than logical (7.1.3);

32 33

• the kind type parameter value of a complex literal constant, if both the real part and imaginary part are of type real with the same precision, but have different kind type parameter values (7.4.3.3);

34

• the kind of a character length type parameter (7.4.4.1);

35

• the blank padding character for nondefault character kind (7.4.4.2)

23

ISO/IEC JTC 1/SC 22/WG5/N2184

545

J3/21-007r1

WD 1539-1

2021-05-21

2

• whether particular control characters can appear within a character literal constant in fixed source form (7.4.4.3);

3

• the collating sequence for each character set (7.4.4.4);

4

• the order of finalization of components of objects of derived type (7.5.6.2);

5

• the order of finalization when several objects are finalized as the consequence of a single event (7.5.6.2);

6

8

• whether and when an object is finalized if it is allocated by pointer allocation and it later becomes unreachable due to all pointers associated with the object having their pointer association status changed (7.5.6.3);

9

• whether an object is finalized by a deallocation in which an error condition occurs (7.5.6.3);

10

• the kind type parameter of the enumerators of an interoperable enumeration (7.6.1);

11

• whether an array is contiguous, except as specified in 8.5.7;

12

• the set of error conditions that can occur in ALLOCATE and DEALLOCATE statements (9.7.1, 9.7.3);

13

15

• the allocation status of a variable after evaluation of an expression if the evaluation of a function would change the allocation status of the variable and if a reference to the function appears in the expression in which the value of the function is not needed to determine the value of the expression (9.7.1.3);

16

• the order of deallocation when several objects are deallocated by a DEALLOCATE statement (9.7.3);

17

• the order of deallocation when several objects are deallocated due to the occurence of an event described in 9.7.3.2;

1

7

14

18 19 20 21 22 23 24

• whether an allocated allocatable subobject is deallocated when an error condition occurs in the deallocation of an object (9.7.3.2); • the positive integer values assigned to the stat-variable in a STAT= specifier as the result of an error condition (9.7.4, 11.7.11); • the allocation status or pointer association status of an allocate-object if an error condition occurs during execution of an ALLOCATE or DEALLOCATE statement (9.7.4);

26

• the value assigned to the errmsg-variable in an ERRMSG= specifier as the result of an error condition (9.7.5, 11.7.11);

27

• the kind type parameter value of the result of a numeric intrinsic binary operation where

25

– both operands are of type integer but with different kind type parameters, and the decimal exponent ranges are the same,

28 29

31

– one operand is of type real or complex and the other is of type real or complex with a different kind type parameter, and the decimal precisions are the same,

32

and for a logical intrinsic binary operation where the operands have different kind type parameters (10.1.9.3);

33

• the character assigned to the variable in an intrinsic assignment statement if the kind of the expression is different and the character is not representable in the kind of the variable (10.2.1.3);

30

34 35 36

• the order of evaluation of the specification expressions within the specification part of a BLOCK construct when the construct is executed (11.1.4);

38

• the ordering between records written by different iterations of a DO CONCURRENT construct if the records are written to a file connected for sequential access by more than one iteration (11.1.7);

39

• the manner in which the stop code of a STOP or ERROR STOP statement is made available (11.4);

40 41

• the value of the count of the notify variable in a NOTIFY WAIT statement if an error condition occurs (11.6);

42

• the mechanisms available for creating dependencies for cooperative synchronization (11.7.5);

37

546

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

• the value of the count of the event variable in an EVENT POST or EVENT WAIT statement if an error condition occurs (11.7.7, 11.7.8);

4

• the image index value established for each image in a team by a FORM TEAM statement without a NEW_INDEX= specifier (11.7.9);

5

• the set of error conditions that can occur in image control statements (11.7.11);

6 7

• the relationship between the file storage units when viewing a file as a stream file, and the records when viewing that file as a record file (12);

8

• whether particular control characters can appear in a formatted record or a formatted stream file (12.2.2);

9

• the form of values in an unformatted record (12.2.3);

10 11

• at any time, the set of allowed access methods, set of allowed forms, set of allowed actions, and set of allowed record lengths for a file (12.3);

12

• the set of allowable names for a file (12.3);

13

• whether a named file on one image is the same as a file with the same name on another image (12.3.1);

14

• the set of external files that exist for a program (12.3.2);

15

• the relationship between positions of successive file storage units in an external file that is connected for formatted stream access (12.3.3.4);

3

16 17 18 19 20

• the external unit preconnected for sequential formatted input and identified by an asterisk or the named constant INPUT_UNIT of the ISO_FORTRAN_ENV intrinsic module (12.5); • the external unit preconnected for sequential formatted output and identified by an asterisk or the named constant OUTPUT_UNIT of the ISO_FORTRAN_ENV intrinsic module (12.5);

23

• the external unit preconnected for sequential formatted output and identified by the named constant ERROR_UNIT of the ISO_FORTRAN_ENV intrinsic module, and whether this unit is the same as OUTPUT_UNIT (12.5);

24

• at any time, the set of external units that exist for an image (12.5.3);

25

• whether a unit can be connected to a file that is also connected to a C stream (12.5.4);

26

• whether a file can be connected to more than one unit at the same time (12.5.4);

27

• the effect of performing input/output operations on multiple units while they are connected to the same external file (12.5.4);

21 22

28 29 30 31 32

• the result of performing input/output operations on a unit connected to a file that is also connected to a C stream (12.5.4); • whether the files connected to the units INPUT_UNIT, OUTPUT_UNIT, and ERROR_UNIT correspond to the predefined C text streams standard input, standard output, and standard error, respectively (12.5.4);

34

• the results of performing input/output operations on an external file both from Fortran and from a procedure defined by means other than Fortran (12.5.4);

35

• the default value for the ACTION= specifier in an OPEN statement (12.5.6.4);

36

• the encoding of a file opened with ENCODING=’DEFAULT’ (12.5.6.9);

37

• the file connected by an OPEN statement with STATUS=’SCRATCH’ (12.5.6.10);

38

• the interpretation of case in a file name (12.5.6.10, 12.10.2.2);

39 40

• the position of a file after executing an OPEN statement with a POSITION= specifier of ASIS, when the file previously existed but was not connected (12.5.6.15);

41

• the default value for the RECL= specifier in an OPEN statement (12.5.6.16);

42

• the effect of RECL= on a record containing any nondefault characters (12.5.6.16);

33

ISO/IEC JTC 1/SC 22/WG5/N2184

547

J3/21-007r1

WD 1539-1

2021-05-21

1

• the default input/output rounding mode (12.5.6.17);

2

• the default sign mode (12.5.6.18);

3

• the file status when STATUS=’UNKNOWN’ is specified in an OPEN statement (12.5.6.19);

4

• the value assigned to the variable in the ID= specifier in an asynchronous data transfer statement when execution of the statement is successfully completed (12.6.2.9);

5 6 7 8 9 10 11 12 13 14 15 16

• whether POS= is permitted with particular files, and whether POS= can position a particular file to a position prior to its current position (12.6.2.12); • the form in which a single value of derived type is treated in an unformatted input/output statement if the effective item is not processed by a defined input/output procedure (12.6.3); • the result of unformatted input when the value stored in the file has a different type or type parameters from that of the input list item (12.6.4.5.2); • the negative value of the unit argument to a defined input/output procedure if the parent data transfer statement accesses an internal file (12.6.4.8.2); • the manner in which the processor makes the value of the iomsg argument of a defined input/output procedure available if the procedure assigns a nonzero value to the iostat argument and the processor therefore terminates execution of the program (12.6.4.8.2);

19

• the action caused by the flush operation, whether the processor supports the flush operation for the specified unit, and the negative value assigned to the IOSTAT= variable if the processor does not support the flush operation for the specified unit (12.9);

20

• the case of characters assigned to the variable in a NAME= specifier in an INQUIRE statement (12.10.2.16);

21

• which of the connected external unit numbers is assigned to the scalar-int-variable in the NUMBER= specifier in an INQUIRE by file statement, if more than one unit on an image is connected to the file (12.10.2.19);

17 18

22 23 24 25

• the value of the variable in a POSITION= specifier in an INQUIRE statement if the file has been repositioned since connection (12.10.2.24);

27

• the relationship between file size and the data stored in records in a sequential or direct access file (12.10.2.31);

28

• the number of file storage units needed to store data in an unformatted file (12.10.3);

29

• the set of error conditions that can occur in input/output statements (12.11.1);

30

• when an input/output error condition occurs or is detected (12.11.1);

31 32

• the positive integer value assigned to the variable in an IOSTAT= specifier as the result of an error condition (12.11.5);

33

• the value assigned to the variable in an IOMSG= specifier as the result of an error condition (12.11.6);

34

• the result of output of non-representable characters to a Unicode file (13.7.1);

35 36

• the interpretation of the optional non-blank characters within the parentheses of a real NaN input field (13.7.2.3.2);

37

• the interpretation of a sign in a NaN input field (13.7.2.3.2);

38 39

• for output of an IEEE NaN, whether after the letters ’NaN’, the processor produces additional alphanumeric characters enclosed in parentheses (13.7.2.3.2);

40

• the choice of binary exponent in EX output editing (13.7.2.3.6);

41

• the effect of the input/output rounding mode PROCESSOR_DEFINED (13.7.2.3.8);

42

• which value is chosen if the input/output rounding mode is NEAREST and the value to be converted is exactly halfway between the two nearest representable values in the result format (13.7.2.3.8);

26

43

548

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

• the field width, decimal part width, and exponent width used for the G0 edit descriptor (13.7.5);

2

• the file position when position editing skips a character of nondefault kind in an internal file of default character kind or an external unit that is not connected to a Unicode file (13.8.1.1);

3

5

• when the sign mode is PROCESSOR_DEFINED, whether a plus sign appears in a numeric output field for a nonnegative value (13.8.4);

6

• the results of list-directed output (13.10.4);

7

• the results of namelist output (13.11.4);

8

• the interaction between argument association and pointer association, (15.5.2.4);

9

• the values returned by some intrinsic functions (16);

10

• how the sequences of atomic actions in unordered segments interleave (16.5);

11

• the value assigned to a STAT argument in a reference to an atomic subroutine when an error condition occurs (16.5);

4

12 13 14

• the effect of calling EXECUTE_COMMAND_LINE on any image other than image 1 in the initial team (16.7);

16

• whether the results returned from CPU_TIME, DATE_AND_TIME and SYSTEM_CLOCK are dependent on which image calls them (16.7);

17

• the set of error conditions that can occur in some intrinsic subroutines (16.9);

18

• the value assigned to a CMDSTAT, ERRMSG, EXITSTAT, STAT, or STATUS argument to indicate a processor-dependent error condition (16.9);

15

19

21

• the computed value of the intrinsic subroutine CO_REDUCE (16.9.57) and the intrinsic subroutine CO_SUM (16.9.58);

22

• the value assigned to the TIME argument by the intrinsic subroutine CPU_TIME (16.9.67);

23

• whether date, clock, and time zone information is available (16.9.69);

24

• whether date, clock, and time zone information on one image is the same as that on another image (16.9.69);

25 26

• the value of command argument zero, if the processor does not support the concept of a command name (16.9.93);

27

• the order of command arguments (16.9.93);

28

• whether the significant length of a command argument includes trailing blanks (16.9.93);

29

• the interpretation of case for the NAME argument of the intrinsic subroutine GET_ENVIRONMENT_VARIABLE (16.9.94);

20

30

32

• whether an environment variable that exists on an image also exists on another image, and if it does exist on both images, whether the values are the same or different (16.9.94);

33

• the value assigned to the pseudorandom number seed by the intrinsic subroutine RANDOM_INIT (16.9.167);

34

• the computation of the seed value used by the pseudorandom number generator (16.9.169);

35 36

• the value assigned to the seed by the intrinsic subroutine RANDOM_SEED when no argument is present (16.9.169);

37

• the values assigned to its arguments by the intrinsic subroutine SYSTEM_CLOCK (16.9.202);

38

• the values of the named constants in the intrinsic module ISO_FORTRAN_ENV (16.10.2);

39 40

• the values returned by the functions COMPILER_OPTIONS and COMPILER_VERSION in the intrinsic module ISO_FORTRAN_ENV (16.10.2);

41

• the extent to which a processor supports IEEE arithmetic (17);

42

• whether a flag that is quiet on entry to a scoping unit that does not access IEEE_FEATURES, IEEE_-

31

ISO/IEC JTC 1/SC 22/WG5/N2184

549

J3/21-007r1

3 4 5 6 7

2021-05-21

EXCEPTIONS, or IEEE_ARITHMETIC is signaling on exit (17.1);

1 2

WD 1539-1

• the conditions under which IEEE_OVERFLOW is raised in a calculation involving non-ISO/IEC/IEEE 60559:2011 floating-point data (17.3); • the conditions under which IEEE_OVERFLOW and IEEE_DIVIDE_BY_ZERO are raised in a floatingpoint exponentiation operation (17.3); • the conditions under which IEEE_DIVIDE_BY_ZERO is raised in a calculation involving floating-point data that do not conform to ISO/IEC/IEEE 60559:2011 (17.3);

11

• whether an exception signals at the end of a sequence of statements that has no invocations of IEEE_GET_FLAG, IEEE_SET_FLAG, IEEE_GET_STATUS, IEEE_SET_STATUS, or IEEE_SET_HALTING_MODE, in which execution of an operation would cause it to signal, if no value of a variable depends upon the result of the operation (17.3);

12

• the initial rounding modes (17.4);

13

• whether the processor supports a particular rounding mode (17.4);

14

• the effect of the rounding mode IEEE_OTHER, if supported (17.4);

15

• the initial underflow mode (17.5);

16

• the initial halting mode (17.6);

17

• whether IEEE_INT implements the convertToInteger{round} or convertToIntegerExact{round} operation specified by ISO/IEC 60559:2020 (17.11.11);

8 9 10

18 19 20 21 22 23 24 25

• which argument is the result value of IEEE_MAX_NUM, IEEE_MAX_NUM_MAG, IEEE_MIN_NUM, or IEEE_MIN_NUM_MAG when both arguments are quiet NaNs or are zeros (17.11.19, 17.11.20, 17.11.23, 17.11.24); • the requirements on the storage sequence to be associated with the pointer FPTR by the C_F_POINTER subroutine (18.2.3.4); • the order of the members of the CFI_dim_t structure defined in the source file CFI_Fortran_binding.h (18.5.2);

27

• members of the CFI_cdesc_t structure defined in the source file CFI_Fortran_binding.h beyond the requirements of 18.5.3;

28

• the value of CFI_MAX_RANK in the source file CFI_Fortran_binding.h (18.5.4);

29

• the value of CFI_VERSION in the source file CFI_Fortran_binding.h (18.5.4);

30 31

• which error condition is detected if more than one error condition could be detected for an invocation of one of the functions declared in the source file CFI_Fortran_binding.h (18.5.5.1);

32

• the values of the attribute specifier macros defined in the source file CFI_Fortran_binding.h (18.5.4);

33

• the values of the type specifier macros defined in the source file CFI_Fortran_binding.h;

34

• which additional type specifier values are defined in the source file CFI_Fortran_binding.h (18.5.4);

35 36

• the values of the error code macros other than CFI_SUCCESS that are defined in the source file CFI_Fortran_binding.h (18.5.4);

37

• the base address of a zero-sized array (18.5.3);

38

• the values of the floating-point exception flags on entry to a procedure defined by means other than Fortran (18.10.3);

26

39 40 41

• whether a procedure defined by means other than Fortran is an asynchronous communication initiation or completion procedure (18.10.4).

550

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

Annex B

2

(Informative)

3

Deleted and obsolescent features

4

B.1

J3/21-007r1

Deleted features from Fortran 90

5

1 These deleted features are those features of Fortran 90 that were redundant and considered largely unused.

6

2 The following Fortran 90 features are not required.

7

(1)

Real and double precision DO variables. In Fortran 77 and Fortran 90, a DO variable was allowed to be of type real or double precision in addition to type integer; this has been deleted. A similar result can be achieved by using a DO construct with no loop control and the appropriate exit test.

(2)

Branching to an END IF statement from outside its block. In Fortran 77 and Fortran 90, it was possible to branch to an END IF statement from outside the IF construct; this has been deleted. A similar result can be achieved by branching to a CONTINUE statement that is immediately after the END IF statement.

(3)

PAUSE statement. The PAUSE statement, provided in Fortran 66, Fortran 77, and Fortran 90, has been deleted. A similar result can be achieved by writing a message to the appropriate unit, followed by reading from the appropriate unit.

(4)

ASSIGN and assigned GO TO statements, and assigned format specifiers. The ASSIGN statement and the related assigned GO TO statement, provided in Fortran 66, Fortran 77, and Fortran 90, have been deleted. Further, the ability to use an assigned integer as a format, provided in Fortran 77 and Fortran 90, has been deleted. A similar result can be achieved by using other control constructs instead of the assigned GO TO statement and by using a default character variable to hold a format specification instead of using an assigned integer.

(5)

H edit descriptor. In Fortran 77 and Fortran 90, there was an alternative form of character string edit descriptor, which had been the only such form in Fortran 66; this has been deleted. A similar result can be achieved by using a character string edit descriptor.

(6)

Vertical format control. In Fortran 66, Fortran 77, Fortran 90, and Fortran 95 formatted output to certain units resulted in the first character of each record being interpreted as controlling vertical spacing. There was no standard way to detect whether output to a unit resulted in this vertical format control, and no way to specify that it needs to be applied; this has been deleted. The effect can be achieved by post-processing a formatted file.

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

3 See ISO/IEC 1539:1991 for detailed rules of how these deleted features worked.

ISO/IEC JTC 1/SC 22/WG5/N2184

551

J3/21-007r1

1

B.2

WD 1539-1

2021-05-21

Deleted features from Fortran 2008

2

1 These deleted features are those features of Fortran 2008 that were redundant and considered largely unused.

3

2 The following Fortran 2008 features are not required.

4

(1)

Arithmetic IF statement. The arithmetic IF statement is incompatible with ISO/IEC 60559:2020 and necessarily involves the use of statement labels; statement labels can hinder optimization, and make code hard to read and maintain. Similar logic can be more clearly encoded using other conditional statements.

(2)

Nonblock DO construct The nonblock forms of the DO loop were confusing and hard to maintain. Shared termination and dual use of labeled action statements as do termination and branch targets were especially errorprone.

5 6 7 8 9 10 11

12

B.3

Obsolescent features

13

B.3.1

General

14

1 The obsolescent features are those features of Fortran 90 that were redundant and for which better methods were

15

available in Fortran 90. The nature of the obsolescent features is described in 4.4.3. The obsolescent features in this document are the following.

16 17

(1)

Alternate return — see B.3.2.

18

(2)

Computed GO TO — see B.3.3.

19

(3)

Statement functions — see B.3.4.

20

(4)

DATA statements amongst executable statements — see B.3.5.

21

(5)

Assumed length character functions — see B.3.6.

22

(6)

Fixed form source — see B.3.7.

23

(7)

CHARACTER* form of CHARACTER declaration — see B.3.8.

24

(8)

ENTRY statements — see B.3.9.

25

(9)

Label form of DO statement – see B.3.10.

26

(10) COMMON and EQUIVALENCE statements, and the block data program unit – see B.3.11.

27

(11) Specific names for intrinsic functions – see B.3.12.

28

(12) FORALL construct and statement – see B.3.13

29

B.3.2

Alternate return

30

1 An alternate return introduces labels into an argument list to allow the called procedure to direct the execution

31

of the caller upon return. The same effect can be achieved with a return code that is used in a SELECT CASE construct on return. This avoids an irregularity in the syntax and semantics of argument association. For example,

32 33 34 35 36

CALL SUBR_NAME (X, Y, Z, *100, *200, *300) can be replaced by CALL SUBR_NAME (X, Y, Z, RETURN_CODE) SELECT CASE (RETURN_CODE)

552

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9

10 11

WD 1539-1

CASE (1) ... CASE (2) ... CASE (3) ... CASE DEFAULT ... END SELECT

B.3.3

Computed GO TO statement

1 The computed GO TO statement has been superseded by the SELECT CASE construct, which is a generalized,

12

easier to use, and clearer means of expressing the same computation.

13

B.3.4

14 15 16

17

J3/21-007r1

Statement functions

1 Statement functions are subject to a number of nonintuitive restrictions and are a potential source of error because

their syntax is easily confused with that of an assignment statement. 2 The internal function is a more generalized form of the statement function and completely supersedes it.

B.3.5

DATA statements among executables

18

1 The statement ordering rules allow DATA statements to appear anywhere in a program unit after the specific-

19 20

ation statements. The ability to position DATA statements amongst executable statements is very rarely used, unnecessary, and a potential source of error.

21

B.3.6

Assumed character length functions

22

1 Assumed character length for functions is an irregularity in the language in that elsewhere in Fortran the philo-

23

sophy is that the attributes of a function result depend only on the actual arguments of the invocation and on any data accessible by the function through host or use association. Some uses of this facility can be replaced with an automatic character length function, where the length of the function result is declared in a specification expression. Other uses can be replaced by the use of a subroutine whose arguments correspond to the function result and the function arguments.

24 25 26 27 28

29

2 Note that dummy arguments of a function can have assumed character length.

B.3.7

Fixed form source

30

1 Fixed form source was designed when the principal machine-readable input medium for new programs was punched

31

cards. Now that new and amended programs are generally entered via keyboards with screen displays, it is an unnecessary overhead, and is potentially error-prone, to have to locate positions 6, 7, or 72 on a line. Free form source was designed expressly for this more modern technology.

32 33 34

2 It is a simple matter for a software tool to convert from fixed to free form source.

ISO/IEC JTC 1/SC 22/WG5/N2184

553

J3/21-007r1

1 2

B.3.8

WD 1539-1

2021-05-21

CHARACTER* form of CHARACTER declaration

1 In addition to the CHARACTER*char-length form introduced in Fortran 77, Fortran 90 provided the CHAR-

3

ACTER([ LEN = ] type-param-value) form. The older form (CHARACTER*char-length) is redundant.

4

B.3.9

5 6 7

ENTRY statements

1 ENTRY statements allow more than one entry point to a subprogram, facilitating sharing of data items and

executable statements local to that subprogram. 2 This can be replaced by a module containing the (private) data items, with a module procedure for each entry

8

point and the shared code in a private module procedure.

9

B.3.10

Label DO statement

10

1 The label in the DO statement is redundant with the construct name. Furthermore, the label allows unrestricted

11 12

branches and, for its main purpose (the target of a conditional branch to skip the rest of the current iteration), is redundant with the CYCLE statement, which is clearer.

13

B.3.11

COMMON and EQUIVALENCE statements and the block data program unit

14

1 Common blocks are error-prone and have largely been superseded by modules. EQUIVALENCE similarly is

15

17

error-prone. Whilst use of these statements was invaluable prior to Fortran 90 they are now redundant and can inhibit performance. The block data program unit exists only to serve common blocks and hence is also redundant.

18

B.3.12

16

19

Specific names for intrinsic functions

1 The specific names of the intrinsic functions are often obscure and hinder portability. They have been redundant

20

since Fortran 90. Use generic names for references to intrinsic procedures.

21

B.3.13

FORALL construct and statement

22

1 The FORALL construct and statement were added to the language in the expectation that they would enable

23

highly efficient execution, especially on parallel processors. However, experience indicates that they are too complex and have too many restrictions for compilers to take advantage of them. They are redundant with the DO CONCURRENT construct, and many of the manipulations for which they might be used can be done more effectively using pointers, especially using pointer rank remapping.

24 25 26

554

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

Annex C

2

(Informative)

3

Extended notes

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

C.1

J3/21-007r1

Features that were new in Fortran 2018

• Data declaration: Constant properties of an object declared in its entity-decl can be used in its initialization. The EQUIVALENCE and COMMON statements and the block data program unit have been redundant since Fortran 90 and are now specified to be obsolescent. Diagnosis of the appearance of a PROTECTED TARGET variable accessed by use association as a data-target in a structure constructor is required. • Data usage and computation: The declared type of the value supplied for a polymorphic allocatable component in a structure constructor is no longer required to be the same as the declared type of the component. FORALL is now specified to be obsolescent. The type and kind of an implied DO variable in an array constructor or DATA statement can be specified within the constructor or statement. The SELECT RANK construct provides structured access to the elements of an assumed-rank array. Completing execution of a BLOCK construct can cause the association status of a pointer with the PROTECTED attribute to become undefined. The standard intrinsic operations <, <=, >, and >= (also known as .LT., .LE., .GT., and .GE.) on IEEE numbers provide compareSignaling{relation} operations; the = and /= operations (also known as .EQ. and .NE.) provide compareQuiet{relation} operations. Finalization of an allocatable subobject during intrinsic assignment has been clarified. The char-length in an executable statement is no longer required to be a specification expression. • Input/output: The SIZE= specifier can be used with advancing input. It is no longer prohibited to open a file on more than one unit. The value assigned by the RECL= specifier in an INQUIRE statement has been standardized. The values assigned by the POS= and SIZE= specifiers in an INQUIRE statement for a unit that has pending asynchronous operations have been standardized. The G0.d edit descriptor can be used for list items of type Integer, Logical, and Character. The D, E, EN, and ES edit descriptors can have a field width of zero, analogous to the F edit descriptor. The exponent width e in a data edit descriptor can be zero, analogous to a field width of zero. Floating-point formatted input accepts hexadecimal-significand numbers that conform to ISO/IEC 60559:2020. The EX edit descriptor provides hexadecimal-significand formatted output conforming to ISO/IEC 60559:2020. An error condition occurs if unacceptable characters are presented for logical or numeric editing during execution of a formatted input statement. • Execution control: The arithmetic IF statement has been deleted. Labeled DO loops have been redundant since Fortran 90 and are now specified to be obsolescent. The nonblock DO construct has been deleted. The locality of a variable used in a DO CONCURRENT construct can be explicitly specified. The stop code in a STOP or ERROR STOP statement can be nonconstant. Output of the stop code and exception summary from the STOP and ERROR STOP statements can be controlled. • Intrinsic procedures and modules: In a reference to the intrinsic function CMPLX with an actual argument of type complex, no keyword

ISO/IEC JTC 1/SC 22/WG5/N2184

555

J3/21-007r1

WD 1539-1

2021-05-21

is needed for a KIND argument. In references to the intrinsic functions ALL, ANY, FINDLOC, IALL, IANY, IPARITY, MAXLOC, MAXVAL, MINLOC, MINVAL, NORM2, PARITY, PRODUCT, SUM, and THIS_IMAGE, the actual argument for DIM can be a present optional dummy argument. The new intrinsic function COSHAPE returns the coshape of a coarray. The new intrinsic function OUT_OF_RANGE tests whether a numeric value can be safely converted to a different type or kind. The new intrinsic subroutine RANDOM_INIT establishes the initial state of the pseudorandom number generator used by RANDOM_NUMBER. The new intrinsic function REDUCE performs user-specified array reductions. A processor is required to report use of a nonstandard intrinsic procedure, use of a nonstandard intrinsic module, and use of a nonstandard procedure from a standard intrinsic module. Integer and logical arguments to intrinsic procedures and intrinsic module procedures that were previously required to be of default kind no longer have that requirement, except for RANDOM_SEED. Specific names for intrinsic functions are now deemed obsolescent. All standard procedures in the intrinsic module ISO_C_BINDING, other than C_F_POINTER, are now pure. The arguments to the intrinsic function SIGN can be of different kind. Nonpolymorphic pointer arguments to the intrinsic functions EXTENDS_TYPE_OF and SAME_TYPE_AS need not have defined pointer association status. The effects of invoking the intrinsic procedures COMMAND_ARGUMENT_COUNT, GET_COMMAND, and GET_COMMAND_ARGUMENT, on images other than image one, are no longer processor dependent. Access to error messages from the intrinsic subroutines GET_COMMAND, GET_COMMAND_ARGUMENT, and GET_ENVIRONMENT_VARIABLE is provided by an optional ERRMSG argument. The result of NORM2 for a zero-sized array argument has been clarified.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

• Program units and procedures:

21

• Features previously described by ISO/IEC TS 29113:2012: A dummy data object can assume its rank from its effective argument. A dummy data object can assume the type from its effective argument, without having the ability to perform type selection. An interoperable procedure can have dummy arguments that are assumed-type and/or assumed-rank. An interoperable procedure can have dummy data objects that are allocatable, assumed-shape, optional, or pointers. The character length of a dummy data object of an interoperable procedure can be assumed. The argument to C_LOC can be a noninteroperable array. The FPTR argument to C_F_POINTER can be a noninteroperable array pointer. The argument to C_FUNLOC can be a noninteroperable procedure. The FPTR argument to C_F_PROCPOINTER can be a noninteroperable procedure pointer. There is a new named constant C_PTRDIFF_T to provide interoperability with the C type ptrdiff_t. Additionally to ISO/IEC TS 29113:2012, a scalar actual argument can be associated with an assumedtype assumed-size dummy argument, an assumed-rank dummy data object that is not associated with an assumed-size array can be used as the argument to the function C_SIZEOF from the intrinsic module ISO_C_BINDING, and the type argument to CFI_establish can have a positive value corresponding to an interoperable C type.

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

• Changes to the intrinsic modules IEEE_ARITHMETIC, IEEE_EXCEPTIONS, and IEEE_FEATURES for conformance with ISO/IEC 60559:2020: There is a new, optional, rounding mode IEEE_AWAY. The new type IEEE_MODES_TYPE encapsulates all floating-point modes. Features associated with subnormal numbers can be accessed with functions and types named . . . SUBNORMAL. . . (the old . . . DENORMAL. . . names remain). The new function IEEE_FMA performs fused multiply-add operations. The function IEEE_INT performs rounded conversions to integer type. The new functions IEEE_MAX_NUM, IEEE_MAX_NUM_MAG, IEEE_MIN_NUM, and IEEE_MIN_NUM_MAG calculate maximum and minimum numeric values. The new functions IEEE_NEXT_DOWN and IEEE_NEXT_UP return the adjacent machine numbers. The new functions IEEE_QUIET_EQ, IEEE_QUIET_GE, IEEE_QUIET_GT, IEEE_QUIET_LE, IEEE_QUIET_LT, and IEEE_QUIET_NE perform quiet comparisons. The new functions IEEE_SIGNALING_EQ,

556

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

WD 1539-1

J3/21-007r1

IEEE_SIGNALING_GE, IEEE_SIGNALING_GT, IEEE_SIGNALING_GE, IEEE_SIGNALING_LE, IEEE_SIGNALING_LT, and IEEE_SIGNALING_NE perform signaling comparisons. The decimal rounding mode can be inquired and set independently of the binary rounding mode, using the RADIX argument to IEEE_GET_ROUNDING_MODE and IEEE_SET_ROUNDING_MODE. The new function IEEE_REAL performs rounded conversions to real type. The function IEEE_REM now requires its arguments to have the same radix. The function IEEE_RINT now has a ROUND argument to perform specific rounding. The new function IEEE_SIGNBIT tests the sign bit of an IEEE number. • Features previously described by ISO/IEC TS 18508:2015: The CRITICAL statement has optional ERRMSG= and STAT= specifiers. The intrinsic subroutines ATOMIC_DEFINE and ATOMIC_REF have an optional STAT argument. The new intrinsic subroutines ATOMIC_ADD, ATOMIC_AND, ATOMIC_CAS, ATOMIC_FETCH_ADD, ATOMIC_FETCH_AND, ATOMIC_FETCH_OR, ATOMIC_FETCH_XOR, ATOMIC_OR, and ATOMIC_XOR perform atomic operations. The new intrinsic functions FAILED_IMAGES and STOPPED_IMAGES return indices of images known to have failed or stopped respectively. The new intrinsic function IMAGE_STATUS returns the image execution status of an image. The intrinsic subroutine MOVE_ALLOC has optional ERRMSG and STAT arguments. The intrinsic functions IMAGE_INDEX and NUM_IMAGES have additional forms with a TEAM or TEAM_NUMBER argument. The intrinsic function THIS_IMAGE has an optional TEAM argument. The EVENT POST and EVENT WAIT statements, the intrinsic subroutine EVENT_QUERY, and the type EVENT_TYPE provide an event facility for one-sided segment ordering. The CHANGE TEAM construct, derived type TEAM_TYPE, FORM TEAM and SYNC TEAM statements, intrinsic functions GET_TEAM and TEAM_NUMBER, and the TEAM= and TEAM_NUMBER= specifiers on image selectors, provide a team facility for a subset of the program’s images to act in concert as if it were the set of all images. This team facility allows an allocatable coarray to be allocated or deallocated on a subset of images. The new intrinsic subroutines CO_BROADCAST, CO_MAX, CO_MIN, CO_REDUCE, and CO_SUM perform collective reduction operations on the images of the current team. The concept of failed images, the FAIL IMAGE statement, the STAT= specifier on image selectors, and the named constant STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV provide support for fault-tolerant parallel execution. • Changes to features previously described by ISO/IEC TS 18508:2015: The CHANGE TEAM and SYNC TEAM statements, and the TEAM= specifier on image selectors, permit the team to be specified by an expression. The intrinsic functions FAILED_IMAGES and STOPPED_IMAGES have no restriction on the kind of their result. The name of the function argument to the intrinsic function CO_REDUCE is OPERATION instead of OPERATOR; this argument is not required to be commutative. The named constant STAT_UNLOCKED_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV indicates that a lock variable was locked by an image that failed. The team number for the initial team can be used in image selectors, and in the intrinsic functions NUM_IMAGES and IMAGE_INDEX. A team variable that appears in a CHANGE TEAM statement can no longer be defined or become undefined during execution of the CHANGE TEAM construct. All images of the current team are no longer required to execute the same CHANGE TEAM statement. A variable of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV is not permitted to be a coarray. A variable of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV can have a pointer component, and a team variable becomes undefined if assigned a value from another image. The intrinsic function UCOBOUND produces a value for the final upper cobound that is always relative to the current team. An EXIT statement can be used to complete execution of a CHANGE TEAM or CRITICAL construct.

ISO/IEC JTC 1/SC 22/WG5/N2184

557

J3/21-007r1

1 2

C.2

WD 1539-1

2021-05-21

Fortran 2008 features not mentioned in its Introduction

1 The following features were new in Fortran 2008 but not originally listed in its Introduction as being new features:

3

• An array or object with a nonconstant length type parameter can have the VALUE attribute.

4

• Multiple allocations are permitted in a single ALLOCATE statement with the SOURCE= specifier.

5

• A PROCEDURE statement can have a double colon before the first procedure name.

6

• An argument to a pure procedure can have default INTENT if it has the VALUE attribute.

7

• The PROTECTED attribute can be specified by the procedure declaration statement.

8

• A defined-operator can be used in a specification expression.

9

• All transformational functions from the intrinsic module ISO_C_BINDING can be used in specification expressions.

10

14

• A contiguous array variable that is not interoperable but which has interoperable type and kind type parameter (if any), and a scalar character variable with length greater than 1 and kind C_CHAR in the intrinsic module ISO_C_BINDING, can be used as the argument of the function C_LOC in the intrinsic module ISO_C_BINDING, provided the variable has the POINTER or TARGET attribute.

15

• The name of an external procedure that has a binding label is a local identifier and not a global identifier.

16

• A procedure that is not a procedure pointer can be an actual argument that corresponds to a procedure pointer dummy argument with the INTENT (IN) attribute.

11 12 13

17

19

• An interface body for an external procedure that does not exist in a program can be used to specify an explicit specific interface.

20

• An internal procedure name can appear in a procedure-stmt in a generic interface block.

18

21

2 All but the last three of the above list were subsequently added to the Introduction by Technical Corrigenda.

22

C.3

Clause 7 notes

23

C.3.1

Selection of the approximation methods (7.4.3.2)

24

1 One can select the real approximation method for an entire program through the use of a module and the

25

parameterized real type. This is accomplished by defining a named integer constant to have a particular kind type parameter value and using that named constant in all real, complex, and derived-type declarations. For example, the specification statements

26 27

INTEGER, PARAMETER :: LONG_FLOAT = 8 REAL (LONG_FLOAT) X, Y COMPLEX (LONG_FLOAT) Z

28 29 30

35

specify that the approximation method corresponding to a kind type parameter value of 8 is supplied for the data objects X, Y, and Z in the program unit. The kind type parameter value LONG_FLOAT can be made available to an entire program by placing the INTEGER specification statement in a module and accessing the named constant LONG_FLOAT with a USE statement. Note that by changing 8 to 4 once in the module, a different approximation method is selected.

36

2 To avoid the use of the processor-dependent values 4 or 8, replace 8 by KIND (0.0) or KIND (0.0D0). Another

37

way to avoid these processor-dependent values is to select the kind value using the intrinsic function SELECTED_REAL_KIND (16.9.183). In the above specification statement, the 8 might be replaced by, for instance,

31 32 33 34

38

558

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

4

SELECTED_REAL_KIND (10, 50), which requires an approximation method to be selected with at least 10 decimal digits of precision and a range from 10−50 to 1050 . There are no magnitude or ordering constraints placed on kind values, in order that implementers have flexibility in assigning such values and can add new kinds without changing previously assigned kind values.

5

3 As kind values have no portable meaning, a good practice is to use them in programs only through named

6 7

constants as described above (for example, SINGLE, IEEE_SINGLE, DOUBLE, and QUAD), rather than using the kind values directly.

8

C.3.2

1 2 3

9 10

Type extension and component accessibility (7.5.2.2, 7.5.4)

1 The default accessibility of the components of an extended type can be specified in the type definition. The

accessibility of its components can be specified individually. For example: module types type base_type private integer :: i integer, private :: j integer, public :: k end type base_type

11 12 13 14 15 16 17

!-- Sets default accessibility !-- a private component !-- another private component !-- a public component

18

type, extends(base_type) :: my_type private !-- Sets default for components declared in my_type integer :: l !-- A private component. integer, public :: m !-- A public component. end type my_type end module types

19 20 21 22 23 24 25

subroutine sub use types type (my_type) :: x ... call another_sub( & x%base_type, & x%base_type%k, &

26 27 28 29 30 31 32 33

x%k, x%base_type%i, x%i) end subroutine sub

34 35 36 37

& &

!-- ok because base_type is a public subobject of x !-- ok because x%base_type is ok and has k as a !-- public component. !-- ok because it is shorthand for x%base_type%k !-- Invalid because i is private. !-- Invalid because it is shorthand for x%base_type%i

38

C.3.3

39

Example of a derived type with generic type-bound procedures:

40 41

Generic type-bound procedures (7.5.5)

1 The only difference between this example and the same thing rewritten to use generic interface blocks is that

with type-bound procedures,

ISO/IEC JTC 1/SC 22/WG5/N2184

559

J3/21-007r1

3

2021-05-21

USE rational_numbers, ONLY: rational

1 2

WD 1539-1

does not block the type-bound procedures; the user still gets access to the defined assignment and extended operations. MODULE rational_numbers IMPLICIT NONE PRIVATE TYPE,PUBLIC :: rational PRIVATE INTEGER n,d CONTAINS ! ordinary type-bound procedure PROCEDURE :: real => rat_to_real ! specific type-bound procedures for generic support PROCEDURE,PRIVATE :: rat_asgn_i, rat_plus_i, rat_plus_rat => rat_plus PROCEDURE,PRIVATE,PASS(b) :: i_plus_rat ! generic type-bound procedures GENERIC :: ASSIGNMENT(=) => rat_asgn_i GENERIC :: OPERATOR(+) => rat_plus_rat, rat_plus_i, i_plus_rat END TYPE CONTAINS ELEMENTAL REAL FUNCTION rat_to_real(this) RESULT(r) CLASS(rational),INTENT(IN) :: this r = REAL(this%n)/this%d END FUNCTION ELEMENTAL SUBROUTINE rat_asgn_i(a,b) CLASS(rational),INTENT(INOUT) :: a INTEGER,INTENT(IN) :: b a%n = b a%d = 1 END SUBROUTINE ELEMENTAL TYPE(rational) FUNCTION rat_plus_i(a,b) RESULT(r) CLASS(rational),INTENT(IN) :: a INTEGER,INTENT(IN) :: b r%n = a%n + b*a%d r%d = a%d END FUNCTION ELEMENTAL TYPE(rational) FUNCTION i_plus_rat(a,b) RESULT(r) INTEGER,INTENT(IN) :: a CLASS(rational),INTENT(IN) :: b r%n = b%n + a*b%d r%d = b%d END FUNCTION ELEMENTAL TYPE(rational) FUNCTION rat_plus(a,b) RESULT(r) CLASS(rational),INTENT(IN) :: a,b r%n = a%n*b%d + b%n*a%d r%d = a%d*b%d

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

560

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2

4 5

J3/21-007r1

END FUNCTION END

1

3

WD 1539-1

C.3.4

Abstract types (7.5.7.1)

1 The following illustrates how an abstract type can be used as the basis for a collection of related types, and how

a non-abstract member of that collection can be created by type extension. TYPE, ABSTRACT :: DRAWABLE_OBJECT REAL, DIMENSION(3) :: RGB_COLOR = (/1.0,1.0,1.0/) ! White REAL, DIMENSION(2) :: POSITION = (/0.0,0.0/) ! Centroid CONTAINS PROCEDURE(RENDER_X), PASS(OBJECT), DEFERRED :: RENDER END TYPE DRAWABLE_OBJECT

6 7 8 9 10 11 12

ABSTRACT INTERFACE SUBROUTINE RENDER_X(OBJECT, WINDOW) IMPORT DRAWABLE_OBJECT, X_WINDOW CLASS(DRAWABLE_OBJECT), INTENT(IN) :: OBJECT CLASS(X_WINDOW), INTENT(INOUT) :: WINDOW END SUBROUTINE RENDER_X END INTERFACE

13 14 15 16 17 18 19 20

...

21 22

TYPE, EXTENDS(DRAWABLE_OBJECT) :: DRAWABLE_TRIANGLE ! Not ABSTRACT REAL, DIMENSION(2,3) :: VERTICES ! In relation to centroid CONTAINS PROCEDURE, PASS(OBJECT) :: RENDER=>RENDER_TRIANGLE_X END TYPE DRAWABLE_TRIANGLE

23 24 25 26 27

28

2 The actual drawing procedure will draw a triangle in WINDOW with vertices at x and y coordinates at

29

OBJECT%POSITION(1)+OBJECT%VERTICES(1,1:3) and OBJECT%POSITION(2)+OBJECT%VERTICES(2,1:3): SUBROUTINE RENDER_TRIANGLE_X(OBJECT, WINDOW) CLASS(DRAWABLE_TRIANGLE), INTENT(IN) :: OBJECT CLASS(X_WINDOW), INTENT(INOUT) :: WINDOW ... END SUBROUTINE RENDER_TRIANGLE_X

30 31 32 33 34

35 36 37 38 39

C.3.5

Structure constructors and generic names (7.5.10)

1 A generic name can be the same as a type name. This can be used to emulate user-defined structure constructors

for that type, even if the type has private components. For example: MODULE mytype_module TYPE mytype

ISO/IEC JTC 1/SC 22/WG5/N2184

561

J3/21-007r1

WD 1539-1

PRIVATE COMPLEX value LOGICAL exact END TYPE INTERFACE mytype MODULE PROCEDURE int_to_mytype END INTERFACE ! Operator definitions etc. ... CONTAINS TYPE(mytype) FUNCTION int_to_mytype(i) INTEGER,INTENT(IN) :: i int_to_mytype%value = i int_to_mytype%exact = .TRUE. END FUNCTION ! Procedures to support operators etc. ... END

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

PROGRAM example USE mytype_module TYPE(mytype) x x = mytype(17) END

20 21 22 23 24

25

2 The type name can still be used as a generic name if the type has type parameters. For example:

26

MODULE m TYPE t(kind) INTEGER, KIND :: kind COMPLEX(kind) value END TYPE INTEGER,PARAMETER :: single = KIND(0.0), double = KIND(0d0) INTERFACE t MODULE PROCEDURE real_to_t1, dble_to_t2, int_to_t1, int_to_t2 END INTERFACE ... CONTAINS TYPE(t(single)) FUNCTION real_to_t1(x) REAL(single) x real_to_t1%value = x END FUNCTION TYPE(t(double)) FUNCTION dble_to_t2(x) REAL(double) x dble_to_t2%value = x END FUNCTION TYPE(t(single)) FUNCTION int_to_t1(x,mold)

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

562

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2021-05-21

WD 1539-1

J3/21-007r1

INTEGER x TYPE(t(single)) mold int_to_t1%value = x END FUNCTION TYPE(t(double)) FUNCTION int_to_t2(x,mold) INTEGER x TYPE(t(double)) mold int_to_t2%value = x END FUNCTION ... END

1 2 3 4 5 6 7 8 9 10 11 12

PROGRAM example USE m TYPE(t(single)) x TYPE(t(double)) y x = t(1.5) x = t(17,mold=x) y = t(1.5d0) y = t(42,mold=y) y = t(kind(0d0)) ((0,1)) END

13 14 15 16 17 18 19 20 21 22

! References real_to_t1 ! References int_to_t1 ! References dble_to_t2 ! References int_to_t2 ! Uses the structure constructor for type t

23

C.3.6

24

Example of a parameterized derived type with final subroutines:

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

Final subroutines (7.5.6, 7.5.6.2, 7.5.6.3, 7.5.6.4)

MODULE m TYPE t(k) INTEGER, KIND :: k REAL(k),POINTER :: vector(:) => NULL() CONTAINS FINAL :: finalize_t1s, finalize_t1v, finalize_t2e END TYPE CONTAINS SUBROUTINE finalize_t1s(x) TYPE(t(KIND(0.0))) x IF (ASSOCIATED(x%vector)) DEALLOCATE(x%vector) END SUBROUTINE SUBROUTINE finalize_t1v(x) TYPE(t(KIND(0.0))) x(:) DO i=LBOUND(x,1),UBOUND(x,1) IF (ASSOCIATED(x(i)%vector)) DEALLOCATE(x(i)%vector) END DO END SUBROUTINE ELEMENTAL SUBROUTINE finalize_t2e(x) TYPE(t(KIND(0.0d0))),INTENT(INOUT) :: x

ISO/IEC JTC 1/SC 22/WG5/N2184

563

J3/21-007r1

WD 1539-1

IF (ASSOCIATED(x%vector)) DEALLOCATE(x%vector) END SUBROUTINE END MODULE

1 2 3 4

SUBROUTINE example(n) USE m TYPE(t(KIND(0.0))) a,b(10),c(n,2) TYPE(t(KIND(0.0d0))) d(n,n) ... ! Returning from this subroutine will effectively do ! CALL finalize_t1s(a) ! CALL finalize_t1v(b) ! CALL finalize_t2e(d) ! No final subroutine will be called for variable C because the user ! omitted to define a suitable specific procedure for it. END SUBROUTINE

5 6 7 8 9 10 11 12 13 14 15 16

17

Example of extended types with final subroutines: MODULE m TYPE t1 REAL a,b END TYPE TYPE,EXTENDS(t1) :: t2 REAL,POINTER :: c(:),d(:) CONTAINS FINAL :: t2f END TYPE TYPE,EXTENDS(t2) :: t3 REAL,POINTER :: e CONTAINS FINAL :: t3f END TYPE ... CONTAINS SUBROUTINE t2f(x) ! Finalizer for TYPE(t2)’s extra components TYPE(t2) :: x IF (ASSOCIATED(x%c)) DEALLOCATE(x%c) IF (ASSOCIATED(x%d)) DEALLOCATE(x%d) END SUBROUTINE SUBROUTINE t3f(y) ! Finalizer for TYPE(t3)’s extra components TYPE(t3) :: y IF (ASSOCIATED(y%e)) DEALLOCATE(y%e) END SUBROUTINE END MODULE

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

SUBROUTINE example

45

564

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2021-05-21

J3/21-007r1

USE m TYPE(t1) x1 TYPE(t2) x2 TYPE(t3) x3 ... ! Returning from this subroutine will effectively do ! ! Nothing to x1; it is not finalizable ! CALL t2f(x2) ! CALL t3f(x3) ! CALL t2f(x3%t2) END SUBROUTINE

1 2 3 4 5 6 7 8 9 10 11

12

WD 1539-1

C.4

Clause 8 notes: The VOLATILE attribute (8.5.20)

13

1 The following example shows the use of a variable with the VOLATILE attribute to communicate with an

14 15

asynchronous process, in this case the operating system. The program detects a user keystroke on the terminal and reacts at a convenient point in its processing.

16

2 The VOLATILE attribute is necessary to prevent an optimizing compiler from storing the communication variable

17 18 19

in a register or from doing flow analysis and deciding that the EXIT statement can never be executed. SUBROUTINE TERMINATE_ITERATIONS LOGICAL, VOLATILE :: USER_HIT_ANY_KEY

20 21 22 23

! Have the OS start to look for a user keystroke and set the variable ! "USER_HIT_ANY_KEY" to TRUE as soon as it detects a keystroke. ! This call is operating system dependent.

24 25 26 27

CALL OS_BEGIN_DETECT_USER_KEYSTROKE( USER_HIT_ANY_KEY ) USER_HIT_ANY_KEY = .FALSE. ! This will ignore any recent keystrokes. PRINT *, " Hit any key to terminate iterations!"

28 29 30 31 32 33

DO I = 1,100 . . . Compute a value for R. PRINT *, I, R IF (USER_HIT_ANY_KEY) ENDDO

EXIT

34 35 36 37

! Have the OS stop looking for user keystrokes. CALL OS_STOP_DETECT_USER_KEYSTROKE END SUBROUTINE TERMINATE_ITERATIONS

ISO/IEC JTC 1/SC 22/WG5/N2184

565

J3/21-007r1

WD 1539-1

1

C.5

Clause 9 notes

2

C.5.1

Structure components (9.4.2)

3 4

2021-05-21

1 Components of a structure are referenced by writing the components of successive levels of the structure hierarchy

until the desired component is described. For example, TYPE ID_NUMBERS INTEGER SSN INTEGER EMPLOYEE_NUMBER END TYPE ID_NUMBERS

5 6 7 8 9

TYPE PERSON_ID CHARACTER (LEN=30) LAST_NAME CHARACTER (LEN=1) MIDDLE_INITIAL CHARACTER (LEN=30) FIRST_NAME TYPE (ID_NUMBERS) NUMBER END TYPE PERSON_ID

10 11 12 13 14 15 16

TYPE PERSON INTEGER AGE TYPE (PERSON_ID) ID END TYPE PERSON

17 18 19 20 21

TYPE (PERSON) GEORGE, MARY

22 23

PRINT *, GEORGE % AGE ! Print the AGE component PRINT *, MARY % ID % LAST_NAME ! Print LAST_NAME of MARY PRINT *, MARY % ID % NUMBER % SSN ! Print SSN of MARY PRINT *, GEORGE % ID % NUMBER ! Print SSN and EMPLOYEE_NUMBER of GEORGE

24 25 26 27

28

2 A structure component can be a data object of intrinsic type as in the case of GEORGE % AGE or it can be

29

of derived type as in the case of GEORGE % ID % NUMBER. The resultant component can be a scalar or an array of intrinsic or derived type.

30

TYPE LARGE INTEGER ELT (10) INTEGER VAL END TYPE LARGE

31 32 33 34 35

TYPE (LARGE) A (5)

! 5 element array, each of whose elements ! includes a 10 element array ELT and ! a scalar VAL. PRINT *, A (1) ! Prints 10 element array ELT and scalar VAL. PRINT *, A (1) % ELT (3) ! Prints scalar element 3 ! of array element 1 of A. PRINT *, A (2:4) % VAL ! Prints scalar VAL for array elements ! 2 to 4 of A.

36 37 38 39 40 41 42 43

566

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

3 Components of an object of extensible type that are inherited from the parent type can be accessed as a whole

2

by using the parent component name, or individually, either with or without qualifying them by the parent component name. For example:

3

TYPE POINT ! A base type REAL :: X, Y END TYPE POINT TYPE, EXTENDS(POINT) :: COLOR_POINT ! An extension of TYPE(POINT) ! Components X and Y, and component name POINT, inherited from parent INTEGER :: COLOR END TYPE COLOR_POINT

4 5 6 7 8 9 10 11

TYPE(POINT), PARAMETER :: PV = POINT(1.0, 2.0) TYPE(COLOR_POINT) :: CPV = COLOR_POINT(POINT=PV, COLOR=3)

12 13 14

PRINT *, CPV%POINT PRINT *, CPV%POINT%X, CPV%POINT%Y PRINT *, CPV%X, CPV%Y

15 16 17

18

C.5.2

! Prints 1.0 and 2.0 ! And this does, too ! And this does, too

Allocation with dynamic type (9.7.1)

19

1 The following example illustrates the use of allocation with the value and dynamic type of the allocated object

20

given by another object. The example copies a list of objects of any type. It copies the list starting at IN_LIST. After copying, each element of the list starting at LIST_COPY has a polymorphic component, ITEM, for which both the value and type are taken from the ITEM component of the corresponding element of the list starting at IN_LIST.

21 22 23

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

TYPE :: LIST ! A list of anything TYPE(LIST), POINTER :: NEXT => NULL() CLASS(*), ALLOCATABLE :: ITEM END TYPE LIST ... TYPE(LIST), POINTER :: IN_LIST, LIST_COPY => NULL() TYPE(LIST), POINTER :: IN_WALK, NEW_TAIL ! Copy IN_LIST to LIST_COPY IF (ASSOCIATED(IN_LIST)) THEN IN_WALK => IN_LIST ALLOCATE(LIST_COPY) NEW_TAIL => LIST_COPY DO ALLOCATE(NEW_TAIL%ITEM, SOURCE=IN_WALK%ITEM) IN_WALK => IN_WALK%NEXT IF (.NOT. ASSOCIATED(IN_WALK)) EXIT ALLOCATE(NEW_TAIL%NEXT) NEW_TAIL => NEW_TAIL%NEXT END DO END IF

ISO/IEC JTC 1/SC 22/WG5/N2184

567

J3/21-007r1

WD 1539-1

1

C.6

Clause 10 notes

2

C.6.1

Evaluation of function references (10.1.7)

2021-05-21

3

1 If more than one function reference appears in a statement, they can be executed in any order (subject to a

4 5

function result being evaluated after the evaluation of its arguments) and their values cannot depend on the order of execution. This lack of dependence on order of evaluation enables parallel execution of the function references.

6

C.6.2

Pointers in expressions (10.1.9.2)

7

1 A data pointer is considered to be like any other variable when it is used as a primary in an expression. If a

8 9

pointer is used as an operand to an operator that expects a value, the pointer will automatically deliver the value stored in the space described by the pointer, that is, the value of the target object associated with the pointer.

10

C.6.3

11 12 13

Pointers in variable definition contexts (10.2.1.3, 19.6.7)

1 The appearance of a data pointer in a context that requires its value is a reference to its target. Similarly, where

a pointer appears in a variable definition context the variable that is defined is the target of the pointer. 2 Executing the program fragment

REAL, POINTER :: A REAL, TARGET :: B = 10.0 A => B A = 42.0 PRINT ’(F4.1)’, B

14 15 16 17 18 19

produces “42.0” as output.

20

C.7

Clause 11 notes

21

C.7.1

The SELECT CASE construct (11.1.9)

22

1 At most one case block is selected for execution within a SELECT CASE construct, and there is no fall-through

23 24

from one block into another block within a SELECT CASE construct. Thus there is no requirement for the user to exit explicitly from a block.

25

C.7.2

26

Loop control (11.1.7)

1 Fortran provides several forms of loop control:

27

(1)

With an iteration count and a DO variable. This is the classic Fortran DO loop.

28

(2)

Test a logical condition before each execution of the loop (DO WHILE).

29

(3)

DO “forever”.

30 31 32

C.7.3

Examples of DO constructs (11.1.7)

1 The following are all valid examples of DO constructs.

Example 1:

568

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11

40

12

WD 1539-1

J3/21-007r1

SUM = 0.0 READ (IUN) N OUTER: DO L = 1, N ! A DO with a construct name READ (IUN) IQUAL, M, ARRAY (1:M) IF (IQUAL < IQUAL_MIN) CYCLE OUTER ! Skip inner loop INNER: DO 40 I = 1, M ! A DO with a label and a name CALL CALCULATE (ARRAY (I), RESULT) IF (RESULT < 0.0) CYCLE SUM = SUM + RESULT IF (SUM > SUM_MAX) EXIT OUTER END DO INNER END DO OUTER

13

2 The outer loop has an iteration count of MAX (N, 0), and will execute that number of times or until SUM exceeds

14

18

SUM_MAX, in which case the EXIT OUTER statement terminates both loops. The inner loop is skipped by the first CYCLE statement if the quality flag, IQUAL, is too low. If CALCULATE returns a negative RESULT, the second CYCLE statement prevents it from being summed. Both loops have construct names and the inner loop also has a label. A construct name is required in the EXIT statement in order to terminate both loops, but is optional in the CYCLE statements because each belongs to its innermost loop.

19

Example 2:

15 16 17

20 21 22 23 24 25 26 27

28 29

50

3 After execution of the above program fragment, I = 11, J = 10, K = 6, L = 5, and N = 50.

Example 3:

30 31 32 33 34 35 36 37

38 39

N = 0 DO 50, I = 1, 10 J = I DO K = 1, 5 L = K N = N + 1 ! This statement executes 50 times END DO ! Nonlabeled DO inside a labeled DO CONTINUE

60

N = 0 DO I = 1, 10 J = I DO 60, K = 5, 1 L = K N = N + 1 CONTINUE END DO

! This inner loop is never executed

! Labeled DO inside a nonlabeled DO

4 After execution of the above program fragment, I = 11, J = 10, K = 5, N = 0, and L is not defined by these

statements.

ISO/IEC JTC 1/SC 22/WG5/N2184

569

J3/21-007r1

1 2 3

C.7.4

DO I = 1, 10 ... END DO LOOP

6

LOOP: DO 1000 I = 1, 10 ... 1000 CONTINUE

9 10

LOOP1: DO ... END DO LOOP2

13 14

DO I = 1, 10 ... 1010 CONTINUE

17 18

! Label required or . . . ! . . . END DO required

Example 5: DO 1020 I = 1, 10 ... 1021 END DO

20 21 22

! Labels don’t match

Example 6: FIRST: DO I = 1, 10 SECOND: DO J = 1, 5 ... END DO FIRST ! Improperly nested DOs END DO SECOND

24 25 26 27 28

29

! Construct names don’t match

Example 4:

16

23

! No matching construct name

Example 3:

12

19

! No matching construct name

Example 2:

8

15

Examples of invalid DO constructs (11.1.7)

Example 1:

5

11

2021-05-21

1 The following are all examples of invalid skeleton DO constructs:

4

7

WD 1539-1

C.7.5

Simple example using events

30

1 A tree is a graph in which every node except one has a single “parent” node to which it is connected by an edge.

31

The node without a parent is the “root” of the tree. The nodes that have a particular node as their parent are the “children” of that node. The root is at level 1, its children are at level 2, and so on.

32

570

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

2 A multifrontal code to solve a sparse set of linear equations involves a tree. Work at a node can start after all of

its children’s work is complete and their data have been passed to it.

3

3 Here we assume that each node has been assigned to an image. Each image has a list of its nodes and these

4

6

are ordered in decreasing tree level (all those at level L preceding those at level L − 1). For each node, array elements hold the number of children, details about the parent, and an event variable. This allows the processing to proceed asynchronously subject to the rule that a parent has to wait for all its children.

7

Outline of example code:

5

PROGRAM TREE USE, INTRINSIC :: ISO_FORTRAN_ENV INTEGER, ALLOCATABLE :: NODE (:) ! Tree nodes that this image handles. INTEGER, ALLOCATABLE :: NC (:) ! NODE(I) has NC(I) children. INTEGER, ALLOCATABLE :: PARENT (:), SUB (:) ! The parent of NODE (I) is NODE (SUB (I)) [PARENT (I)]. TYPE (EVENT_TYPE), ALLOCATABLE :: DONE (:) [:] INTEGER :: I, J, STATUS ! Set up the tree, including allocation of all arrays. DO I = 1, SIZE (NODE) ! Wait for children to complete IF (NC (I) > 0) THEN EVENT WAIT (DONE (I), UNTIL_COUNT=NC (I), STAT=STATUS) IF (STATUS/=0) EXIT END IF

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

! Process node, using data from children. IF (PARENT (I)>0) THEN ! Node is not the root. ! Place result on image PARENT (I) for node NODE (SUB) [PARENT (I)] ! Tell PARENT (I) that this has been done. EVENT POST (DONE (SUB (I)) [PARENT (I)], STAT=STATUS) IF (STATUS/=0) EXIT END IF END DO END PROGRAM TREE

24 25 26 27 28 29 30 31 32 33

34

C.7.6

Example using three teams

35

1 The following example illustrates the structure of a routine that will compute fluxes based on surface properties

36

over land, sea, and ice, each in a different team. Each image will deal with areas containing exactly one of the three surface types.

37 38 39 40 41 42

SUBROUTINE COMPUTE_FLUXES (FLUX_MOM, FLUX_SENS, FLUX_LAT) USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE REAL, INTENT (OUT) :: FLUX_MOM (:,:), FLUX_SENS (:,:), FLUX_LAT (:,:) INTEGER, PARAMETER :: LAND = 1, SEA = 2, ICE = 3 CHARACTER (LEN=10) :: SURFACE_TYPE

ISO/IEC JTC 1/SC 22/WG5/N2184

571

J3/21-007r1

INTEGER TYPE (TEAM_TYPE)

1 2

WD 1539-1

2021-05-21

:: MY_SURFACE_TYPE, N_IMAGE :: TEAM_SURFACE_TYPE

3

CALL GET_SURFACE_TYPE(THIS_IMAGE (), SURFACE_TYPE) SELECT CASE (SURFACE_TYPE) CASE ("LAND") MY_SURFACE_TYPE = LAND CASE ("SEA") MY_SURFACE_TYPE = SEA CASE ("ICE") MY_SURFACE_TYPE = ICE CASE DEFAULT ERROR STOP END SELECT FORM TEAM (MY_SURFACE_TYPE, TEAM_SURFACE_TYPE)

4 5 6 7 8 9 10 11 12 13 14 15 16

CHANGE TEAM (TEAM_SURFACE_TYPE) SELECT CASE (TEAM_NUMBER ( )) CASE (LAND) ! Compute fluxes over land surface CALL COMPUTE_FLUXES_LAND (FLUX_MOM, FLUX_SENS, FLUX_LAT) CASE (SEA) ! Compute fluxes over sea surface CALL COMPUTE_FLUXES_SEA (FLUX_MOM, FLUX_SENS, FLUX_LAT) CASE (ICE) ! Compute fluxes over ice surface CALL COMPUTE_FLUXES_ICE (FLUX_MOM, FLUX_SENS, FLUX_LAT) CASE DEFAULT ERROR STOP END SELECT END TEAM END SUBROUTINE COMPUTE_FLUXES

17 18 19 20 21 22 23 24 25 26 27 28 29

30 31

C.7.7

Accessing coarrays in sibling teams

1 The following program illustrates subdividing a 4 × 4 grid into 2 × 2 teams, and the denotation of sibling teams.

PROGRAM DEMO ! Initial team : 16 images. Algorithm design is a 4 by 4 grid. ! Desire 4 teams, for the upper left (UL), upper right (UR), ! lower left (LL), lower right (LR) USE,INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE TYPE (TEAM_TYPE) :: T INTEGER, PARAMETER :: UL=11, UR=22, LL=33, LR=44 REAL :: A(10,10)[4,*] INTEGER :: MYPE, TEAMNUM, NEWPE TYPE TRANS_T INTEGER :: NEW_TEAM (16), NEW_INDEX (16) END TYPE TYPE (TRANS_T) :: TRANS

32 33 34 35 36 37 38 39 40 41 42 43 44

572

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

TRANS = TRANS_T ([UL, UL, LL, LL, UL, UL, LL, LL, UR, UR, LR, LR, UR, UR, LR, LR], & [1, 2, 1, 2, 3, 4, 3, 4, 1, 2, 1, 2, 3, 4, 3, 4])

1 2 3

MYPE = THIS_IMAGE () FORM TEAM (TRANS%NEW_TEAM(MYPE), T, NEW_INDEX=TRANS%NEW_INDEX(MYPE))

4 5 6

A = 3.14

7 8

CHANGE TEAM (T, B[2,*] => A) ! Inside change team, image pattern for B is a 2 by 2 grid. B (5, 5) = B (1, 1)[2, 1]

9 10 11 12

! Outside the team addressing:

13 14

NEWPE = THIS_IMAGE () SELECT CASE (TEAM_NUMBER ()) CASE (UL) IF (NEWPE==3) THEN ! Right column of UL gets left column of UR. B (:, 10) = B (:, 1)[1, 1, TEAM_NUMBER=UR] ELSE IF (NEWPE==4) THEN B (:, 10) = B (:, 1)[2, 1, TEAM_NUMBER=UR] END IF CASE (LL) ! Similar to complete column exchange across middle of the original grid. ... END SELECT END TEAM END PROGRAM DEMO

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

30

C.7.8

Example involving failed images

31

1 Parallel algorithms often use work sharing schemes based on a specific mapping between image indices and global

32

34

data addressing. To allow such programs to continue when one or more images fail, spare images can be used to re-establish execution of the algorithm with the failed images replaced by spare images, while retaining the previous image mapping for nonfailed images.

35

2 The following example illustrates how this might be done. In this example, failure cannot be tolerated for image

33

36 37 38 39 40 41 42 43

1 in the initial team. PROGRAM possibly_recoverable_simulation USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE, STAT_FAILED_IMAGE IMPLICIT NONE INTEGER, ALLOCATABLE :: failures (:) INTEGER :: images_used, i, images_spare, status, k INTEGER :: id [*], me [*] TYPE (TEAM_TYPE) :: simulation_team

ISO/IEC JTC 1/SC 22/WG5/N2184

573

J3/21-007r1

WD 1539-1

2021-05-21

LOGICAL :: read_checkpoint, done [*]

1 2

! Keep 1% spare images if we have a lot, just 1 if 10-199 images, 0 if <10. images_spare = MAX (INT (0.01*NUM_IMAGES ()), 0, MIN (NUM_IMAGES () - 10, 1)) images_used = NUM_IMAGES () - images_spare read_checkpoint = THIS_IMAGE () > images_used

3 4 5 6 7

setup : DO me = THIS_IMAGE () id = MERGE (1, 2, me<=images_used) ! ! Set up spare images as replacement for failed ones. ! IF (IMAGE_STATUS (1) == STAT_FAILED_IMAGE) & ERROR STOP "cannot recover" IF (me == 1) THEN failures = FAILED_IMAGES () k = images_used DO i = 1, SIZE (failures) DO k = k+1, NUM_IMAGES () IF (IMAGE_STATUS (k) == 0) EXIT END DO IF (k > NUM_IMAGES ()) ERROR STOP "cannot recover" me [k] = failures (i) id [k] = 1 END DO images_used = k END IF ! ! Set up a simulation team of constant size. ! Team 2 is the set of spares, so does not participate in the simulation. ! FORM TEAM (id, simulation_team, NEW_INDEX=me, STAT=status) simulation : CHANGE TEAM (simulation_team, STAT=status) IF (status == STAT_FAILED_IMAGE) EXIT simulation IF (TEAM_NUMBER () == 1) THEN iter : DO CALL simulation_procedure (read_checkpoint, status, done) ! The simulation_procedure: ! - sets up and performs some part of the simulation; ! - resets to the last checkpoint if requested; ! - sets status from its internal synchronizations; ! - sets done to .TRUE. when the simulation has completed. IF (status == STAT_FAILED_IMAGE) THEN read_checkpoint = .TRUE. EXIT simulation

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

574

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

ELSE IF (done) THEN EXIT iter END IF read_checkpoint = .FALSE. END DO iter END IF END TEAM (STAT=status) simulation SYNC ALL (STAT=status) IF (THIS_IMAGE () > images_used) done = done[1] IF (done) EXIT setup END DO setup END PROGRAM possibly_recoverable_simulation

1 2 3 4 5 6 7 8 9 10 11 12

13

3 Supporting fault-tolerant execution imposes obligations on library writers who use the parallel language facilities.

14

16

Every synchronization statement, allocation or deallocation of coarrays, or invocation of a collective procedure will need to be prepared to handle error conditions, and implicit deallocation of coarrays will need to be avoided. Also, coarray module variables that are allocated inside the team execution context are not persistent.

17

C.7.9

15

EVENT_QUERY example that tolerates image failure

18

1 This example is an adaptation of the later EVENT_QUERY example of C.12.2 to make it able to execute in

19

the presence of the failure of one or more of the worker images. The function create_work_item now accepts an integer argument to indicate which work item is required. It is assumed that the work items are indexed 1, 2, and so on. It is also assumed that if an image fails while processing a work item, that work item can subsequently be processed by another image.

20 21 22 23 24 25 26 27 28 29 30

PROGRAM work_share USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: EVENT_TYPE USE :: mod_work, ONLY: & ! Module that creates work items work, & ! Type for holding a work item create_work_item, & ! Function that creates work item process_item, & ! Function that processes an item work_done ! Logical function that returns true ! if all work done

31 32 33 34 35 36 37 38 39 40

TYPE :: worker_type TYPE (EVENT_TYPE), ALLOCATABLE :: free (:) END TYPE TYPE (EVENT_TYPE) :: submit [*] ! Whether work ready for a worker TYPE (worker_type) :: worker [*] ! Whether worker is free TYPE (work) :: work_item [*] ! Holds the data for a work item INTEGER :: count, i, k, kk, nbusy [*], np, status INTEGER, ALLOCATABLE :: working (:) ! Items being worked on INTEGER, ALLOCATABLE :: pending (:) ! Items pending after image failure

41 42 43

IF (THIS_IMAGE () == 1) THEN ! Get started

ISO/IEC JTC 1/SC 22/WG5/N2184

575

J3/21-007r1

WD 1539-1

ALLOCATE (worker%free (2:NUM_IMAGES ())) ALLOCATE (working (2: NUM_IMAGES ()), pending(NUM_IMAGES ()-1)) nbusy = 0 ! This holds the number of workers working k = 1 ! Index of next work item np = 0 ! Number of work items in array pending DO i = 2, NUM_IMAGES () ! Start the workers working IF (work_done ()) EXIT working (i) = 0 IF (IMAGE_STATUS (i) == STAT_FAILED_IMAGE) CYCLE work_item [i] = create_work_item (k) working (i) = k k = k + 1 nbusy = nbusy + 1 EVENT POST (submit [i], STAT=status) END DO ! Main work distribution loop master : DO image : DO i = 2, NUM_IMAGES () IF (IMAGE_STATUS (i) == STAT_FAILED_IMAGE) THEN IF (working (i)>0) THEN ! It failed while working np = np + 1 pending (np) = working (i) working (i) = 0 END IF CYCLE image END IF CALL EVENT_QUERY (worker%free (i), count) IF (count == 0) CYCLE image ! Worker is not free EVENT WAIT (worker%free (i)) nbusy = nbusy - 1 IF (np>0) THEN kk = pending (np) np = np - 1 ELSE IF (work_done ()) CYCLE image kk = k k = k + 1 END IF nbusy = nbusy + 1 working (i) = kk work_item [i] = create_work_item (kk) EVENT POST (submit [i], STAT=status) ! If image i has failed, the failure will be handled on ! the next iteration of the master loop. END DO image IF ( nbusy==0 ) THEN ! All done. Exit on all images.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

576

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2021-05-21

WD 1539-1

DO i = 2, NUM_IMAGES () EVENT POST (submit [i], STAT=status) IF (status == STAT_FAILED_IMAGE) CYCLE END DO EXIT master END IF END DO master ELSE ! Work processing loop worker : DO EVENT WAIT (submit) IF (nbusy [1] == 0) EXIT worker CALL process_item(work_item) EVENT POST (worker[1]%free (THIS_IMAGE ())) END DO worker END IF END PROGRAM work_share

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

18

C.8

Clause 12 notes

19

C.8.1

External files (12.3)

20

C.8.1.1

File cataloging

21 22

J3/21-007r1

1 This document accommodates, but does not require, file cataloging. To do this, several concepts are introduced.

C.8.1.2

File existence (12.3.2)

23

1 Totally independent of the connection state is the property of existence, this being a file property. The processor

24

“knows” of a set of files that exist at a given time for a given program. This set would include tapes ready to read, files in a catalog, a keyboard, a printer, etc. The set might exclude files inaccessible to the program because of security, because they are already in use by another program, etc. This document does not specify which files exist, hence wide latitude is available to a processor to implement security, locks, privilege techniques, etc. Existence is a convenient concept to designate all of the files that a program can potentially process.

25 26 27 28 29

30

2 All four combinations of connection and existence can occur:

Connect

Exist

Examples

Yes

Yes

A card reader loaded and ready to be read

Yes

No

A printer before the first line is written

No

Yes

A file named ’JOAN’ in the catalog

No

No

A file on a reel of tape, not known to the processor

3 Means are provided to create, delete, connect, and disconnect files.

ISO/IEC JTC 1/SC 22/WG5/N2184

577

J3/21-007r1

1

C.8.1.3

WD 1539-1

2021-05-21

File access (12.3.3)

2

1 This document does not address problems of security, protection, locking, and many other concepts that might

3

be part of the concept of “right of access”. Such concepts are considered to be in the province of an operating system.

4 5

2 The OPEN and INQUIRE statements can be extended naturally to consider these things.

6

3 Possible access methods for a file are: sequential, stream and direct. The processor might implement three

7 8

different types of files, each with its own access method. It might instead implement one type of file with three different access methods.

9

4 Direct access to files is of a simple and commonly available type, that is, fixed-length records. The key is a

10

positive integer.

11

C.8.1.4

File connection (12.5)

12

1 Before any input/output can be performed on a file, it needs to be connected to a unit. The unit then serves as a

13

16

designator for that file as long as it is connected. To be connected does not imply that “buffers” have or have not been allocated, that “file-control tables” have or have not been filled, or that any other method of implementation has been used. Connection means that (barring some other fault) a READ or WRITE statement can be executed on the unit, hence on the file. Without a connection, a READ or WRITE statement cannot be executed.

17

C.8.1.5

14 15

File names (12.5.6.10)

18

1 A file can have a name. The form of a file name is not specified. If a system does not have some form of cataloging

19

22

or tape labeling for at least some of its files, all file names disappear at the termination of execution. This is a valid implementation. Nowhere does this document require names to survive for any period of time longer than the execution time span of a program. Therefore, this document does not impose cataloging as a prerequisite. The naming feature is intended to enable use of a cataloging system where one exists.

23

C.8.2

20 21

Nonadvancing input/output (12.3.4.2)

24

1 Data transfer statements affect the positioning of an external file. In Fortran 77, if no error or end-of-file

25

29

condition exists, the file is positioned after the record just read or written and that record becomes the preceding record. This document contains the ADVANCE= specifier in a data transfer statement that provides the capability of maintaining a position within the current record from one formatted data transfer statement to the next data transfer statement. The value NO provides this capability. The value YES positions the file after the record just read or written. The default is YES.

30

2 The tab edit descriptor and the slash are still appropriate for use with this type of record access but the tab

26 27 28

31 32 33

cannot reposition before the left tab limit. 3 A BACKSPACE of a file that is positioned within a record causes the specified unit to be positioned before the

current record.

34

4 If the next input/output operation on a file after a nonadvancing write is a rewind, backspace, end file or close

35

operation, the file is positioned implicitly after the current record before an ENDFILE record is written to the file, that is, a REWIND, BACKSPACE, or ENDFILE statement following a nonadvancing WRITE statement causes the file to be positioned at the end of the current output record before the endfile record is written to the

36 37

578

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

J3/21-007r1

file.

2

5 This document provides a SIZE= specifier to be used with formatted data transfer statements. The variable in

3 4

the SIZE= specifier is assigned the count of the number of characters that make up the sequence of values read by the data edit descriptors in the input statement.

5

6 The count is especially helpful if there is only one list item in the input list because it is the number of characters

6

that appeared for the item.

7

7 The EOR= specifier is provided to indicate when an EOR condition is encountered during a nonadvancing data

8

17

transfer statement. The EOR condition is not an error condition. If this specifier appears, an input list item that requires more characters than the record contained is padded with blanks if PAD= ’YES’ is in effect. This means that the input list item completed successfully. The file is positioned after the current record. If the IOSTAT= specifier appears, the specified variable is defined with the value of the named constant IOSTAT_EOR from the intrinsic module ISO_FORTRAN_ENV and the data transfer statement is terminated. Program execution continues with the statement specified in the EOR= specifier. The EOR= specifier gives the capability of taking control of execution when the EOR condition is encountered. The do-variables in io-implied-dos retain their last defined value and any remaining items in the input-item-list retain their definition status when an EOR condition occurs. If the SIZE= specifier appears, the specified variable is assigned the number of characters read with the data edit descriptors during the READ statement.

18

8 For nonadvancing input, the processor is not required to read partial records. The processor could read the entire

19

record into an internal buffer and make successive portions of the record available to successive input statements.

20

9 In an implementation of nonadvancing input/output in which a nonadvancing write to a terminal device causes

21

immediate display of the output, such a write can be used as a mechanism to output a prompt. In this case, the statement

9 10 11 12 13 14 15 16

22

WRITE (*, FMT=’(A)’, ADVANCE=’NO’) ’CONTINUE?(Y/N): ’

23 24

would result in the prompt

25

CONTINUE?(Y/N):

26 27

being displayed with no subsequent line feed. 10 The response, which might be read by a statement of the form

READ (*, FMT=’(A)’) ANSWER

28 29

can then be entered on the same line as the prompt as in CONTINUE?(Y/N): Y

30

31

11 This document does not require that an implementation of nonadvancing input/output operate in this manner.

32

34

For example, an implementation of nonadvancing output in which the display of the output is deferred until the current record is complete is also standard-conforming. Such an implementation will not, however, allow a prompting mechanism of this kind to operate.

35

C.8.3

33

OPEN statement (12.5.6)

36

1 A file can become connected to a unit either by preconnection or by execution of an OPEN statement. Precon-

37

nection is performed prior to the beginning of execution of a program by means external to Fortran. For example,

ISO/IEC JTC 1/SC 22/WG5/N2184

579

J3/21-007r1

WD 1539-1

2021-05-21

2

it could be done by job control action or by processor-established defaults. Execution of an OPEN statement is not required in order to access preconnected files (12.5.5).

3

2 The OPEN statement provides a means to access existing files that are not preconnected. An OPEN statement

4

6

can be used in either of two ways: with a file name (open-by-name) and without a file name (open-by-unit). A unit is given in either case. Open-by-name connects the specified file to the specified unit. Open-by-unit connects a processor-dependent default file to the specified unit. (The default file might or might not have a name.)

7

3 Therefore, there are three ways a file can become connected and hence processed: preconnection, open-by-name,

8 9

and open-by-unit. Once a file is connected, there is no means in standard Fortran to determine how it became connected.

10

4 An OPEN statement can also be used to create a new file. In fact, any of the foregoing three connection methods

11 12

can be performed on a file that does not exist. When a unit is preconnected, writing the first record creates the file. With the other two methods, execution of the OPEN statement creates the file.

13

5 When an OPEN statement is executed, the unit specified in the OPEN statement might or might not already be

14

17

connected to a file. If it is already connected to a file (either through preconnection or by prior execution of an OPEN statement), then omitting the FILE= specifier in the OPEN statement implies that the file is to remain connected to the unit. Such an OPEN statement can be used to change the values of the blank interpretation mode, decimal edit mode, pad mode, input/output rounding mode, delimiter mode, and sign mode.

18

6 If the value of the ACTION= specifier is WRITE, then a READ statement cannot refer to the connection.

19

21

ACTION = ’WRITE’ does not restrict positioning by a BACKSPACE statement or positioning specified by the POSITION= specifier with the value APPEND. However, a BACKSPACE statement or an OPEN statement containing POSITION = ’APPEND’ might fail if the processor needs to read the file to achieve the positioning.

22

7 The following examples illustrate these rules. In the first example, unit 10 is preconnected to a SCRATCH file;

1

5

15 16

20

23

the OPEN statement changes the value of PAD= to YES. CHARACTER (LEN = 20) CH1 WRITE (10, ’(A)’) ’THIS IS RECORD 1’ OPEN (UNIT = 10, STATUS = ’OLD’, PAD = ’YES’) REWIND 10 READ (10, ’(A20)’) CH1 ! CH1 now has the value ! ’THIS IS RECORD 1 ’

24 25 26 27 28 29

30

8 In the next example, unit 12 is first connected to a file named FRED, with a status of OLD. The second OPEN

31

statement then opens unit 12 again, retaining the connection to the file FRED, but changing the value of the DELIM= specifier to QUOTE.

32

CHARACTER (LEN = 25) CH2, CH3 OPEN (12, FILE = ’FRED’, STATUS = ’OLD’, DELIM = ’NONE’) CH2 = ’"THIS STRING HAS QUOTES."’ ! Quotes in string CH2 WRITE (12, *) CH2 ! Written with no delimiters OPEN (12, DELIM = ’QUOTE’) ! Now quote is the delimiter REWIND 12 READ (12, *) CH3 ! CH3 now has the value ! ’THIS STRING HAS QUOTES. ’

33 34 35 36 37 38 39 40 41

580

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

9 The next example is invalid because it attempts to change the value of the STATUS= specifier.

4

OPEN (10, FILE = ’FRED’, STATUS = ’OLD’) WRITE (10, *) A, B, C OPEN (10, STATUS = ’SCRATCH’) ! Attempts to make FRED a SCRATCH file

5

10 The previous example could be made valid by closing the unit first, as in the next example.

2 3

OPEN (10, FILE = ’FRED’, STATUS = ’OLD’) WRITE (10, *) A, B, C CLOSE (10) OPEN (10, STATUS = ’SCRATCH’) ! Opens a different SCRATCH file

6 7 8 9

10 11 12

J3/21-007r1

C.8.4

Connection properties (12.5.4)

1 When a unit becomes connected to a file, either by execution of an OPEN statement or by preconnection, the

following connection properties, among others, are established.

13

(1)

An access method, which is sequential, direct, or stream, is established for the connection (12.5.6.3).

14

(2)

A form, which is formatted or unformatted, is established for a connection to a file that exists or is created by the connection. For a connection that results from execution of an OPEN statement, a default form (which depends on the access method, as described in 12.3.3) is established if no form is specified. For a preconnected file that exists, a form is established by preconnection. For a preconnected file that does not exist, a form might be established, or the establishment of a form might be delayed until the file is created (for example, by execution of a formatted or unformatted WRITE statement) (12.5.6.11).

(3)

A record length might be established. If the access method is direct, the connection establishes a record length that specifies the length of each record of the file. A direct access file can only contain records that are all of equal length.

(4)

25

A sequential file can contain records of varying lengths. In this case, the record length established specifies the maximum length of a record in the file (12.5.6.16).

26

2 A processor has wide latitude in adapting these concepts and actions to its own cataloging and job control

27

30

conventions. Some processors might need job control action to specify the set of files that exist or that will be created by a program. Some processors might not need any job control action prior to execution. This document enables processors to perform dynamic open, close, or file creation operations, but it does not require such capabilities of the processor.

31

3 The meaning of “open” in contexts other than Fortran might include such things as mounting a tape, console

32

35

messages, spooling, label checking, security checking, etc. These actions might occur upon job control action external to Fortran, upon execution of an OPEN statement, or upon execution of the first read or write of the file. The OPEN statement describes properties of the connection to the file and might or might not cause physical activities to take place.

36

C.8.5

15 16 17 18 19 20 21 22 23 24

28 29

33 34

Asynchronous input/output (12.6.2.5)

37

1 Rather than limit support for asynchronous input/output to what has been traditionally provided by facilities

38

such as BUFFERIN/BUFFEROUT, this document builds upon existing Fortran syntax. This permits alternative

ISO/IEC JTC 1/SC 22/WG5/N2184

581

J3/21-007r1

WD 1539-1

2021-05-21

2

approaches for implementing asynchronous input/output, and simplifies the task of adapting existing standardconforming programs to use asynchronous input/output.

3

2 Not all processors actually perform input/output asynchronously, nor will every processor that does be able to

4

handle data transfer statements with complicated input/output item lists in an asynchronous manner. Such processors can still be standard-conforming.

1

5 6

3 This document allows for at least two different conceptual models for asynchronous input/output.

7

4 Model 1: the processor performs asynchronous input/output when the item list is simple (perhaps one contiguous

8

named array) and the input/output is unformatted. The implementation cost is reduced, and this is the scenario most likely to be beneficial on traditional “big-iron” machines.

9 10

5 Model 2: The processor is free to do any of the following:

(1)

on output, create a buffer inside the input/output library, completely formatted, and then start an asynchronous write of the buffer, and immediately return to the next statement in the program. The processor is free to wait for previously issued WRITEs, or not, or

(2)

17

pass the input/output list addresses to another processor/process, which processes the list items independently of the processor that executes the user’s code. The addresses of the list items will need to be computed before the asynchronous READ/WRITE statement completes. There is still an ordering requirement on list item processing to handle things like READ (. . . ) N,(a(i),i=1,N).

18

6 A program can issue a large number of asynchronous input/output requests, without waiting for any of them to

19 20

complete, and then wait for any or all of them. That does not constitute a requirement for the processor to keep track of each individual request separately.

21

7 It is not necessary for all requests to be tracked by the runtime library. If an ID= specifier does not appear in on a

22

READ or WRITE statement, the runtime library can forget about this particular request once it has successfully completed. If an error or end-of-file condition occurs for a request, the processor can report this during any input/output operation to that unit. If an ID= specifier appears, the processor’s runtime input/output library will need to keep track of any end-of-file or error conditions for that particular input/output request. However, if the input/output request succeeds without any exceptional conditions occurring, then the runtime can forget that ID= value. A runtime library might only keep track of the last request made, or perhaps a very few. Then, when a user WAITs for a particular request, either the library will know about it (and does the right thing with respect to error handling, etc.), or can assume it is a request that successfully completed and was forgotten about (and will just return without signaling any end-of-file or error condition). A standard-conforming program can only pass valid ID= values, but there is no requirement on the processor to detect invalid ID= values. There might be a processor dependent limit on how many outstanding input/output requests that generate an end-of-file or error condition can be handled before the processor runs out of memory to keep track of such conditions. The restrictions on the SIZE= variables are designed to enable the processor to update such variables at any time (after the request has been processed, but before the wait operation), and then forget about them. Only error and end-of-file conditions are expected to be tracked by individual request by the runtime, and then only if an ID= specifier appears. The END= and EOR= specifiers have not been added to all statements that can perform wait operations. Instead, the IOSTAT variable can be queried after a wait operation to handle this situation. This choice was made because the WAIT statement is expected to be the usual method of waiting for input/output to complete (and WAIT does support the END= and EOR= specifiers). This particular choice is philosophical, and was not based on significant technical difficulties.

11 12 13 14 15 16

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

582

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

8 The requirement to set the IOSTAT variable correctly means that a processor will need to remember which

2

5

input/output requests encountered an end-of-record condition, so that a subsequent wait operation can return the correct IOSTAT value. Therefor there might be a processor defined limit on the number of outstanding nonadvancing input/output requests that have encountered an end-of-record condition (constrained by available memory to keep track of this information, similar to end-of-file and error conditions).

6

C.9

Clause 13 notes

7

C.9.1

Number of records (13.4, 13.5, 13.8.2)

3 4

8

1 The number of records read by an explicitly formatted advancing input statement can be determined from the

9

11

following rule: a record is read at the beginning of the format scan (even if the input list is empty unless the most recently previous operation on the unit was not a nonadvancing read operation), at each slash edit descriptor encountered in the format, and when a format rescan occurs at the end of the format.

12

2 The number of records written by an explicitly formatted advancing output statement can be determined from

13

the following rule: a record is written when a slash edit descriptor is encountered in the format, when a format rescan occurs at the end of the format, and at completion of execution of an advancing output statement (even if the output list is empty). Thus, the occurrence of n successive slashes between two other edit descriptors causes n − 1 blank lines if the records are printed. The occurrence of n slashes at the beginning or end of a complete format specification causes n blank lines if the records are printed. However, a complete format specification containing n slashes (n > 0) and no other edit descriptors causes n + 1 blank lines if the records are printed. For example, the statements

10

14 15 16 17 18 19 20 21

PRINT 3 3 FORMAT (/)

22

will write two records that cause two blank lines if the records are printed.

23

C.9.2

List-directed input (13.10.3)

24

1 The following examples illustrate list-directed input. A blank character is represented by b.

25

2 Example 1:

26

Program:

27 28 29

30 31 32

J = 3 READ *, I READ *, J Sequential input file: record 1: record 2:

b1b,4bbbbb ,2bbbbbbbb

33

3 Result: I = 1, J = 3.

34

4 Explanation: The second READ statement reads the second record. The initial comma in the record designates

35

a null value; therefore, J is not redefined.

ISO/IEC JTC 1/SC 22/WG5/N2184

583

J3/21-007r1

1

5 Example 2:

2

Program:

2021-05-21

CHARACTER A *8, B *1 READ *, A, B

3 4

5

WD 1539-1

Sequential input file: record 1: record 2:

6 7

’bbbbbbbb’ ’QXY’b’Z’

8

6 Result: A = ’bbbbbbbb’, B = ’Q’

9

7 Explanation: In the first record, the rightmost apostrophe is interpreted as delimiting the constant (it cannot

10

13

be the first of a pair of embedded apostrophes representing a single apostrophe because this would involve the prohibited “splitting” of the pair by the end of a record); therefore, A is assigned the character constant ’bbbbbbbb’. The end of a record acts as a blank, which in this case is a value separator because it occurs between two constants.

14

C.10

Clause 14 notes

15

C.10.1

Main program and block data program unit (14.1, 14.3)

11 12

16 17

1 The name of the main program or of a block data program unit has no explicit use within the Fortran language.

It is available for documentation and for possible use by a processor.

18

2 A processor might implement an unnamed program unit by assigning it a global identifier that is not used

19 20

elsewhere in the program. This could be done by using a default name that does not satisfy the rules for Fortran names.

21

C.10.2

Dependent compilation (14.2)

22

C.10.2.1

Separate translation

23

1 This document, like its predecessors, is intended to enable the implementation of conforming processors in which

24

33

a program can be broken into multiple units, each of which can be separately translated in preparation for execution. Such processors are commonly described as supporting separate compilation. There is an important difference between the way separate compilation can be implemented under this document and the way it could be implemented under the Fortran 77 International Standard. Under the Fortran 77 standard, any information required to translate a program unit was specified in that program unit. Each translation was thus totally independent of all others. Under this document, a program unit can use information that was specified in a separate module and thus can be dependent on that module. The implementation of this dependency in a processor might be that the translation of a program unit depends on the results of translating one or more modules. Processors implementing the dependency this way are commonly described as supporting dependent compilation.

34

2 The dependencies involved here are new only in the sense that the Fortran processor is now aware of them. The

35

same information dependencies existed under the Fortran 77 International Standard, but it was the program-

25 26 27 28 29 30 31 32

584

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

mer’s responsibility to transport the information necessary to resolve them by making redundant specifications of the information in multiple program units. The availability of separate but dependent compilation offers several potential advantages over the redundant textual specification of information. (1)

Specifying information at a single place in the program ensures that different program units using that information are translated consistently. Redundant specification leaves the possibility that different information can be erroneously be specified. Even if an INCLUDE line is used to ensure that the text of the specifications is identical in all involved program units, the presence of other specifications (for example, an IMPLICIT statement) could change the interpretation of that text.

(2)

During the revision of a program, it is possible for a processor to assist in determining whether different program units have been translated using different (incompatible) versions of a module, although there is no requirement that a processor provide such assistance. Inconsistencies in redundant textual specification of information, on the other hand, tend to be much more difficult to detect.

(3)

Putting information in a module provides a way of packaging it. Without modules, redundant specifications frequently are interleaved with other specifications in a program unit, making convenient packaging of such information difficult.

(4)

18

Because a processor can be implemented such that the specifications in a module are translated once and then repeatedly referenced, there is the potential for greater efficiency than when the processor translates redundant specifications of information in multiple program units.

19

3 The exact meaning of the requirement that the public portions of a module be available at the time of reference

20

22

is processor dependent. For example, a processor could consider a module to be available only after it has been compiled and require that if the module has been compiled separately, the result of that compilation be identified to the compiler when compiling program units that use it.

23

C.10.2.2

4 5 6 7 8 9 10 11 12 13 14 15 16 17

21

USE statement and dependent compilation (14.2.2)

24

1 Another benefit of the USE statement is its enhanced facilities for name management. If one needs to use only

25

32

selected entities in a module, one can do so without having to worry about the names of all the other entities in that module. If one needs to use two different modules that happen to contain entities with the same name, there are several ways to deal with the conflict. If none of the entities with the same name are to be used, they can simply be ignored. If the name happens to refer to the same entity in both modules (for example, if both modules obtained it from a third module), then there is no confusion about what the name denotes and the name can be freely used. If the entities are different and one or both is to be used, the local renaming facility in the USE statement makes it possible to give those entities different names in the program unit containing the USE statements.

33

2 A benefit of using the ONLY option consistently, as compared to USE without it, is that the module from which

34 35

each accessed entity is accessed is explicitly specified in each program unit. This means that one need not search other program units to find where each one is defined. This reduces maintenance costs.

36

3 A typical implementation of dependent but separate compilation might involve storing the result of translating a

37

39

module in a file whose name is derived from the name of the module. Note, however, that the name of a module is limited only by the Fortran rules and not by the names allowed in the file system. Thus the processor might have to provide a mapping between Fortran names and file system names.

40

4 The result of translating a module could reasonably either contain only the information textually specified in the

41

module (with “pointers” to information originally textually specified in other modules) or contain all information specified in the module (including copies of information originally specified in other modules). Although the former

26 27 28 29 30 31

38

42

ISO/IEC JTC 1/SC 22/WG5/N2184

585

J3/21-007r1

WD 1539-1

2021-05-21

3

approach would appear to save on storage space, the latter approach can greatly simplify the logic necessary to process a USE statement and can avoid the necessity of imposing a limit on the logical “nesting” of modules via the USE statement.

4

5 There is an increased potential for undetected errors in a scoping unit that uses both implicit typing and the

1 2

5

USE statement. For example, in the program fragment SUBROUTINE SUB USE MY_MODULE IMPLICIT INTEGER (I-N), REAL (A-H, O-Z) X = F (B) A = G (X) + H (X + 1) END SUBROUTINE SUB

6 7 8 9 10 11

15

X could be either an implicitly typed real variable or a variable obtained from the module MY_MODULE and might change from one to the other because of changes in MY_MODULE unrelated to the action performed by SUB. Logic errors resulting from this kind of situation can be extremely difficult to locate. Thus, the use of these features together is discouraged.

16

C.10.2.3

12 13 14

Accessibility attributes (8.5.2)

17

1 The PUBLIC and PRIVATE attributes, which can be declared only in modules, divide the entities in a module

18

23

into those that are actually relevant to a scoping unit referencing the module and those that are not. This information might be used to improve the performance of a Fortran processor. For example, it might be possible to discard much of the information about the private entities once a module has been translated, thus saving on both storage and the time to search it. Similarly, it might be possible to recognize that two versions of a module differ only in the private entities they contain and avoid retranslating program units that use that module when switching from one version of the module to the other.

24

C.10.3

Examples of the use of modules (14.2.1)

25

C.10.3.1

Global data (14.2.1)

19 20 21 22

26

1 A module could contain only data objects, for example:

27

MODULE DATA_MODULE SAVE REAL A (10), B, C (20,20) INTEGER :: I=0 INTEGER, PARAMETER :: J=10 COMPLEX D (J,J) END MODULE DATA_MODULE

28 29 30 31 32 33

34

2 Data objects made global in this manner can have any combination of data types.

35

3 Access to some of these can be made by a USE statement with the ONLY option, such as:

USE DATA_MODULE, ONLY: A, B, D

36 37

and access to all of them can be made by the following USE statement:

586

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

2 3

4 5 6 7 8 9 10 11

WD 1539-1

J3/21-007r1

USE DATA_MODULE 4 Access to all of them with some renaming to avoid name conflicts can be made by, for example:

USE DATA_MODULE, AMODULE => A, DMODULE => D C.10.3.2

Derived types (14.2.1)

1 A derived type can be defined in a module and accessed in a number of program units. For example,

MODULE SPARSE TYPE NONZERO REAL A INTEGER I, J END TYPE NONZERO END MODULE SPARSE

13

defines a type consisting of a real component and two integer components for holding the numerical value of a nonzero matrix element and its row and column indices.

14

C.10.3.3

12

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

34 35 36

Global allocatable arrays (14.2.1)

1 Many programs need large global allocatable arrays whose sizes are not known before program execution. A

simple form for such a program is: PROGRAM GLOBAL_WORK CALL CONFIGURE_ARRAYS ! Perform the appropriate allocations CALL COMPUTE ! Use the arrays in computations END PROGRAM GLOBAL_WORK MODULE WORK_ARRAYS ! An example set of work arrays INTEGER N REAL, ALLOCATABLE :: A (:), B (:, :), C (:, :, :) END MODULE WORK_ARRAYS SUBROUTINE CONFIGURE_ARRAYS ! Process to set up work arrays USE WORK_ARRAYS READ (*, *) N ALLOCATE (A (N), B (N, N), C (N, N, 2 * N)) END SUBROUTINE CONFIGURE_ARRAYS SUBROUTINE COMPUTE USE WORK_ARRAYS . . . Computations involving arrays A, B, and C. END SUBROUTINE COMPUTE 2 Typically, many subprograms need access to the work arrays, and all such subprograms would contain the

statement USE WORK_ARRAYS

ISO/IEC JTC 1/SC 22/WG5/N2184

587

J3/21-007r1

1 2 3 4

C.10.3.4

2021-05-21

Procedure libraries (14.2.2)

1 Interface bodies for external procedures in a library can be gathered into a module. An interface body specifies

an explicit interface (15.4.2.2). 2 An example is the following library module:

MODULE LIBRARY_LLS INTERFACE SUBROUTINE LLS (X, A, F, FLAG) REAL X (:, :) ! The SIZE in the next statement is an intrinsic function REAL, DIMENSION (SIZE (X, 2)) :: A, F INTEGER FLAG END SUBROUTINE LLS ... END INTERFACE ... END MODULE LIBRARY_LLS

5 6 7 8 9 10 11 12 13 14 15 16

17

WD 1539-1

3 This module provides an explicit interface that is necessary for the subroutine LLS to be invoked. for example:

USE LIBRARY_LLS ... CALL LLS (X = ABC, A = D, F = XX, FLAG = IFLAG) ...

18 19 20 21

22

4 Because dummy argument names in an interface body for an external procedure are not required to be the same

23 24

as in the procedure definition, different versions can be constructed for different applications using argument keywords appropriate to each application.

25

C.10.3.5

26 27

Operator extensions (14.2.2)

1 In order to extend an intrinsic operator symbol to have an additional meaning, an interface block specifying that

operator symbol in the OPERATOR option of the INTERFACE statement could be placed in a module.

28

2 For example, // can be extended to perform concatenation of two derived-type objects serving as varying length

29 30

character strings and + can be extended to specify matrix addition for type MATRIX or interval arithmetic addition for type INTERVAL.

31

3 A module might contain several such interface blocks. An operator can be defined by an external function (either

32

in Fortran or some other language) and its procedure interface placed in the module.

33

C.10.3.6

Data abstraction (14.2.2)

34

1 In addition to providing a portable means of avoiding the redundant specification of information in multiple

35

program units, a module provides a convenient means of “packaging” related entities, such as the definitions of the representation and operations of an abstract data type. The following example of a module defines a data abstraction for a SET type where the elements of each set are of type integer. The usual set operations of UNION,

36 37

588

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

6

INTERSECTION, and DIFFERENCE are provided. The CARDINALITY function returns the cardinality of (number of elements in) its set argument. Two functions returning logical values are included, ELEMENT and SUBSET. ELEMENT defines the operator .IN. and SUBSET extends the operator <=. ELEMENT determines if a given scalar integer value is an element of a given set, and SUBSET determines if a given set is a subset of another given set. (Two sets can be checked for equality by comparing cardinality and checking that one is a subset of the other, or checking to see if each is a subset of the other.)

7

2 The transfer function SETF converts a vector of integer values to the corresponding set, with duplicate values

8

removed. Thus, a vector of constant values can be used as set constants. An inverse transfer function VECTOR returns the elements of a set as a vector of values in ascending order. In this SET implementation, set data objects have a maximum cardinality of 200.

1 2 3 4 5

9 10 11 12 13 14

3 Here is the example module:

MODULE INTEGER_SETS ! This module is intended to illustrate use of the module facility ! to define a new type, along with suitable operators.

15 16

INTEGER, PARAMETER :: MAX_SET_CARD = 200

17 18 19 20 21 22

TYPE SET PRIVATE INTEGER CARD INTEGER ELEMENT (MAX_SET_CARD) END TYPE SET

! Define SET type

23 24 25 26

INTERFACE OPERATOR (.IN.) MODULE PROCEDURE ELEMENT END INTERFACE OPERATOR (.IN.)

27 28 29 30

INTERFACE OPERATOR (<=) MODULE PROCEDURE SUBSET END INTERFACE OPERATOR (<=)

31 32 33 34

INTERFACE OPERATOR (+) MODULE PROCEDURE UNION END INTERFACE OPERATOR (+)

35 36 37 38

INTERFACE OPERATOR (-) MODULE PROCEDURE DIFFERENCE END INTERFACE OPERATOR (-)

39 40 41 42

INTERFACE OPERATOR (*) MODULE PROCEDURE INTERSECTION END INTERFACE OPERATOR (*)

43 44

CONTAINS

45

ISO/IEC JTC 1/SC 22/WG5/N2184

589

J3/21-007r1

WD 1539-1

INTEGER FUNCTION CARDINALITY (A) TYPE (SET), INTENT (IN) :: A CARDINALITY = A % CARD END FUNCTION CARDINALITY

1 2 3 4

! Returns cardinality of set A

5

LOGICAL FUNCTION ELEMENT (X, A) ! Determines if INTEGER, INTENT(IN) :: X ! element X is in set A TYPE (SET), INTENT(IN) :: A ELEMENT = ANY (A % ELEMENT (1 : A % CARD) == X) END FUNCTION ELEMENT

6 7 8 9 10 11

FUNCTION UNION (A, B) ! Union of sets A and B TYPE (SET) UNION TYPE (SET), INTENT(IN) :: A, B INTEGER J UNION = A DO J = 1, B % CARD IF (.NOT. (B % ELEMENT (J) .IN. A)) THEN IF (UNION % CARD < MAX_SET_CARD) THEN UNION % CARD = UNION % CARD + 1 UNION % ELEMENT (UNION % CARD) = B % ELEMENT (J) ELSE ! Maximum set size exceeded . . . END IF END IF END DO END FUNCTION UNION

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

FUNCTION DIFFERENCE (A, B) ! Difference of sets A and B TYPE (SET) DIFFERENCE TYPE (SET), INTENT(IN) :: A, B INTEGER J, X DIFFERENCE % CARD = 0 ! The empty set DO J = 1, A % CARD X = A % ELEMENT (J) IF (.NOT. (X .IN. B)) DIFFERENCE = DIFFERENCE + SET (1, X) END DO END FUNCTION DIFFERENCE

29 30 31 32 33 34 35 36 37 38 39

FUNCTION INTERSECTION (A, B) TYPE (SET) INTERSECTION TYPE (SET), INTENT(IN) :: A, B INTERSECTION = A - (A - B) END FUNCTION INTERSECTION

40 41 42 43 44

! Intersection of sets A and B

45

LOGICAL FUNCTION SUBSET (A, B)

46

590

! Determines if set A is

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2021-05-21

1 2 3 4 5 6 7 8

WD 1539-1

J3/21-007r1

TYPE (SET), INTENT(IN) :: A, B ! a subset of set B INTEGER I SUBSET = A % CARD <= B % CARD IF (.NOT. SUBSET) RETURN ! For efficiency DO I = 1, A % CARD SUBSET = SUBSET .AND. (A % ELEMENT (I) .IN. B) END DO END FUNCTION SUBSET

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

TYPE (SET) FUNCTION SETF (V) ! Transfer function between a vector INTEGER V (:) ! of elements and a set of elements INTEGER J ! removing duplicate elements SETF % CARD = 0 DO J = 1, SIZE (V) IF (.NOT. (V (J) .IN. SETF)) THEN IF (SETF % CARD < MAX_SET_CARD) THEN SETF % CARD = SETF % CARD + 1 SETF % ELEMENT (SETF % CARD) = V (J) ELSE ! Maximum set size exceeded . . . END IF END IF END DO END FUNCTION SETF

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

41 42 43

FUNCTION VECTOR (A) ! Transfer the values of set A TYPE (SET), INTENT (IN) :: A ! into a vector in ascending order INTEGER, POINTER :: VECTOR (:) INTEGER I, J, K ALLOCATE (VECTOR (A % CARD)) VECTOR = A % ELEMENT (1 : A % CARD) DO I = 1, A % CARD - 1 ! Use a better sort if DO J = I + 1, A % CARD ! A % CARD is large IF (VECTOR (I) > VECTOR (J)) THEN K = VECTOR (J); VECTOR (J) = VECTOR (I); VECTOR (I) = K END IF END DO END DO END FUNCTION VECTOR END MODULE INTEGER_SETS 4 Examples of using INTEGER_SETS (A, B, and C are variables of type SET; X is an integer variable):

! Check to see if A has more than 10 elements IF (CARDINALITY (A) > 10) . . .

44 45

! Check for X an element of A but not of B

ISO/IEC JTC 1/SC 22/WG5/N2184

591

J3/21-007r1

WD 1539-1

2021-05-21

IF (X .IN. (A - B)) . . .

1 2

! C is the union of A and the result of B intersected ! with the integers 1 to 100 C = A + B * SETF ([(I, I = 1, 100)])

3 4 5 6

! Does A have any even numbers in the range 1:100? IF (CARDINALITY (A * SETF ([(I, I = 2, 100, 2)])) > 0) . . .

7 8 9

PRINT *, VECTOR (B) ! Print out the elements of set B, in ascending order

10

11

C.10.3.7

Public entities renamed (14.2.2)

12

1 At times it might be necessary to rename entities that are accessed with USE statements.

13

2 The following example illustrates renaming features of the USE statement.

MODULE J; REAL JX, JY, JZ; END MODULE J MODULE K USE J, ONLY : KX => JX, KY => JY ! KX and KY are local names to module K REAL KZ ! KZ is local name to module K REAL JZ ! JZ is local name to module K END MODULE K PROGRAM RENAME USE J; USE K ! Module J’s entity JX is accessible under names JX and KX ! Module J’s entity JY is accessible under names JY and KY ! Module K’s entity KZ is accessible under name KZ ! Module J’s entity JZ and K’s entity JZ are different entities ! and cannot be referenced ... END PROGRAM RENAME

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

30 31 32

C.10.4

Modules with submodules (14.2.3)

1 Each submodule specifies that it is the child of exactly one parent module or submodule. Therefore, a module

and all of its descendant submodules stand in a tree-like relationship one to another.

33

2 A separate module procedure that is declared in a module to have public accessibility can be accessed by use

34

40

association even if it is defined in a submodule. No other entity in a submodule can be accessed by use association. Each program unit that references a module by use association depends on it, and each submodule depends on its ancestor module. Therefore, if one changes a separate module procedure body in a submodule but does not change its corresponding module procedure interface, a tool for automatic program translation would not need to reprocess program units that reference the module by use association. This is so even if the tool exploits the relative modification times of files as opposed to comparing the result of translating the module to the result of a previous translation.

41

3 By constructing taller trees, one can put entities at intermediate levels that are shared by submodules at lower

35 36 37 38 39

592

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

5

levels; changing these entities cannot change the interpretation of anything that is accessible from the module by use association. Developers of modules that embody large complicated concepts can exploit this possibility to organize components of the concept into submodules, while preserving the privacy of entities that are shared by the submodules and that ought not to be exposed to users of the module. Putting these shared entities at an intermediate level also prevents cascades of reprocessing and testing if some of them are changed.

6

4 The following example illustrates a module, color_points, with a submodule, color_points_a, that in turn has

7

9

a submodule, color_points_b. Public entities declared within color_points can be accessed by use association. The submodules color_points_a and color_points_b can be changed without causing retranslation of program units that reference the module color_points.

10

5 The module color_points does not have a module-subprogram-part, but a module-subprogram-part is not pro-

11

hibited. The module could be published as definitive specification of the interface, without revealing trade secrets contained within color_points_a or color_points_b. Of course, a similar module without the module prefix in the interface bodies would serve equally well as documentation – but the procedures would be external procedures. It would make little difference to the consumer, but the developer would forfeit all of the advantages of modules.

1 2 3 4

8

12 13 14 15

module color_points

16 17 18 19 20 21

type color_point private real :: x, y integer :: color end type color_point

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

interface

! Interfaces for procedures with separate ! bodies in the submodule color_points_a module subroutine color_point_del ( p ) ! Destroy a color_point object type(color_point), allocatable :: p end subroutine color_point_del ! Distance between two color_point objects real module function color_point_dist ( a, b ) type(color_point), intent(in) :: a, b end function color_point_dist module subroutine color_point_draw ( p ) ! Draw a color_point object type(color_point), intent(in) :: p end subroutine color_point_draw module subroutine color_point_new ( p ) ! Create a color_point object type(color_point), allocatable :: p end subroutine color_point_new end interface

39 40

end module color_points

41

6 The only entities within color_points_a that can be accessed by use association are the separate module

42

procedures that were declared in color_points. If the procedures are changed but their interfaces are not, the interface from program units that access them by use association is unchanged. If the module and submodule are in separate files, utilities that examine the time of modification of a file would notice that changes in the module

43 44

ISO/IEC JTC 1/SC 22/WG5/N2184

593

J3/21-007r1

WD 1539-1

2021-05-21

3

could affect the translation of its submodules or of program units that reference the module by use association, but that changes in submodules could not affect the translation of the parent module or program units that reference it by use association.

4

7 The variable instance_count in the following example is not accessible by use association of color_points, but

1 2

5

is accessible within color_points_a, and its submodules. submodule ( color_points ) color_points_a ! Submodule of color_points

6 7

integer :: instance_count = 0

8 9

interface

! Interface for a procedure with a separate ! body in submodule color_points_b module subroutine inquire_palette ( pt, pal ) use palette_stuff ! palette_stuff, especially submodules thereof, ! can reference color_points by use association ! without causing a circular dependence during ! translation because this use is not in the module. ! Furthermore, changes in the module palette_stuff ! do not affect the translation of color_points. type(color_point), intent(in) :: pt type(palette), intent(out) :: pal end subroutine inquire_palette end interface

10 11 12 13 14 15 16 17 18 19 20 21 22 23

contains ! Invisible bodies for public separate module procedures ! declared in the module module subroutine color_point_del ( p ) type(color_point), allocatable :: p instance_count = instance_count - 1 deallocate ( p ) end subroutine color_point_del real module function color_point_dist ( a, b ) result ( dist ) type(color_point), intent(in) :: a, b dist = SQRT ( (b%x - a%x)**2 + (b%y - a%y)**2 ) end function color_point_dist module subroutine color_point_new ( p ) type(color_point), allocatable :: p instance_count = instance_count + 1 allocate ( p ) end subroutine color_point_new

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

end submodule color_points_a

41

42

8 The subroutine inquire_palette is accessible within color_points_a because its interface is declared therein.

43

It is not, however, accessible by use association, because its interface is not declared in the module, color_points. Since the interface is not declared in the module, changes in the interface cannot affect the translation of program

44

594

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11 12 13

WD 1539-1

J3/21-007r1

units that reference the module by use association. module palette_stuff type :: palette ; . . . ; end type palette contains subroutine test_palette ( p ) ! Draw a color wheel using procedures from the color_points module use color_points ! This does not cause a circular dependency because ! the "use palette_stuff" that is logically within ! color_points is in the color_points_a submodule. type(palette), intent(in) :: p ... end subroutine test_palette end module palette_stuff

14 15

submodule ( color_points:color_points_a ) color_points_b ! Subsidiary**2 submodule

16 17 18 19 20 21 22 23 24

contains ! Invisible body for interface declared in the ancestor module module subroutine color_point_draw ( p ) use palette_stuff, only: palette type(color_point), intent(in) :: p type(palette) :: MyPalette . . . ; call inquire_palette ( p, MyPalette ); . . . end subroutine color_point_draw

25 26 27 28 29

! Invisible body for interface declared in the parent submodule module procedure inquire_palette . . . Implementation of inquire_palette. end procedure inquire_palette

30 31 32 33

subroutine private_stuff ! not accessible from color_points_a ... end subroutine private_stuff

34 35

end submodule color_points_b

36

9 There is a use palette_stuff in color_points_a, and a use color_points in palette_stuff. The use

37

palette_stuff would cause a circular reference if it appeared in color_points. In this case, it does not cause a circular dependence because it is in a submodule. Submodules cannot be referenced by use association, and therefore what would be a circular appearance of use palette_stuff is not accessed.

38 39 40 41 42 43 44

program main use color_points ! "instance_count" and "inquire_palette" are not accessible here ! because they are not declared in the "color_points" module. ! "color_points_a" and "color_points_b" cannot be referenced by

ISO/IEC JTC 1/SC 22/WG5/N2184

595

J3/21-007r1

WD 1539-1

2021-05-21

17

! use association. interface draw ! just to demonstrate it’s possible module procedure color_point_draw end interface type(color_point) :: C_1, C_2 real :: RC ... call color_point_new (c_1) ! body in color_points_a, interface in color_points ... call draw (c_1) ! body in color_points_b, specific interface ! in color_points, generic interface here. ... rc = color_point_dist (c_1, c_2) ! body in color_points_a, interface in color_points ... call color_point_del (c_1) ! body in color_points_a, interface in color_points ... end program main

18

10 A multilevel submodule system can be used to package and organize a large and interconnected concept without

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

19

exposing entities of one subsystem to other subsystems.

20

11 Consider a Plasma module from a Tokomak simulator. A plasma simulation requires attention at least to fluid

21

flow, thermodynamics, and electromagnetism. Fluid flow simulation requires simulation of subsonic, supersonic, and hypersonic flow. This problem decomposition can be reflected in the submodule structure of the Plasma module:

22 23

Plasma module Flow submodule

24

Thermal submodule

Subsonic

Supersonic

Hypersonic

submodule

submodule

submodule

Electromagnetics submodule

25

12 Entities can be shared among the Subsonic, Supersonic, and Hypersonic submodules by putting them within

26

31

the Flow submodule. One then need not worry about accidental use of these entities by use association or by the Thermal or Electromagnetics submodules, or the development of a dependency of correct operation of those subsystems upon the representation of entities of the Flow subsystem as a consequence of maintenance. Since these entities are not accessible by use association, if any of them are changed, the new values cannot be accessed in program units that reference the Plasma module by use association; the answer to the question “where are these entities used” is therefore confined to the set of descendant submodules of the Flow submodule.

32

C.11

Clause 15 notes

33

C.11.1

Portability problems with external procedures (15.4.3.5)

27 28 29 30

34

1 There is a potential portability problem in a scoping unit that references an external procedure without explicitly

35

declaring it to have the EXTERNAL attribute (8.5.9). On a different processor, the name of that procedure might be the name of a nonstandard intrinsic procedure and in such a case the processor would interpret those

36

596

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

6

procedure references as references to that intrinsic procedure. (On that processor, the program would also be viewed as not conforming to this document because of the references to the nonstandard intrinsic procedure.) Declaration of the EXTERNAL attribute causes the references to be to the external procedure regardless of the availability of an intrinsic procedure with the same name. Note that declaration of the type of a procedure is not enough to make it external, even if the type is inconsistent with the type of the result of an intrinsic procedure of the same name.

7

C.11.2

1 2 3 4 5

Procedures defined by means other than Fortran (15.6.3)

8

1 A processor is not required to provide any means other than Fortran for defining external procedures. Among the

9

13

means that might be supported are the machine assembly language, other high level languages, the Fortran language extended with nonstandard features, and the Fortran language as supported by another Fortran processor (for example, a previously existing Fortran 77 processor). The means other than Fortran for defining external procedures, including any restrictions on the structure or organization of those procedures, are not specified by this document.

14

2 A Fortran processor might limit its support of procedures defined by means other than Fortran such that these

15

17

procedures can affect entities in the Fortran environment only on the same basis as procedures written in Fortran. For example, it might not support the value of a local variable from being changed by a procedure reference unless that variable were one of the arguments to the procedure.

18

C.11.3

10 11 12

16

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

Abstract interfaces and procedure pointer components (15.4, 7.5)

1 This is an example of a library module providing lists of callbacks that the user can register and invoke.

MODULE callback_list_module ! ! Type for users to extend with their own data, if they so desire ! TYPE callback_data END TYPE ! ! Abstract interface for the callback procedures ! ABSTRACT INTERFACE SUBROUTINE callback_procedure(data) IMPORT callback_data CLASS(callback_data),OPTIONAL :: data END SUBROUTINE END INTERFACE ! ! The callback list type. ! TYPE callback_list PRIVATE TYPE(callback_record),POINTER :: first => NULL() END TYPE !

ISO/IEC JTC 1/SC 22/WG5/N2184

597

J3/21-007r1

WD 1539-1

! Internal: each callback registration creates one of these ! TYPE,PRIVATE :: callback_record PROCEDURE(callback_procedure),POINTER,NOPASS :: proc TYPE(callback_record),POINTER :: next CLASS(callback_data),POINTER :: data => NULL(); END TYPE PRIVATE invoke,forward_invoke CONTAINS ! ! Register a callback procedure with optional data ! SUBROUTINE register_callback(list, entry, data) TYPE(callback_list),INTENT(INOUT) :: list PROCEDURE(callback_procedure) :: entry CLASS(callback_data),OPTIONAL :: data TYPE(callback_record),POINTER :: new ALLOCATE(new) new%proc => entry IF (PRESENT(data)) ALLOCATE(new%data,SOURCE=data) new%next => list%first list%first => new END SUBROUTINE ! ! Internal: Invoke a single callback and destroy its record ! SUBROUTINE invoke(callback) TYPE(callback_record),POINTER :: callback IF (ASSOCIATED(callback%data)) THEN CALL callback%proc(callback%data) DEALLOCATE(callback%data) ELSE CALL callback%proc END IF DEALLOCATE(callback) END SUBROUTINE ! ! Call the procedures in reverse order of registration ! SUBROUTINE invoke_callback_reverse(list) TYPE(callback_list),INTENT(INOUT) :: list TYPE(callback_record),POINTER :: next,current current => list%first NULLIFY(list%first) DO WHILE (ASSOCIATED(current)) next => current%next

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

598

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

2021-05-21

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

22

J3/21-007r1

CALL invoke(current) current => next END DO END SUBROUTINE ! ! Internal: Forward mode invocation ! SUBROUTINE forward_invoke(callback) TYPE(callback_record),POINTER :: callback IF (ASSOCIATED(callback%next)) CALL forward_invoke(callback%next) CALL invoke(callback) END SUBROUTINE ! ! Call the procedures in forward order of registration ! SUBROUTINE invoke_callback_forward(list) TYPE(callback_list),INTENT(INOUT) :: list IF (ASSOCIATED(list%first)) CALL forward_invoke(list%first) END SUBROUTINE END

1

21

WD 1539-1

C.11.4

Pointers and targets as arguments (15.5.2.4, 15.5.2.6, 15.5.2.7)

1 If a dummy argument is declared to be a pointer, the corresponding actual argument could be a pointer or could

23

be a nonpointer variable or procedure. Consider the two cases separately.

24

Case (i):

The actual argument is a pointer. When procedure execution commences the pointer association status of the dummy argument becomes the same as that of the actual argument. If the pointer association status of the dummy argument is changed, the pointer association status of the actual argument changes in the same way.

Case (ii):

30

The actual argument is not a pointer. This only occurs when the actual argument has the TARGET attribute or is a procedure, and the dummy argument has the INTENT (IN) attribute. The dummy argument becomes pointer associated with the actual argument.

31

2 When execution of a procedure completes, any data pointer that remains defined and that is associated with a

32

dummy argument that has the TARGET attribute and is either a scalar or an assumed-shape array, remains associated with the corresponding actual argument if the actual argument has the TARGET attribute and is not an array section with a vector subscript.

25 26 27 28 29

33 34 35 36 37 38 39 40 41 42

3 For example, consider:

REAL, POINTER :: PBEST REAL, TARGET :: B (10000) CALL BEST (PBEST, B) ! On return PBEST is associated with the ‘best’ element of B. ... CONTAINS SUBROUTINE BEST (P, A) REAL, POINTER, INTENT (OUT) :: P

ISO/IEC JTC 1/SC 22/WG5/N2184

599

J3/21-007r1

2021-05-21

REAL, TARGET, INTENT (IN) :: A (:) . . . Find the ‘‘best’’ element A(I). P => A (I) END SUBROUTINE BEST END

1 2 3 4 5 6

WD 1539-1

When procedure BEST completes, the pointer PBEST is associated with an element of B.

7

4 An actual argument without the TARGET attribute can become associated with a dummy argument with the

8

TARGET attribute. This enables a pointer to become associated with the dummy argument during execution of the procedure that contains the dummy argument. For example:

9

INTEGER LARGE(100,100) CALL SUB (LARGE) ... CALL SUB () CONTAINS SUBROUTINE SUB(ARG) INTEGER, TARGET, OPTIONAL :: ARG(100,100) INTEGER, POINTER, DIMENSION(:,:) :: PARG IF (PRESENT(ARG)) THEN PARG => ARG ELSE ALLOCATE (PARG(100,100)) PARG = 0 ENDIF . . . Code with lots of references to PARG. IF (.NOT. PRESENT(ARG)) DEALLOCATE(PARG) END SUBROUTINE SUB END

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

30

Within subroutine SUB the pointer PARG is either associated with the dummy argument ARG or it is associated with an allocated target. The bulk of the code can reference PARG without further calls to the intrinsic function PRESENT.

31

5 If a nonpointer dummy argument has the TARGET attribute and the corresponding actual argument does not,

32 33

any pointers that become associated with the dummy argument, and therefore with the actual argument, during execution of the procedure, become undefined when execution of the procedure completes.

34

C.11.5

28 29

35 36

Polymorphic Argument Association (15.5.2.9)

1 The following example illustrates the polymorphic argument association rules using the derived types defined in

7.5.7.2, NOTE 4. TYPE(POINT) :: T2 TYPE(COLOR_POINT) :: T3 CLASS(POINT) :: P2 CLASS(COLOR_POINT) :: P3 ! Dummy argument is polymorphic and actual argument is of fixed type

37 38 39 40 41

600

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

SUBROUTINE SUB2 ( X2 ); CLASS(POINT) :: X2; . . . SUBROUTINE SUB3 ( X3 ); CLASS(COLOR_POINT) :: X3; . . .

3 4 5 6 7 8 9 10 11 12 13 14 15

CALL SUB2 ( T2 ) ! Valid -- The declared type of T2 is the same as the ! declared type of X2. CALL SUB2 ( T3 ) ! Valid -- The declared type of T3 is extended from ! the declared type of X2. CALL SUB3 ( T2 ) ! Invalid -- The declared type of T2 is neither the ! same as nor extended from the declared type ! type of X3. CALL SUB3 ( T3 ) ! Valid -- The declared type of T3 is the same as the ! declared type of X3. ! Actual argument is polymorphic and dummy argument is of fixed type SUBROUTINE TUB2 ( D2 ); TYPE(POINT) :: D2; . . . SUBROUTINE TUB3 ( D3 ); TYPE(COLOR_POINT) :: D3; . . .

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

CALL TUB2 ( P2 ) ! Valid -- The declared type of P2 is the same as the ! declared type of D2. CALL TUB2 ( P3 ) ! Invalid -- The declared type of P3 differs from the ! declared type of D2. CALL TUB2 ( P3%POINT ) ! Valid alternative to the above CALL TUB3 ( P2 ) ! Invalid -- The declared type of P2 differs from the ! declared type of D3. SELECT TYPE ( P2 ) ! Valid conditional alternative to the above CLASS IS ( COLOR_POINT ) ! Works if the dynamic type of P2 is the same CALL TUB3 ( P2 ) ! as the declared type of D3, or a type ! extended therefrom. CLASS DEFAULT ! Cannot work if not. END SELECT CALL TUB3 ( P3 ) ! Valid -- The declared type of P3 is the same as the ! declared type of D3. ! Both the actual and dummy arguments are of polymorphic type. CALL SUB2 ( P2 ) ! Valid -- The declared type of P2 is the same as the ! declared type of X2. CALL SUB2 ( P3 ) ! Valid -- The declared type of P3 is extended from ! the declared type of X2. CALL SUB3 ( P2 ) ! Invalid -- The declared type of P2 is neither the ! same as nor extended from the declared ! type of X3. SELECT TYPE ( P2 ) ! Valid conditional alternative to the above CLASS IS ( COLOR_POINT ) ! Works if the dynamic type of P2 is the CALL SUB3 ( P2 ) ! same as the declared type of X3, or a ! type extended therefrom. CLASS DEFAULT ! Cannot work if not.

ISO/IEC JTC 1/SC 22/WG5/N2184

601

J3/21-007r1

2 3

5

2021-05-21

END SELECT CALL SUB3 ( P3 ) ! Valid -- The declared type of P3 is the same as the ! declared type of X3.

1

4

WD 1539-1

C.11.6

Rules ensuring unambiguous generics (15.4.3.4.5)

1 The rules in 15.4.3.4.5 are intended to ensure

6

• that it is possible to reference each specific procedure or binding in the generic collection,

7

• that for any valid generic procedure reference, the determination of the specific procedure referenced is unambiguous, and

8

10

• that the determination of the specific procedure or binding referenced can be made before execution of the program begins (during compilation).

11

2 Interfaces of specific procedures or bindings are distinguished by fixed properties of their arguments, specifically

12

15

type, kind type parameters, rank, and whether the dummy argument has the POINTER or ALLOCATABLE attribute. A valid reference to one procedure in a generic collection will differ from another because it has an argument that the other cannot accept, because it is missing an argument that the other requires, or because one of these fixed properties is different.

16

3 Although the declared type of a data entity is a fixed property, polymorphic variables allow for a limited degree

17

19

of type mismatch between dummy arguments and actual arguments, so the requirement for distinguishing two dummy arguments is type incompatibility, not merely different types. (This is illustrated in the BAD6 example later in this subclause.)

20

4 That same limited type mismatch means that two dummy arguments that are not type incompatible can be

21 22

distinguished on the basis of the values of the kind type parameters they have in common; if one of them has a kind type parameter that the other does not, that is irrelevant in distinguishing them.

23

5 Rank is a fixed property, but some forms of array dummy arguments allow rank mismatches when a procedure is

24

28

referenced by its specific name. In order to allow rank to always be usable in distinguishing generics, such rank mismatches are disallowed for those arguments when the procedure is referenced as part of a generic. Additionally, the fact that elemental procedures can accept array arguments is not taken into account when applying these rules, so apparent ambiguity between elemental and nonelemental procedures is possible; in such cases, the reference is interpreted as being to the nonelemental procedure.

29

6 For procedures referenced as operators or defined-assignment, syntactically distinguished arguments are mapped

30 31

to specific positions in the argument list, so the rule for distinguishing such procedures is that it be possible to distinguish the arguments at one of the argument positions.

32

7 For defined input/output procedures, only the dtv argument corresponds to something explicitly written in the

33 34

program, so it is the dtv that is required to be distinguished. Because dtv arguments are required to be scalar, they cannot differ in rank. Thus this rule effectively involves only type and kind type parameters.

35

8 For generic procedure names, the rules are more complicated because optional arguments can be omitted and

9

13 14

18

25 26 27

36

because arguments can be specified either positionally or by name.

37

9 In the special case of type-bound procedures with passed-object dummy arguments, the passed-object argument

38

is syntactically distinguished in the reference, so rule (3) in 15.4.3.4.5 can be applied. The type of passed-object

602

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

2

arguments is constrained in ways that prevent passed-object arguments in the same scoping unit from being type incompatible. Thus this rule effectively involves only kind type parameters and rank.

3

10 The primary means of distinguishing named generics is rule (4). The most common application of that rule is a

1

4 5 6 7 8 9 10 11 12

13 14

single argument satisfying both (4a) and (4b): INTERFACE GOOD1 FUNCTION F1A(X) REAL :: F1A,X END FUNCTION F1A FUNCTION F1B(X) INTEGER :: F1B,X END FUNCTION F1B END INTERFACE GOOD1 11 Whether one writes GOOD1(1.0) or GOOD1(X=1.0), the reference is to F1A because F1B would require an integer

argument whereas these references provide the real constant 1.0.

15

12 This example and those that follow are expressed using interface bodies, with type as the distinguishing property.

16

18

This was done to make it easier to write and describe the examples. The principles being illustrated are equally applicable when the procedures get their explicit interfaces in some other way or when kind type parameters or rank are the distinguishing property.

19

13 Another common variant is the argument that satisfies (4a) and (4b) by being required in one specific and

17

20

completely missing in the other:

21

INTERFACE GOOD2 FUNCTION F2A(X) REAL :: F2A,X END FUNCTION F2A FUNCTION F2B(X,Y) COMPLEX :: F2B REAL :: X,Y END FUNCTION F2B END INTERFACE GOOD2

22 23 24 25 26 27 28 29

30

14 Whether one writes GOOD2(0.0,1.0), GOOD2(0.0,Y=1.0), or GOOD2(Y=1.0,X=0.0), the reference is to F2B,

31

because F2A has no argument in the second position or with the name Y. This approach is used as an alternative to optional arguments when one wants a function to have different result type, kind type parameters, or rank, depending on whether the argument is present. In many of the intrinsic functions, the DIM argument works this way.

32 33 34 35 36 37 38 39 40

15 It is possible to construct cases where different arguments are used to distinguish positionally and by name:

INTERFACE GOOD3 SUBROUTINE S3A(W,X,Y,Z) REAL :: W,Y INTEGER :: X,Z END SUBROUTINE S3A

ISO/IEC JTC 1/SC 22/WG5/N2184

603

J3/21-007r1

WD 1539-1

2021-05-21

SUBROUTINE S3B(X,W,Z,Y) REAL :: W,Z INTEGER :: X,Y END SUBROUTINE S3B END INTERFACE GOOD3

1 2 3 4 5

6

16 If one writes GOOD3(1.0,2,3.0,4) to reference S3A, then the third and fourth arguments are consistent with a

7

reference to S3B, but the first and second are not. If one switches to writing the first two arguments as keyword arguments in order for them to be consistent with a reference to S3B, the latter two arguments will also need to be written as keyword arguments, GOOD3(X=2,W=1.0,Z=4,Y=3.0), and the named arguments Y and Z are distinguished.

8 9 10 11

17 The ordering requirement in rule (4) is critical:

INTERFACE BAD4 ! this interface is invalid ! SUBROUTINE S4A(W,X,Y,Z) REAL :: W,Y INTEGER :: X,Z END SUBROUTINE S4A SUBROUTINE S4B(X,W,Z,Y) REAL :: X,Y INTEGER :: W,Z END SUBROUTINE S4B END INTERFACE BAD4

12 13 14 15 16 17 18 19 20 21

22

18 In this example, the positionally distinguished arguments are Y and Z, and it is W and X that are distinguished by

23

name. In this order it is possible to write BAD4(1.0,2,Y=3.0,Z=4), which is a valid reference for both S4A and S4B.

24 25

19 Rule (1) can be used to distinguish some cases that are not covered by rule (4):

INTERFACE GOOD5 SUBROUTINE S5A(X) REAL :: X END SUBROUTINE S5A SUBROUTINE S5B(Y,X) REAL :: Y,X END SUBROUTINE S5B END INTERFACE GOOD5

26 27 28 29 30 31 32 33

34

20 In attempting to apply rule (4), position 2 and name Y are distinguished, but they are in the wrong order, just like

35

38

the BAD4 example. However, when we try to construct a similarly ambiguous reference, we get GOOD5(1.0,X=2.0), which can’t be a reference to S5A because it would be attempting to associate two different actual arguments with the dummy argument X. Rule (4) catches this case by recognizing that S5B requires two real arguments, and S5A cannot possibly accept more than one.

39

21 The application of rule (1) becomes more complicated when extensible types are involved. If FRUIT is an extensible

36 37

40

type, PEAR and APPLE are extensions of FRUIT, and BOSC is an extension of PEAR, then

604

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8 9 10 11

WD 1539-1

INTERFACE BAD6 ! this interface is invalid ! SUBROUTINE S6A(X,Y) CLASS(PEAR) :: X,Y END SUBROUTINE S6A SUBROUTINE S6B(X,Y) CLASS(FRUIT) :: X CLASS(BOSC) :: Y END SUBROUTINE S6B END INTERFACE BAD6 might, at first glance, seem distinguishable this way, but because of the limited type mismatching allowed, BAD6(A_PEAR,A_BOSC) is a valid reference to both S6A and S6B.

12

22 It is important to try rule (1) for each type that appears:

13

INTERFACE GOOD7 SUBROUTINE S7A(X,Y,Z) CLASS(PEAR) :: X,Y,Z END SUBROUTINE S7A SUBROUTINE S7B(X,Z,W) CLASS(FRUIT) :: X CLASS(BOSC) :: Z CLASS(APPLE),OPTIONAL :: W END SUBROUTINE S7B END INTERFACE GOOD7

14 15 16 17 18 19 20 21 22

J3/21-007r1

23

23 Looking at the most general type, S7A has a minimum and maximum of 3 FRUIT arguments, while S7B has a

24

27

minimum of 2 and a maximum of three. Looking at the most specific, S7A has a minimum of 0 and a maximum of 3 BOSC arguments, while S7B has a minimum of 1 and a maximum of 2. However, when we look at the intermediate, S7A has a minimum and maximum of 3 PEAR arguments, while S7B has a minimum of 1 and a maximum of 2. Because S7A’s minimum exceeds S7B’s maximum, they can be distinguished.

28

24 In identifying the minimum number of arguments with a particular set of properties, we exclude optional argu-

29

32

ments and test TKR compatibility, so the corresponding actual arguments are required to have those properties. In identifying the maximum number of arguments with those properties, we include the optional arguments and test not distinguishable, so we include actual arguments which could have those properties but are not required to have them.

33

25 These rules are sufficient to ensure that references to procedures that meet them are unambiguous, but there

25 26

30 31

34 35 36 37 38 39 40 41 42

remain examples that fail to meet these rules but which can be shown to be unambiguous: INTERFACE BAD8 ! this interface is invalid ! ! despite the fact that it is unambiguous ! SUBROUTINE S8A(X,Y,Z) REAL,OPTIONAL :: X INTEGER :: Y REAL :: Z END SUBROUTINE S8A SUBROUTINE S8B(X,Z,Y)

ISO/IEC JTC 1/SC 22/WG5/N2184

605

J3/21-007r1

WD 1539-1

2021-05-21

INTEGER,OPTIONAL :: X INTEGER :: Z REAL :: Y END SUBROUTINE S8B END INTERFACE BAD8

1 2 3 4 5

6

26 This interface fails rule (4) because there are no required arguments that can be distinguished from the positionally

7

10

corresponding argument, but in order for the mismatch of the optional arguments not to be relevant, the later arguments need to be specified as keyword arguments, so distinguishing by name does the trick. This interface is nevertheless invalid so a standard-conforming Fortran processor is not required to do such reasoning. The rules to cover all cases are too complicated to be useful.

11

27 If one dummy argument has the POINTER attribute and a corresponding argument in the other interface body

12

14

has the ALLOCATABLE attribute the generic interface is not ambiguous. If one dummy argument has either the POINTER or ALLOCATABLE attribute and a corresponding argument in the other interface body has neither attribute, the generic interface might be ambiguous.

15

C.12

Clause 16 notes

16

C.12.1

Atomic memory consistency

17

C.12.1.1

Relaxed memory model

8 9

13

18

1 Parallel programs sometimes have apparently impossible behavior because data transfers and other messages can

19

23

be delayed, reordered and even repeated, by hardware, communication software, and caching and other forms of optimization. Requiring processors to deliver globally consistent behavior is incompatible with performance on many systems. This document specifies that all ordered actions will be consistent (5.3.5 and 11.7), but all consistency between unordered segments is deliberately left processor dependent. Depending on the hardware, this can be observed even when only two images and one mechanism are involved.

24

C.12.1.2

20 21 22

Examples with atomic operations

25

1 When variables are being referenced (atomically) from segments that are unordered with respect to the segment

26

that is atomically defining or redefining the variables, the results are processor dependent. This supports use of so-called “relaxed memory model” architectures, which can enable more efficient execution on some hardware implementations.

27 28 29

2 The following examples assume these declarations:

MODULE EXAMPLE USE,INTRINSIC :: ISO_FORTRAN_ENV INTEGER(ATOMIC_INT_KIND) :: X [*] = 0, Y [*] = 0, TMP

30 31 32

33 34

3 Example 1

With X [j] and Y [j] still in their initial state (both zero), image j executes the following sequence of statements: CALL ATOMIC_DEFINE (X, 1) CALL ATOMIC_DEFINE (Y, 1)

35 36

606

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

WD 1539-1

and a different image, k, executes the following sequence of statements:

2

DO

3

CALL ATOMIC_REF (TMP, Y [j ]) IF (TMP==1) EXIT END DO CALL ATOMIC_REF (TMP, X [j ]) PRINT *, TMP

4 5 6 7

J3/21-007r1

8

4 The final value of TMP on image k could be either 0 or 1. That is, even though image j thinks that it defined X

9

[j] before it defined Y [j], this ordering is not guaranteed to be observed on image k. There are many aspects of hardware and software implementation that can cause this effect, but conceptually this example can be thought of as the change in the value of Y propagating faster through the inter-image connections than the change in the value of X.

10 11 12 13

5 Even if image j executed the sequence

14

CALL ATOMIC_DEFINE (X, 1) SYNC MEMORY CALL ATOMIC_DEFINE (Y, 1)

15 16

18

the same effect could be seen. That is because even though X and Y are defined in ordered segments, the references from image k are both from a segment that is unordered with respect to image j.

19

6 Only if the reference on image k to Y [j] is in a segment that is ordered after the segment on image j that defined

17

20 21 22 23 24 25 26 27 28 29 30

Y, will TMP be guaranteed to have the value 1. 7 Example 2:

With the initial state of X and Y on image j (i.e. X [j] and Y [j]) still being zero, execution of CALL ATOMIC_REF (TMP, X [j ]) CALL ATOMIC_DEFINE (Y [j ], 1) PRINT *, TMP on image k1 , and execution of CALL ATOMIC_REF (TMP, Y [j ]) CALL ATOMIC_DEFINE (X [j ], 1) PRINT *, TMP on image k2 , in unordered segments, might print the value 1 both times.

31

8 This can happen by such mechanisms as “load buffering”; one might imagine that what is happening is that

32

the definitions (ATOMIC_DEFINE) are overtaking the references (ATOMIC_REF). On some processors it is possible that insertion of SYNC MEMORY statements between the calls to ATOMIC_REF and ATOMIC_DEFINE might be sufficient to make the output print the value 1 at most one time (or even exactly one time), but this is still processor dependent unless the SYNC MEMORY statement executions cause the relevant segments on images k1 and k2 to be ordered.

33 34 35 36 37 38 39

9 Example 3:

Because there are no segment boundaries implied by collective subroutines, with the initial state as before, execution of

ISO/IEC JTC 1/SC 22/WG5/N2184

607

J3/21-007r1

2 3 4 5 6 7 8 9

11 12

could print the values 42 and 0. 10 Example 4:

Assuming the declarations INTEGER (ATOMIC_INT_KIND) :: X [*] = 0, Z = 0

13 14

2021-05-21

IF (THIS_IMAGE ()==1) THEN CALL ATOMIC_DEFINE (X [3], 23) Y = 42 END IF CALL CO_BROADCAST (Y, 1) IF (THIS_IMAGE ()==2) THEN CALL ATOMIC_REF (TMP, X [3]) PRINT *, Y, TMP END IF

1

10

WD 1539-1

the statements CALL ATOMIC_ADD (X [1], 1) ! (A) IF (THIS_IMAGE() == 2) THEN wait: DO CALL ATOMIC_REF (Z, X [1]) ! (B) IF (Z == NUM_IMAGES ()) EXIT wait END DO wait ! (C) END IF

15 16 17 18 19 20 21

29

will execute the “wait” loop on image 2 until all images have completed statement (A). The updates of X [1] are performed by each image in the same manner, but in an arbitrary order. Because the result from the complete set of updates will eventually become visible by execution of statement (B) for some loop iteration on image 2, the termination condition is guaranteed to be eventually fulfilled, provided that no image failure occurs, every image executes the above code, and no other code is executed in an unordered segment that performs an update to X [1]. Furthermore, if two SYNC MEMORY statements are inserted in the above code before statement (A) and after statement (C), respectively, the segment started by the second SYNC MEMORY on image 2 is ordered after the segments on all images that end with the first SYNC MEMORY.

30

C.12.2

22 23 24 25 26 27 28

EVENT_QUERY example

31

1 The following example illustrates the use of events via a program in which image 1 acts as the master image,

32 33

distributing work items to the other images. Only one work item at a time can be active on a worker image, and each deals with the result (e.g. via input/output) without directly feeding data back to the master image.

34

2 Because the work items are not expected to be balanced, the master keeps cycling through all images to find one

35

that is waiting for work.

36

3 An event is posted by each worker to indicate that it has completed its work item. Since the corresponding

37 38

variables are needed only on the master, we place them in an allocatable array component of a coarray. An event on each worker is needed for the master to post the fact that it has made a work item available for it.

39

Example code:

608

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6 7 8

WD 1539-1

J3/21-007r1

PROGRAM work_share USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: EVENT_TYPE USE :: mod_work, ONLY: & ! Module that creates work items work, & ! Type for holding a work item create_work_item, & ! Function that creates work item process_item, & ! Function that processes an item work_done ! Logical function that returns true ! if all work has been done.

9 10 11 12 13 14 15 16

TYPE :: worker_type TYPE (EVENT_TYPE), ALLOCATABLE :: free (:) END TYPE TYPE (EVENT_TYPE) :: submit [*] ! Post when work ready for a worker TYPE (worker_type) :: worker [*] ! Post when worker is free TYPE (work) :: work_item [*] ! Holds the data for a work item INTEGER :: count, i, nbusy [*]

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

IF (THIS_IMAGE ()==1) THEN ! Get started ALLOCATE (worker%free (2:NUM_IMAGES ())) nbusy = 0 ! This holds the number of workers working DO i = 2, NUM_IMAGES () ! Start the workers working IF (work_done ()) EXIT nbusy = nbusy + 1 work_item [i] = create_work_item () EVENT POST (submit [i]) END DO ! Main work distribution loop master: DO image: DO i = 2, NUM_IMAGES () CALL EVENT_QUERY (worker%free (i), count) IF (count==0) CYCLE image ! Worker is not free EVENT WAIT (worker%free (i)) nbusy = nbusy - 1 IF (work_done ()) CYCLE nbusy = nbusy + 1 work_item [i] = create_work_item () EVENT POST (submit [i]) END DO image IF (nbusy==0) THEN ! All done. Exit on all images. DO i = 2, NUM_IMAGES () EVENT POST (submit [i]) END DO EXIT master END IF

ISO/IEC JTC 1/SC 22/WG5/N2184

609

J3/21-007r1

1 2 3 4 5 6 7 8 9 10 11

12 13 14

WD 1539-1

2021-05-21

END DO master ELSE ! Work processing loop worker: DO EVENT WAIT (submit) IF (nbusy[1] == 0) EXIT CALL process_item (work_item) EVENT POST (worker [1]%free (THIS_IMAGE ())) END DO worker END IF END PROGRAM work_share

C.12.3

Collective subroutine examples

1 The following example computes a dot product of two scalar coarrays using CO_SUM to store the result in a

noncoarray scalar variable. SUBROUTINE codot (x, y, x_dot_y) REAL :: x [*], y [*], x_dot_y x_dot_y = x*y CALL CO_SUM (x_dot_y) END SUBROUTINE codot

15 16 17 18 19

20

2 The function below demonstrates passing a noncoarray dummy argument to CO_MAX. The function uses CO_-

21

MAX to find the maximum value of the dummy argument across all images. Then the function flags all images that hold values matching the maximum. The function then returns the maximum image index for an image that holds the maximum value.

22 23

FUNCTION find_max (j) RESULT (j_max_location) INTEGER, INTENT (IN) :: j INTEGER j_max, j_max_location j_max = j CALL CO_MAX (j_max) ! Flag images that hold the maximum j. IF (j==j_max) THEN j_max_location = THIS_IMAGE () ELSE j_max_location = 0 END IF ! Return highest image index associated with a maximal j. CALL CO_MAX(j_max_location) END FUNCTION find_max

24 25 26 27 28 29 30 31 32 33 34 35 36 37

610

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

1

C.13

Clause 18 notes

2

C.13.1

Runtime environments (18.1)

3 4 5 6 7

J3/21-007r1

1 This document allows programs to contain procedures defined by means other than Fortran. That raises the

issues of initialization of and interaction between the runtime environments involved. 2 Implementations are free to solve these issues as they see fit, provided that

• heap allocation/deallocation (e.g., (DE)ALLOCATE in a Fortran subprogram and malloc/free in a C function) can be performed without interference,

9

• input/output to and from external files can be performed without interference, as long as procedures defined by different means do not do input/output with the same external file,

10

• input/output preconnections exist as required by the respective standards, and

11

• initialized data are initialized according to the respective standards.

8

12

C.13.2

13

C Function Prototype:

14

15 16 17 18 19 20 21 22 23 24 25 26 27

Example of Fortran calling C (18.3)

int C_Library_Function(void* sendbuf, int sendcount, int *recvcounts); Fortran Module: MODULE CLIBFUN_INTERFACE INTERFACE INTEGER (C_INT) FUNCTION C_LIBRARY_FUNCTION (SENDBUF, SENDCOUNT, RECVCOUNTS) & BIND(C, NAME=’C_Library_Function’) USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE TYPE (C_PTR), VALUE :: SENDBUF INTEGER (C_INT), VALUE :: SENDCOUNT INTEGER (C_INT) :: RECVCOUNTS(*) END FUNCTION C_LIBRARY_FUNCTION END INTERFACE END MODULE CLIBFUN_INTERFACE

28

1 The module CLIBFUN_INTERFACE contains the declaration of the Fortran dummy arguments, which corres-

29 30

pond to the C formal parameters. The NAME= is used in the BIND attribute in order to handle the case-sensitive name change between Fortran and C from “c_library_function” to “C_Library_Function”.

31

2 The first C formal parameter is the pointer to void sendbuf, which corresponds to the Fortran dummy argument

32 33 34 35 36 37

SENDBUF, which has the type C_PTR and the VALUE attribute. 3 The second C formal parameter is the int sendcount, which corresponds to the Fortran dummy argument

SENDCOUNT, which has the type INTEGER (C_INT) and the VALUE attribute. 4 The third C formal parameter is the pointer to int recvcounts, which corresponds to the Fortran dummy

argument RECVCOUNTS, which is an assumed-size array of type INTEGER (C_INT). 5 This example shows how C_Library_Function might be referenced in a Fortran program unit:

ISO/IEC JTC 1/SC 22/WG5/N2184

611

J3/21-007r1

WD 1539-1

2021-05-21

USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT, C_FLOAT, C_LOC USE CLIBFUN_INTERFACE ... REAL (C_FLOAT), TARGET :: SEND(100) INTEGER (C_INT) :: SENDCOUNT, RET INTEGER (C_INT), ALLOCATABLE :: RECVCOUNTS(:) ... ALLOCATE( RECVCOUNTS(100) ) ... RET = C_LIBRARY_FUNCTION(C_LOC(SEND), SENDCOUNT, RECVCOUNTS) ...

1 2 3 4 5 6 7 8 9 10 11

12

6 The first Fortran actual argument is a reference to the function C_LOC which returns the value of the C address

13 14

of its argument, SEND. This value becomes the value of the first formal parameter, the pointer sendbuf, in C_Library_Function.

15

7 The second Fortran actual argument is SENDCOUNT of type INTEGER (C_INT). Its value becomes the initial

16

value of the second formal parameter, the int sendcount, in C_Library_Function.

17

8 The third Fortran actual argument is the allocatable array RECVCOUNTS of type INTEGER (C_INT). The

18

21

base C address of this array becomes the value of the third formal parameter, the pointer recvcounts, in C_Library_Function. Note that interoperability is based on the characteristics of the dummy arguments in the specified interface and not on those of the actual arguments. Thus, the fact that the actual argument is allocatable is not relevant here.

22

C.13.3

23

Fortran Code:

19 20

Example of C calling Fortran (18.3)

SUBROUTINE SIMULATION(ALPHA, BETA, GAMMA, DELTA, ARRAYS) BIND(C) USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE INTEGER (C_LONG), VALUE :: ALPHA REAL (C_DOUBLE), INTENT(INOUT) :: BETA INTEGER (C_LONG), INTENT(OUT) :: GAMMA REAL (C_DOUBLE),DIMENSION(*),INTENT(IN) :: DELTA TYPE, BIND(C) :: PASS INTEGER (C_INT) :: LENC, LENF TYPE (C_PTR) :: C, F END TYPE PASS TYPE (PASS), INTENT(INOUT) :: ARRAYS REAL (C_FLOAT), ALLOCATABLE, TARGET, SAVE :: ETA(:) REAL (C_FLOAT), POINTER :: C_ARRAY(:) ... ! Associate C_ARRAY with an array allocated in C CALL C_F_POINTER (ARRAYS%C, C_ARRAY, [ ARRAYS%LENC ]) ... ! Allocate an array and make it available in C

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

612

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5

C Structure Declaration:

7

struct pass { int lenc, lenf; float *c, *f; };

9 10

11 12 13

14 15

16 17

J3/21-007r1

ARRAYS%LENF = 100 ALLOCATE (ETA(ARRAYS%LENF)) ARRAYS%F = C_LOC(ETA) ... END SUBROUTINE SIMULATION

6

8

WD 1539-1

C Function Prototype: void simulation(long alpha, double *beta, long *gamma, double delta[], struct pass *arrays); C Calling Sequence: simulation(alpha, beta, gamma, delta, arrays); 1 The above-listed Fortran code specifies a subroutine SIMULATION. This subroutine corresponds to the C void

function simulation.

18

2 The Fortran subroutine references the intrinsic module ISO_C_BINDING.

19

3 The first Fortran dummy argument of the subroutine is ALPHA, which has the type INTEGER(C_LONG) and

20 21

the VALUE attribute. This dummy argument corresponds to the C formal parameter alpha, which is a long. The C actual argument is also a long.

22

4 The second Fortran dummy argument of the subroutine is BETA, which has the type REAL(C_DOUBLE) and

23 24

the INTENT (INOUT) attribute. This dummy argument corresponds to the C formal parameter beta, which is a pointer to double. An address is passed as the C actual argument.

25

5 The third Fortran dummy argument of the subroutine is GAMMA, which has the type INTEGER(C_LONG)

26 27

and the INTENT (OUT) attribute. This dummy argument corresponds to the C formal parameter gamma, which is a pointer to long. An address is passed as the C actual argument.

28

6 The fourth Fortran dummy argument is the assumed-size array DELTA, which has the type REAL (C_DOUBLE)

29 30

and the INTENT (IN) attribute. This dummy argument corresponds to the C formal parameter delta, which is a double array. The C actual argument is also a double array.

31

7 The fifth Fortran dummy argument is ARRAYS, which is a structure for accessing an array allocated in C and

32

an array allocated in Fortran. The lengths of these arrays are held in the components LENC and LENF; their C addresses are held in components C and F.

33

ISO/IEC JTC 1/SC 22/WG5/N2184

613

J3/21-007r1

1

C.13.4

WD 1539-1

2021-05-21

Example of calling C functions with noninteroperable data (18.10)

2

1 Many Fortran processors support 16-byte real numbers, which might not be supported by the C processor.

3

Assume a Fortran programmer wants to use a C procedure from a message passing library for an array of these reals. The C prototype of this procedure is

4

void ProcessBuffer(void *buffer, int n_bytes);

5 6

with the corresponding Fortran interface USE, INTRINSIC :: ISO_C_BINDING INTERFACE SUBROUTINE PROCESS_BUFFER(BUFFER,N_BYTES) BIND(C,NAME="ProcessBuffer") IMPORT :: C_PTR, C_INT TYPE(C_PTR), VALUE :: BUFFER ! The ‘‘C address’’ of the array buffer INTEGER (C_INT), VALUE :: N_BYTES ! Number of bytes in buffer END SUBROUTINE PROCESS_BUFFER END INTERFACE

7 8 9 10 11 12 13 14

15 16

2 This can be done using C_LOC if the particular Fortran processor specifies that C_LOC returns an appropriate

address: REAL(R_QUAD), DIMENSION(:), ALLOCATABLE, TARGET :: QUAD_ARRAY ... CALL PROCESS_BUFFER(C_LOC(QUAD_ARRAY), INT(16*SIZE(QUAD_ARRAY),C_INT)) ! One quad real takes 16 bytes on this processor

17 18 19 20

21 22 23

C.13.5

Example of opaque communication between C and Fortran (18.3)

1 The following example demonstrates how a Fortran processor can make a modern object-oriented random number

generator written in Fortran available to a C program. USE, INTRINSIC :: ISO_C_BINDING ! Assume this code is inside a module

24 25 26

TYPE RANDOM_STREAM ! A (uniform) random number generator (URNG) CONTAINS PROCEDURE(RANDOM_UNIFORM), DEFERRED, PASS(STREAM) :: NEXT ! Generates the next number from the stream END TYPE RANDOM_STREAM

27 28 29 30 31 32 33

ABSTRACT INTERFACE ! Abstract interface of Fortran URNG SUBROUTINE RANDOM_UNIFORM(STREAM, NUMBER) IMPORT :: RANDOM_STREAM, C_DOUBLE CLASS(RANDOM_STREAM), INTENT(INOUT) :: STREAM REAL(C_DOUBLE), INTENT(OUT) :: NUMBER END SUBROUTINE RANDOM_UNIFORM END INTERFACE

34 35 36 37 38 39 40 41

614

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

1

2 A polymorphic object with declared type RANDOM_STREAM is not interoperable with C. However, we can

2

make such a random number generator available to C by packaging it inside another nonpolymorphic, nonparameterized derived type:

3 4 5 6

7 8 9 10 11 12 13 14

TYPE :: URNG_STATE ! No BIND(C), as this type is not interoperable CLASS(RANDOM_STREAM), ALLOCATABLE :: STREAM END TYPE URNG_STATE 3 The following two procedures will enable a C program to use our Fortran uniform random number generator:

! Initialize a uniform random number generator: SUBROUTINE INITIALIZE_URNG(STATE_HANDLE, METHOD) & BIND(C, NAME="InitializeURNG") TYPE(C_PTR), INTENT(OUT) :: STATE_HANDLE ! An opaque handle for the URNG CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: METHOD ! The algorithm to be used

15 16 17

TYPE(URNG_STATE), POINTER :: STATE ! An actual URNG object

18 19 20 21 22 23 24 25 26

ALLOCATE(STATE) ! There needs to be a corresponding finalization ! procedure to avoid memory leaks, not shown in this example ! Allocate STATE%STREAM with a dynamic type depending on METHOD ... STATE_HANDLE=C_LOC(STATE) ! Obtain an opaque handle to return to C END SUBROUTINE INITIALIZE_URNG

27 28 29 30 31 32 33

! Generate a random number: SUBROUTINE GENERATE_UNIFORM(STATE_HANDLE, NUMBER) & BIND(C, NAME="GenerateUniform") TYPE(C_PTR), INTENT(IN), VALUE :: STATE_HANDLE ! An opaque handle: Obtained via a call to INITIALIZE_URNG REAL(C_DOUBLE), INTENT(OUT) :: NUMBER

34 35 36

TYPE(URNG_STATE), POINTER :: STATE ! A pointer to the actual URNG

37 38 39 40 41 42

CALL C_F_POINTER(CPTR=STATE_HANDLE, FPTR=STATE) ! Convert the opaque handle into a usable pointer CALL STATE%STREAM%NEXT(NUMBER) ! Use the type-bound procedure NEXT to generate NUMBER END SUBROUTINE GENERATE_UNIFORM

ISO/IEC JTC 1/SC 22/WG5/N2184

615

J3/21-007r1

WD 1539-1

1

C.13.6

Using assumed type to interoperate with C

2

C.13.6.1

Overview

3 4

2021-05-21

1 The mechanism for handling unlimited polymorphic entities whose dynamic type is interoperable with C is

designed to handle the following two situations: (1)

A formal parameter that is a C pointer to void. This is an address, and no further information about the entity is provided. The formal parameter corresponds to a dummy argument that is a nonallocatable nonpointer scalar or is an assumed-size array.

(2)

10

A formal parameter that is the address of a C descriptor. Additional information on the status, type, size, and shape is implicitly provided. The formal parameter corresponds to a dummy argument that is assumed-shape or assumed-rank.

11

2 In the first situation, it is the programmer’s responsibility to explicitly provide any information needed on the

5 6 7 8 9

12

status, type, size, and shape of the entity.

13

C.13.6.2

14

Mapping of interfaces with void * C parameters to Fortran

1 A C interface for message passing or input/output functionality could be provided in the form

15

int EXAMPLE_send(const void *buffer, size_t buffer_size, const HANDLE_t *handle);

16

18

where the buffer_size argument is given in units of bytes, and the handle argument (which is of a type aliased to int) provides information about the target the buffer is to be transferred to. In this example, type resolution is not required.

19

2 The first method provides a thin binding; a call to EXAMPLE_send from Fortran directly invokes the C function.

17

INTERFACE INTEGER (C_INT) FUNCTION example_send(buffer, buffer_size, handle) & BIND(C, NAME=’EXAMPLE_send’) USE, INTRINSIC :: ISO_C_BINDING TYPE(*), INTENT (IN) :: buffer(*) INTEGER (C_SIZE_T), VALUE :: buffer_size INTEGER (C_INT), INTENT (IN) :: handle END FUNCTION END INTERFACE

20 21 22 23 24 25 26 27 28

29 30

3 It is assumed that this interface is declared in the specification part of the module MOD_EXAMPLE_OLD. An

example of its use follows: USE, INTRINSIC :: ISO_C_BINDING USE MOD_EXAMPLE_OLD

31 32 33

REAL(C_FLOAT) :: x(100) INTEGER(C_INT) :: y(10,10) REAL(C_DOUBLE) :: z INTEGER(C_INT) :: status, handle ...

34 35 36 37 38

616

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3 4 5 6

7 8

WD 1539-1

J3/21-007r1

! Assign values to x, y, z and initialize handle. ... ! Send values in x, y, and z using EXAMPLE_send. status = example_send(x, C_SIZEOF(x), handle) status = example_send(y, C_SIZEOF(y), handle) status = example_send([ z ], C_SIZEOF(z), handle) 4 In those invocations, x and y are passed directly with sequence association, but it is necessary to make an array

expression containing the value of z to pass it.

9

5 The second method provides a Fortran interface which is easier to use, but requires writing a separate C wrapper

10

routine. With this method, a C descriptor is created because the buffer is assumed-rank in the Fortran interface; the use of an optional argument is also demonstrated.

11 12 13 14 15 16 17 18 19

20 21 22 23

INTERFACE SUBROUTINE example_send(buffer, handle, status) BIND(C, NAME="EG_send_fortran") USE, INTRINSIC :: ISO_C_BINDING TYPE(*), CONTIGUOUS, INTENT (IN) :: buffer(..) INTEGER (C_INT), INTENT (IN) :: handle INTEGER (C_INT), INTENT(OUT), OPTIONAL :: status END SUBROUTINE END INTERFACE 6 It is assumed that this interface is declared in the specification part of a module MOD_EXAMPLE_NEW.

Example invocations from Fortran are then USE, INTRINSIC :: iso_c_binding USE mod_example_new

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

TYPE, BIND(C) :: my_derived INTEGER(C_INT) :: len_used REAL(C_FLOAT) :: stuff(100) END TYPE TYPE(my_derived) :: w(3) REAL(C_FLOAT) :: x(100) INTEGER(C_INT) :: y(10,10) REAL(C_DOUBLE) :: z INTEGER(C_INT) :: status, handle ... ! Assign values to w, x, y, z and initialize handle. ... ! Send values in w, x, y, and z using example_send. CALL example_send(w, handle, status) CALL example_send(x, handle) CALL example_send(y, handle) CALL example_send(z, handle) CALL example_send(y(:,5), handle) ! Fifth column of y. CALL example_send(y(1,5), handle) ! Scalar y(1,5) passed by descriptor.

ISO/IEC JTC 1/SC 22/WG5/N2184

617

J3/21-007r1

1

WD 1539-1

2021-05-21

7 The wrapper routine can be written in C as follows.

#include "ISO_Fortran_binding.h"

2 3

void EXAMPLE_send_fortran(const CFI_cdesc_t *buffer, const HANDLE_t *handle, int *status) { int status_local; size_t buffer_size; int i;

4 5 6 7 8 9 10

buffer_size = buffer->elem_len; for (i=0; i<buffer->rank; i++) { buffer_size *= buffer->dim[i].extent; } status_local = EXAMPLE_send(buffer->base_addr,buffer_size, handle); if (status != NULL) *status = status_local;

11 12 13 14 15 16

}

17

18

C.13.7

Using assumed-type variables in Fortran

19

1 An assumed-type dummy argument in a Fortran procedure can be used as an actual argument corresponding to an

20

assumed-type dummy in a call to another procedure. In the following example, the Fortran subroutine SIMPLE_SEND serves as a wrapper to hide the complications associated with calls to a C function named ACTUAL_Send. Module COMM_INFO contains node and address information for the current data transfer operations.

21 22

SUBROUTINE SIMPLE_SEND(buffer, nbytes) USE comm_info, ONLY: my_node, r_node, r_addr USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE

23 24 25 26 27

TYPE(*), INTENT (IN) :: buffer(*) INTEGER :: nbytes, ierr

28 29 30

INTERFACE SUBROUTINE actual_Send(buffer, nbytes, node, addr, ierr) & BIND(C, NAME="ACTUAL_Send") IMPORT :: C_SIZE_T, C_INT, C_INTPTR_T TYPE(*), INTENT (IN) :: buffer(*) INTEGER(C_SIZE_T), VALUE :: nbytes INTEGER(C_INT), VALUE :: node INTEGER(C_INTPTR_T), VALUE :: addr INTEGER(C_INT), INTENT(OUT) :: ierr END SUBROUTINE actual_Send END INTERFACE

31 32 33 34 35 36 37 38 39 40 41 42

CALL actual_Send(buffer, INT(nbytes, C_SIZE_T), r_node, r_addr, ierr)

43 44

618

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

J3/21-007r1

IF (ierr /= 0) THEN PRINT *, "Error sending from node", my_node, "to node", r_node PRINT *, "Program Aborting" ! Or call a recovery procedure ERROR STOP ! Omit in the recovery case END IF END SUBROUTINE simple_Send

1 2 3 4 5 6

7

WD 1539-1

C.13.8

Simplifying interfaces for arbitrary rank procedures

8

1 There are situations where an assumed-rank dummy argument can be useful in Fortran, although a Fortran

9

11

procedure cannot itself access its value. For example, the IEEE inquiry functions in Clause 14 could be written using an assumed-rank dummy argument instead of writing 16 separate specific routines, one for each possible rank.

12

2 In particular, the specific procedures for the IEEE_SUPPORT_DIVIDE function could possibly be implemented

10

13

in Fortran as follows: INTERFACE ieee_support_divide MODULE PROCEDURE ieee_support_divide_noarg, ieee_support_divide_onearg_r, & ieee_support_divide_onearg_d END INTERFACE ieee_support_divide

14 15 16 17 18

...

19 20

LOGICAL FUNCTION ieee_support_divide_noarg () ieee_support_divide_noarg = .TRUE. END FUNCTION ieee_support_divide_noarg

21 22 23 24

LOGICAL FUNCTION ieee_support_divide_onearg_r (x) REAL, INTENT (IN) :: x(..) ieee_support_divide_onearg_r4 = .TRUE. END FUNCTION ieee_support_divide_onearg_r

25 26 27 28 29

LOGICAL FUNCTION ieee_support_divide_onearg_d (x) DOUBLE PRECISION, INTENT (IN) :: x(..) ieee_support_divide_onearg_r8 = .TRUE. END FUNCTION ieee_support_divide_onearg_d

30 31 32 33

34

C.13.9

Processing assumed-shape arrays in C

35

1 The example shown below calculates the product of individual elements of arrays A and B and returns the result

36

in array C. The Fortran interface of elemental_mult will accept arguments of any type and rank. However, the C function will return an error code if any argument is not a two-dimensional int array. Note that the arguments are permitted to be array sections, so the C function does not assume that any argument is contiguous.

37 38 39 40

2 The Fortran interface is:

INTERFACE

ISO/IEC JTC 1/SC 22/WG5/N2184

619

J3/21-007r1

2021-05-21

FUNCTION elemental_mult(a, b, c) BIND(C, NAME="elemental_mult_c") RESULT(err) USE, INTRINSIC :: ISO_C_BINDING INTEGER(C_INT) :: err TYPE(*), DIMENSION(..) :: a, b, c END FUNCTION elemental_mult END INTERFACE

1 2 3 4 5 6

7

WD 1539-1

3 The definition of the C function is:

#include "ISO_Fortran_binding.h"

8 9

int elemental_mult_c(CFI_cdesc_t * a_desc, CFI_cdesc_t * b_desc, CFI_cdesc_t * c_desc) { size_t i, j, ni, nj;

10 11 12 13

int err = 1;

14

/* this error code represents all errors */

15

char * a_col = (char*) a_desc->base_addr; char * b_col = (char*) b_desc->base_addr; char * c_col = (char*) c_desc->base_addr; char *a_elt, *b_elt, *c_elt;

16 17 18 19 20

/* Only support int. */ if (a_desc->type != CFI_type_int || b_desc->type != CFI_type_int || c_desc->type != CFI_type_int) { return err; }

21 22 23 24 25 26

/* Only support two dimensions. */ if (a_desc->rank != 2 || b_desc->rank != 2 || c_desc->rank != 2) { return err; }

27 28 29 30 31

ni = a_desc->dim[0].extent; nj = a_desc->dim[1].extent;

32 33 34

/* Ensure the shapes conform. */ if (ni != b_desc->dim[0].extent || ni != c_desc->dim[0].extent) return err; if (nj != b_desc->dim[1].extent || nj != c_desc->dim[1].extent) return err;

35 36 37 38

/* Multiply the elements of the two arrays. */ for (j = 0; j < nj; j++) { a_elt = a_col; b_elt = b_col; c_elt = c_col; for (i = 0; i < ni; i++) { *(int*)a_elt = *(int*)b_elt * *(int*)c_elt;

39 40 41 42 43 44 45

620

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

a_elt += a_desc->dim[0].sm; b_elt += b_desc->dim[0].sm; c_elt += c_desc->dim[0].sm;

1 2 3

} a_col += a_desc->dim[1].sm; b_col += b_desc->dim[1].sm; c_col += c_desc->dim[1].sm;

4 5 6 7

} return 0;

8 9 10

}

11

C.13.10

Creating a contiguous copy of an array

12

1 A C function might need to create a contiguous copy of an array section, for example, to pass the array section

13

as an actual argument corresponding to a dummy argument with the CONTIGUOUS attribute. The following example provides functions that can be used to copy an array described by a CFI_cdesc_t descriptor to a contiguous buffer. The input array need not be contiguous.

14 15 16 17 18

2 The C functions are:

#include "ISO_Fortran_binding.h" /* Other necessary includes omitted. */

19 20 21 22 23 24 25 26 27 28

/* * Returns the number of elements in the object described by desc. * If it is an array, it need not be contiguous. * (The number of elements could be zero). */ size_t numElements(const CFI_cdesc_t * desc) { CFI_rank_t r; size_t num = 1;

29

for (r = 0; r < desc->rank; r++) { num *= desc->dim[r].extent; } return num;

30 31 32 33 34

}

35 36 37 38 39 40 41 42 43 44

/* * Auxiliary recursive function to copy an array of a given rank. * Recursion is useful because an array of rank n is composed of an * ordered set of arrays of rank n-1. */ static void *_copyToContiguous (const CFI_cdesc_t *vald, void *output, const void *input, CFI_rank_t rank) { CFI_index_t e;

ISO/IEC JTC 1/SC 22/WG5/N2184

621

J3/21-007r1

WD 1539-1

2021-05-21

1

if (rank == 0) { /* Copy scalar element. */ memcpy (output, input, vald->elem_len); output = (void *)((char *)output + vald->elem_len); } else { for (e = 0; e < vald->dim[rank-1].extent; e++) { /* Recurse on subarrays of lesser rank. */ output = _copyToContiguous (vald, output, input, rank-1); input = (void *) ((char *)input + vald->dim[rank].sm); } } return output;

2 3 4 5 6 7 8 9 10 11 12 13 14

}

15 16

/* * General routine to copy the elements in the array described by vald * to buffer, as done by sequence association. The array itself can * be non-contiguous. This is not the most efficient approach. */ void copyToContiguous (void * buffer, const CFI_cdesc_t * vald) { _copyToContiguous (vald, buffer, vald->base_addr, vald->rank); }

17 18 19 20 21 22 23 24

25

C.13.11

Changing the attributes of an array

26

1 A C programmer might want to call more than one Fortran procedure and the attributes of an array involved

27

might differ between the procedures. In this case, it is necessary to set up more than one C descriptor for the array. For example, this code fragment initializes the first C descriptor for an allocatable entity of rank 2, calls a procedure that allocates the array described by the first C descriptor, constructs the second C descriptor by invoking CFI_section with the value CFI_attribute_other for the attribute parameter, then calls a procedure that expects an assumed-shape array.

28 29 30 31

CFI_CDESC_T(2) loc_alloc, loc_assum; CFI_cdesc_t * desc_alloc = (CFI_cdesc_t *)&loc_alloc, * desc_assum = (CFI_cdesc_t *)&loc_assum; CFI_index_t extents[2]; CFI_rank_t rank = 2; int flag;

32 33 34 35 36 37 38

flag = CFI_establish(desc_alloc, NULL, CFI_attribute_allocatable, CFI_type_double, sizeof(double), rank,

39 40 41 42 43 44

622

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

NULL);

1 2 3

Fortran_factor (desc_alloc, . . . ); /* Allocates array described by desc_alloc. */

4 5 6 7

/* Extract extents from descriptor. */ extents[0] = desc_alloc->dim[0].extent; extents[1] = desc_alloc->dim[1].extent;

8 9 10 11 12 13 14 15

flag = CFI_establish(desc_assum, desc_alloc->base_addr, CFI_attribute_other, CFI_type_double, sizeof(double), rank, extents);

16 17

Fortran_solve (desc_assum, . . . ); /* Uses array allocated in Fortran_factor. */

18

2 After invocation of the second CFI_establish, the lower bounds stored in the dim member of desc_assum will

19

have the value 0 even if the corresponding entries in desc_alloc have different values.

20

C.13.12

Creating an array section in C using CFI_section

21

1 The C function set_odd sets every second element of an array to a specific value, beginning with the first element.

22

It does this by making an array section descriptor for the elements to be set, and calling a Fortran subroutine SET_ALL that sets every element of an assumed-shape array to a specific value. An interface block for set_odd permits it to be also called from Fortran.

23 24 25 26 27 28 29

SUBROUTINE set_all(int_array, val) BIND(C) INTEGER(C_INT) :: int_array(:) INTEGER(C_INT), VALUE :: val int_array = val END SUBROUTINE

30 31 32 33 34 35 36 37

INTERFACE SUBROUTINE set_odd(int_array, val) BIND(C) USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_INT INTEGER(C_INT) :: int_array(:) INTEGER(C_INT), VALUE :: val END SUBROUTINE END INTERFACE

38 39

#include "ISO_Fortran_binding.h"

40 41 42 43

void set_odd(CFI_cdesc_t *int_array, int val) { CFI_index_t lower_bound[1], upper_bound[1], stride[1];

ISO/IEC JTC 1/SC 22/WG5/N2184

623

J3/21-007r1

WD 1539-1

2021-05-21

CFI_CDESC_T(1) array; int status; /* Create a new descriptor which will contain the section. */ status = CFI_establish((CFI_cdesc_t *)&array, NULL, CFI_attribute_other, int_array->type, int_array->elem_len, /* rank */ 1, /* extents is ignored */NULL);

1 2 3 4 5 6 7 8 9 10 11

lower_bound[0] = int_array->dim[0].lower_bound; upper_bound[0] = lower_bound[0] + (int_array->dim[0].extent - 1); stride[0] = 2;

12 13 14 15

status = CFI_section((CFI_cdesc_t *)&array, int_array, lower_bound, upper_bound, stride);

16 17 18 19 20 21

set_all( (CFI_cdesc_t *) &array, val);

22 23

/* Here one could make use of int_array and access all its data. */

24

}

25

26

2 The set_odd procedure can be called from Fortran as follows:

INTEGER(C_INT) :: d(5) d = (/ 1, 2, 3, 4, 5 /) CALL set_odd(d, -1) PRINT *, d

27 28 29 30

31

3 This program will print something like:

-1

32

33 34

2

-1

4

-1

4 During execution of the subroutine SET_ALL, its dummy argument INT_ARRAY would have size (and upper

bound) 3.

35

5 It is also possible to invoke set_odd() from C. However, it would be the C programmer’s responsibility to make

36 37

sure that all members of the C descriptor have the correct value on entry to the function. Inserting additional checking into the function could alleviate this problem.

38

6 Following is an example C function that dynamically generates a C descriptor for an assumed-shape array and

39

calls set_odd. #include <stdio.h>

40

624

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2

WD 1539-1

J3/21-007r1

#include <stdlib.h> #include "ISO_Fortran_binding.h"

3 4

#define ARRAY_SIZE 5

5 6 7 8 9 10 11 12

void example_of_calling_set_odd(void) { CFI_CDESC_T(1) d; CFI_index_t extent[1]; CFI_index_t subscripts[1]; void *base; int i, status;

13

base = malloc(ARRAY_SIZE*sizeof(int)); extent[0] = ARRAY_SIZE; status = CFI_establish((CFI_cdesc_t *)&d, base, CFI_attribute_other, CFI_type_int, /* element length is ignored */ 0, /* rank */ 1, extent);

14 15 16 17 18 19 20 21 22 23

set_odd((CFI_cdesc_t *)&d, -1);

24 25

for (i=0; i<ARRAY_SIZE; i++) { subscripts[0] = i; printf(" %d",*((int *)CFI_address((CFI_cdesc_t *)&d, subscripts))); } putc(10, stdout); free(base);

26 27 28 29 30 31 32

}

33

The above C function will print similar output to that of the preceding Fortran program.

34

C.13.13

35 36 37

Use of CFI_setpointer

1 The C function change_target modifies a pointer to an integer variable to become associated with a global

variable defined inside C: #include "ISO_Fortran_binding.h"

38 39

int y = 2;

40 41 42 43 44

void change_target(CFI_cdesc_t *ip) { CFI_CDESC_T(0) yp; int status; /* Make local yp point at y. */

ISO/IEC JTC 1/SC 22/WG5/N2184

625

J3/21-007r1

2 3 4 5 6 7 8 9 10 11 12

}

13

15 16

2 The restrictions on the use of CFI_establish prohibit direct modification of the incoming pointer entity ip by

invoking that function on it. 3 The following program illustrates the usage of change_target from Fortran.

PROGRAM change_target_example USE, INTRINSIC :: ISO_C_BINDING INTERFACE SUBROUTINE change_target(ip) BIND(C) IMPORT :: C_INT INTEGER(C_INT), POINTER :: ip END SUBROUTINE END INTERFACE INTEGER(C_INT), TARGET :: it = 1 INTEGER(C_INT), POINTER :: it_ptr it_ptr => it WRITE (*,*) it_ptr CALL change_target(it_ptr) WRITE (*,*) it_ptr

17 18 19 20 21 22 23 24 25 26 27 28 29 30

31

2021-05-21

status = CFI_establish((CFI_cdesc_t *)&yp, &y, CFI_attribute_pointer, CFI_type_int, /* elem_len is ignored */ sizeof(int), /* rank */ 0, /* extents are ignored */ NULL); /* Pointer-associate ip with (the target of) yp. */ status = CFI_setpointer(ip, (CFI_cdesc_t *)&yp, NULL); if (status != CFI_SUCCESS) { . . . Report run time error. }

1

14

WD 1539-1

4 This will print something similar to

33

1 2

34

C.13.14

32

Mapping of MPI interfaces to Fortran

35

1 The Message Passing Interface (MPI) specifies procedures for exchanging data between MPI processes. This

36

example shows the usage of MPI_Send and is similar to the second variant of EXAMPLE_Send in C.13.6.2. It also shows the usage of assumed-length character dummy arguments and optional dummy arguments.

37 38

2 MPI_Send has the C prototype:

int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);

39 40

626

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1 2 3

WD 1539-1

J3/21-007r1

where MPI_Datatype and MPI_Comm are opaque handles. Most MPI C functions return an error code, which in Fortran is the last dummy argument to the corresponding subroutine and can be made optional. Thus, the use of a Fortran subroutine requires a wrapper function, declared as

5

void MPI_Send_f(CFI_cdesc_t *buf, int count, MPI_Datatype_f datatype, int dest, int tag, MPI_Datatype_f comm, int *ierror);

6

3 This wrapper function will convert MPI_Datatype_f and MPI_Comm_f to MPI_Datatype and MPI_Comm, and pro-

4

7 8 9

10 11 12 13 14 15 16

duce a contiguous void * buffer from CFI_cdesc_t *buf (if necessary). 4 Similarly, the wrapper function for MPI_Comm_set_name could have the C prototype:

void MPI_Comm_set_name_f(MPI_Comm comm, CFI_cdesc_t *comm_name, int *ierror); 5 The Fortran handle types and interfaces are defined in the module MPI_F08. For example,

MODULE mpi_f08 ... TYPE, BIND(C) :: mpi_comm PRIVATE INTEGER(C_INT) :: mpi_val END TYPE mpi_comm

17 18 19 20 21 22 23 24 25 26 27 28

INTERFACE SUBROUTINE MPI_SEND(buf,count,datatype,dest,tag,comm,ierror) & BIND(C, NAME=’MPI_Send_f’) USE, INTRINSIC :: ISO_C_BINDING IMPORT :: MPI_Datatype, MPI_Comm TYPE(*), DIMENSION(..), INTENT (IN) :: buf INTEGER(C_INT), VALUE, INTENT (IN) :: count, dest, tag TYPE(mpi_datatype), INTENT (IN) :: datatype TYPE(mpi_comm), INTENT (IN) :: comm INTEGER(C_INT), OPTIONAL, INTENT (OUT) :: ierror END SUBROUTINE mpi_send

29 30 31 32 33 34 35 36 37 38 39 40

41

SUBROUTINE mpi_comm_set_name(comm,comm_name,ierror) & BIND(C, NAME=’MPI_Comm_set_name_f’) USE, INTRINSIC :: ISO_C_BINDING IMPORT :: mpi_comm TYPE(mpi_comm), INTENT (IN) :: comm CHARACTER(KIND=C_CHAR, LEN=*), INTENT (IN) :: comm_name INTEGER(C_INT), OPTIONAL, INTENT (OUT) :: ierror END SUBROUTINE mpi_comm_set_name END INTERFACE ... END MODULE mpi_f08 6 Some examples of invocation from Fortran are:

ISO/IEC JTC 1/SC 22/WG5/N2184

627

J3/21-007r1

WD 1539-1

2021-05-21

USE, INTRINSIC :: ISO_C_BINDING USE :: MPI_f08

1 2 3

TYPE(mpi_comm) :: comm REAL :: x(100) INTEGER :: y(10,10) REAL(KIND(1.0d0)) :: z INTEGER :: dest, tag, ierror ... ! Assign values to x, y, z and initialize MPI variables. ...

4 5 6 7 8 9 10 11 12

! Set the name of the communicator. CALL mpi_comm_set_name(comm, "Communicator Name", ierror)

13 14 15

! Send values in x, y, and z. CALL mpi_send(x, 100, MPI_REAL, dest, tag, comm, ierror) IF (ierror/=0) PRINT *, ’WARNING: X send error’, ierror CALL mpi_send(y(3,:), 10, MPI_INTEGER, dest, tag, comm) CALL mpi_send(z, 1, MPI_DOUBLE_PRECISION, dest, tag, comm)

16 17 18 19 20

21

7 The first example sends the entire array X and includes the optional error argument return value. The second

22 23

example sends a noncontiguous subarray (the third row of Y) and the third example sends a scalar Z. Note the differences between the calls in this example and those in C.13.6.2.

24

C.14

Clause 19 notes

25

C.14.1

Examples of global identifiers and binding labels (19.2)

26

Example 1: MODULE M1 INTERFACE SUBROUTINE S() BIND(C,NAME=’X’) END END INTERFACE END MODULE MODULE M2 INTERFACE SUBROUTINE S() BIND(C,NAME=’Y’) END END INTERFACE END MODULE

27 28 29 30 31 32 33 34 35 36 37 38

39 40

1 The name S in each module is a local identifier. The two interfaces declare two different external procedures, one

with the global identifier “X”, the other with the global identifier “Y”.

628

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

1

MODULE M1 INTERFACE SUBROUTINE S1() BIND(C,NAME=’X’) END END INTERFACE END MODULE MODULE M2 INTERFACE SUBROUTINE S2() BIND(C,NAME=’X’) END END INTERFACE END MODULE

3 4 5 6 7 8 9 10 11 12 13

2 The names S1 and S2 are local identifiers. The interfaces declare the same external procedure, which has the

15

global identifier “X”.

16

C.14.2

17

Examples of host association (19.5.1.4)

1 The first two examples are examples of valid host association. The third example is an example of invalid host

18

association.

19

Example 1:

20 21 22 23 24 25

PROGRAM A INTEGER I, J ... CONTAINS SUBROUTINE B INTEGER I

26

29 30 31

32 33 34 35 36 37 38 39 40

! Declaration of I hides ! program A’s declaration of I

... I = J

27 28

J3/21-007r1

Example 2:

2

14

WD 1539-1

! Use of variable J from program A ! through host association END SUBROUTINE B END PROGRAM A Example 2: PROGRAM A TYPE T ... END TYPE T ... CONTAINS SUBROUTINE B IMPLICIT TYPE (T) (C)

! Refers to type T declared below

ISO/IEC JTC 1/SC 22/WG5/N2184

629

J3/21-007r1

WD 1539-1

! in subroutine B, not type T ! declared above in program A

1 2

... TYPE T ... END TYPE T ... END SUBROUTINE B END PROGRAM A

3 4 5 6 7 8 9

10

2021-05-21

Example 3: PROGRAM Q REAL (KIND = 1) :: C ... CONTAINS SUBROUTINE R REAL (KIND = KIND (C)) :: D

11 12 13 14 15 16 17

! Invalid declaration ! See below

REAL (KIND = 2) :: C ... END SUBROUTINE R END PROGRAM Q

18 19 20 21

22

2 In the declaration of D in subroutine R, the use of C would refer to the declaration of C in subroutine R, not

23

program Q. However, it is invalid because the declaration of C is required to occur before it is used in the declaration of D (10.1.12).

24

630

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

Index In the index, entries in italics denote BNF terms, and page numbers in bold face denote primary text or definitions.

Symbols

A

−, 157 <, 161, 460 <=, 161 >, 161 >=, 161 *, 52, 55, 57, 58, 63, 102, 106, 117, 141, 157, 246, 275, 288, 293, 315, 334 **, 157 +, 157 -stmt, 18 .AND., 152, 153, 156, 160, 160, 358 .EQ., 151, 153, 156, 160, 161, 161, 163, 306, 460 .EQV., 152, 153, 156, 160, 160 .FALSE., 66, 494 .GE., 151, 153, 156, 160, 161, 163, 306, 460 .GT., 151, 153, 156, 160, 161, 163, 306, 460 .LE., 151, 153, 156, 160, 161, 163, 306, 460 .LT., 151, 153, 156, 160, 161, 163, 306, 460 .NE., 151, 153, 156, 160, 161, 161, 163, 306, 460 .NEQV., 152, 153, 156, 160, 160, 422 .NOT., 152, 153, 156, 160, 160 .OR., 152, 153, 156, 160, 160, 359 .TRUE., 66, 494 /, 157 / edit descriptor, 285 //, 159 /=, 161, 460 : edit descriptor, 286 ;, 51 <=, 460 ==, 161, 460 >, 460 >=, 460 &, 51, 292

A edit descriptor, 282 ABS, 355, 463 ABSTRACT, 67, 67, 83, 306, 307 ABSTRACT attribute, 21, 67, 83 abstract interface, 13, 13, 298, 305, 307, 313, 332, 525, 529 abstract interface block, 13, 13, 307 abstract type, 21, 56, 80, 83, 83, 86, 133, 141 ac-do-variable (R784), 94, 94, 95, 166, 168, 527 ac-implied-do (R782), 94, 94, 95, 155, 527 ac-implied-do-control (R783), 94, 94, 155, 166–168, 527 ac-spec (R778), 94, 94 ac-value (R781), 93, 94, 94, 95 access-id (R832), 114, 114 access-name, 114 access-spec (R807), 67, 72, 73, 78–80, 91, 97, 100, 100, 114, 115, 308, 312 access-stmt (R831), 33, 91, 100, 114, 114, 115 ACCESS= specifier, 231, 232, 259, 260 accessibility attribute, 100, 114, 298 accessibility statement, 114 ACHAR, 65, 172, 356 ACOS, 356 ACOSD, 356 ACOSH, 28, 356 ACOSPI, 357 ACQUIRED_LOCK= specifier, 217, 540, 544 action, 223 action-stmt (R515), 5, 34, 34, 155, 199, 207 ACTION= specifier, 232, 233, 259, 260, 580 active image, 12, 38, 143, 144, 147, 148, 188, 217, 220, 347, 416 actual argument, 3, 14, 28, 29, 38, 42–44, 57, 60, 70, 82, 104, 106–110, 133, 135, 144, 146, 155, 164,

ISO/IEC JTC 1/SC 22/WG5/N2184

631

J3/21-007r1

WD 1539-1

165, 196, 251, 309–311, 314–326, 328, 336, 338, 339, 341–344, 348, 353, 355, 379, 403, 404, 420, 430, 446–448, 452, 463, 498–500, 502, 504, 506, 507, 528, 532–534, 537, 542–544, 553, 558, 599, 600, 602, 604, 605 actual-arg (R1524), 315, 315 actual-arg-spec (R1523), 86, 315, 315 add-op (R1009), 48, 150, 150, 151 add-operand (R1005), 150, 150, 151, 154 ADJUSTL, 357 ADJUSTR, 357 ADVANCE= specifier, 237, 238, 239, 239, 251, 578 advancing input/output statement, 226 AIMAG, 134, 357 AINT, 358 ALL, 123, 358 alloc-opt (R930), 141, 141, 142, 147 allocatable, 3, 3, 18, 28, 42, 43, 55, 58, 68, 74, 75, 77, 82, 85–87, 98, 102, 106, 108, 109, 113, 116, 127, 128, 133, 134, 141, 144–147, 165, 167, 169–173, 175, 176, 196, 211, 243, 244, 248, 289, 304, 305, 315, 319, 321, 322, 325, 333, 339, 343, 359, 378, 388, 403, 404, 415–417, 420, 431, 434, 437, 440, 444, 447, 448, 458, 464, 494, 499, 502–504, 508, 515, 517–519, 531, 532, 541 ALLOCATABLE attribute, 3, 55–57, 66, 72, 100, 100, 102, 106, 107, 111–113, 115, 133, 136, 185, 191, 195, 202, 203, 302, 305, 310, 311, 321, 325, 332, 341, 503, 531, 537, 538, 602, 606 ALLOCATABLE statement, 115 allocatable-decl (R834), 115, 115 allocatable-stmt (R833), 33, 115, 529 ALLOCATE statement, 55, 57, 63, 64, 103, 106, 141, 144, 147, 148, 175, 210, 452, 454, 513, 532, 533, 540, 542, 546, 558 allocate-coarray-spec (R940), 141, 141, 142 allocate-coshape-spec (R941), 141, 141, 142 allocate-object (R934), 63, 64, 141, 141–148, 210, 452– 454, 543, 544, 546 allocate-shape-spec (R935), 141, 141–144 allocate-stmt (R929), 34, 141, 544 ALLOCATED, 72, 73, 144, 148, 358 allocation (R933), 141, 141–144 allocation status, 43, 85, 87, 109, 112, 113, 144, 144– 148, 196, 211, 214, 322, 325, 326, 358, 416, 420, 519, 537, 541

632

2021-05-21

alphanumeric-character (R601), 46, 46, 47 alt-return-spec (R1525), 5, 207, 315, 315 ancestor component, 84 ancestor-module-name, 301 and-op (R1019), 48, 152, 152 and-operand (R1014), 152, 152 ANINT, 359 ANY, 359 arg-name, 73, 75, 79, 80 argument dummy, 319 argument association, 4, 4, 21, 55, 64, 74, 75, 102, 106, 113, 114, 146, 147, 303, 317, 318, 328, 335, 508, 528, 534, 536, 537, 552, 600 argument keyword, 10, 14, 44, 305, 308, 317, 343, 348, 463, 525, 526, 527, 588 arithmetic IF statement, 552 array, 3, 5, 11, 18, 43, 104–107, 135–139 assumed-shape, 3, 57, 103–106, 112, 125, 139, 305, 319–321, 323, 326, 332, 494, 505, 519, 599, 616, 622, 624 assumed-size, 3, 104, 106–108, 113, 126, 135, 136, 149, 166, 169, 191, 203, 204, 242, 319–321, 324, 325, 403, 434, 437, 447, 448, 499, 500, 504–508, 512, 515–519, 611, 613, 616 deferred-shape, 3, 106, 112 explicit-shape, 3, 57, 74, 102, 104, 105, 169, 319, 321, 324, 504–507 array bound, 5, 73, 75, 99, 167 array constructor, 93, 93 array element, 3, 42, 136 array element order, 137 array pointer, 3, 3, 103, 106, 165, 361, 504 array section, 3, 103, 116, 117, 134, 136, 138, 139, 185, 228, 229, 319, 320, 326, 531, 534 array-constructor (R777), 94, 94, 149, 150 array-element (R917), 116, 117, 126, 131, 132, 135, 195 array-name, 118, 529 array-section (R918), 3, 131, 135, 136–138, 195 array-spec (R815), 25, 97, 98, 100, 104, 104, 106, 107, 115, 118, 120, 128 ASCII character, 3, 63, 65, 169, 228, 229, 244, 274, 288, 289, 356, 373, 395, 398, 405, 406, 418, 432 ASCII collating sequence, 65, 356, 373, 395, 398, 405, 406, 418 ASIN, 360

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

ASIND, 360 ASINH, 360 ASINPI, 360 ASSIGN statement, 551 assigned format, 551 assigned GO TO statement, 551 ASSIGNMENT, 79, 173, 306, 310, 311 assignment, 169–182 defined, 79, 173, 310 elemental, 10, 173, 174 elemental array (FORALL), 180 masked array (WHERE), 178 pointer, 174 assignment statement, 14, 15, 28, 41, 55, 82, 169, 182, 210, 211, 454, 491, 539, 541 assignment-stmt (R1032), 34, 169, 169, 178, 180, 181, 543 ASSOCIATE construct, 43, 184, 187, 325, 527, 528, 531, 543 associate name, 4, 4, 22, 55, 58, 85, 102, 108, 146, 184, 185, 187, 205, 528, 531, 532, 537, 543 ASSOCIATE statement, 43, 184, 531 associate-construct (R1102), 34, 184, 184 associate-construct-name, 184 associate-name, 184, 202–206, 527 associate-stmt (R1103), 5, 184, 184, 207 ASSOCIATED, 72, 73, 145, 148, 344, 361 associating entity, 4, 43, 64, 140, 184, 185, 187, 189, 206, 335, 537, 537 association, 4 argument, 4, 4, 21, 55, 64, 74, 75, 102, 106, 113, 114, 146, 147, 303, 317, 318, 328, 335, 508, 528, 534, 536, 537, 552, 600 common, 129 construct, 4, 4, 146, 147, 528, 531, 534, 537 equivalence, 127 host, 4, 4, 36, 57, 58, 64, 101, 114, 116, 121, 129, 166, 167, 175, 301, 303, 325, 337, 339, 340, 526, 528, 530, 531, 534, 537, 629 inheritance, 4, 4, 7, 44, 84, 86, 534, 537 linkage, 4, 4, 521, 528, 531, 531 name, 4, 4, 44, 528, 534 pointer, 4, 4, 8–10, 20–22, 41, 44, 82, 85, 87, 103, 109, 111, 113, 114, 133, 146, 148, 174–176, 195, 196, 211, 214, 245, 304, 318, 319, 322, 324, 325, 333, 335, 349, 361, 416, 420, 497–499, 508, 519,

J3/21-007r1

523, 532–599 sequence, 324 storage, 4, 4, 43, 44, 126–128, 336, 339, 440, 534– 537 use, 4, 4, 28, 36, 44, 57, 64, 83, 100, 101, 111, 114, 121, 126–128, 166, 167, 175, 298, 297– 301, 307, 335, 339, 340, 526–529, 532 association (R1104), 184, 184 association status, see pointer association status assumed type parameter, 22, 22, 55, 56, 319, 321 assumed-implied-spec (R824), 106, 106, 107 assumed-rank dummy data object, 4, 42, 57, 81, 82, 103, 104, 139, 202, 203, 304, 305, 311, 319– 321, 326, 332, 402, 403, 427, 434, 437, 447, 448, 494, 500, 505, 616, 617, 619 assumed-rank-spec (R828), 104, 107 assumed-shape array, 3, 57, 103–106, 112, 125, 139, 305, 319–321, 323, 326, 332, 494, 505, 519, 599, 616, 622, 624 assumed-shape-bounds-spec (R822), 104, 106, 106 assumed-shape-spec (R821), 104, 105, 106 assumed-size array, 3, 104, 106–108, 113, 126, 135, 136, 149, 166, 169, 191, 203, 204, 242, 319–321, 324, 325, 403, 434, 437, 447, 448, 499, 500, 504–508, 512, 515–519, 611, 613, 616 assumed-size-spec (R825), 104, 106, 106 assumed-type, 5, 56, 57, 319, 320, 332, 499, 505, 618 ASYNCHRONOUS attribute, 100, 100, 101, 115, 185, 191, 195, 240, 298, 300, 304, 305, 320, 321, 375, 428, 520, 523, 529, 530 asynchronous communication, 100, 523 asynchronous input/output, 100, 231, 233, 235, 240– 242, 245, 246, 252, 255–258, 261, 263 ASYNCHRONOUS statement, 115, 186, 301, 527, 530 asynchronous-stmt (R835), 34, 115 ASYNCHRONOUS= specifier, 232, 233, 237–239, 240, 259, 261 AT edit descriptor, 282 ATAN, 361 ATAN2, 30, 362 ATAN2D, 362 ATAN2PI, 363 ATAND, 363 ATANH, 363 ATANPI, 364 atomic subroutine, 20, 38, 211, 212, 343, 346–348, 364–

ISO/IEC JTC 1/SC 22/WG5/N2184

633

J3/21-007r1

WD 1539-1

368, 386, 450, 455, 543 ATOMIC_ADD, 364, 451, 454 ATOMIC_AND, 364 ATOMIC_CAS, 365 ATOMIC_DEFINE, 365, 606, 607 ATOMIC_FETCH_ADD, 365 ATOMIC_FETCH_AND, 366 ATOMIC_FETCH_OR, 366 ATOMIC_FETCH_XOR, 367 ATOMIC_INT_KIND, 364–368, 450 ATOMIC_LOGICAL_KIND, 365, 368, 450 ATOMIC_OR, 367 ATOMIC_REF, 368, 607 ATOMIC_XOR, 368 attr-spec (R802), 97, 97–99, 120 attribute, 5, 56, 66, 70, 97–114, 300 ABSTRACT, 21, 67, 83 accessibility, 100, 114, 298 ALLOCATABLE, 3, 55–57, 66, 72, 100, 100, 102, 106, 107, 111–113, 115, 133, 136, 185, 191, 195, 202, 203, 302, 305, 310, 311, 321, 325, 332, 341, 503, 531, 537, 538, 602, 606 ASYNCHRONOUS, 100, 100, 101, 115, 185, 191, 195, 240, 298, 300, 304, 305, 320, 321, 375, 428, 520, 523, 529, 530 BIND, 4, 5, 41, 66, 68, 69, 83, 88, 101, 101, 113, 115, 127, 128, 174, 176, 195, 205, 302, 304, 305, 331, 333, 502–505, 519–522, 531, 538, 611 CODIMENSION, 57, 73, 98, 101, 101, 108, 116 CONTIGUOUS, 72, 75, 103, 103, 104, 116, 139, 176, 195, 304, 319, 321–323, 326, 505–507, 535 DEFERRED, 79, 80, 83 DIMENSION, 73, 98, 104, 104, 112, 118, 128 EXTENDS, 21, 83, 83, 502 EXTERNAL, 26, 27, 108, 108, 111, 120, 121, 123, 175, 298, 302, 304, 307, 312, 324, 329, 330, 529, 530, 596, 597 INTENT, 108, 108–110, 119, 195, 558 INTENT (IN), 108, 108–110, 114, 191, 309–311, 319, 322, 324, 326, 338, 339, 344, 364–368, 374–376, 386, 387, 392, 393, 417, 425, 426, 465, 496–499, 519, 543, 558, 599, 613 INTENT (INOUT), 28, 108, 109, 110, 113, 196, 310, 320, 322, 328, 340, 341, 355, 364–368, 373–376, 387, 391–393, 415–417, 452–454, 543, 544, 613

634

2021-05-21

INTENT (OUT), 27, 29, 57, 81, 82, 106, 108, 108– 110, 113, 146, 166, 310, 320, 322, 328, 338, 340, 341, 355, 364–368, 374–376, 379, 381, 386, 387, 391–393, 416, 418, 424, 426, 441, 442, 467–469, 496, 498, 499, 519, 533, 534, 539, 540, 542–544, 613 INTRINSIC, 108, 110, 110, 111, 298, 314, 329, 530 NON_OVERRIDABLE, 79, 80 NON_RECURSIVE, 305, 331, 331, 332, 335, 336 OPTIONAL, 56, 110, 110, 113, 119, 166, 185, 191, 305 PARAMETER, 7, 41, 89, 99, 110, 110, 111, 119, 132 PASS, 73, 75, 80, 315 POINTER, 3, 15, 55–57, 66, 72, 98, 106, 107, 111, 111–113, 118, 120, 133, 136, 145, 174, 175, 185, 195, 202, 203, 303–305, 307, 310, 311, 313, 321, 324–327, 332, 339, 341, 499, 503, 519, 531, 534, 537, 538, 558, 602, 606 PRIVATE, 69, 84, 100, 100, 114, 339, 586 PROTECTED, 28, 111, 111, 112, 120, 127, 195, 299, 558 PUBLIC, 84, 100, 100, 114, 586 SAVE, 17, 22, 31, 43, 76, 83, 99, 101, 102, 112, 112, 116, 120, 127, 129, 147, 195, 313, 338, 533 SEQUENCE, 17, 66, 68, 68–70, 83, 128, 174, 176, 205, 502 TARGET, 4, 20, 28, 76, 111, 113, 113, 120, 127, 129, 145, 146, 175, 185, 195, 203, 305, 311, 319, 320, 322, 326, 327, 375, 416, 428, 496, 498, 499, 520, 532–534, 542, 558, 599, 600 VALUE, 57, 75, 81, 108, 113, 113, 120, 195, 245, 304, 305, 307, 309, 310, 318–322, 332, 338, 341, 375, 428, 505, 506, 523, 534, 558, 611, 613 VOLATILE, 28, 29, 113, 113, 114, 121, 174, 176, 185, 191, 195, 298, 300, 304, 305, 320–322, 338, 529, 530, 534, 540, 543, 565 attribute specification statements, 114–130 automatic data object, 5, 30, 98, 99, 102, 112, 116, 127, 128, 540, 553

B B edit descriptor, 281 BACKSPACE statement, 223, 226, 252, 255, 257, 257, 578, 580 backspace-stmt (R1224), 34, 256, 339

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

base object, 5, 100, 103, 127, 133, 139, 166, 240, 325, 339, 341 BESSEL_J0, 368 BESSEL_J1, 369 BESSEL_JN, 369 BESSEL_Y0, 369 BESSEL_Y1, 370 BESSEL_YN, 370 BGE, 370 BGT, 371 binary-constant (R773), 93, 93 binary-reduce-op (R1132), 191, 191, 196 BIND (C), see BIND attribute BIND attribute, 4, 5, 41, 66, 68, 69, 83, 88, 101, 101, 113, 115, 127, 128, 174, 176, 195, 205, 302, 304, 305, 331, 333, 502–505, 519–522, 531, 538, 611 BIND statement, 115, 301, 520, 526 bind-entity (R837), 115, 115 bind-stmt (R836), 34, 115 binding, 5, 79, 80, 80, 83, 84, 162, 173, 249, 254, 311, 331, 525, 526 binding label, 5, 101, 305, 313, 332, 334, 520–522, 524, 525, 558 binding name, 5, 79, 80, 84, 315, 526 binding-attr (R752), 79, 79, 80 binding-name, 79, 80, 315, 330, 331, 526 binding-private-stmt (R747), 79, 79, 80 bit model, 345 BIT_SIZE, 345, 371, 417 blank common, 6, 98, 116, 128, 129, 533, 536 blank interpretation mode, 233 blank-interp-edit-desc (R1317), 271, 272 BLANK= specifier, 232, 233, 237–239, 240, 252, 259, 261, 287 BLE, 371 block, 5 interface, 299 block (R1101), 5, 183, 184, 186–190, 193, 195, 197–199, 202, 204 BLOCK construct, 17, 28, 38, 41, 82, 99, 101, 103, 105, 111, 112, 114, 121, 123–125, 146, 166, 185, 338, 527, 533, 534, 540, 542, 546 block data program unit, 301 BLOCK DATA statement, 50, 297, 301 block scoping unit, 12, 17 BLOCK statement, 99, 103, 105, 186, 540

J3/21-007r1

block-construct (R1107), 34, 186, 186 block-construct-name, 186 block-data (R1420), 32, 123, 301, 301, 302 block-data-name, 301 block-data-stmt (R1421), 32, 301, 301 block-specification-part (R1109), 18, 186, 186 block-stmt (R1108), 5, 186, 186, 207 BLT, 372 BN edit descriptor, 287 bound, 3, 5, 5, 42, 43, 72, 73, 85, 87, 105, 141, 143, 148, 176, 211, 416, 528 bounds, 105–107, 135–139 bounds-remapping (R1036), 174, 175, 176 bounds-spec (R1035), 174, 175, 176 boz-literal-constant (R772), 48, 89, 93, 93, 94, 118, 169, 171, 244, 281, 345, 370–373, 381, 383, 384, 396, 398, 400, 412, 427, 428 branch, 207, 336, 551 branch target statement, 5, 37, 49, 178, 194, 207, 207, 208, 232, 236, 238, 256–258, 260, 316, 336 BTEST, 372 BZ edit descriptor, 287

C C address, 5, 496–500, 502, 503, 508, 512, 514, 541, 542, 613 C descriptor, 6, 146, 505, 507–509, 511–520 C_ALERT, 495 C_ASSOCIATED, 496 C_BACKSPACE, 495 C_BOOL, 494, 495 C_CARRIAGE_RETURN, 495 C_CHAR, 495, 498–500, 558 C_DOUBLE, 495 C_DOUBLE_COMPLEX, 495 C_F_POINTER, 495, 496 C_F_PROCPOINTER, 498 C_F_STRPOINTER, 495, 498 C_FLOAT, 495 C_FLOAT_COMPLEX, 495 C_FORM_FEED, 495 C_FUNLOC, 498, 499, 522 C_FUNPTR, 5, 72, 83, 101, 133, 142, 143, 172, 494– 496, 498, 499, 502, 503, 542, 543 C_HORIZONTAL_TAB, 495 C_INT, 494 C_INT16_T, 494

ISO/IEC JTC 1/SC 22/WG5/N2184

635

J3/21-007r1

WD 1539-1

C_INT32_T, 494 C_INT64_T, 494 C_INT8_T, 494 C_INT_FAST16_T, 494 C_INT_FAST32_T, 494 C_INT_FAST64_T, 494 C_INT_FAST8_T, 494 C_INT_LEAST16_T, 494 C_INT_LEAST32_T, 494 C_INT_LEAST64_T, 494 C_INT_LEAST8_T, 494 C_INTMAX_T, 494 C_INTPTR_T, 494 C_LOC, 57, 108, 339, 499, 558 C_LONG, 494 C_LONG_DOUBLE, 495 C_LONG_DOUBLE_COMPLEX, 495 C_LONG_LONG, 494 C_NEW_LINE, 495 C_NULL_CHAR, 495, 500 C_NULL_FUNPTR, 494, 495 C_NULL_PTR, 494, 495 C_PTR, 5, 72, 83, 101, 133, 142, 143, 172, 494–496, 498, 499, 502, 503, 506, 541–543, 611 C_PTRDIFF_T, 494 C_SHORT, 494 C_SIGNED_CHAR, 494 C_SIZE_T, 494 C_SIZEOF, 108, 166, 500 C_VERTICAL_TAB, 495 CALL statement, 20, 207, 210, 303, 315, 328, 336, 416 call-stmt (R1521), 34, 315, 316, 317 CASE statement, 199 case-construct (R1142), 34, 199, 200 case-construct-name, 199, 200 case-expr (R1146), 199, 200, 200 case-selector (R1147), 200, 200 case-stmt (R1144), 199, 200, 200 case-value (R1149), 200, 200 case-value-range (R1148), 200, 200 CEILING, 372 CFI_address, 512 CFI_allocate, 512, 519 CFI_cdesc_t, 6, 505, 507, 508, 508, 509, 512–519 CFI_deallocate, 509, 513, 519 CFI_establish, 514

636

2021-05-21

CFI_is_contiguous, 515 CFI_section, 516 CFI_select_part, 517 CFI_setpointer, 518 CHANGE TEAM construct, 20, 43, 140, 185, 187, 194, 207, 325, 527, 528, 543 CHANGE TEAM statement, 20, 37, 43, 187, 210, 220, 347, 531 change-team-construct (R1111), 34, 187, 187 change-team-stmt (R1112), 187, 187 changeable mode, 229 CHAR, 65, 373 char-length (R723), 63, 63, 64, 72, 73, 97–99, 554 char-length, 555 char-literal-constant (R724), 48, 52, 53, 64, 251, 271, 272, 545 char-selector (R721), 59, 63, 64 char-string-edit-desc (R1322), 270, 272 char-variable (R905), 131, 131, 228, 229 character context, 6, 46, 50–52, 64 character literal constant, 64 character sequence type, 18, 68, 127–129, 536, 539 character set, 46 character storage unit, 19, 19, 107, 127, 129, 450, 535, 539, 541 character string edit descriptor, 270, 287 character type, 62–66 CHARACTER_KINDS, 450 CHARACTER_STORAGE_SIZE, 450 characteristics, 6, 84, 176, 177, 249, 250, 304, 305, 307, 313, 314, 323, 328, 331, 333, 336, 355, 420 dummy argument, 304 procedure, 304 child data transfer statement, 227, 228, 239, 241, 244, 250, 248–252, 268, 291 CLASS, 56, 56–58, 249 CLASS DEFAULT statement, 205 CLASS IS statement, 205, 388 CLASSOF, 56, 56 CLOSE statement, 223, 224, 228, 230, 231, 235, 235, 252, 255, 578 close-spec (R1209), 236, 236 close-stmt (R1208), 34, 236, 339 CMPLX, 172, 345, 373, 459 CO_BROADCAST, 373 CO_MAX, 374

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

CO_MIN, 374 CO_REDUCE, 375, 549 CO_SUM, 376, 549 coarray, 6, 6, 8, 28, 38, 42, 43, 67, 72, 74, 82, 101–103, 108, 110, 111, 113, 114, 127, 128, 134, 141–144, 147, 148, 169, 170, 172, 175, 176, 185, 187–189, 191, 210–212, 298, 305, 315, 320, 322, 323, 326, 328, 332, 347, 348, 351, 353, 364–368, 378, 399, 404, 415, 416, 444, 445, 448, 453, 503, 504 established, 6, 43, 188 coarray-association (R1113), 43, 187, 187 coarray-name, 116, 187, 527, 529 coarray-spec (R809), 72–74, 97, 98, 101, 101, 102, 115, 116, 120 cobound, 6, 42, 43, 101–103, 140, 143, 167, 185, 189, 323, 351, 353, 404, 416, 448, 528 codimension, 6, 6, 8, 42, 103, 140, 185, 304, 378, 404, 448 CODIMENSION attribute, 57, 73, 98, 101, 101, 108, 116 codimension-decl (R839), 116, 116, 185, 187, 188, 527 codimension-stmt (R838), 34, 116, 529 coindexed object, 6, 28, 38, 42, 43, 76, 116, 133, 140, 142, 170, 172, 175, 176, 184, 209, 212, 216, 315, 316, 319, 320, 322, 326, 339, 364–368, 373–376, 386, 415, 416, 445, 455, 496, 498, 499 coindexed-named-object (R914), 131, 132, 134, 134 collating sequence, 6, 65, 66, 161, 274, 356, 373, 395, 398, 405, 406, 409–412, 414, 415, 418 collective subroutine, 20, 343, 347, 348, 373–376, 389, 440, 455, 543 COMMAND_ARGUMENT_COUNT, 168, 376, 392 comment, 51, 52, 294 common association, 129 common block, 6, 31, 35, 41, 98, 99, 101, 111, 112, 115, 116, 127–130, 166, 301, 302, 520, 521, 524–527, 531, 534–536, 541, 554 common block storage sequence, 128 COMMON statement, 6, 128, 128–130, 186, 300, 301, 526, 536, 552 common-block-name, 115, 120, 128, 186, 300 common-block-object (R878), 128, 128, 300, 529 common-stmt (R877), 34, 128, 529 companion processor, 5, 7, 13, 39, 45, 66, 89, 101, 495, 500, 521, 522 compatibility

J3/21-007r1

Fortran 77, 30 Fortran 2003, 29 Fortran 2008, 28 Fortran 2018, 27 Fortran 90, 30 Fortran 95, 30 COMPILER_OPTIONS, 166, 451 COMPILER_VERSION, 166, 451 completion step, 39, 236 complex part designator, 9, 40, 134 complex type, 62 complex-literal-constant (R718), 48, 62 complex-part-designator (R915), 131, 134, 134, 135, 139 component, 7, 8, 12, 14, 18, 19, 66, 68, 72, 86, 121, 526 direct, 7, 7, 66, 67, 76, 320, 458, 502 parent, 4, 7, 77, 78, 82, 84, 87, 537, 567 potential subobject, 7, 66, 67, 339 ultimate, 7, 28, 29, 66, 67, 72, 101–103, 106, 108, 113, 127, 128, 142, 143, 145, 168, 170, 248, 319, 320, 338, 535 component definition statement, 56, 72 component keyword, 14, 44, 77, 86, 87, 526 component order, 7, 77, 78, 86, 87, 243, 244 component-array-spec (R740), 72, 72, 73 component-attr-spec (R738), 72, 72–75 component-data-source (R758), 86, 86, 87 component-decl (R739), 64, 72, 72–76 component-def-stmt (R736), 7, 72, 72, 73 component-initialization (R743), 72, 75, 75, 76 component-name, 72, 76 component-part (R735), 67, 72, 78, 80 component-spec (R757), 86, 86, 167 computed GO TO statement, 5, 207, 208, 552, 553 computed-goto-stmt (R1160), 35, 208, 208 concat-op (R1011), 48, 151, 151 CONCURRENT, 190 concurrent-control (R1126), 180, 181, 191, 191, 193 concurrent-header (R1125), 180, 182, 190, 191, 191, 192, 527 concurrent-limit (R1127), 155, 181, 191, 191–193 concurrent-locality (R1129), 190, 191, 191 concurrent-step (R1128), 155, 181, 191, 191–193 conformable, 7, 42, 144, 155, 163, 169, 173, 328, 341, 389, 395, 396, 401, 410, 411, 413, 414, 422, 424, 441, 449, 481 CONJG, 377

ISO/IEC JTC 1/SC 22/WG5/N2184

637

J3/21-007r1

WD 1539-1

connect-spec (R1205), 231, 231, 232 connected, 7, 11, 14, 15, 223–227, 230, 231, 233, 234, 236, 241, 246–248 connection mode, 229 constant, 7, 41, 48, 54 integer, 59 named, 119 constant (R604), 48, 48, 117, 132, 150 constant expression, 5, 8, 22, 30, 54, 55, 64, 71–76, 94, 99, 103, 105, 107, 116, 117, 119, 127, 166, 167, 168, 168, 240, 304, 305, 325, 344, 356, 358, 359, 372, 373, 378, 379, 388–390, 395, 398–400, 403–405, 407, 408, 410, 413, 418, 428, 430, 432, 434, 437, 440, 447–449, 503, 504 constant-expr (R1029), 22, 55, 75, 76, 98, 99, 107, 110, 119, 168, 168, 200 constant-subobject (R851), 117, 117 construct ASSOCIATE, 43, 183, 184, 187, 202, 325, 527, 528, 531, 543 BLOCK, 12, 17, 18, 28, 38, 41, 82, 99, 101, 103, 105, 111, 112, 114, 121, 123–125, 146, 166, 183, 185, 338, 527, 533, 534, 540, 542, 546 CHANGE TEAM, 20, 43, 140, 183, 185, 187, 194, 207, 325, 527, 528, 543, 557 CRITICAL, 183, 189, 189, 194, 207, 347 DO, 38, 49, 95, 117, 183, 190, 207, 244, 551, 568, 570 DO CONCURRENT, xiii, 28, 190, 194, 197, 207, 339, 340, 527, 528, 534, 540, 542, 546, 554, 555 FORALL, 180, 339, 340, 527, 528, 540, 552, 554 IF, 38, 183, 198, 466, 551 nonblock DO, 552, 555 SELECT CASE, 38, 183, 199, 552, 553, 568 SELECT RANK, 38, 43, 106, 107, 183, 185, 202, 325, 527, 528, 543, 555 SELECT TYPE, 38, 43, 55, 57, 183, 185, 204, 325, 527, 528, 531, 543 WHERE, 14, 178 construct association, 4, 4, 146, 147, 528, 531, 534, 537 construct entity, 4, 8, 114, 124, 184, 186, 187, 192, 195, 204, 524, 525, 527, 534 construct-name, 207 constructor array, 93 derived-type, 86

638

2021-05-21

structure, 86 CONTAINS statement, 36, 37, 79, 337 contains-stmt (R1543), 33, 79, 298, 337 contiguous, 8, 18, 28, 69, 75, 103, 132, 140, 176, 177, 185, 196, 240, 247, 402, 499, 535, 558 CONTIGUOUS attribute, 72, 75, 103, 103, 104, 116, 139, 176, 195, 304, 319, 321–323, 326, 505–507, 535 CONTIGUOUS statement, 116 contiguous-stmt (R840), 34, 116 continuation, 51, 52 CONTINUE statement, 208, 551 continue-stmt (R1161), 34, 192, 208 control character, 46, 64, 222, 225 control edit descriptor, 270, 284–287 control information list, 237 control mask, 179 control-edit-desc (R1313), 270, 271 conversion numeric, 171 corank, 8, 42, 43, 74, 101–104, 133, 140, 142, 149, 185, 189, 304, 322, 378, 399, 404, 415, 416, 444, 448, 528 COS, 377 COSD, 377 COSH, 377 COSHAPE, 378 COSPI, 378 cosubscript, 8, 42, 43, 103, 140, 353, 398, 399, 444, 448 cosubscript (R927), 133, 140, 140 COUNT, 344, 378 CPU_TIME, 379 CRITICAL construct, 189, 194, 207 CRITICAL statement, 163, 189, 210, 220 critical-construct (R1116), 34, 189, 189 critical-construct-name, 189 critical-stmt (R1117), 5, 189, 189, 207 CSHIFT, 380 current record, 226 current team, 20, 82, 140, 143, 144, 147, 148, 187, 188, 212, 213, 215–217, 220, 347, 348, 374, 388, 389, 393, 399, 416, 421, 440, 443, 444, 448, 451, 455 CURRENT_TEAM, 393, 451 CYCLE statement, 184, 190, 194, 194, 554 cycle-stmt (R1135), 34, 194, 194

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

J3/21-007r1

D

deallocate-stmt (R944), 34, 145, 544 decimal edit descriptor, 287 d (R1310), 271, 271, 276–280, 283, 284, 291 decimal edit mode, 233 D edit descriptor, 277 decimal symbol, 8, 233, 240, 261, 274–280, 287, 289 data edit descriptor, 270, 274–284 decimal-edit-desc (R1318), 271, 272 data entity, 6, 7, 8, 15–17, 23, 40–42 DECIMAL= specifier, 232, 233, 237–239, 240, 252, data object, 5–7, 8, 8, 9, 17, 19, 22, 35–37, 40, 42, 43 259, 261, 287 data object designator, 9, 17, 42, 131 declaration, 8, 36, 97–130 data object reference, 17, 41–43 data pointer, 15, 15, 43, 74, 76, 86, 87, 111, 129, 131, declaration-construct (R507), 33, 33, 186 141, 175, 322, 333, 496, 497, 508, 514, 518, declaration-type-spec (R703), 56, 56, 57, 63, 72, 73, 97, 99, 121, 166, 312, 313, 331, 334 532, 534, 535, 568, 599 DATA statement, 31, 37, 93, 99, 116, 129, 301, 420, declared type, 21, 57, 58, 75, 86, 87, 94, 97, 133, 134, 142, 143, 145, 162, 164, 169, 172, 173, 175, 527, 530, 538, 552, 553 176, 184, 203, 205, 206, 254, 310, 315, 318, data transfer, 246 321, 331, 338, 388, 412, 416, 430, 431, 452, data transfer input statement, 237 453, 528 data transfer output statement, 237 DEFAULT, 191, 200, 205 data transfer statement, 31, 49, 93, 222–228, 230, 237, 242, 245–247, 251, 255, 257, 266–270, 281, 286, default character, 63 288–293, 295, 453, 539, 541, 548, 578, 579, 582, default complex, 62 default initialization, 8, 8, 74–77, 86, 87, 99, 106, 108, 583 116, 127–129, 320, 420, 532, 536, 537, 542 data type, 21, see type default real, 61 data-component-def-stmt (R737), 72, 72–74 default-char-constant-expr (R1030), 101, 168, 168, 237, data-edit-desc (R1307), 270, 270 238 data-i-do-object (R845), 116, 116, 117 default-char-expr (R1025), 164, 164, 168, 208, 231–242 data-i-do-variable (R846), 116, 116, 117, 168, 527 default-char-variable (R906), 131, 131, 141, 232, 259– data-implied-do (R844), 116, 116, 117, 168, 527 265 data-pointer-component-name, 174 default-initialized, 8, 76, 109, 332, 532–534, 538, 540, data-pointer-initialization compatible, 75 542 data-pointer-object (R1034), 174, 174, 175, 181, 361, DEFERRED attribute, 79, 80, 83 544 data-ref (R911), 5, 56, 57, 132, 133–135, 174, 175, 240, deferred type parameter, xiii, 22, 22, 28, 55, 56, 64, 87, 111, 129, 134, 141, 143, 144, 148, 169, 170, 315, 317, 325, 330, 331 176, 196, 211, 289, 304, 321, 322, 332, 355, data-stmt (R841), 33, 116, 307, 338, 529 404, 420, 440, 496, 498, 505, 532, 537 data-stmt-constant (R849), 93, 117, 117, 118 deferred-coshape-spec (R810), 72, 101, 102, 102 data-stmt-object (R843), 116, 116–118 deferred-shape array, 3, 106, 112 data-stmt-repeat (R848), 117, 117 deferred-shape-spec (R823), 72, 104, 106, 106, 119 data-stmt-set (R842), 116, 116 definable, 8, 109–111, 139, 170, 185, 242, 318, 320, 322, data-stmt-value (R847), 116, 117, 117 327, 534, 544 data-target (R1037), 86, 87, 111, 174, 175, 175, 181, 325, 339, 361 defined, 8, 9, 23, 41, 43 DATE_AND_TIME, 380 defined assignment, 9, 20, 169, 172–174, 178, 181, 303, 310, 315, 320, 339, 340 DBLE, 345, 381 DC edit descriptor, 287 defined assignment statement, 29, 173, 328, 543 dealloc-opt (R945), 145, 146, 146, 147 defined input/output, 9, 229, 234, 243, 244, 248, 249, DEALLOCATE statement, 145, 147, 148, 210, 452, 249, 250, 250, 250, 251, 252, 252, 252, 248– 454, 513, 546 255, 265, 284, 291, 295, 296, 303, 309, 311, 315,

ISO/IEC JTC 1/SC 22/WG5/N2184

639

J3/21-007r1

WD 1539-1

328, 339, 453, 602 defined operation, 9, 17, 153, 162, 163–165, 191, 303, 309, 315, 328, 339 defined-binary-op (R1023), 15, 49, 152, 152, 153, 162, 299 defined-io-generic-spec (R1509), 9, 79, 249, 250, 254, 306, 306, 309, 311 defined-operator (R609), 49, 79, 300, 306, 558 defined-unary-op (R1003), 15, 49, 150, 150, 153, 162, 299 definition, 8, 9 definition of variables, 538 deleted features, 26, 27, 30, 31, 551, 552 DELIM= specifier, 232, 233, 237–239, 241, 252, 259, 261, 294, 295, 580 delimiter mode, 233 derived type, 9, 19, 21, 39, 40, 44, 54, 66–88, 94, 502, 503 derived type definition statement, see TYPE statement derived type determination, 69 derived-type type specifier, 57 derived-type-def (R726), 33, 57, 58, 67, 68, 70, 71, 502 derived-type-spec (R754), 22, 56, 57, 63, 85, 86, 205, 249, 526 derived-type-stmt (R727), 67, 67, 68, 70, 71, 100, 529 descendant, 9, 36, 68, 78, 80, 111, 301, 525 designator, 6, 9, 9, 44, 107, 108, 113, 116, 127, 128, 135, 135, 164, 166, 167, 292, 293, 324, 325, 339, 341 data object, 131 designator (R901), 75, 76, 116, 117, 131, 131, 133–135, 149, 150, 175, 184, 195, 292, 338, 339, 378, 399, 404, 444, 448 designator, 149 digit, 24, 46, 46, 49, 59, 93, 289 digit-string (R711), 24, 59, 59–61, 275, 276, 282 digit-string, 59 DIGITS, 382 DIM, 382 DIMENSION attribute, 73, 98, 104, 104, 112, 118, 128 DIMENSION statement, 118, 301 dimension-spec (R814), 104 dimension-stmt (R852), 34, 118, 529 direct access, 224 direct access data transfer statement, 241 direct component, 7, 7, 66, 67, 76, 320, 458, 502 DIRECT= specifier, 259, 261

640

2021-05-21

disassociated, 9, 10, 22, 43, 58, 75–77, 99, 106, 118, 145, 147, 148, 165, 174, 176, 313, 325, 343, 388, 420, 431, 440, 464, 532, 533, 542 distinguishable, 311 DO CONCURRENT construct, 28, 190, 194, 197, 207, 339, 340, 527, 528, 534, 540, 542, 546, 554 DO CONCURRENT statement, 57, 181, 190 DO construct, 38, 49, 95, 117, 190, 207, 244, 551, 568, 570 DO statement, 190, 539, 552, 554 DO WHILE statement, 190 do-construct (R1119), 34, 190, 192, 194, 207 do-construct-name, 190, 192, 194 do-stmt (R1120), 5, 190, 190, 192, 207, 543 do-variable (R1124), 94, 116, 190, 190, 192, 242, 243, 266–268, 290, 539, 541, 543, 579 DOT_PRODUCT, 382 DOUBLE PRECISION, 50, 59, 61, 67 DP edit descriptor, 287 DPROD, 383 DSHIFTL, 383 DSHIFTR, 383 DT edit descriptor, 284 dtv-type-spec (R1221), 249 dummy argument, 3, 4, 6, 10, 10, 14–16, 22, 23, 28, 38, 43, 44, 47, 55–58, 63, 64, 70, 73, 75, 80–82, 84, 85, 98, 100, 102, 104–106, 108–110, 112– 114, 116, 119, 120, 125, 127, 128, 142–144, 146, 147, 162, 165, 166, 173, 176, 191, 196, 211, 245, 250–252, 303–312, 314, 315, 317–325, 332, 336, 338, 339, 341, 452, 505–507, 526–528, 534, 543, 544, 558, 588, 599 characteristics of, 304 restrictions, 325 dummy data object, 4, 6, 10, 57, 75, 99, 106–108, 112, 113, 304, 309–311 assumed-rank, 4, 42, 57, 81, 82, 103, 104, 139, 202, 203, 304, 305, 311, 319–321, 326, 332, 402, 403, 427, 434, 437, 447, 448, 494, 500, 505, 616, 617, 619 dummy function, 10, 63, 98 dummy procedure, 6, 10, 12, 16, 108, 121, 125, 167, 175, 303, 304, 306, 307, 312, 313, 316, 323, 324, 330, 332, 335, 338, 340, 341, 522, 525, 530 dummy-arg (R1536), 334, 334–336

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

dummy-arg-name (R1531), 119, 120, 303, 333, 333, 334, 337, 529 dynamic type, 15, 21, 22, 57, 58, 81, 83, 85, 87, 94, 113, 143, 145, 147, 162, 164, 170, 172, 173, 175, 176, 185, 204, 205, 211, 214, 254, 315, 321, 330, 331, 388, 412, 416, 430, 431, 440, 505, 528, 532, 537, 567, 616

E e (R1311), 271, 271, 277–280, 283, 284, 291 E edit descriptor, 277 edit descriptor, 270 /, 285 :, 286 A, 282 AT, 282 B, 281 BN, 287 BZ, 287 character string, 270, 287 control, 270, 284–287 D, 277 data, 270, 274–284 DC, 287 decimal, 287 DP, 287 DT, 284 E, 277 EN, 278 ES, 279 EX, 280 F, 276 G, 282, 283 H, 551 I, 275 L, 282 LZ, 286 LZP, 286 LZS, 286 O, 281 P, 286 position, 284 RC, 287 RD, 287 RN, 287 round, 287 RP, 287

J3/21-007r1

RU, 287 RZ, 287 S, 286 SP, 286 SS, 286 T, 285 TL, 285 TR, 285 X, 285 Z, 281 effective argument, 3, 4, 10, 22, 55, 57, 58, 64, 103–107, 109, 110, 211, 318–321, 323, 324, 327, 330, 427, 497, 505, 506, 528, 534, 537, 539, 542 effective item, 10, 244, 246, 248, 251, 252, 254, 267, 272, 273, 286, 288–290, 293, 294 effective position, 312 element sequence, 324 ELEMENTAL, 11, 331, 332, 336, 338, 341 elemental, 10, 20, 42, 63, 82, 84, 162, 163, 168, 173, 174, 177–180, 303–305, 313, 320, 323, 328, 330, 336, 341, 343, 348, 369, 370, 417, 464, 465 elemental array assignment (FORALL), 180 elemental assignment, 10, 173, 174 elemental operation, 10, 155, 165, 179 elemental operator, 10, 155, 458 elemental procedure, 10, 42, 165, 175, 313, 316, 325, 329, 331, 340, 341, 341, 343, 344 elemental reference, 10, 179, 320, 328–331, 341 elemental subprogram, 11, 331, 332, 341 ELSE IF statement, 50, 198 ELSE statement, 198 else-if-stmt (R1138), 198, 198 else-stmt (R1139), 198, 198 ELSEWHERE statement, 50, 178 elsewhere-stmt (R1048), 178, 178 EN edit descriptor, 278 ENCODING= specifier, 232, 233, 259, 261, 547 END ASSOCIATE statement, 50, 184 END BLOCK DATA statement, 50, 301 END BLOCK statement, 50, 147, 186 END CRITICAL statement, 50, 163, 189, 210 END DO statement, 50, 192 END ENUM statement, 50, 88 END ENUMERATION TYPE statement, 91 END FORALL statement, 50, 180 END FUNCTION statement, 50, 333

ISO/IEC JTC 1/SC 22/WG5/N2184

641

J3/21-007r1

WD 1539-1

END IF statement, 50, 198, 551 END INTERFACE statement, 50, 306 END MODULE statement, 50, 298 END PROCEDURE statement, 50, 335 END PROGRAM statement, 50, 297 END SELECT statement, 50, 200, 205 END statement, 11, 37, 37, 38, 50, 52, 82, 83, 111, 112, 129, 146, 147, 210, 497, 542 END SUBMODULE statement, 50, 301 END SUBROUTINE statement, 50, 334 END TEAM statement, 37, 50, 187, 207, 210, 220, 347 END TYPE statement, 50, 68 END WHERE statement, 50, 178 end-associate-stmt (R1106), 5, 184, 184, 207 end-block-data-stmt (R1422), 11, 33, 37, 301, 301 end-block-stmt (R1110), 5, 186, 186, 207 end-change-team-stmt (R1114), 187, 187, 188 end-critical-stmt (R1118), 5, 189, 189, 207 end-do (R1133), 190, 192, 192, 194 end-do-stmt (R1134), 5, 192, 192, 207 end-enum-stmt (R763), 88, 88 end-enumeration-type-stmt (R769), 91, 91 end-forall-stmt (R1054), 180, 180 end-function-stmt (R1533), 5, 11, 18, 32, 37, 207, 306, 333, 333, 337 end-if-stmt (R1140), 5, 198, 198, 207 end-interface-stmt (R1504), 306, 306 end-module-stmt (R1406), 11, 32, 37, 298, 298 end-mp-subprogram-stmt (R1540), 5, 11, 18, 33, 37, 207, 335, 335, 337 end-program-stmt (R1403), 5, 11, 18, 32, 37, 39, 83, 207, 208, 297, 297 end-select-rank-stmt (R1153), 5, 202, 202, 203, 207 end-select-stmt (R1145), 5, 199, 200, 200, 207 end-select-type-stmt (R1157), 5, 204, 205, 205–207 end-submodule-stmt (R1419), 11, 32, 37, 301, 301 end-subroutine-stmt (R1537), 5, 11, 18, 32, 37, 207, 306, 334, 334, 337 end-type-stmt (R730), 67, 68 end-where-stmt (R1049), 178, 178 END= specifier, 5, 237, 238, 256, 266 endfile record, 223 ENDFILE statement, 50, 223, 224, 226, 233, 252, 255, 257, 578 endfile-stmt (R1225), 34, 256, 339 entity-decl (R803), 64, 73, 97, 98, 98, 99, 167, 168, 529

642

2021-05-21

entity-name, 115, 120 ENTRY statement, 10, 37, 162, 173, 298, 303, 307, 331, 333, 335, 340, 526, 536, 552, 554 entry-name, 333, 335, 336, 526 entry-stmt (R1541), 33, 298, 301, 307, 335, 335, 526, 529 enum constructor, 89, 164, 166, 167 ENUM statement, 88 enum type, 57, 58, 72, 88, 243, 275, 289, 294 enum-constructor (R765), 89, 89, 117, 149 enum-def (R759), 33, 88, 88, 89, 529 enum-def-stmt (R760), 88, 88 enum-type-name, 88, 172, 529 enum-type-spec (R764), 56, 57, 88, 88, 89 enumeration, 88 enumeration constructor, 164, 166, 167 enumeration type, 57, 72, 90, 156, 161, 200, 243, 275, 281, 394, 400, 418, 424 ENUMERATION TYPE statement, 91 enumeration-constructor (R771), 91, 117, 149 enumeration-enumerator-stmt (R768), 91, 91 enumeration-type-def (R766), 91 enumeration-type-name, 91, 529 enumeration-type-spec (R770), 56, 57, 91, 91 enumeration-type-stmt (R767), 91, 91, 529 enumerator, 88 enumerator (R762), 88, 88 ENUMERATOR statement, 88 enumerator-def-stmt (R761), 88, 88 EOR= specifier, 5, 237, 238, 256, 267, 267, 579 EOSHIFT, 384 EPSILON, 385 equiv-op (R1021), 48, 152, 152 equiv-operand (R1016), 152, 152 equivalence association, 127 EQUIVALENCE statement, 126, 126–129, 186, 300, 301, 536, 552, 554 equivalence-object (R876), 126, 126–128, 300 equivalence-set (R875), 126, 126, 127 equivalence-stmt (R874), 34, 126, 529 ERF, 385 ERFC, 385 ERFC_SCALED, 385 ERR= specifier, 5, 232, 236, 237, 256–260, 266 errmsg-variable (R931), 141, 141, 142, 146, 148, 207, 209, 210, 212, 213, 216, 218–220, 543, 546

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

ERRMSG= specifier, 141, 144, 146, 148, 189, 210, 212, 219, 540, 546, 557 error indicator, 511 ERROR STOP statement, 38, 39, 208, 546 error termination, 39, 83, 144, 146, 208, 210, 252, 266, 267, 347, 364–368, 386, 387, 416, 418, 424, 429, 545, 548 error-stop-stmt (R1163), 34, 83, 208 ERROR_UNIT, 229, 230, 234, 451 ES edit descriptor, 279 established coarray, 6, 43, 140, 188 evaluation operations, 155 optional, 163 parentheses, 164 EVENT POST statement, 210, 216, 216, 220, 386, 451, 452, 540, 543, 547 event variable, 23, 38, 211, 216, 220, 386, 451, 452, 540 EVENT WAIT statement, 210, 216, 216, 219, 451, 452, 540, 543, 547 event-post-stmt (R1174), 34, 216 event-variable (R1175), 216, 216, 219, 452, 543 event-wait-spec (R1177), 209, 216, 216 event-wait-stmt (R1176), 34, 216, 216 EVENT_QUERY, 386, 557, 575, 609 EVENT_TYPE, 23, 67, 108, 142, 143, 216, 451 EX edit descriptor, 280 executable construct, 183 executable statement, 18, 18, 36 executable-construct (R514), 18, 33, 34, 335 EXECUTE_COMMAND_LINE, 353, 386 execution control, 183 execution-part (R509), 32, 33, 33, 297, 332–335 execution-part-construct (R510), 33, 33, 183 exist, 223, 230 EXIST= specifier, 259, 261 EXIT statement, 184, 194, 207 exit-stmt (R1158), 34, 207, 207 EXP, 387 explicit formatting, 269–287 explicit initialization, 11, 76, 77, 98, 99, 116, 532, 536, 538 explicit interface, 13, 29, 75, 79, 121, 125, 176, 177, 304– 308, 313–315, 317, 323, 324, 337, 339, 525, 526, 543, 558, 588 explicit-bounds-expr (R820), 105, 105, 106

J3/21-007r1

explicit-coshape-spec (R811), 101, 102, 102 explicit-shape array, 3, 57, 74, 102, 104, 105, 169, 319, 321, 324, 504–507 explicit-shape-bounds-spec (R819), 3, 104, 105, 105 explicit-shape-spec (R816), 3, 72, 73, 100, 104, 105, 105–107, 128 EXPONENT, 387, 471 exponent (R717), 61, 61 exponent-letter (R716), 61, 61 expr (R1022), 25, 82, 86, 89, 93, 94, 141, 149, 150, 152, 152, 153, 164–173, 175, 176, 179–181, 184, 187, 196, 200, 242, 315, 316, 337, 339, 491, 543 expression, 149, 149–169 constant, 5, 8, 22, 30, 54, 55, 64, 71–76, 94, 99, 103, 105, 107, 116, 117, 119, 127, 166, 167, 168, 168, 240, 304, 305, 325, 344, 356, 358, 359, 372, 373, 378, 379, 388–390, 395, 398–400, 403–405, 407, 408, 410, 413, 418, 428, 430, 432, 434, 437, 440, 447–449, 503, 504 specification, 18, 22, 38, 71–73, 82, 100, 135, 166, 167, 167, 186, 336, 459, 553 extended real model, 346 extended type, 4, 7, 12, 21, 21, 71, 77, 78, 81–84, 537, 559, 564 extended-intrinsic-op (R610), 49, 49 EXTENDS attribute, 21, 83, 83, 502 EXTENDS_TYPE_OF, 72, 73, 388 extensible type, 21, 56, 67, 75, 83, 249, 388, 430, 431, 567, 604 extension operation, 153 extension type, 21, 58, 83, 84, 205, 321, 388, 604 extent, 11, 42, 320 EXTERNAL attribute, 26, 27, 108, 108, 111, 120, 121, 123, 175, 298, 302, 304, 307, 312, 324, 329, 330, 529, 530, 596, 597 external file, 11, 11, 30, 222–227, 229–231, 235, 240, 258, 274, 284, 294, 340, 522, 578, 611 external input/output unit, 11, 524 external linkage, 101, 494, 520–522 external procedure, 16, 26, 35, 79, 108, 121, 175, 215, 303, 304, 306–308, 312, 313, 316, 324, 330, 524, 525, 529, 530, 558, 588, 593, 596, 597 EXTERNAL statement, 108, 312 external subprogram, 16, 20, 35, 303 external unit, 11, 229–231, 246, 251, 252, 262, 268, 451, 452, 455

ISO/IEC JTC 1/SC 22/WG5/N2184

643

J3/21-007r1

WD 1539-1

external-name, 312 external-stmt (R1511), 34, 312 external-subprogram (R503), 32, 32, 123, 335

F F edit descriptor, 276 F_C_STRING, 500 FAIL IMAGE statement, 209 fail-image-stmt (R1165), 34, 209 failed image, 12, 38, 140, 143, 147, 148, 188, 218, 347, 348, 416 FAILED_IMAGES, 388 field, 272 file connected, 230 external, 11, 11, 30, 222–227, 229–231, 235, 240, 258, 274, 284, 294, 340, 522, 578, 611 internal, 14, 14, 222, 228, 229, 231, 240, 244, 246– 248, 251, 252, 266, 267, 284, 285, 539, 541 file access method, 223–225 file connection, 228–236 file inquiry statement, 259 file position, 223, 226 file positioning statement, 223, 256 file storage unit, 11, 19, 222, 225–228, 235, 240, 241, 247, 257, 263–265, 452, 535 file-name-expr (R1206), 232, 232, 233, 259, 260, 262 file-unit-number (R1202), 228, 228, 229, 231, 232, 236, 238, 251, 256–262, 264, 265, 339, 453 FILE= specifier, 231, 232, 233, 234, 235, 259, 260, 260, 543, 580 FILE_STORAGE_SIZE, 452 FINAL statement, 11, 81 final subroutine, 5, 11, 11, 29, 80–82, 138, 319, 563, 564 final-procedure-stmt (R753), 79, 81 final-subroutine-name, 81 finalizable, 11, 29, 81, 82, 106, 108, 147, 191 finalization, 11, 17, 81, 82, 138, 180, 303, 315, 328, 338, 339 FINDLOC, 389 fixed source form, 51, 51 FLOOR, 390 FLUSH statement, 224, 255, 258, 267 flush-spec (R1229), 258, 258 flush-stmt (R1228), 34, 258, 339 FMT= specifier, 237, 239

644

2021-05-21

FORALL construct, 180, 339, 340, 527, 528, 540, 552, 554 FORALL statement, 57, 155, 181, 527, 528, 539 forall-assignment-stmt (R1053), 155, 180, 180–182, 340 forall-body-construct (R1052), 180, 180–182 forall-construct (R1050), 34, 180, 180, 181 forall-construct-name, 180 forall-construct-stmt (R1051), 5, 180, 180, 207 forall-stmt (R1055), 35, 180, 181, 182, 182, 207 FORM TEAM statement, 20, 37, 188, 210, 216, 220, 540, 543, 544, 547 form-team-spec (R1182), 216, 217, 217 form-team-stmt (R1179), 34, 216 FORM= specifier, 232, 234, 259, 261 format (R1215), 237, 238, 239, 239, 246, 269, 270 format control, 272 format descriptor, see edit descriptor FORMAT statement, 26, 37, 49, 239, 269, 269, 298 format-item (R1304), 270, 270 format-items (R1303), 269, 270, 270 format-specification (R1302), 269, 269 format-stmt (R1301), 33, 269, 269, 298, 301, 307 FORMATTED, 249, 306 formatted data transfer, 248 formatted input/output statement, 222, 239 formatted record, 222 FORMATTED= specifier, 259, 262 formatting explicit, 269–287 list-directed, 248, 288–291 namelist, 248, 292–296 forms, 223 Fortran 2003 compatibility, 29 Fortran 2008 compatibility, 28 Fortran 2018 compatibility, 27 Fortran 77 compatibility, 30 Fortran 90 compatibility, 30 Fortran 95 compatibility, 30 Fortran character set, 46, 63 FRACTION, 390 free source form, 50, 50 function, 11 intrinsic, 343 intrinsic elemental, 343 intrinsic inquiry, 343 function reference, 17, 40, 41, 328

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

function result, 11, 29, 64, 97, 121, 127, 128, 146, 304, 333, 336, 341, 505, 526, 536, 542 FUNCTION statement, 10, 57, 58, 121, 162, 166, 297, 331, 332, 335, 336, 526 function-name, 98, 307, 333, 335, 337, 526, 529 function-reference (R1520), 86, 98, 131, 149, 150, 315, 317, 328 function-stmt (R1530), 32, 306, 307, 331, 332, 333, 333, 526, 529 function-subprogram (R1529), 19, 32, 33, 298, 332, 335

J3/21-007r1

host scoping unit, 12, 35, 121, 124, 329, 530, 537 HUGE, 394 HYPOT, 394

I

I edit descriptor, 275 IACHAR, 65, 172, 395 IALL, 395 IAND, 191, 195, 364, 396 IANY, 396 IBCLR, 397 IBITS, 397 IBSET, 397 G edit descriptor, 282, 283 ICHAR, 65, 398 GAMMA, 390 generic identifier, 12, 13, 298, 307–309, 311, 330, 343, id-variable (R1214), 237, 238 ID= specifier, 237, 238, 241, 255, 259, 260, 262, 543, 524, 529 582 generic interface, 13, 80, 84, 88, 110, 162, 173, 254, 299, IEEE infinity, 12 300, 308, 308–310, 329, 525, 606 IEEE NaN, 12, 162, 459, 460, 483 generic interface block, 13, 13, 307, 308, 311, 558 IEEE_ALL, 458 generic procedure reference, 311 IEEE_ARITHMETIC, 166, 168, 355, 457–491 GENERIC statement, 79, 80, 308, 308, 311, 329 IEEE_AWAY, 461, 468 generic-name, 79, 80, 306, 526, 529 generic-spec (R1508), 13, 79, 80, 84, 114, 162, 173, 299, IEEE_CLASS, 464, 466, 466 IEEE_CLASS_TYPE, 458, 466, 491 300, 306, 306–308, 329, 526, 529 IEEE_COPY_SIGN, 463, 464, 466 generic-stmt (R1510), 33, 308 IEEE_DATATYPE, 458 GET_COMMAND, 391 IEEE_DENORMAL, 458 GET_COMMAND_ARGUMENT, 391 IEEE_DIVIDE, 458 GET_ENVIRONMENT_VARIABLE, 392, 549 IEEE_DIVIDE_BY_ZERO, 458 GET_TEAM, 168, 393, 451, 452, 455 IEEE_DOWN, 458, 461 global entity, 524 IEEE_EXCEPTIONS, 166, 168, 194, 457–491 global identifier, 524 IEEE_FEATURES, 457–458 GO TO statement, 5, 50, 207, 207 IEEE_FEATURES_TYPE, 458 goto-stmt (R1159), 34, 207, 207 IEEE_FLAG_TYPE, 458, 467, 481, 487 graphic character, 46, 64, 295 IEEE_FMA, 464, 467 IEEE_GET_FLAG, 194, 460, 465, 467, 492, 493, 550 halting mode, 457, 462, 462, 465, 467, 481, 487, 523, IEEE_GET_HALTING_MODE, 194, 465, 467, 468 550 IEEE_GET_MODES, 462, 465, 468, 468, 481 hex-constant (R775), 93, 93 IEEE_GET_ROUNDING_MODE, 461, 464, 468, hex-digit (R776), 93, 93, 282 468, 482 hex-digit-string (R1323), 282, 282 IEEE_GET_STATUS, 460, 465, 469, 469, 482, 492, host, 12, 12, 35, 301, 337, 526, 529, 530 550 host association, 4, 4, 15, 36, 57, 58, 64, 101, 114, 116, IEEE_GET_UNDERFLOW_MODE, 464, 469, 483 121, 129, 166, 167, 175, 301, 303, 325, 337, IEEE_HALTING, 458 339, 340, 526, 528, 530, 531, 534, 537, 629 IEEE_INEXACT, 458 host instance, 12, 176, 316, 317, 324, 334, 335, 361, 529, IEEE_INEXACT_FLAG, 458 533, 537, 542 IEEE_INF, 458

G

H

ISO/IEC JTC 1/SC 22/WG5/N2184

645

J3/21-007r1

WD 1539-1

IEEE_INT, 464, 469 IEEE_INVALID, 458 IEEE_INVALID_FLAG, 458 IEEE_IS_FINITE, 464, 470 IEEE_IS_NAN, 464, 470 IEEE_IS_NEGATIVE, 464, 470 IEEE_IS_NORMAL, 464, 471 IEEE_LOGB, 463, 464, 471 IEEE_MAX, 464, 471 IEEE_MAX_MAG, 464, 472 IEEE_MAX_NUM, 28, 464, 472 IEEE_MAX_NUM_MAG, 28, 464, 473 IEEE_MIN, 464, 473 IEEE_MIN_MAG, 464, 474 IEEE_MIN_NUM, 28, 464, 474 IEEE_MIN_NUM_MAG, 28, 464, 475 IEEE_MODES_TYPE, 458, 462, 468, 481 IEEE_NAN, 458 IEEE_NEAREST, 458, 461 IEEE_NEGATIVE_DENORMAL, 458 IEEE_NEGATIVE_INF, 458 IEEE_NEGATIVE_NORMAL, 458 IEEE_NEGATIVE_SUBNORMAL, 458, 458, 466, 470 IEEE_NEGATIVE_ZERO, 458 IEEE_NEXT_AFTER, 464, 475 IEEE_NEXT_DOWN, 464, 475, 476 IEEE_NEXT_UP, 464, 476 IEEE_OTHER, 458, 461 IEEE_OTHER_VALUE, 458 IEEE_OVERFLOW, 458 IEEE_POSITIVE_DENORMAL, 458 IEEE_POSITIVE_INF, 458 IEEE_POSITIVE_NORMAL, 458 IEEE_POSITIVE_SUBNORMAL, 458, 458, 466, 470 IEEE_POSITIVE_ZERO, 458 IEEE_QUIET_EQ, 464, 476 IEEE_QUIET_GE, 464, 476 IEEE_QUIET_GT, 464, 477 IEEE_QUIET_LE, 464, 477 IEEE_QUIET_LT, 464, 478 IEEE_QUIET_NAN, 458 IEEE_QUIET_NE, 464, 478 IEEE_REAL, 464, 478 IEEE_REM, 463, 464, 479 IEEE_RINT, 463, 464, 479

646

2021-05-21

IEEE_ROUND_TYPE, 458, 468, 469, 479, 482, 488 IEEE_ROUNDING, 458 IEEE_SCALB, 464, 480 IEEE_SELECTED_REAL_KIND, 464, 480 IEEE_SET_FLAG, 460, 465, 469, 481, 482, 492, 493, 550 IEEE_SET_HALTING_MODE, 194, 460, 465, 468, 481, 487, 492, 493, 550 IEEE_SET_MODES, 462, 465, 468, 481, 482 IEEE_SET_ROUNDING_MODE, 461, 464, 468, 482, 482 IEEE_SET_STATUS, 460, 461, 465, 469, 482, 482, 493, 550 IEEE_SET_UNDERFLOW_MODE, 464, 468, 469, 482, 483 IEEE_SIGNALING_EQ, 464, 483 IEEE_SIGNALING_GE, 464, 483 IEEE_SIGNALING_GT, 464, 484 IEEE_SIGNALING_LE, 465, 484 IEEE_SIGNALING_LT, 465, 484 IEEE_SIGNALING_NAN, 458 IEEE_SIGNALING_NE, 465, 485 IEEE_SIGNBIT, 465, 485 IEEE_SQRT, 458 IEEE_STATUS_TYPE, 458, 462, 469, 482, 492 IEEE_SUBNORMAL, 458 IEEE_SUPPORT_DATATYPE, 457–459, 465–467, 469, 471–479, 482–485, 486, 486, 489–491 IEEE_SUPPORT_DENORMAL, 465, 486 IEEE_SUPPORT_DIVIDE, 465, 486, 489 IEEE_SUPPORT_FLAG, 465, 487, 489 IEEE_SUPPORT_HALTING, 465, 487, 489 IEEE_SUPPORT_INF, 462, 463, 465, 475, 476, 487, 489, 491 IEEE_SUPPORT_IO, 465, 488 IEEE_SUPPORT_NAN, 459, 460, 462, 465, 488, 489, 491 IEEE_SUPPORT_ROUNDING, 465, 482, 488, 489 IEEE_SUPPORT_SQRT, 465, 489, 489 IEEE_SUPPORT_STANDARD, 463, 465, 489 IEEE_SUPPORT_SUBNORMAL, 462, 463, 465, 466, 476, 486, 489, 490, 491 IEEE_SUPPORT_UNDERFLOW_CONTROL, 465, 490 IEEE_TO_ZERO, 458, 461 IEEE_UNDERFLOW, 458

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

IEEE_UNDERFLOW_FLAG, 458 IEEE_UNORDERED, 463, 465, 490 IEEE_UP, 458, 461 IEEE_USUAL, 458 IEEE_VALUE, 465, 491 IEOR, 191, 195, 368, 398 IF construct, 38, 198, 551 IF statement, 155, 199 if-construct (R1136), 34, 198, 198 if-construct-name, 198 if-stmt (R1141), 34, 199, 199 if-then-stmt (R1137), 5, 198, 198, 207 imag-part (R720), 62, 62 image, 1, 12, 12, 20, 28, 37–39, 42, 43, 82, 102, 140– 144, 147, 172, 175, 176, 188, 189, 208, 210–215, 217–220, 223, 224, 229, 230, 262, 315, 319, 323, 326, 328, 343, 347, 348, 352, 353, 364–368, 379, 381, 393, 399, 416, 421, 425, 426, 441, 442, 444, 448, 452, 455, 456, 462, 524, 532, 533, 540, 543 active, 12, 148 failed, 12, 143, 147, 148, 218, 416 stopped, 12, 143, 147, 148, 416 image control statement, 12, 38, 163, 189, 194, 209, 210, 210–212, 215, 219–221, 328, 339, 347, 348, 389, 440, 455 image index, 12, 37, 42, 140, 213, 217, 223, 323, 353, 398, 399, 425, 444, 448, 524 image-selector (R926), 6, 8, 37, 132–134, 140, 140, 141, 292 image-selector-spec (R928), 140, 140 image-set (R1171), 213, 213 IMAGE_INDEX, 398 IMAGE_STATUS, 399 imaginary part, 62 implicit interface, 13, 73, 177, 298, 313–315, 323, 324, 499, 530 IMPLICIT NONE statement, 121 IMPLICIT statement, 37, 121, 126, 301 implicit-none-spec (R870), 121, 121 implicit-part (R505), 33, 33 implicit-part-stmt (R506), 33, 33 implicit-spec (R868), 121, 121 implicit-stmt (R867), 33, 121, 121 implied-shape array, 107 implied-shape-or-assumed-size-spec (R826), 104, 106, 107, 107

J3/21-007r1

implied-shape-spec (R827), 104, 107, 107 IMPORT statement, 37, 123, 524, 530 import-name, 123, 124 import-stmt (R871), 33, 123, 186 IMPURE, 331, 332, 336, 338, 341 IN, 108 INCLUDE line, 50, 52 inclusive scope, 12, 186, 207, 208, 232, 236, 238, 239, 256–258, 260, 316, 336, 524, 525 INDEX, 399 index-name, 180–182, 190, 191, 193, 527, 528, 540 inherit, 4, 7, 12, 67, 79–81, 83, 84, 537, 567 inheritance association, 4, 4, 7, 44, 84, 86, 534, 537 initial team, 20, 43, 140, 229, 353, 393, 399, 421, 425, 443, 452 initial-data-target (R744), 28, 75, 75, 76, 98, 99, 111, 117, 118 initial-proc-target (R1518), 76, 313, 313, 314 INITIAL_TEAM, 393, 452 initialization, 99 default, 8, 8, 74–77, 86, 87, 99, 106, 108, 116, 127– 129, 320, 532, 536, 537, 542 explicit, 11, 76, 77, 98, 99, 116, 532, 536, 538 initialization (R805), 93, 98, 98, 99, 168 INOUT, 50, 108 input statement, 237 input-item (R1216), 237, 238, 242, 242, 243, 255, 268, 543 input/output editing, 269–296 input/output list, 242 input/output statement, 539 input/output statements, 222–268 input/output unit, 14, 22, 37 INPUT_UNIT, 229, 230, 234, 251, 452 INQUIRE statement, 30, 224, 225, 227, 228, 230, 231, 241, 251, 252, 255, 259, 267, 268, 453, 539, 541–543, 548, 578 inquire-spec (R1231), 259, 259, 260, 268 inquire-stmt (R1230), 34, 259, 339 inquiry function, 13, 20, 102, 106, 108, 133, 144, 166, 318, 319, 343–346, 348, 358, 361, 371, 378, 382, 385, 388, 394, 402–404, 409, 413, 418, 423–425, 427, 430, 434, 437, 440, 444, 447, 448, 461–464, 486–490, 500 inquiry, type parameter, 134 instance, 334

ISO/IEC JTC 1/SC 22/WG5/N2184

647

J3/21-007r1

WD 1539-1

INT, 118, 171, 172, 345, 383, 384, 396, 398, 400, 400, 412 int-constant (R607), 48, 48, 117 int-constant-expr (R1031), 59, 63, 70, 71, 88, 89, 112, 116, 168, 168, 202, 203 int-constant-name, 59 int-constant-subobject (R850), 117, 117 int-expr (R1026), 37, 55, 91, 94, 105, 132, 135–137, 140, 141, 155, 164, 164, 166–168, 190–192, 208, 209, 213, 216, 217, 228, 229, 232, 237, 242, 245, 256, 259, 336 int-literal-constant (R708), 48, 59, 59, 63, 270, 271 int-variable (R907), 131, 131, 147, 232, 238, 259, 260, 262–267, 548 int-variable-name, 190 INT16, 452 INT32, 452 INT64, 452 INT8, 452 integer constant, 59 integer editing, 275 integer model, 346 integer type, 59–60 integer-type-spec (R705), 57, 59, 59, 70, 94, 116, 191, 527 INTEGER_KINDS, 453 INTENT (IN) attribute, 108, 108–110, 114, 191, 309– 311, 319, 322, 324, 326, 338, 339, 344, 364–368, 374–376, 386, 387, 392, 393, 417, 425, 426, 465, 496–499, 519, 543, 558, 599, 613 INTENT (INOUT) attribute, 28, 108, 109, 110, 113, 196, 310, 320, 322, 328, 340, 341, 355, 364– 368, 373–376, 387, 391–393, 415–417, 452–454, 543, 544, 613 INTENT (OUT) attribute, 27, 29, 57, 81, 82, 106, 108, 108–110, 113, 146, 166, 310, 320, 322, 328, 338, 340, 341, 355, 364–368, 374–376, 379, 381, 386, 387, 391–393, 416, 418, 424, 426, 441, 442, 467–469, 496, 498, 499, 519, 533, 534, 539, 540, 542–544, 613 INTENT attribute, 108, 108–110, 119, 195, 558 INTENT statement, 119, 186 intent-spec (R829), 97, 108, 119, 313 intent-stmt (R853), 34, 119 interface, 13, 13, 36, 41, 44, 73, 79, 80, 110, 249, 250, 284, 304, 305, 315, 323, 324, 328, 329, 335,

648

2021-05-21

337, 339, 504–507, 521, 522, 588 abstract, 13, 13, 298, 305, 307, 313, 332, 525, 529 explicit, 13, 29, 75, 79, 121, 125, 176, 177, 304–308, 313–315, 317, 323, 324, 337, 339, 525, 526, 543, 558, 588 generic, 13, 80, 84, 88, 110, 162, 173, 254, 299, 300, 308, 308–310, 329, 525 implicit, 13, 73, 177, 298, 313–315, 323, 324, 499, 530 procedure, 305 specific, 13, 254, 307, 307, 308, 313, 329, 558 interface block, 13, 36, 249, 255, 299, 306–308, 329, 588 interface body, 13, 17, 37, 103, 105, 108, 121, 166, 306, 306, 331, 332, 335, 337, 507, 526, 529, 588 INTERFACE statement, 306, 588 interface-block (R1501), 33, 306, 306 interface-body (R1505), 306, 306, 307 interface-name (R1516), 79, 80, 312, 313, 313 interface-specification (R1502), 306, 306, 307 interface-stmt (R1503), 306, 306–309, 529 internal file, 14, 14, 222, 228, 229, 231, 240, 244, 246– 248, 251, 252, 266, 267, 284, 285, 539, 541 internal procedure, 12, 16, 35, 175, 303–306, 316, 324, 330, 332, 335, 361, 522, 525, 526, 530, 558 internal subprogram, 20, 35, 37, 121, 124, 303, 329, 529 internal unit, 14, 14, 229, 231, 246, 251, 260, 268, 453 internal-file-variable (R1203), 228, 228, 229, 238, 268, 543 internal-subprogram (R512), 33, 33 internal-subprogram-part (R511), 32, 33, 33, 297, 333– 335 interoperable, 13, 88, 89, 101, 332, 337, 494, 496–507, 520, 521 interoperable enumeration, 88, 494 interoperate, 494 intrinsic, 7, 10, 12, 13, 13, 15, 16, 20, 21, 40, 42, 44, 55, 57, 82, 93, 108, 305, 322, 329, 330, 341, 450, 525, 527 intrinsic assignment statement, 29, 86, 140, 146, 148, 165, 169, 174, 175, 195, 220, 228, 259, 268, 294, 339, 348, 355, 539, 546 INTRINSIC attribute, 108, 110, 110, 111, 298, 314, 329, 530 intrinsic function, 343 intrinsic operation, 155–162 intrinsic procedure, 343–450

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

INTRINSIC statement, 301, 314 intrinsic subroutines, 343 intrinsic type, 7, 21, 39, 40, 54, 58–66, 505, 510 intrinsic-operator (R608), 15, 48, 49, 150, 152, 155, 156, 162, 309 intrinsic-procedure-name, 314, 529 intrinsic-stmt (R1519), 34, 314, 529 intrinsic-type-spec (R704), 56, 57, 59, 64 io-control-spec (R1213), 237, 237, 238, 241, 251, 268 io-implied-do (R1218), 242, 242–244, 247, 268, 539, 541, 543, 579 io-implied-do-control (R1220), 242, 242, 245 io-implied-do-object (R1219), 242, 242, 247 io-unit (R1201), 22, 228, 228, 229, 237, 238, 339 IOLENGTH= specifier, 227, 259, 265 iomsg-variable (R1207), 232, 232, 236, 237, 256, 258, 259, 266–268, 539 IOMSG= specifier, 232, 236, 237, 256, 258, 259, 266, 267, 268, 539 IOR, 191, 195, 367, 400 IOSTAT= specifier, 232, 236, 237, 251, 256, 258, 259, 266, 267, 267, 402, 403, 453, 539, 548, 579 IOSTAT_END, 252, 267, 453 IOSTAT_EOR, 252, 267, 453 IOSTAT_INQUIRE_INTERNAL_UNIT, 251, 267, 453, 456 IPARITY, 401 IS_CONTIGUOUS, 57, 402 IS_IOSTAT_END, 402 IS_IOSTAT_EOR, 402 ISHFT, 401 ISHFTC, 402 ISO 10646 character, 14, 63, 65, 169, 228, 229, 233, 244, 274, 288, 289, 418, 432 ISO_C_BINDING, 5, 57, 72, 83, 101, 108, 133, 142, 143, 166, 172, 339, 450, 494–502, 541–543, 558 ISO_Fortran_binding.h, 507 ISO_FORTRAN_ENV, 23, 28, 67, 72, 101, 108, 133, 140, 142, 143, 148, 166, 172, 187, 208–210, 216–220, 227, 229, 234, 246, 251, 267, 347, 348, 364–368, 388, 389, 393, 394, 399, 416, 421, 440, 441, 443, 444, 450–456, 540, 543, 549, 579

K k (R1314), 271, 271, 278, 283, 284, 286 keyword, 14

J3/21-007r1

argument, 10, 14, 44, 305, 308, 317, 343, 348, 463, 525, 526, 527, 588 component, 14, 44, 77, 86, 87, 526 statement, 14, 44 type parameter, 14, 44, 85 keyword (R516), 44, 44, 85, 86, 315 KIND, 59–63, 66, 71, 89, 135, 171, 172, 403 kind type parameter, 22, 26, 39, 55, 58–64, 66, 71, 81, 82, 89, 94, 167–171, 292, 310, 319, 332, 382, 388, 431, 452, 454, 455, 494, 495, 501, 558 kind-param (R709), 59, 59–61, 63, 64, 66 kind-selector (R706), 25, 59, 59, 66

L L edit descriptor, 282 label, see statement label label (R611), 5, 49, 49, 190, 192, 207, 208, 232, 236–239, 256–260, 266, 267, 315, 316 label-do-stmt (R1121), 190, 190, 192 language-binding-spec (R808), 97, 101, 115, 332 LBOUND, 57, 170, 176, 185, 203, 403 lbracket (R779), 72, 94, 94, 97, 98, 115, 116, 120, 140, 141 LCOBOUND, 404 leading zero mode, 234, 241, 286 leading-zero-edit-desc (R1319), 271, 272 LEADING_ZERO= specifier, 232, 234, 237–239, 241, 259, 262, 286 LEADZ, 404 left tab limit, 285 LEN, 135, 404 LEN_TRIM, 405 length type parameter, 22, 22, 39, 55, 66, 75, 94, 110, 144, 170, 319, 404, 499, 501, 558 length-selector (R722), 25, 63, 63, 64 letter, 46, 46, 47, 49, 121, 150, 152 letter-spec (R869), 121, 121 level-1-expr (R1002), 150, 150, 151, 154 level-2-expr (R1006), 150, 150, 151, 154 level-3-expr (R1010), 151, 151, 152 level-4-expr (R1012), 151, 152 level-5-expr (R1017), 152, 152, 153 lexical token, 12, 14, 24, 47, 49 LGE, 66, 405 LGT, 66, 405 line, 14, 50–53 linkage association, 4, 4, 521, 528, 531, 531

ISO/IEC JTC 1/SC 22/WG5/N2184

649

J3/21-007r1

WD 1539-1

list-directed formatting, 248, 288–291 list-directed input/output statement, 239 literal constant, 7, 41, 132, 164 literal-constant (R605), 48, 48, 149 LLE, 66, 406 LLT, 66, 406 LOCAL, 191, 195, 197, 527, 534, 542 local identifier, 524, 525 local procedure pointer, 15, 334 local variable, 15, 23, 28, 29, 41, 99, 101, 103, 105, 112, 114, 145, 146, 316, 334, 338 local-defined-operator (R1414), 299, 299, 300 local-name, 299, 300 LOCAL_INIT, 191, 195, 527, 534, 540, 542 locality, 195, 196, 527, 534, 540, 542 locality-spec (R1130), 191, 191, 192 LOCK statement, 210, 217, 220, 453–456, 540, 544 lock variable, 23, 38, 220, 453, 455, 456, 540, 543 lock-stat (R1184), 217, 218, 218 lock-stmt (R1183), 34, 217 lock-variable (R1186), 217, 218, 218, 219, 453, 544 LOCK_TYPE, 23, 28, 67, 108, 142, 143, 218, 453 LOG, 30, 407 LOG10, 407 LOG_GAMMA, 407 LOGICAL, 407 logical intrinsic operation, 159 logical type, 66 logical-expr (R1024), 164, 164, 178, 190, 193, 194, 198, 199, 208 logical-literal-constant (R725), 48, 66, 150, 152 logical-variable (R904), 131, 131, 218, 219, 259–263, 544 LOGICAL16, 454 LOGICAL32, 454 LOGICAL64, 454 LOGICAL8, 454 LOGICAL_KINDS, 454 loop-control (R1123), 190, 190, 192, 193, 197 lower-bound (R817), 105, 105–107 lower-bound-expr (R936), 141, 141, 175 lower-bounds-expr (R937), 141, 141–143, 174, 176 lower-cobound (R812), 102, 103, 103 LZ edit descriptor, 286 LZP edit descriptor, 286 LZS edit descriptor, 286

650

2021-05-21

M m (R1309), 270, 271, 271, 275, 276, 281, 282 main program, 14, 16, 20, 35, 38, 41 main-program (R1401), 32, 35, 123, 297, 297 mask-expr (R1046), 178, 178–181, 191–193 masked array assignment, 14, 178, 539 masked array assignment (WHERE), 178 masked-elsewhere-stmt (R1047), 178, 178, 179, 181 MASKL, 408 MASKR, 408 MATMUL, 408 MAX, 191, 195, 341, 344, 409 MAXEXPONENT, 409 MAXLOC, 344, 410 MAXVAL, 411 MERGE, 411 MERGE_BITS, 412 MIN, 191, 195, 412 MINEXPONENT, 413 MINLOC, 413 MINVAL, 414 MOD, 30, 415 mode blank interpretation, 233 changeable, 229 connection, 229 decimal edit, 233 delimiter, 233 halting, 457, 462, 462, 465, 467, 481, 487, 523, 550 IEEE rounding, 457, 458, 461, 462, 463 input/output rounding, 229, 235, 242, 264, 281, 286, 287, 488 leading zero, 234, 241, 286 pad, 234 sign, 235, 286 underflow, 461, 462, 464, 469, 483, 490, 550 model bit, 345 extended real, 346 integer, 346 real, 346 MODULE, 306, 307, 331, 331, 332, 335 module, 14, 15, 16, 17, 19, 20, 35, 36, 41, 297 module (R1404), 32, 123, 298 module procedure, 16, 79, 125, 175, 303–307, 313, 316, 324, 330, 331, 335, 338, 340, 341, 450, 525, 526

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

module procedure interface body, 124, 307 module reference, 17, 298 MODULE statement, 297, 298 module subprogram, 20, 35, 37, 121, 124, 329, 529 module-name, 298, 299, 529 module-nature (R1410), 299, 299 module-stmt (R1405), 32, 298, 298 module-subprogram (R1408), 33, 298, 298, 335 module-subprogram-part (R1407), 32, 81, 85, 298, 298, 301, 593 MODULO, 30, 415 MOLD= specifier, 141 MOVE_ALLOC, 144, 210, 343, 415 mp-subprogram-stmt (R1539), 33, 335, 335 mult-op (R1008), 48, 150, 150, 151 mult-operand (R1004), 150, 150, 151, 154 multiple-subscript (R920), 135, 136 multiple-subscript-triplet (R923), 136, 136, 137 MVBITS, 343, 344, 417

J3/21-007r1

NEWUNIT= specifier, 229, 232, 234, 251, 540, 543 NEXT, 418 NEXTREC= specifier, 260, 262 NINT, 418 NML= specifier, 237, 239, 543 NON_INTRINSIC, 299 NON_OVERRIDABLE attribute, 79, 80 NON_RECURSIVE, 331, 332 NON_RECURSIVE attribute, 305, 331, 331, 332, 335, 336 nonadvancing input/output statement, 226 nonblock DO construct, 552 NONE, 121, 123, 191 nonexecutable statement, 18, 36 nonlabel-do-stmt (R1122), 190, 190, 192 nonstandard intrinsic, 14, 26, 556, 596, 597 NOPASS, 73, 75, 79 NOPASS attribute, see PASS attribute NORM2, 419

N

normal number, 462

n (R1316), 271, 271, 272, 285 name, 15, 44, 47, 524 name (R603), 25, 44, 47, 47, 48, 98, 120, 131, 191, 196, 205, 247, 313, 333 name association, 4, 4, 44, 528, 534 name-value subsequence, 292, 293 NAME= specifier, 97, 101, 115, 259, 260, 262, 313, 313, 332, 521 named constant, 7, 22, 41, 44, 47, 55, 59, 62–64, 107, 110, 111, 114, 117, 119, 127, 132, 337 named-constant (R606), 48, 48, 52, 62, 88, 119, 529 named-constant-def (R856), 119, 119, 529 NAMED= specifier, 259, 262 namelist formatting, 248, 292–296 namelist input/output statement, 239 NAMELIST statement, 126, 186, 292, 300 namelist-group-name, 126, 237–239, 246, 248, 269, 292, 296, 300, 529, 543 namelist-group-object (R873), 126, 126, 246–248, 255, 268, 292, 300 namelist-stmt (R872), 34, 126, 529, 543 NaN, 15, 276–280, 283, 355, 387, 390, 430, 434, 438, 459, 462, 463, 465, 466, 470, 488 NEAREST, 417 NEW_INDEX= specifier, 217, 547 NEW_LINE, 283, 418

normal termination, 12, 37, 38, 39, 83, 208, 223, 235, 236, 399, 440, 455 NOT, 419 not-op (R1018), 48, 152, 152 notify variable, 23, 38, 211, 454 NOTIFY WAIT statement, 140, 209, 211, 454, 541, 546 notify-variable (R1167), 140, 209, 209, 454, 543 notify-wait-stmt (R1166), 34, 209 NOTIFY= specifier, 140, 210, 211, 454, 541 NOTIFY_TYPE, 23, 67, 108, 142, 143, 209, 454 NULL, 87, 98, 165, 167, 168, 324, 344, 420, 532, 533 null-init (R806), 75, 76, 98, 98, 99, 117, 118, 313 NULLIFY statement, 145 nullify-stmt (R942), 34, 145, 544 NUM_IMAGES, 168, 421, 448 NUMBER= specifier, 260, 262 numeric conversion, 171 numeric editing, 275 numeric intrinsic operation, 156 numeric sequence type, 18, 68, 69, 127–129, 536, 539 numeric storage unit, 19, 19, 129, 455, 535, 539, 541 numeric type, 21, 58–62, 156–158, 160, 164, 171, 382, 408, 409, 424, 441 numeric-expr (R1027), 164, 164 NUMERIC_STORAGE_SIZE, 455

ISO/IEC JTC 1/SC 22/WG5/N2184

651

J3/21-007r1

WD 1539-1

O O edit descriptor, 281 object, 8, 8, 40–42 object designator, 9, 40, 41, 113, 117, 132, 166, 292 object-name (R804), 98, 98, 115, 116, 119–121, 131, 139, 195, 529 obsolescent feature, 26, 27, 31, 552–554 octal-constant (R774), 93, 93 ONLY, 123, 124, 125, 299, 299, 300, 531, 585, 586 only (R1412), 299, 299, 300 only-use-name (R1413), 299, 299, 300 OPEN statement, 31, 223, 224, 228–230, 231, 231, 235, 240, 248, 252, 262, 265, 281, 294, 540, 543, 547, 548, 578–581 open-stmt (R1204), 34, 231, 339 OPENED= specifier, 260, 263 operand, 15 operation, 54 defined, 9, 17, 79, 153, 162, 163–165, 191, 303, 309, 315, 328, 339 elemental, 10, 155, 165, 179 intrinsic, 155–162 logical, 159 numeric , 156 relational, 160 OPERATOR, 54, 79, 162, 299, 306, 309, 588 operator, 15, 48 character, 151 defined binary, 152 defined unary, 150 elemental, 10, 155, 458 logical, 152 numeric, 150 relational, 151 operator precedence, 153 OPTIONAL attribute, 56, 110, 110, 113, 119, 166, 185, 191, 305 optional dummy argument, 325 OPTIONAL statement, 119, 186 optional-stmt (R854), 34, 119 or-op (R1020), 48, 152, 152 or-operand (R1015), 152, 152 other-specification-stmt (R513), 33, 33 OUT, 108 OUT_OF_RANGE, 421 output statement, 237

652

2021-05-21

output-item (R1217), 93, 237, 238, 242, 242, 255, 259 OUTPUT_UNIT, 229, 230, 234, 251, 455 override, 76, 84, 97, 98, 121, 248, 275, 536

P P edit descriptor, 286 PACK, 422 pad mode, 234 PAD= specifier, 30, 31, 232, 234, 237–239, 241, 252, 260, 263 padding, 345, 345, 400, 428 PARAMETER attribute, 7, 41, 89, 99, 110, 110, 111, 119, 132 PARAMETER statement, 37, 119, 121, 301 parameter-stmt (R855), 33, 119, 529 parent component, 4, 7, 77, 78, 82, 84, 87, 537, 567 parent data transfer statement, 241, 250, 248–252, 268, 291 parent team, 20, 43, 140, 188, 215, 216, 388, 393, 399, 421, 440, 443, 444, 455 parent type, 7, 21, 67, 71, 78, 81–84, 311, 567 parent-identifier (R1418), 301, 301 parent-string (R909), 103, 132, 132 parent-submodule-name, 301 parent-type-name, 67 PARENT_TEAM, 393, 455 parentheses, 164 PARITY, 422 part-name, 5, 132–134, 139 part-ref (R912), 103, 117, 127, 132, 132–135, 138, 139, 378, 399, 404, 444, 448 partially associated, 536 PASS attribute, 73, 75, 80, 315 passed-object dummy argument, 15, 75, 79, 80, 84, 312, 317, 602 PAUSE statement, 551 pending affector, 100, 240, 245, 523 PENDING= specifier, 260, 263 POINTER, 72, 73, 74 pointer, 4, 9, 10, 15, 18, 20, 22, 43, 68, 74, 139, 145–147, 168, 304, 305, 320, 339, 440, 494, 517, 532, 599 procedure, 498 pointer assignment, 15, 106, 108, 145, 172, 174, 175, 325, 533 pointer assignment statement, 15, 20, 55, 75, 87, 165, 174, 176, 181, 182, 353, 361

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

pointer association, 4, 4, 8–10, 20–22, 41, 44, 82, 85, 87, 103, 109, 111, 113, 114, 133, 146, 148, 174–176, 195, 196, 211, 214, 245, 304, 318, 319, 322, 324, 325, 333, 335, 349, 361, 416, 420, 497–499, 508, 519, 523, 532–599 pointer association context, 108, 111, 339, 544 pointer association status, 532 POINTER attribute, 3, 15, 55–57, 66, 72, 98, 106, 107, 111, 111–113, 118, 120, 133, 136, 145, 174, 175, 185, 195, 202, 203, 303–305, 307, 310, 311, 313, 321, 324–327, 332, 339, 341, 499, 503, 519, 531, 534, 537, 538, 558, 602, 606 POINTER statement, 119, 301 pointer-assignment-stmt (R1033), 34, 174, 174, 180, 181, 339, 544 pointer-decl (R858), 119, 119 pointer-object (R943), 145, 145, 544 pointer-stmt (R857), 34, 119, 529 polymorphic, 15, 28, 29, 57, 58, 75, 87, 106, 108, 133, 145, 164, 169, 170, 175, 176, 184, 185, 191, 194, 203, 205, 206, 243, 248, 304, 305, 315, 318–321, 338, 339, 388, 412, 416, 430, 440, 532, 537 POPCNT, 423 POPPAR, 423 POS= specifier, 225–227, 237, 238, 241, 241, 260, 263, 548 position edit descriptor, 284 position-edit-desc (R1315), 271, 271 position-spec (R1227), 256, 256, 257 POSITION= specifier, 231, 232, 234, 260, 263, 580 positional arguments, 343 potential subobject component, 7, 28, 66, 67, 142, 339, 452–454 power-op (R1007), 48, 150, 150, 151 pre-existing, 537 precedence of operators, 153 PRECISION, 60, 423, 480 preconnected, 15, 224, 229–231, 234, 240, 246, 451, 452, 455 preconnection, 231 prefix (R1526), 331, 331–334 prefix-spec (R1527), 331, 331, 332, 338, 340, 341 PRESENT, 57, 72, 73, 110, 166, 325, 344, 424, 600 present, 325 PREVIOUS, 424 primary, 149

J3/21-007r1

primary (R1001), 149, 149–151, 337 PRINT statement, 224, 233, 237, 246, 251, 252, 255 print-stmt (R1212), 35, 237, 339 PRIVATE attribute, 69, 84, 100, 100, 114, 339, 586 PRIVATE statement, 78, 79, 80, 114, 300 private-components-stmt (R745), 68, 78, 78 private-or-sequence (R729), 67, 68, 68 proc-attr-spec (R1514), 312, 312, 313 proc-component-attr-spec (R742), 73, 73, 74 proc-component-def-stmt (R741), 72, 73, 73 proc-component-ref (R1039), 175, 175, 315, 325 proc-decl (R1515), 73, 76, 312, 313, 313 proc-entity-name, 119, 120 proc-interface (R1513), 73, 312, 312, 313 proc-language-binding-spec (R1528), 312, 313, 332, 332–334, 337, 504 proc-pointer-init (R1517), 313, 313 proc-pointer-name (R862), 120, 120, 145, 175 proc-pointer-object (R1038), 174, 175, 175, 181, 361, 544 proc-target (R1040), 86, 87, 174, 175, 175, 181, 325, 361 PROCEDURE, 73, 79, 312, 335 procedure, 9, 16, 17, 45, 110, 306 characteristics of, 304 dummy, 6, 10, 12, 16, 108, 121, 125, 167, 175, 303, 304, 306, 307, 312, 313, 316, 323, 324, 330, 332, 338, 340, 341, 522, 525, 530 elemental, 10, 42, 165, 175, 313, 316, 325, 329, 331, 340, 341, 341, 343, 344 external, 16, 26, 35, 79, 108, 121, 175, 215, 303, 304, 306–308, 312, 313, 316, 324, 330, 524, 525, 529, 530, 558, 588, 593, 596, 597 internal, 12, 16, 35, 175, 303–306, 316, 324, 330, 332, 335, 361, 522, 525, 526, 530, 558 intrinsic, 343–450 module, 16, 79, 125, 175, 303–307, 313, 316, 324, 330, 331, 335, 338, 340, 341, 450, 525, 526 non-Fortran, 337 pure, 16, 28, 29, 84, 176, 180, 191, 304, 305, 307, 313, 323, 331, 332, 336, 338–340, 340, 343, 428 simple, 16, 84, 176, 177, 304, 305, 307, 313, 323, 332, 338, 340, 343, 348, 415, 417, 438, 445, 450, 458, 464, 465, 495, 498 type-bound, 5, 12, 15, 16, 66–68, 75, 80, 80, 81, 83, 84, 172, 173, 254, 299, 309, 315, 317, 319,

ISO/IEC JTC 1/SC 22/WG5/N2184

653

J3/21-007r1

WD 1539-1

330, 338, 340, 341, 525, 526 procedure declaration statement, 37, 108, 305, 307, 312, 337, 353, 526, 558 procedure designator, 9, 17, 42 procedure interface, 305 procedure pointer, 6, 12, 15, 15, 35, 37, 55, 73–76, 86, 87, 98, 108, 109, 111, 112, 120, 128, 149, 175, 176, 184, 242, 303, 304, 307, 312, 316, 317, 323–325, 330, 333, 335, 338, 340, 341, 361, 420, 498, 499, 522, 526, 529, 533, 558, 599 procedure reference, 3, 17, 29, 42, 110, 135, 251, 303, 309, 315, 317 generic, 311 resolving, 328 type-bound, 330 PROCEDURE statement, 306, 308, 558 procedure-component-name, 175 procedure-declaration-stmt (R1512), 33, 312, 313 procedure-designator (R1522), 315, 315, 325, 330, 331 procedure-entity-name, 313, 314 procedure-name, 79, 80, 175, 177, 306, 307, 313, 315, 316, 335 procedure-stmt (R1506), 306, 306, 307, 558 processor, 16, 26, 27, 45 processor dependent, 16, 27, 45, 545–550 PRODUCT, 424 program, 16, 26, 27, 35 program (R501), 32 PROGRAM statement, 297 program unit, 14, 15, 16, 16, 17, 19, 26, 32, 35–37, 39, 43, 44, 46, 47, 49–52, 70, 112, 121, 229, 235, 297, 301, 394, 520, 524, 532, 553, 558, 584–588, 592–596, 611 program-name, 297 program-stmt (R1402), 32, 297, 297 program-unit (R502), 25, 32, 32, 35 PROTECTED attribute, 28, 111, 111, 112, 120, 127, 195, 299, 558 PROTECTED statement, 120 protected-stmt (R859), 34, 120 PUBLIC attribute, 84, 100, 100, 114, 586 PUBLIC statement, 114, 300 PURE, 331, 332, 336, 338 pure procedure, 16, 28, 29, 84, 176, 180, 191, 304, 305, 307, 313, 323, 331, 332, 336, 338–340, 340, 343, 428, 558

654

2021-05-21

Q QUIET= specifier, 208

R r (R1306), 270, 270–273 RADIX, 60, 425, 457, 480 RANDOM_INIT, 425, 426, 549 RANDOM_NUMBER, 426, 426 RANDOM_SEED, 344, 425, 426 RANGE, 59, 60, 427, 480 RANK, 57, 104, 106, 112, 112, 427 rank, 16, 18, 40–43, 73, 75, 81, 82, 86, 87, 97, 101, 103, 104, 106, 107, 119, 129, 133–136, 138, 139, 142, 144, 162, 164, 165, 169–171, 173, 174, 176, 177, 185, 213, 304, 309–311, 320, 321, 325, 330, 341, 353, 358, 359, 378–380, 384, 389, 395, 396, 401, 403, 404, 408, 410, 411, 413–416, 419, 420, 422–426, 428, 429, 434, 437, 439, 441, 444, 446–448, 492, 497, 504, 528, 535, 602, 603 RANK ( * ), 106, 202 RANK DEFAULT, 107, 202 rank-clause (R830), 97, 106, 112, 112 rbracket (R780), 72, 94, 94, 97, 98, 115, 116, 120, 140, 141 RC edit descriptor, 287 RD edit descriptor, 287 READ (FORMATTED), 249, 306 READ (UNFORMATTED), 249, 306 READ statement, 31, 41, 225, 229, 233, 237, 246, 251, 252, 255, 258, 266, 542, 578–580, 582, 583 read-stmt (R1210), 35, 237, 238, 339, 543 READ= specifier, 260, 264 READWRITE= specifier, 260, 264 REAL, 134, 171, 172, 345, 427, 458 real and complex editing, 276 real model, 346 real part, 62 real type, 60–61, 61 real-literal-constant (R714), 48, 61, 61 real-part (R719), 62, 62 REAL128, 455 REAL16, 455 REAL32, 455 REAL64, 455 REAL_KINDS, 455 REC= specifier, 226, 237, 238, 241

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

RECL= specifier, 232, 234, 248, 260, 264, 265, 541, 547 record, 16, 222 record file, 11, 17, 222, 224, 226–228 record number, 224 RECURSIVE, 63, 331, 332, 336 recursive input/output statement, 268 REDUCE, 191, 195, 196, 428 reduce-operation (R1131), 191, 191, 192, 195, 196 reference, 17, 42 procedure, 29 rel-op (R1013), 48, 151, 151, 161, 459 relational intrinsic operation, 160 rename (R1411), 299, 299, 300, 525 rep-char, 64, 64, 272, 289, 294 REPEAT, 429 repeat specification, 270 representation method, 59, 60, 62, 66 RESHAPE, 95, 430 resolving procedure reference, 328 resolving procedure references defined input/output, 254 restricted expression, 166 RESULT, 333, 333, 335, 336 result-name, 333, 335, 336, 529 RETURN statement, 38, 83, 111, 112, 129, 146, 147, 187, 189, 194, 336, 497, 542 return-stmt (R1542), 35, 37, 336, 336 REWIND statement, 223, 224, 226, 252, 255, 257, 258, 578 rewind-stmt (R1226), 35, 256, 339 RN edit descriptor, 287 round edit descriptor, 287 round-edit-desc (R1320), 271, 272 ROUND= specifier, 232, 235, 237–239, 242, 252, 260, 264, 287 rounding mode IEEE, 457, 458, 461, 462, 463, 468, 479, 482, 488 input/output, 229, 235, 242, 264, 281, 286, 287, 488 RP edit descriptor, 287 RRSPACING, 430 RU edit descriptor, 287 RZ edit descriptor, 287

S S edit descriptor, 286

J3/21-007r1

SAME_TYPE_AS, 72, 73, 430 SAVE attribute, 17, 22, 31, 43, 76, 83, 99, 101, 102, 112, 112, 116, 120, 127, 129, 147, 195, 313, 338, 533 SAVE statement, 120, 186, 301, 526 save-stmt (R860), 34, 120, 529 saved, 17, 532, 538 saved-entity (R861), 120, 120, 186 scalar, 17, 17, 19, 341 scalar-xyz (R403), 25, 25 SCALE, 431 scale factor, 271, 286 SCAN, 431 scoping unit, 4, 12, 17, 23, 35, 37, 38, 41, 44, 64, 69, 70, 78, 82, 86, 99–101, 108, 110, 112, 114, 120, 121, 123–126, 128, 129, 146, 167, 175, 186, 187, 191, 192, 195, 196, 240, 243, 244, 298–300, 305, 307, 311, 328–331, 333, 335, 337, 338, 457, 459, 520, 525–531, 534, 536, 537, 541, 586, 596, 603 section subscript, 138 section-subscript (R921), 23, 132, 133, 135, 136, 136– 139 segment, 211 SELECT CASE construct, 38, 199, 553, 568 SELECT CASE statement, 50, 199 SELECT RANK construct, 38, 43, 106, 107, 185, 202, 325, 527, 528, 543 SELECT RANK statement, 43, 108, 202, 531 SELECT TYPE construct, 38, 43, 55, 57, 185, 204, 325, 527, 528, 531, 543 SELECT TYPE statement, 43, 50, 204, 531 select-case-stmt (R1143), 5, 199, 199, 200, 207 select-construct-name, 202–205 select-rank-case-stmt (R1152), 202, 202, 203 select-rank-construct (R1150), 34, 202, 202, 203 select-rank-stmt (R1151), 5, 202, 202, 207 select-type-construct (R1154), 34, 204, 205 select-type-stmt (R1155), 5, 204, 204, 205, 207 SELECTED_CHAR_KIND, 63, 432 SELECTED_INT_KIND, 59, 71, 433 SELECTED_LOGICAL_KIND, 433 SELECTED_REAL_KIND, 60, 344, 433, 558, 559 selector, 184 selector (R1105), 184, 184, 185, 187, 188, 202, 204–206, 325, 532, 543 separate module procedure, 335

ISO/IEC JTC 1/SC 22/WG5/N2184

655

J3/21-007r1

WD 1539-1

separate module subprogram statement, 335 separate-module-subprogram (R1538), 33, 298, 335, 335 sequence, 17 sequence association, 324 SEQUENCE attribute, 17, 66, 68, 68–70, 83, 128, 174, 176, 205, 502 SEQUENCE statement, 68 sequence structure, 17 sequence type, 17, 17, 29, 66, 68, 68, 127, 503, 535 character, 18, 68, 127–129, 536, 539 numeric, 18, 68, 69, 127–129, 536, 539 sequence-stmt (R731), 68, 68 sequential access, 224 sequential access data transfer statement, 241 SEQUENTIAL= specifier, 260, 264 SET_EXPONENT, 434 SHAPE, 57, 434 shape, 18, 42, 211 SHARED, 191, 195, 196 SHIFTA, 435 SHIFTL, 435 SHIFTR, 435 sibling teams, 20, 20, 216, 399, 421, 443 SIGN, 30, 31, 61, 436 sign (R712), 59, 59, 61, 276 sign mode, 235, 275, 286 sign-edit-desc (R1321), 271, 272 SIGN= specifier, 232, 235, 238, 239, 242, 260, 264, 286 signed-digit-string (R710), 59, 61, 275–277 signed-int-literal-constant (R707), 59, 59, 62, 117, 271 signed-real-literal-constant (R713), 61, 62, 117 significand (R715), 61, 61 SIMPLE, 331, 332, 338 simple procedure, 16, 84, 176, 177, 304, 305, 307, 313, 323, 332, 338, 340, 343, 348, 415, 417, 438, 445, 450, 458, 464, 465, 495, 498 simply contiguous, 18, 139, 139, 140, 176, 319–323, 498 SIN, 436 SIND, 436 SINH, 437 SINPI, 437 SIZE, 57, 437 size, 18, 42 size of a common block, 129 SIZE= specifier, 238, 242, 260, 265, 266, 267, 539, 542,

656

2021-05-21

579 source-expr (R932), 141, 141–145, 339, 532–534 SOURCE= specifier, 141, 143, 145, 339, 452, 454, 540, 542, 558 SP edit descriptor, 286 SPACING, 438 special character, 46 specific interface, 13, 254, 307, 307, 308, 313, 329, 558 specific interface block, 13, 13, 307 specific name, 18 specific-procedure (R1507), 306, 306, 308 specification, 97–130 specification expression, 18, 22, 38, 71–73, 82, 100, 135, 166, 167, 167, 186, 336, 459, 553, 558 specification function, 167 specification inquiry, 166 specification-construct (R508), 33, 33, 186 specification-expr (R1028), 5, 99, 103, 105, 166, 166, 341 specification-part (R504), 32, 33, 33, 38, 79, 100, 101, 114, 167, 168, 297, 298, 301, 302, 306, 332, 334, 335, 338, 340, 341 SPLIT, 438 SPREAD, 439 SQRT, 30, 439, 463, 489 SS edit descriptor, 286 standard intrinsic, 14, 26, 450, 556 standard-conforming program, 18, 26 stat-variable (R946), 38, 140–142, 146, 147, 147, 148, 207, 209, 210, 212, 213, 216–220, 232, 236, 237, 256, 258, 259, 266, 267, 402, 403, 540, 543, 546 STAT= specifier, 140, 140, 141, 144–146, 147, 189, 210, 212, 219, 455, 456, 540, 543, 546, 557 STAT_FAILED_IMAGE, 38, 140, 148, 219, 220, 347, 348, 389, 416, 455, 456 STAT_LOCKED, 220, 455, 456 STAT_LOCKED_OTHER_IMAGE, 220, 455, 456 STAT_STOPPED_IMAGE, 148, 219, 220, 348, 416, 440, 455, 456 STAT_UNLOCKED, 220, 456, 456 STAT_UNLOCKED_FAILED_IMAGE, 220, 456, 456 statement, 18, 50 accessibility, 114 ALLOCATABLE, 115 ALLOCATE, 55, 57, 63, 64, 103, 106, 141, 144,

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

147, 148, 175, 210, 452, 454, 513, 532, 533, 540, 542, 546, 558 arithmetic IF, 552 ASSIGN, 551 assigned GO TO, 551 assignment, 14, 15, 28, 41, 55, 82, 169, 182, 210, 211, 454, 491, 539, 541 ASSOCIATE, 43, 184, 531 ASYNCHRONOUS, 115, 186, 301, 527, 530 attribute specification, 114–130 BACKSPACE, 223, 226, 252, 255, 257, 257, 578, 580 BIND, 115, 301, 520, 526 BLOCK, 99, 103, 105, 186, 540 BLOCK DATA, 50, 297, 301 CALL, 20, 207, 210, 303, 315, 328, 336, 416 CASE, 199 CHANGE TEAM, 20, 37, 43, 187, 210, 220, 347, 531 CLASS DEFAULT, 205 CLASS IS, 205, 388 CLOSE, 223, 224, 228, 230, 231, 235, 235, 252, 255, 578 COMMON, 6, 128, 128–130, 186, 300, 301, 526, 536, 552 component definition, 56, 72 computed GO TO, 5, 207, 208, 552, 553 CONTAINS, 36, 37, 79, 337 CONTIGUOUS, 116 CONTINUE, 208, 551 CRITICAL, 163, 189, 210, 220 CYCLE, 184, 190, 194, 194, 554 DATA, 31, 37, 93, 99, 116, 129, 301, 420, 527, 530, 538, 552, 553 data transfer, 31, 49, 93, 222–228, 230, 237, 242, 245–247, 251, 255, 257, 266–270, 281, 286, 288–293, 295, 453, 539, 541, 548, 578, 579, 582, 583 DEALLOCATE, 145, 147, 148, 210, 452, 454, 513, 546 defined assignment, 29, 173, 173, 328, 543 derived type definition, see statement, TYPE DIMENSION, 118, 301 DO, 190, 539, 552, 554 DO CONCURRENT, 57, 181, 190 DO WHILE, 190

J3/21-007r1

ELSE, 198 ELSE IF, 50, 198 ELSEWHERE, 50, 178 END, 11, 37, 111, 112, 129, 146, 147, 210, 497, 542 END ASSOCIATE, 50, 184 END BLOCK, 50, 147, 186 END BLOCK DATA, 50, 301 END CRITICAL, 50, 163, 189, 210 END DO, 50, 192 END ENUM, 50, 88 END ENUMERATION TYPE, 91 END FORALL, 50, 180 END FUNCTION, 50, 333 END IF, 50, 198, 551 END INTERFACE, 50, 306 END MODULE, 50, 298 END PROCEDURE, 50, 335 END PROGRAM, 50, 297 END SELECT, 50, 200, 205 END SUBMODULE, 50, 301 END SUBROUTINE, 50, 334 END TEAM, 37, 50, 187, 207, 210, 220, 347 END TYPE, 50, 68 END WHERE, 50, 178 ENDFILE, 50, 223, 224, 226, 233, 252, 255, 257, 578 ENTRY, 10, 37, 162, 173, 298, 303, 307, 331, 333, 335, 340, 526, 536, 552, 554 ENUM, 88 ENUMERATION TYPE, 91 ENUMERATOR, 88 EQUIVALENCE, 126, 126–129, 186, 300, 301, 536, 552, 554 ERROR STOP, 38, 39, 208, 546 EVENT POST, 210, 216, 216, 220, 386, 451, 452, 540, 543, 547 EVENT WAIT, 210, 216, 216, 219, 451, 452, 540, 543, 547 executable, 18, 18, 36 EXIT, 184, 194, 207 EXTERNAL, 108, 312 FAIL IMAGE, 209 file inquiry, 259 file positioning, 223, 256 FINAL, 11, 81 FLUSH, 224, 255, 258, 267

ISO/IEC JTC 1/SC 22/WG5/N2184

657

J3/21-007r1

WD 1539-1

FORALL, 57, 155, 181, 527, 528, 539 FORM TEAM, 20, 37, 188, 210, 216, 220, 540, 543, 544, 547 FORMAT, 26, 37, 49, 239, 269, 269, 298 formatted input/output, 222, 239 FUNCTION, 10, 57, 58, 121, 162, 166, 297, 331, 332, 335, 336, 526 GENERIC, 79, 80, 308, 308, 311, 329 GO TO, 5, 50, 207, 207 IF, 155, 199 IMPLICIT, 37, 121, 126, 301 IMPLICIT NONE, 121 IMPORT, 37, 123, 524, 530 input/output, 222–268, 539 INQUIRE, 30, 224, 225, 227, 228, 230, 231, 241, 251, 252, 255, 259, 267, 268, 453, 539, 541– 543, 548, 578 INTENT, 119, 186 INTERFACE, 306, 588 INTRINSIC, 301, 314 intrinsic assignment, 29, 86, 140, 146, 148, 165, 169, 174, 175, 195, 220, 228, 259, 268, 294, 339, 348, 355, 539, 546 list-directed input/output, 239 LOCK, 210, 217, 220, 453–456, 540, 544 MODULE, 297, 298 NAMELIST, 126, 186, 292, 300 namelist input/output, 239 nonexecutable, 18, 36 NOTIFY WAIT, 140, 209, 211, 454, 541, 546 NULLIFY, 145 OPEN, 31, 223, 224, 228–230, 231, 231, 235, 240, 248, 252, 262, 265, 281, 294, 540, 543, 547, 548, 578–581 OPTIONAL, 119, 186 PARAMETER, 37, 119, 121, 301 PAUSE, 551 POINTER, 119, 301 pointer assignment, 15, 20, 55, 75, 87, 165, 174, 176, 181, 182, 353, 361 PRINT, 224, 233, 237, 246, 251, 252, 255 PRIVATE, 78, 79, 80, 114, 300 PROCEDURE, 306, 308, 558 procedure declaration, 37, 108, 305, 307, 312, 337, 353, 526, 558 PROGRAM, 297

658

2021-05-21

PROTECTED, 120 PUBLIC, 114, 300 READ, 31, 41, 225, 229, 233, 237, 246, 251, 252, 255, 258, 266, 542, 578–580, 582, 583 RETURN, 38, 83, 111, 112, 129, 146, 147, 187, 189, 194, 336, 497, 542 REWIND, 223, 224, 226, 252, 255, 257, 258, 578 SAVE, 120, 186, 301, 526 SELECT CASE, 50, 199 SELECT RANK, 43, 108, 202, 531 SELECT TYPE, 43, 50, 204, 531 separate module subprogram, 335 SEQUENCE, 68 statement function, 10, 37, 64, 186, 298, 329, 336, 337, 527, 528, 553 STOP, 38, 39, 208, 210, 340, 546 SUBMODULE, 297, 301 SUBROUTINE, 10, 173, 297, 331, 334, 336 SYNC ALL, 188, 210, 212, 213, 214, 220 SYNC IMAGES, 210, 213, 220, 221 SYNC MEMORY, 210, 214, 219, 220, 607 SYNC TEAM, 188, 210, 215, 220 TARGET, 120, 301 TYPE, 67, 70, 71, 100, 529 type declaration, 37, 56, 57, 76, 97, 97–99, 108, 121, 126, 129, 167, 298, 301, 302, 333, 335, 337, 538 type guard, 63, 64, 205 TYPE IS, 205, 431 type parameter definition, 70 type-bound procedure, 79, 80 unformatted input/output, 223, 239 UNLOCK, 210, 217, 220, 453–456, 540, 544 USE, 4, 17, 37, 70, 114, 298, 301, 329, 330, 525, 527, 529, 531, 585, 586, 592 VALUE, 120, 186 VOLATILE, 121, 186, 301, 527, 530 WAIT, 230, 241, 255, 255, 582 WHERE, 14, 155, 178 WRITE, 27, 29, 224, 229, 233, 237, 246, 251, 252, 255, 268, 539, 578, 581, 582 statement entity, 19, 195, 524, 525, 527 statement function, 337–338, 553 statement function statement, 10, 37, 64, 186, 298, 329, 336, 337, 527, 528, 553 statement keyword, 14, 44

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

statement label, 5, 19, 49, 49–52, 316, 524 statement order, 36 STATUS= specifier, 231–234, 235, 236, 236, 547, 548, 581 stmt-function-stmt (R1544), 33, 298, 301, 307, 337, 529 STOP statement, 38, 39, 208, 210, 340, 546 stop-code (R1164), 208, 208, 209 stop-stmt (R1162), 35, 83, 208 stopped image, 12, 38, 143, 147, 148, 347, 348, 416 STOPPED_IMAGES, 440 storage association, 4, 4, 43, 44, 126–130, 336, 339, 440, 534–537 storage sequence, 19, 66, 68, 127–130, 302, 361, 496– 498, 514, 535, 535, 536 storage unit, 19, 19, 126–130, 240, 245, 252, 255, 302, 324, 361, 535–537 character, 19, 19, 107, 127, 129, 450, 535, 539, 541 file, 11, 19, 222, 225–228, 235, 240, 241, 247, 257, 263–265, 452, 535 numeric, 19, 19, 129, 455, 535, 539, 541 unspecified, 19, 19, 535, 539, 541 STORAGE_SIZE, 93, 440 stream access, 225 stream access data transfer statement, 241 stream file, 11, 19, 222, 225, 227, 266 STREAM= specifier, 260, 265 stride (R924), 136, 136, 137, 139, 245 structure, 7, 19, 40, 66 structure component, 19, 117, 132, 133, 135, 502, 566 structure constructor, 7, 14, 19, 40, 44, 54, 77, 86, 87, 117, 118, 164, 166, 167, 420, 453, 526, 561 structure-component (R913), 116, 117, 131, 132, 133, 139, 141, 145 structure-constructor (R756), 19, 86, 86, 117, 149, 150, 339 subcomponent, 7, 8, 76, 86, 175, 532–534, 538, 540, 542 submodule, 14, 16, 19, 19, 20, 35, 36, 41, 124, 301, 529 submodule (R1416), 32, 301 submodule identifier, 301 SUBMODULE statement, 297, 301 submodule-name, 301 submodule-stmt (R1417), 32, 301, 301 subobject, 3, 7, 8, 19, 40–42, 108, 133, 319, 532, 533 subprogram, 14, 19, 35, 37, 38, 41, 121 elemental, 11, 331, 332, 341 external, 16, 20, 35, 303

J3/21-007r1

internal, 20, 35, 37, 124, 303, 529 module, 20, 35, 37, 124, 529 subroutine, 20 atomic, 20, 38, 211, 212, 343, 346–348, 364–368, 386, 450, 455, 543 collective, 20, 343, 347, 348, 373–376, 389, 440, 455, 543 subroutine reference, 328 SUBROUTINE statement, 10, 173, 297, 331, 334, 336 subroutine-name, 307, 334, 526 subroutine-stmt (R1535), 32, 306, 307, 331, 332, 334, 334, 526, 529 subroutine-subprogram (R1534), 19, 32, 33, 298, 334, 335 subroutines intrinsic, 343 subscript, 135 section, 138 subscript (R919), 117, 133, 135, 135–137, 139, 245 subscript triplet, 138 subscript-triplet (R922), 136, 136, 139 substring, 132 substring (R908), 126, 127, 131, 132 substring ending point., 132 substring starting point, 132 substring-range (R910), 103, 132, 132, 134–136, 139, 245 suffix (R1532), 333, 333, 335 SUM, 441 SYNC ALL statement, 188, 210, 212, 213, 214, 220 SYNC IMAGES statement, 210, 213, 220, 221 SYNC MEMORY statement, 210, 214, 219, 220, 607 SYNC TEAM statement, 188, 210, 215, 220 sync-all-stmt (R1168), 35, 212 sync-images-stmt (R1170), 35, 213 sync-memory-stmt (R1172), 35, 214 sync-stat (R1169), 187, 189, 212, 212–220 sync-team-stmt (R1173), 35, 215 synchronous input/output, 233, 240, 242, 244 SYSTEM_CLOCK, 27–29, 441

T T edit descriptor, 285 TAN, 442 TAND, 442 TANH, 443 TANPI, 443

ISO/IEC JTC 1/SC 22/WG5/N2184

659

J3/21-007r1

WD 1539-1

target, 10, 20, 41, 43, 58, 75–77, 82, 87, 99, 102, 103, 106, 108, 109, 111, 112, 118, 131, 133, 141, 144, 145, 147, 164, 165, 170, 174–176, 181, 182, 242, 243, 247, 248, 313, 316, 318, 320, 322, 324, 496, 498, 499, 531–534, 537, 540, 542, 544 TARGET attribute, 4, 20, 28, 76, 111, 113, 113, 120, 127, 129, 145, 146, 175, 185, 195, 203, 305, 311, 319, 320, 322, 326, 327, 375, 416, 428, 496, 498, 499, 520, 532–534, 542, 558, 599, 600 TARGET statement, 120, 301 target-decl (R864), 120, 120 target-stmt (R863), 34, 120, 529 team, 12, 20, 20, 37, 42, 43, 140, 147, 188, 212, 213, 215, 217, 220, 343, 347, 399, 421, 440, 444 current, 347 team number, 20, 140, 217 team variable, 23, 188, 456, 540, 541, 543 team-construct-name, 187 team-number (R1180), 216, 217, 217 team-value (R1115), 140, 187, 187, 188, 215 team-variable (R1181), 216, 217, 217, 219, 544 TEAM= specifier, 140, 140 TEAM_NUMBER, 168, 443 TEAM_NUMBER= specifier, 140, 140 TEAM_TYPE, 23, 72, 101, 133, 142, 143, 172, 187, 217, 388, 393, 394, 399, 421, 440, 443, 444, 456, 543 THEN, 198 THIS_IMAGE, 168, 444 TINY, 438, 444 TKR compatible, 311 TL edit descriptor, 285 TOKENIZE, 445 totally associated, 536 TR edit descriptor, 285 TRAILZ, 446 TRANSFER, 168, 446 transfer of control, 183, 207, 266, 267 transformational function, 20, 168, 337, 343, 343, 344, 348, 369, 370, 451, 464 TRANSPOSE, 447 TRIM, 447 truncation, 345, 400, 428 TYPE, 56 type, 21, 39, 54–95 abstract, 21, 56, 80, 83, 83, 86, 133, 141

660

2021-05-21

character, 62–66 complex, 62 declared, 21, 57, 58, 75, 86, 87, 94, 97, 133, 134, 142, 143, 145, 162, 164, 169, 172, 173, 175, 176, 184, 203, 205, 206, 254, 310, 315, 318, 321, 331, 338, 388, 412, 416, 430, 431, 452, 453, 528 derived, 9, 19, 21, 39, 40, 44, 54, 66–88, 94, 502, 503 dynamic, 15, 21, 22, 57, 58, 81, 83, 85, 87, 94, 113, 143, 145, 147, 162, 164, 170, 172, 173, 175, 176, 185, 204, 205, 211, 214, 254, 315, 321, 330, 331, 388, 412, 416, 430, 431, 440, 528, 532, 537, 567, 616 expression, 164 extended, 4, 7, 12, 21, 21, 71, 77, 78, 81–84, 537, 559, 564 extensible, 21, 56, 67, 75, 83, 249, 388, 430, 431, 567, 604 extension, 21, 58, 83, 84, 205, 321, 388, 604 integer, 59–60 intrinsic, 7, 21, 39, 40, 54, 58–66 logical, 66 numeric, 21, 58–62, 156–158, 160, 164, 171, 382, 408, 409, 424, 441 operation, 165 parent, 7, 21, 67, 71, 78, 81–84, 311, 567 primary, 164 real, 60–61, 61 type compatible, 21, 58, 75, 141, 142, 169, 174, 311, 319, 416 type conformance, 169 type declaration statement, 37, 56, 57, 76, 97, 97–99, 108, 121, 126, 129, 167, 298, 301, 302, 333, 335, 337, 538 type equality, 69 type guard statement, 63, 64, 205 TYPE IS statement, 205, 431 type parameter, 3, 5, 12, 14, 21, 29, 39, 55–58, 66, 68, 71, 75, 86, 94, 97–99, 119, 129, 164, 167, 169, 185, 187, 203, 211, 304, 319, 341, 412, 416, 446, 497, 502, 526, 528 type parameter definition statement, 70 type parameter inquiry, 22, 134, 164, 166 type parameter keyword, 14, 44, 85 type parameter order, 22, 71

ISO/IEC JTC 1/SC 22/WG5/N2184

2021-05-21

WD 1539-1

type specifier, 56 CHARACTER, 63 CLASS, 57 COMPLEX, 62 derived type, 57 DOUBLE PRECISION, 61 INTEGER, 59 LOGICAL, 66 REAL, 61 TYPE, 57 TYPE statement, 67, 70, 71, 100, 529 type-attr-spec (R728), 67, 67, 83 type-bound procedure, 5, 12, 15, 16, 66–68, 75, 80, 80, 81, 83, 84, 172, 173, 254, 299, 309, 315, 317, 319, 330, 338, 340, 341, 525, 526 type-bound procedure statement, 79, 80 type-bound-generic-stmt (R751), 79, 79, 309 type-bound-proc-binding (R748), 79, 79 type-bound-proc-decl (R750), 79, 79 type-bound-procedure-part (R746), 67, 68, 79, 80, 502 type-bound-procedure-stmt (R749), 79, 79 type-declaration-stmt (R801), 33, 63, 64, 97, 97, 338, 529 type-guard-stmt (R1156), 204, 205, 205 type-name, 67, 68, 70, 79, 85 type-param-attr-spec (R734), 70, 71, 71 type-param-decl (R733), 70, 70, 71 type-param-def-stmt (R732), 67, 70, 70 type-param-inquiry (R916), 22, 134, 135, 149, 150, 526 type-param-name, 67, 70, 71, 73, 134, 149, 150, 526, 529 type-param-name-list, 71 type-param-spec (R755), 14, 44, 85, 85 type-param-value (R701), 22, 55, 55, 56, 63, 64, 73, 85, 86, 98, 141, 143, 332, 554 type-spec (R702), 56, 56, 57, 63, 64, 93, 94, 141–144, 205 TYPEOF, 56

U UBOUND, 57, 203, 447 UCOBOUND, 448 ultimate argument, 22, 143, 147, 176, 318, 323, 324, 326, 347 ultimate component, 7, 28, 29, 66, 67, 72, 101–103, 106, 108, 113, 114, 127, 128, 142, 143, 145, 168, 170, 248, 319, 320, 338, 535 ultimate entity, 300

J3/21-007r1

undefined, 10, 22, 41, 146, 532, 533, 538, 539 undefinition of variables, 538 underflow mode, 461, 462, 464, 469, 483, 490, 550 underscore (R602), 46, 46 UNFORMATTED, 249, 250, 306 unformatted data transfer, 247 unformatted input/output statement, 223, 239 unformatted record, 222 UNFORMATTED= specifier, 260, 265 Unicode file, 233 unit, 7, 15, 22, 223–225, 228, 228–231, 233–236, 241, 244–247, 250, 251, 255–265, 267, 268, 284, 291, 451, 452, 539, 541, 578–583 UNIT= specifier, 231, 236, 237, 255, 256, 258, 259 unlimited polymorphic, 22, 57, 57, 58, 94, 128, 141, 174, 205, 321, 388, 430, 431, 440, 616 unlimited-format-item (R1305), 269, 270, 270, 273 UNLOCK statement, 210, 217, 220, 453–456, 540, 544 unlock-stmt (R1185), 35, 218 unordered segments, 211, 211, 212, 346, 353, 386 UNPACK, 449 unsaved, 22, 145, 146, 334, 533, 534, 540–542 unspecified storage unit, 19, 19, 535, 539, 541 until-spec (R1178), 216, 216 UNTIL_COUNT= specifier, 216, 386 upper-bound (R818), 105, 105 upper-bound-expr (R938), 141, 141, 175 upper-bounds-expr (R939), 141, 141–143, 174, 176 upper-cobound (R813), 102, 103, 103 use association, 4, 4, 15, 28, 36, 44, 57, 64, 83, 100, 101, 111, 114, 115, 121, 126–128, 166, 167, 175, 298, 297–301, 307, 335, 339, 340, 526–529, 532 use path, 300 USE statement, 4, 17, 37, 70, 114, 298, 301, 329, 330, 525, 527, 529, 531, 585, 586, 592 use-defined-operator (R1415), 299, 299, 300 use-name, 299, 300, 525 use-stmt (R1409), 33, 186, 299, 299, 529

V v (R1312), 251, 271, 271, 284 VALUE attribute, 57, 75, 81, 108, 113, 113, 120, 195, 245, 304, 305, 307, 309, 310, 318–322, 332, 338, 341, 375, 428, 505, 506, 523, 534, 558, 611, 613 value separator, 288 VALUE statement, 120, 186 value-stmt (R865), 34, 120

ISO/IEC JTC 1/SC 22/WG5/N2184

661

J3/21-007r1

WD 1539-1

variable, 8, 19, 23, 40, 41, 44, 47, 110 definition & undefinition, 538 variable (R902), 86, 93, 116, 117, 131, 131, 139, 169– 172, 174, 175, 179, 181, 184, 195, 196, 204, 209, 216–218, 242, 315, 325, 491, 543 variable-name (R903), 126, 128, 131, 131, 132, 141, 145, 174, 191, 529, 543 vector subscript, 23, 42, 76, 103, 133, 138, 139, 184, 204, 228, 229, 292, 319, 320, 326, 531, 534, 599 vector-subscript (R925), 136, 136, 137 VERIFY, 449 VOLATILE attribute, 28, 29, 113, 113, 114, 121, 174, 176, 185, 191, 195, 298, 300, 304, 305, 320–322, 338, 529, 530, 534, 540, 543, 565 VOLATILE statement, 121, 186, 301, 527, 530 volatile-stmt (R866), 34, 121

W w (R1308), 270, 271, 271, 275–284, 289, 291, 294 wait operation, 231, 235, 242, 244, 245, 255, 255–258, 263, 266, 267 WAIT statement, 230, 241, 255, 255, 582 wait-spec (R1223), 255, 256, 256 wait-stmt (R1222), 35, 255, 339 WHERE construct, 14, 178

662

2021-05-21

WHERE statement, 14, 155, 178 where-assignment-stmt (R1045), 155, 178, 178–181 where-body-construct (R1044), 178, 178, 179 where-construct (R1042), 34, 178, 178, 180, 181 where-construct-name, 178 where-construct-stmt (R1043), 5, 178, 178, 179, 181, 207 where-stmt (R1041), 35, 178, 178, 180, 181 WHILE, 190, 193 whole array, 23, 135, 135, 136, 403, 448 WRITE (FORMATTED), 249, 306 WRITE (UNFORMATTED), 249, 250, 306 WRITE statement, 27, 29, 224, 229, 233, 237, 246, 251, 252, 255, 268, 539, 578, 581, 582 write-stmt (R1211), 35, 237, 238, 339, 543 WRITE= specifier, 260, 265

X X edit descriptor, 285 xyz, 25 xyz-list (R401), 25 xyz-name (R402), 25

Z Z edit descriptor, 281 zero-size array, 42, 105, 117

ISO/IEC JTC 1/SC 22/WG5/N2184

Related documents

Record · ID 601223 · SHA-256 f952cbc394c632c0
Conceptio Open Knowledge Archive — every document is proof-bundled with source, license, and retrieval metadata.