WORKING DRAFT J3/07-007 5th January 2007 18:42 This is an internal working document of J3. 2006/01/05 WORKING DRAFT J3/07-007 Contents 1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.3 Inclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.4 Exclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.5 Conformance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.6 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.6.1 New intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.6.2 New intrinsic data type and operator . . . . . . . . . . . . . . . . . . . . . . . . 3 1.6.3 Fortran 2003 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.6.4 Fortran 95 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.6.5 Fortran 90 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.6.6 FORTRAN 77 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.7 Notation used in this part of ISO/IEC 1539 . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.7.1 Applicability of requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.7.2 Informative notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.7.3 Syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.7.4 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.7.5 Assumed syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.7.6 Syntax conventions and characteristics . . . . . . . . . . . . . . . . . . . . . . . 7 1.7.7 Text conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.8 Deleted and obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.8.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.8.2 Nature of deleted features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.8.3 Nature of obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 1.9 Normative references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2 Fortran terms and concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.1 High level syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2 Program unit concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.1 Program units and scoping units . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.2 Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.3 Main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.2.4 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.2.5 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2.6 Submodule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3 Execution concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.1 Statement classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.2 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.3 Executable/nonexecutable statements . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3.4 Statement order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3.5 The END statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.3.6 Execution sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.4 Data concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.4.1 Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.4.2 Data value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.4.3 Data entity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 i J3/07-007 WORKING DRAFT 2006/01/05 2.4.4 Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.4.5 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.4.6 Co-array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.4.7 Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.4.8 Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5 Fundamental terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.1 Name and designator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.2 Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.3 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.4 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.5 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.6 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.7 Intrinsic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.8 Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.9 Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.10 Companion processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3 Lexical tokens, source form, and macro processing . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1 Processor character set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.1 Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.2 Digits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.3 Underscore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.4 Special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.1.5 Other characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2 Low-level syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2.1 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.4 Statement labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.2.5 Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.3 Source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.3.1 Free source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 3.3.2 Fixed source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.4 Including source text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.5 Macro processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.5.1 Macro definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.5.2 Macro expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.1 The concept of type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.1.1 Set of values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.1.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.1.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.2 Type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.3 Relationship of types and values to objects . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.3.1 Type specifiers and type compatibility . . . . . . . . . . . . . . . . . . . . . . . 45 4.4 Intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.4.1 Classification and specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.4.2 Integer type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.4.3 Real type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 4.4.4 Complex type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 4.4.5 Character type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.4.6 Logical type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 4.4.7 Bits type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 ii 2006/01/05 WORKING DRAFT J3/07-007 4.5 Derived types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.5.1 Derived type concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.5.2 Derived-type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 4.5.3 Derived-type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4.5.4 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 4.5.5 Type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 4.5.6 Final subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.5.7 Type extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.5.8 Derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 4.5.9 Derived-type specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 4.5.10 Construction of derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . 77 4.5.11 Derived-type operations and assignment . . . . . . . . . . . . . . . . . . . . . . 80 4.6 Enumerations and enumerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 4.7 Construction of array values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 5 Attribute declarations and specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.2 Type declaration statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.2.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.2.2 Automatic data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 5.2.3 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.2.4 Examples of type declaration statements . . . . . . . . . . . . . . . . . . . . . . 87 5.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.3.1 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.3.2 Accessibility attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.3.3 ALLOCATABLE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.3.4 ASYNCHRONOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.3.5 BIND attribute for data entities . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 5.3.6 CONTIGUOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 5.3.7 DIMENSION attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 5.3.8 EXTERNAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.9 INTENT attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.10 INTRINSIC attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.3.11 OPTIONAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.3.12 PARAMETER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3.13 POINTER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3.14 PROTECTED attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3.15 SAVE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.3.16 TARGET attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.3.17 VALUE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.3.18 VOLATILE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4 Attribute specification statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.4.1 Accessibility statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.4.2 ALLOCATABLE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.4.3 ASYNCHRONOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.4.4 BIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.4.5 CONTIGUOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.4.6 DATA statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 5.4.7 DIMENSION statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5.4.8 INTENT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5.4.9 OPTIONAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.4.10 PARAMETER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.4.11 POINTER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 5.4.12 PROTECTED statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 iii J3/07-007 WORKING DRAFT 2006/01/05 5.4.13 SAVE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.4.14 TARGET statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.4.15 VALUE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.4.16 VOLATILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.5 IMPLICIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 5.6 NAMELIST statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5.7 Storage association of data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5.7.1 EQUIVALENCE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5.7.2 COMMON statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5.7.3 Restrictions on common and equivalence . . . . . . . . . . . . . . . . . . . . . . 115 6 Use of data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 6.1 Scalars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 6.1.1 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 6.1.2 Structure components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 6.1.3 Complex parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.1.4 Type parameter inquiry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 6.2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 6.2.1 Whole arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 6.2.2 Array elements and array sections . . . . . . . . . . . . . . . . . . . . . . . . . . 122 6.2.3 Image selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6.3 Dynamic association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6.3.1 ALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 6.3.2 NULLIFY statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 6.3.3 DEALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 6.3.4 STAT= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 6.3.5 ERRMSG= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 7 Expressions and assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1.2 Form of an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1.3 Precedence of operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 7.1.4 Evaluation of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 7.1.5 Intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 7.1.6 Defined operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 7.1.7 Evaluation of operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 7.1.8 Integrity of parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 7.1.9 Type, type parameters, and shape of an expression . . . . . . . . . . . . . . . . 152 7.1.10 Conformability rules for elemental operations . . . . . . . . . . . . . . . . . . . 154 7.1.11 Specification expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 7.1.12 Initialization expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 7.2 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 7.2.1 Assignment statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 7.2.2 Pointer assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 7.2.3 Masked array assignment ­ WHERE . . . . . . . . . . . . . . . . . . . . . . . . 166 7.2.4 FORALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 8 Execution control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 8.1 Executable constructs containing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 8.1.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 8.1.2 Rules governing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 8.1.3 ASSOCIATE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 8.1.4 BLOCK construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 iv 2006/01/05 WORKING DRAFT J3/07-007 8.1.5 CASE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 8.1.6 CRITICAL construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 8.1.7 DO construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 8.1.8 IF construct and statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 8.1.9 SELECT TYPE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 8.1.10 EXIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 8.2 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 8.2.1 GO TO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 8.2.2 Computed GO TO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 8.2.3 Arithmetic IF statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 8.3 CONTINUE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 8.4 STOP statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 8.5 Image execution control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 8.5.1 Image control statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 8.5.2 SYNC ALL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 8.5.3 SYNC TEAM statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 8.5.4 SYNC IMAGES statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 8.5.5 NOTIFY and QUERY statements . . . . . . . . . . . . . . . . . . . . . . . . . . 203 8.5.6 SYNC MEMORY statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 8.5.7 STAT= and ERRMSG= specifiers in image execution control statements . . . . 206 9 Input/output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 9.1 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 9.1.1 Formatted record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 9.1.2 Unformatted record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 9.1.3 Endfile record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 9.2 External files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 9.2.1 File existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 9.2.2 File access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 9.2.3 File position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 9.2.4 File storage units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 9.3 Internal files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 9.4 File connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 9.4.1 Connection modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 9.4.2 Unit existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 9.4.3 Connection of a file to a unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 9.4.4 Preconnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 9.4.5 OPEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 9.4.6 CLOSE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 9.5 Data transfer statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 9.5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 9.5.2 Control information list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 9.5.3 Data transfer input/output list . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 9.5.4 Execution of a data transfer input/output statement . . . . . . . . . . . . . . . 231 9.5.5 Termination of data transfer statements . . . . . . . . . . . . . . . . . . . . . . 243 9.6 Waiting on pending data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 9.6.1 Wait operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 9.6.2 WAIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.7 File positioning statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.7.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.7.2 BACKSPACE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 9.7.3 ENDFILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 9.7.4 REWIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 9.8 FLUSH statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 v J3/07-007 WORKING DRAFT 2006/01/05 9.9 File inquiry statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 9.9.1 Forms of the INQUIRE statement . . . . . . . . . . . . . . . . . . . . . . . . . . 247 9.9.2 Inquiry specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 9.9.3 Inquire by output list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 9.10 Error, end-of-record, and end-of-file conditions . . . . . . . . . . . . . . . . . . . . . . . . 254 9.10.1 Error conditions and the ERR= specifier . . . . . . . . . . . . . . . . . . . . . . 255 9.10.2 End-of-file condition and the END= specifier . . . . . . . . . . . . . . . . . . . . 255 9.10.3 End-of-record condition and the EOR= specifier . . . . . . . . . . . . . . . . . . 255 9.10.4 IOSTAT= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 9.10.5 IOMSG= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 9.11 Restrictions on input/output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10 Input/output editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 10.1 Format specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 10.2 Explicit format specification methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 10.2.1 FORMAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 10.2.2 Character format specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 10.3 Form of a format item list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 10.3.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 10.3.2 Edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 10.3.3 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 10.4 Interaction between input/output list and format . . . . . . . . . . . . . . . . . . . . . . 262 10.5 Positioning by format control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 10.6 Decimal symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 10.7 Data edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 10.7.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 10.7.2 Numeric and bits editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 10.7.3 Logical editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 10.7.4 Character editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 10.7.5 Generalized editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 10.7.6 User-defined derived-type editing . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8 Control edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8.1 Position editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 10.8.2 Slash editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.8.3 Colon editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.8.4 SS, SP, and S editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.8.5 P editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.8.6 BN and BZ editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 10.8.7 RU, RD, RZ, RN, RC, and RP editing . . . . . . . . . . . . . . . . . . . . . . . 277 10.8.8 DC and DP editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 10.9 Character string edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.10 List-directed formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.10.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.10.2 Values and value separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.10.3 List-directed input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 10.10.4 List-directed output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 10.11 Namelist formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 10.11.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 10.11.2 Name-value subsequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 10.11.3 Namelist input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 10.11.4 Namelist output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 11 Program units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 11.1 Main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 vi 2006/01/05 WORKING DRAFT J3/07-007 11.2 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 11.2.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 11.2.2 The USE statement and use association . . . . . . . . . . . . . . . . . . . . . . . 291 11.2.3 Submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 11.3 Block data program units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 12 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.2 Procedure classifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.2.1 Procedure classification by reference . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.2.2 Procedure classification by means of definition . . . . . . . . . . . . . . . . . . . 297 12.3 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 12.3.1 Characteristics of procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 12.3.2 Characteristics of dummy arguments . . . . . . . . . . . . . . . . . . . . . . . . 298 12.3.3 Characteristics of function results . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4 Procedure interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4.2 Implicit and explicit interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4.3 Specification of the procedure interface . . . . . . . . . . . . . . . . . . . . . . . 300 12.5 Procedure reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 12.5.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 12.5.2 Actual arguments, dummy arguments, and argument association . . . . . . . . . 313 12.5.3 Function reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 12.5.4 Subroutine reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 12.5.5 Resolving named procedure references . . . . . . . . . . . . . . . . . . . . . . . . 326 12.5.6 Resolving type-bound procedure references . . . . . . . . . . . . . . . . . . . . . 328 12.6 Procedure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 12.6.1 Intrinsic procedure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328 12.6.2 Procedures defined by subprograms . . . . . . . . . . . . . . . . . . . . . . . . . 329 12.6.3 Definition and invocation of procedures by means other than Fortran . . . . . . 336 12.6.4 Statement function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 12.7 Pure procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 12.8 Elemental procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 12.8.1 Elemental procedure declaration and interface . . . . . . . . . . . . . . . . . . . 339 12.8.2 Elemental function actual arguments and results . . . . . . . . . . . . . . . . . . 339 12.8.3 Elemental subroutine actual arguments . . . . . . . . . . . . . . . . . . . . . . . 340 13 Intrinsic procedures and modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.1 Classes of intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.2 Arguments to intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.2.1 General rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.2.2 The shape of array arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.2.3 Mask arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.2.4 Arguments to collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.3 Bit model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.4 Numeric models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.5 Standard generic intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13.5.1 Numeric functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13.5.2 Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.3 Character functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.4 Kind functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.5 Miscellaneous type conversion functions . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.6 Numeric inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.7 Array inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 vii J3/07-007 WORKING DRAFT 2006/01/05 13.5.8 Other inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.9 Bit manipulation procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.10 Floating-point manipulation functions . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.11 Vector and matrix multiply functions . . . . . . . . . . . . . . . . . . . . . . . . 348 13.5.12 Array reduction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.5.13 Array construction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.5.14 Array location functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.5.15 Collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 13.5.16 Null function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 13.5.17 Allocation transfer procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 13.5.18 Random number subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 13.5.19 System environment procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 13.6 Specific names for standard intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . 350 13.7 Specifications of the standard intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . 351 13.8 Standard intrinsic modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 13.8.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 13.8.2 The ISO FORTRAN ENV intrinsic module . . . . . . . . . . . . . . . . . . . . 435 14 Exceptions and IEEE arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 14.1 Derived types and constants defined in the modules . . . . . . . . . . . . . . . . . . . . . 440 14.2 The exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 14.3 The rounding modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 14.4 Underflow mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 14.5 Halting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 14.6 The floating-point status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 14.7 Exceptional values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444 14.8 IEEE arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 14.9 Tables of the procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 14.9.1 Inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 14.9.2 Elemental functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 14.9.3 Kind function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 14.9.4 Elemental subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 14.9.5 Nonelemental subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 14.10 Specifications of the procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 14.11 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 15 Interoperability with C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 15.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 15.2 The ISO C BINDING intrinsic module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 15.2.1 Summary of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 15.2.2 Named constants and derived types in the module . . . . . . . . . . . . . . . . . 467 15.2.3 Procedures in the module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 15.3 Interoperability between Fortran and C entities . . . . . . . . . . . . . . . . . . . . . . . 472 15.3.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 15.3.2 Interoperability of intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . 472 15.3.3 Interoperability with C pointer types . . . . . . . . . . . . . . . . . . . . . . . . 474 15.3.4 Interoperability of derived types and C struct types . . . . . . . . . . . . . . . . 475 15.3.5 Interoperability of scalar variables . . . . . . . . . . . . . . . . . . . . . . . . . . 476 15.3.6 Interoperability of array variables . . . . . . . . . . . . . . . . . . . . . . . . . . 476 15.3.7 Interoperability of procedures and procedure interfaces . . . . . . . . . . . . . . 477 15.4 Interoperation with C global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 15.4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 15.4.2 Binding labels for common blocks and variables . . . . . . . . . . . . . . . . . . 480 15.5 Interoperation with C functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 viii 2006/01/05 WORKING DRAFT J3/07-007 15.5.1 Definition and reference of interoperable procedures . . . . . . . . . . . . . . . . 480 15.5.2 Binding labels for procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 15.5.3 Exceptions and IEEE arithmetic procedures . . . . . . . . . . . . . . . . . . . . 481 16 Scope, association, and definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 16.1 Identifiers and entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 16.2 Scope of global identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 16.3 Scope of local identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 16.3.1 Classes of local identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 16.3.2 Local identifiers that are the same as common block names . . . . . . . . . . . . 485 16.3.3 Function results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 16.3.4 Components, type parameters, and bindings . . . . . . . . . . . . . . . . . . . . 485 16.3.5 Argument keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486 16.4 Statement and construct entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486 16.5 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 16.5.1 Name association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 16.5.2 Pointer association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 16.5.3 Storage association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 16.5.4 Inheritance association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 16.5.5 Establishing associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 16.6 Definition and undefinition of variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 16.6.1 Definition of objects and subobjects . . . . . . . . . . . . . . . . . . . . . . . . . 497 16.6.2 Variables that are always defined . . . . . . . . . . . . . . . . . . . . . . . . . . 498 16.6.3 Variables that are initially defined . . . . . . . . . . . . . . . . . . . . . . . . . . 498 16.6.4 Variables that are initially undefined . . . . . . . . . . . . . . . . . . . . . . . . 498 16.6.5 Events that cause variables to become defined . . . . . . . . . . . . . . . . . . . 498 16.6.6 Events that cause variables to become undefined . . . . . . . . . . . . . . . . . . 501 16.6.7 Variable definition context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 16.6.8 Pointer association context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 Annex A (informative)Glossary of technical terms . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Annex B (informative)Decremental features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 B.1 Deleted features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 B.2 Obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 B.2.1 Alternate return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 B.2.2 Computed GO TO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 B.2.3 Statement functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 B.2.4 DATA statements among executables . . . . . . . . . . . . . . . . . . . . . . . . 521 B.2.5 Assumed character length functions . . . . . . . . . . . . . . . . . . . . . . . . . 521 B.2.6 Fixed form source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521 B.2.7 CHARACTER* form of CHARACTER declaration . . . . . . . . . . . . . . . . 521 Annex C (informative)Extended notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 C.1 Clause 4 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 C.1.1 Selection of the approximation methods (4.4.3) . . . . . . . . . . . . . . . . . . 523 C.1.2 Type extension and component accessibility (4.5.2.2, 4.5.4) . . . . . . . . . . . . 523 C.1.3 Abstract types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 C.1.4 Pointers (4.5.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 C.1.5 Structure constructors and generic names . . . . . . . . . . . . . . . . . . . . . . 526 C.1.6 Generic type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 C.1.7 Final subroutines (4.5.6, 4.5.6.2, 4.5.6.3, 4.5.6.4) . . . . . . . . . . . . . . . . . . 529 C.2 Clause 5 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531 C.2.1 The POINTER attribute (5.3.13) . . . . . . . . . . . . . . . . . . . . . . . . . . 531 C.2.2 The TARGET attribute (5.3.16) . . . . . . . . . . . . . . . . . . . . . . . . . . . 532 ix J3/07-007 WORKING DRAFT 2006/01/05 C.2.3 The VOLATILE attribute (5.3.18) . . . . . . . . . . . . . . . . . . . . . . . . . . 532 C.3 Clause 6 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533 C.3.1 Structure components (6.1.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533 C.3.2 Allocation with dynamic type (6.3.1) . . . . . . . . . . . . . . . . . . . . . . . . 535 C.3.3 Pointer allocation and association . . . . . . . . . . . . . . . . . . . . . . . . . . 535 C.4 Clause 7 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 C.4.1 Character assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 C.4.2 Evaluation of function references . . . . . . . . . . . . . . . . . . . . . . . . . . 536 C.4.3 Pointers in expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 C.4.4 Pointers on the left side of an assignment . . . . . . . . . . . . . . . . . . . . . . 537 C.4.5 An example of a FORALL construct containing a WHERE construct . . . . . . 537 C.4.6 Examples of FORALL statements . . . . . . . . . . . . . . . . . . . . . . . . . . 538 C.5 Clause 8 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 C.5.1 Loop control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 C.5.2 The CASE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 C.5.3 Examples of DO constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 C.5.4 Examples of invalid DO constructs . . . . . . . . . . . . . . . . . . . . . . . . . 542 C.6 Clause 9 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 C.6.1 External files (9.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 C.6.2 Nonadvancing input/output (9.2.3.1) . . . . . . . . . . . . . . . . . . . . . . . . 544 C.6.3 Asynchronous input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545 C.6.4 OPEN statement (9.4.5) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546 C.6.5 Connection properties (9.4.3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548 C.6.6 CLOSE statement (9.4.6) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548 C.7 Clause 10 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548 C.7.1 Number of records (10.4, 10.5, 10.8.2) . . . . . . . . . . . . . . . . . . . . . . . . 548 C.7.2 List-directed input (10.10.3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549 C.8 Clause 11 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550 C.8.1 Main program and block data program unit (11.1, 11.3) . . . . . . . . . . . . . 550 C.8.2 Dependent compilation (11.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550 C.8.3 Examples of the use of modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 552 C.8.4 Modules with submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558 C.9 Clause 12 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 C.9.1 Portability problems with external procedures (12.4.3.5) . . . . . . . . . . . . . 563 C.9.2 Procedures defined by means other than Fortran (12.6.3) . . . . . . . . . . . . . 563 C.9.3 Procedure interfaces (12.4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564 C.9.4 Abstract interfaces (12.4) and procedure pointer components (4.5) . . . . . . . . 564 C.9.5 Argument association and evaluation (12.5.2) . . . . . . . . . . . . . . . . . . . 566 C.9.6 Pointers and targets as arguments (12.5.2.5, 12.5.2.7, 12.5.2.8) . . . . . . . . . . 567 C.9.7 Polymorphic Argument Association (12.5.2.10) . . . . . . . . . . . . . . . . . . . 568 C.10 Clause 13 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570 C.10.1 Module for THIS IMAGE and IMAGE INDEX . . . . . . . . . . . . . . . . . . 570 C.10.2 Collective co-array subroutine variations . . . . . . . . . . . . . . . . . . . . . . 570 C.11 Clause 15 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 C.11.1 Runtime environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571 C.11.2 Examples of Interoperation between Fortran and C Functions . . . . . . . . . . 571 C.12 Clause 16 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 C.12.1 Examples of host association (16.5.1.4) . . . . . . . . . . . . . . . . . . . . . . . 577 C.12.2 Rules ensuring unambiguous generics (12.4.3.4.5) . . . . . . . . . . . . . . . . . 578 C.13 Array feature notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 C.13.1 Summary of features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 C.13.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583 C.13.3 FORmula TRANslation and array processing . . . . . . . . . . . . . . . . . . . 588 C.13.4 Sum of squared residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589 x 2006/01/05 WORKING DRAFT J3/07-007 C.13.5 Vector norms: infinity-norm and one-norm . . . . . . . . . . . . . . . . . . . . . 589 C.13.6 Matrix norms: infinity-norm and one-norm . . . . . . . . . . . . . . . . . . . . . 589 C.13.7 Logical queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589 C.13.8 Parallel computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590 C.13.9 Example of element-by-element computation . . . . . . . . . . . . . . . . . . . . 590 C.13.10 Bit manipulation and inquiry procedures . . . . . . . . . . . . . . . . . . . . . . 591 Annex D (informative)Processor Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 D.1 Unspecified Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 D.2 Processor Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 D.3 Unresolved Technical Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596 Annex E (informative)Syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 E.1 Extract of all syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 E.2 Syntax rule cross-reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644 Annex F (informative)Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659 xi J3/07-007 WORKING DRAFT 2006/01/05 xii 2006/01/05 WORKING DRAFT J3/07-007 List of Tables 2.1 Requirements on statement ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2 Statements allowed in scoping units . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.1 Special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.1 Subscript order value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 7.2 Categories of operations and relative precedence . . . . . . . . . . . . . . . . . . . 137 7.3 Type of operands and results for intrinsic operators . . . . . . . . . . . . . . . . . 141 7.4 Interpretation of the numeric intrinsic operators . . . . . . . . . . . . . . . . . . . 143 7.6 Interpretation of the character intrinsic operator // . . . . . . . . . . . . . . . . . 145 7.7 Interpretation of the logical intrinsic operators . . . . . . . . . . . . . . . . . . . . 146 7.8 The values of operations involving logical intrinsic operators . . . . . . . . . . . . 146 7.9 Interpretation of the bits intrinsic operators . . . . . . . . . . . . . . . . . . . . . . 147 7.10 The values of bits intrinsic operations other than // . . . . . . . . . . . . . . . . . 147 7.11 Interpretation of the relational intrinsic operators . . . . . . . . . . . . . . . . . . 148 7.12 Type conformance for the intrinsic assignment statement . . . . . . . . . . . . . . 158 7.13 Numeric conversion and the assignment statement . . . . . . . . . . . . . . . . . . 160 7.14 Bits conversion and the assignment statement . . . . . . . . . . . . . . . . . . . . . 161 10.1 E and D exponent forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 10.2 EN exponent forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 10.3 ES exponent forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 13.1 Characteristics of the result of NULL ( ) . . . . . . . . . . . . . . . . . . . . . . . . 412 15.1 Names of C characters with special semantics . . . . . . . . . . . . . . . . . . . . . 468 15.2 Interoperability between Fortran and C types . . . . . . . . . . . . . . . . . . . . . 472 xiii J3/07-007 WORKING DRAFT 2006/01/05 Foreword ISO (the International Organization for Standardization) and IEC (the International Electrotechni- cal Commission) 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 organi- zations, governmental and nongovernmental, 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. International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2. The main task of the joint technical committee is to prepare International Standards. Draft Interna- tional Standards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an International Standard requires approval by at least 75 % of the national bodies casting a vote. 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. ISO/IEC 1539-1 was prepared by Joint Technical Committee ISO/IEC/JTC1, Information technology, Subcommittee SC22, Programming languages, their environments and system software interfaces. This fifth edition cancels and replaces the fourth edition (ISO/IEC 1539-1:2004), which has been tech- nically revised. It also incorporates the Technical Corrigenda ISO/IEC 1539-1:2004/Cor. 1:2005 and ISO/IEC 15391:2004/Cor. 2:2006. ISO/IEC 1539 consists of the following parts, under the general title Information technology -- Pro- gramming languages -- Fortran: -- Part 1: Base language -- Part 2: Varying length character strings -- Part 3: Conditional Compilation xiv 2006/01/05 WORKING DRAFT J3/07-007 Introduction International Standard programming language Fortran This part of the International Standard comprises the specification of the base Fortran language, infor- mally known as Fortran 2008. With the limitations noted in 1.6.3, the syntax and semantics of Fortran 2003 are contained entirely within Fortran 2008. Therefore, any standard-conforming Fortran 2003 pro- gram not affected by such limitations is a standard-conforming Fortran 2008 program. New features of Fortran 2008 can be compatibly incorporated into such Fortran 2003 programs, with any exceptions indicated in the text of this part of ISO/IEC 1539. Fortran 2008 contains several extensions to Fortran 2003; some of these are listed below. (1) The maximum rank of an array has been increased from seven to fifteen. (2) Performance enhancements: The DO CONCURRENT construct, which allows loop itera- tions to be executed in any order or potentially concurrently. (3) Pointers can be initialized to point to a target. (4) Performance enhancements: CONTIGUOUS attribute. (5) The ATAN intrinsic is extended so that ATAN (Y, X) is ATAN2 (Y,X). (6) Allocatable components of recursive type. (7) The MOLD= specifier has been added to the ALLOCATE statement. (8) OPEN statement enhancements that allow the processor to select a unit number when opening an external unit. Such a unit number is guaranteed not to interfere with any program-managed unit numbers. (9) The BLOCK construct (allows declarations within executable statements). (10) A disassociated or deallocated actual argument can correspond to an optional nonpointer nonallocatable dummy argument. (11) The concept of variable now includes references to pointer functions which return associated pointers. (12) The COMPILER VERSION and COMPILER OPTIONS functions provide information about the translation phase of the execution of a program. (13) The real and imaginary parts of a COMPLEX variable can be selected using a component- like syntax. (14) Scoped macros which can generate whole Fortran statements and subprograms. (15) A FINDLOC intrinsic was added and a BACK= argument was also added to MAXLOC and MINLOC. (16) Parallel programming support: SPMD parallel programming, co-arrays for data exchange between images, image control statements, and collective procedures. (17) A BITS data type for non-numeric programming and enhanced handling of binary, octal, and hexadecimal constants. (18) The G0 edit descriptor. (19) Additional mathematical intrinsic functions for computing Bessel functions, error functions, the Gamma function, and generalized L2 norms. J3 internal note Unresolved Technical Issue 080 The laundry list needs to be redone at a later time. RAH suggests going down the list of things in spread sheet and having a big feature and a little feature list. xv J3/07-007 WORKING DRAFT 2006/01/05 Organization of this part of ISO/IEC 1539 This part of ISO/IEC 1539 is organized in 16 clauses, dealing with 8 conceptual areas. These 8 areas, and the clauses in which they are treated, are: High/low level concepts Clauses 1, 2, 3 Data concepts Clauses 4, 5, 6 Computations Clauses 7, 13, 14 Execution control Clause 8 Input/output Clauses 9, 10 Program units Clauses 11, 12 Interoperability with C Clause 15 Scoping and association rules Clause 16 It also contains the following nonnormative material: Glossary A Decremental features B Extended notes C Syntax rules D Index E xvi 2006/01/05 WORKING DRAFT J3/07-007 Information technology -- Programming languages -- 1 2Fortran -- 3Part 1: Base Language 4 51 Overview 1.1 Scope 6 7ISO/IEC 1539 is a multipart International Standard; the parts are published separately. This publi- 8cation, ISO/IEC 1539-1, which is the first part, specifies the form and establishes the interpretation 9of programs expressed in the base Fortran language. The purpose of this part of ISO/IEC 1539 is to 10promote portability, reliability, maintainability, and efficient execution of Fortran programs for use on 11a variety of computing systems. The second part, ISO/IEC 1539-2, defines additional facilities for the 12manipulation of character strings of variable length; this has been largely subsumed by allocatable char- 13acters with deferred length parameters. The third part, ISO/IEC 1539-3, defines a standard conditional 14compilation facility for Fortran. A processor conforming to part 1 need not conform to ISO/IEC 1539-2 or ISO/IEC 1539-3; however, conformance to either assumes conformance to this part. 15 161.2 Processor 17The combination of a computing system and the mechanism by which programs are transformed for use on that computing system is called a processor in this part of ISO/IEC 1539. 18 191.3 Inclusions This part of ISO/IEC 1539 specifies 20 (1) the forms that a program written in the Fortran language may take, 21 (2) the rules for interpreting the meaning of a program and its data, 22 (3) the form of the input data to be processed by such a program, and 23 (4) the form of the output data resulting from the use of such a program. 24 251.4 Exclusions This part of ISO/IEC 1539 does not specify 26 (1) the mechanism by which programs are transformed for use on computing systems, 27 (2) the operations required for setup and control of the use of programs on computing systems, 28 29 (3) the method of transcription of programs or their input or output data to or from a storage 30 medium, 31 (4) the program and processor behavior when this part of ISO/IEC 1539 fails to establish an 32 interpretation except for the processor detection and reporting requirements in items (2) to (8) of 1.5, 1 J3/07-007 WORKING DRAFT 2006/01/05 1 (5) the size or complexity of a program and its data that will exceed the capacity of any 2 particular computing system or the capability of a particular processor, (6) the mechanism for determining the number of images of a program, 3 4 (7) the physical properties of an image or the relationship between images and the computational 5 elements of a computing system, J3 internal note Unresolved Technical Issue 099 Image properties not specified by the standard. According to later notes, we don't specify this kind of stuff. I think it belongs in Exclusions. It definitely does not belong in a note! 6 (8) the physical properties of the representation of quantities and the method of rounding, 7 approximating, or computing numeric values on a particular processor, (9) the physical properties of input/output records, files, and units, or 8 (10) the physical properties and implementation of storage. 9 101.5 Conformance 11A program (2.2.2) is a standard-conforming program if it uses only those forms and relationships 12described herein and if the program has an interpretation according to this part of ISO/IEC 1539. A 13program unit (2.2.1) conforms to this part of ISO/IEC 1539 if it can be included in a program in a 14manner that allows the program to be standard conforming. A processor conforms to this part of ISO/IEC 1539 if: 15 16 (1) it executes any standard-conforming program in a manner that fulfills the interpretations 17 herein, subject to any limits that the processor may impose on the size and complexity of 18 the program; 19 (2) it contains the capability to detect and report the use within a submitted program unit of 20 a form designated herein as obsolescent, insofar as such use can be detected by reference to 21 the numbered syntax rules and constraints; 22 (3) it contains the capability to detect and report the use within a submitted program unit of 23 an additional form or relationship that is not permitted by the numbered syntax rules or 24 constraints, including the deleted features described in Annex B; 25 (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 (4.4); 26 27 (5) it contains the capability to detect and report the use within a submitted program unit of 28 source form or characters not permitted by Clause 3; 29 (6) it contains the capability to detect and report the use within a submitted program of name 30 usage not consistent with the scope rules for names, labels, operators, and assignment 31 symbols in Clause 16; 32 (7) it contains the capability to detect and report the use within a submitted program unit of 33 intrinsic procedures whose names are not defined in Clause 13; and (8) it contains the capability to detect and report the reason for rejecting a submitted program. 34 35However, in a format specification that is not part of a FORMAT statement (10.2.1), a processor need not 36detect or report the use of deleted or obsolescent features, or the use of additional forms or relationships. 37A standard-conforming processor may allow additional forms and relationships provided that such ad- 38ditions do not conflict with the standard forms and relationships. However, a standard-conforming 39processor may allow additional intrinsic procedures even though this could cause a conflict with the 2 2006/01/05 WORKING DRAFT J3/07-007 1name of a procedure in a standard-conforming program. If such a conflict occurs and involves the name 2of an external procedure, the processor is permitted to use the intrinsic procedure unless the name is 3given the EXTERNAL attribute (5.3.8) in the scoping unit (2.2.1). A standard-conforming program 4shall not use nonstandard intrinsic procedures or modules that have been added by the processor. 5Because a standard-conforming program may place demands on a processor that are not within the 6scope of this part of ISO/IEC 1539 or may include standard items that are not portable, such as 7external procedures defined by means other than Fortran, conformance to this part of ISO/IEC 1539 8does not ensure that a program will execute consistently on all or any standard-conforming processors. 9In some cases, the provision of facilities that are not completely specified in thisstandard is allowed. 10These facilities are identified as processor dependent. They shall be provided, with methods or 11semantics determined by the processor. NOTE 1.1 The processor should be accompanied by documentation that specifies the limits it imposes on the size and complexity 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. The processor should be accompanied by documentation that specifies the methods or semantics of processor-dependent facilities. 1.6 Compatibility 12 1.6.1 New intrinsic procedures 13 14Each Fortran International Standard since ISO 1539:1980 (informally referred to as Fortran 77), defines 15more intrinsic procedures than the previous one. Therefore, a Fortran program conforming to an older 16standard may have a different interpretation under a newer standard if it invokes an external procedure 17having the same name as one of the new standard intrinsic procedures, unless that procedure is specified 18to have the EXTERNAL attribute. 1.6.2 New intrinsic data type and operator 19 20This part of ISO/IEC 1539 specifies a new intrinsic type, BITS, which will conflict with a derived type 21of the same name. 22This part of ISO/IEC 1539 specifies a new intrinsic operator, .XOR., which might conflict with a user- 23defined operator of the same name, has a different precedence from that of a user-defined operator, and 24a different syntax from that of a user-defined unary operator. 1.6.3 Fortran 2003 compatibility 25 26Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension 27to the preceding Fortran International Standard, ISO/IEC 1539-1:2004 (Fortran 2003). Any standard- 28conforming Fortran 2003 program that does not use a derived type called BITS, and does not use a user-defined operator called .XOR., remains standard-conforming under this part of ISO/IEC 1539. 29 1.6.4 Fortran 95 compatibility 30 31Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension to 32ISO/IEC 1539-1:1997 (Fortran 95). Any standard-conforming Fortran 95 program that does not use a 3 J3/07-007 WORKING DRAFT 2006/01/05 1derived type called BITS or a user-defined operator called .XOR. remains standard-conforming under 2this part of ISO/IEC 1539. The following Fortran 95 features may have different interpretations in this part of ISO/IEC 1539. 3 4 (1) Earlier Fortran standards had the concept of printing, meaning that column one of formatted 5 output had special meaning for a processor-dependent (possibly empty) set of external 6 files. This could be neither detected nor specified by a standard-specified means. The interpretation of the first column is not specified by this part of ISO/IEC 1539. 7 8 (2) This part of ISO/IEC 1539 specifies a different output format for real zero values in list- 9 directed and namelist output. 10 (3) If the processor can distinguish between positive and negative real zero, this part of ISO/IEC 11 1539 requires different returned values for ATAN2(Y,X) when X < 0 and Y is negative real 12 zero and for LOG(X) and SQRT(X) when X is complex with REAL(X) < 0 and negative 13 zero imaginary part. 1.6.5 Fortran 90 compatibility 14 15Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this part 16of ISO/IEC 1539 is an upward compatible extension to ISO/IEC 1539:1991 (Fortran 90). Any standard- 17conforming Fortran 90 program that does not use a derived type called BITS, a user-defined operator 18called .XOR., or one of the deleted features remains standard-conforming under this part of ISO/IEC 191539. 20The PAD= specifier in the INQUIRE statement in this part of ISO/IEC 1539 returns the value UNDE- 21FINED if there is no connection or the connection is for unformatted input/output. Fortran 90 specified 22YES. 23Fortran 90 specified that if the second argument to MOD or MODULO was zero, the result was processor dependent. this part of ISO/IEC 1539 specifies that the second argument shall not be zero. 24 1.6.6 FORTRAN 77 compatibility 25 26Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this part 27of ISO/IEC 1539 is an upward compatible extension to ISO 1539:1980 (Fortran 77). Any standard- 28conforming Fortran 77 program that does not use one of the deleted features noted in Annex B.1 and 29that does not depend on the differences specified here remains standard-conforming under this part of 30ISO/IEC 1539. This part of ISO/IEC 1539 restricts the behavior for some features that were processor 31dependent in Fortran 77. Therefore, a standard-conforming Fortran 77 program that uses one of 32these processor-dependent features may have a different interpretation under this part of ISO/IEC 1539, 33yet remain a standard-conforming program. The following Fortran 77 features may have different interpretations in this part of ISO/IEC 1539. 34 35 (1) Fortran 77 permitted a processor to supply more precision derived from a real constant 36 than can be represented in a real datum when the constant is used to initialize a data object 37 of type double precision real in a DATA statement. This part of ISO/IEC 1539 does not 38 permit a processor this option. 39 (2) If a named variable that was not in a common block was initialized in a DATA statement and 40 did not have the SAVE attribute specified, Fortran 77 left its SAVE attribute processor 41 dependent. This part of ISO/IEC 1539 specifies (5.4.6) that this named variable has the 42 SAVE attribute. 43 (3) Fortran 77 specified that the number of characters required by the input list was to be 44 less than or equal to the number of characters in the record during formatted input. This 45 part of ISO/IEC 1539 specifies (9.5.4.4.2) that the input record is logically padded with 46 blanks if there are not enough characters in the record, unless the PAD= specifier with the 47 value 'NO' is specified in an appropriate OPEN or READ statement. 4 2006/01/05 WORKING DRAFT J3/07-007 1 (4) A value of 0 for a list item in a formatted output statement will be formatted in a different 2 form for some G edit descriptors. In addition, this part of ISO/IEC 1539 specifies how 3 rounding of values will affect the output field form, but Fortran 77 did not address this 4 issue. Therefore, some Fortran 77 processors may produce an output form different from 5 the output form produced by Fortran 2003 processors for certain combinations of values and 6 G edit descriptors. 7 (5) If the processor can distinguish between positive and negative real zero, the behavior of the 8 SIGN intrinsic function when the second argument is negative real zero is changed by this part of ISO/IEC 1539. 9 1.7 Notation used in this part of ISO/IEC 1539 10 1.7.1 Applicability of requirements 11 12In this part of ISO/IEC 1539, "shall" is to be interpreted as a requirement; conversely, "shall not" is 13to be interpreted as a prohibition. Except where stated otherwise, such requirements and prohibitions 14apply to programs rather than processors. 151.7.2 Informative notes 16Informative notes of explanation, rationale, examples, and other material are interspersed with the 17normative body of this part of ISO/IEC 1539. The informative material is nonnormative; it is identified 18by being in shaded, framed boxes that have numbered headings beginning with "NOTE." 1.7.3 Syntax rules 19 20Syntax rules describe the forms that Fortran lexical tokens, statements, and constructs may take. These syntax rules are expressed in a variation of Backus-Naur form (BNF) with the following conventions. 21 22 (1) Characters from the Fortran character set (3.1) are interpreted literally as shown, except 23 where otherwise noted. 24 (2) Lower-case italicized letters and words (often hyphenated and abbreviated) represent gen- 25 eral syntactic classes for which particular syntactic entities shall be substituted in actual 26 statements. 27 Common abbreviations used in syntactic terms are: arg for argument attr for attribute decl for declaration def for definition desc for descriptor expr for expression int for integer op for operator spec for specifier stmt for statement (3) The syntactic metasymbols used are: 28 is introduces a syntactic class definition or 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 29 (4) Each syntax rule is given a unique identifying number of the form Rsnn, where s is a 30 one- or two-digit clause number and nn is a two-digit sequence number within that clause. 5 J3/07-007 WORKING DRAFT 2006/01/05 1 The syntax rules are distributed as appropriate throughout the text, and are referenced by 2 number as needed. Some rules in Clauses 2 and 3 are more fully described in later clauses; in 3 such cases, the clause number s is the number of the later clause where the rule is repeated. 4 (5) The syntax rules are not a complete and accurate syntax description of Fortran, and cannot 5 be used to generate a Fortran parser automatically; where a syntax rule is incomplete, it is 6 restricted by corresponding constraints and text. NOTE 1.2 An example of the use of the syntax rules is: digit-string is 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 If particular entities are substituted for digit, actual digit strings might be: 4 67 1999 10243852 71.7.4 Constraints 8Each constraint is given a unique identifying number of the form Csn, where s is a one or two digit clause 9number and nn is a two or three digit sequence number within that clause. 10Often a constraint is associated with a particular syntax rule. Where that is the case, the constraint is 11annotated with the syntax rule number in parentheses. A constraint that is associated with a syntax 12rule constitutes part of the definition of the syntax term defined by the rule. It thus applies in all places 13where the syntax term appears. 14Some constraints are not associated with particular syntax rules. The effect of such a constraint is similar 15to that of a restriction stated in the text, except that a processor is required to have the capability to 16detect and report violations of constraints (1.5). In some cases, a broad requirement is stated in text 17and a subset of the same requirement is also stated as a constraint. This indicates that a standard- 18conforming program is required to adhere to the broad requirement, but that a standard-conforming 19processor is required only to have the capability of diagnosing violations of the constraint. 1.7.5 Assumed syntax rules 20 21In order to minimize the number of additional syntax rules and convey appropriate constraint informa- 22tion, the following rules are assumed. R101 xyz-list is xyz [ , xyz ] ... 23 24R102 xyz-name is name 25R103 scalar-xyz is xyz C101 (R103) scalar-xyz shall be scalar. 26 6 2006/01/05 WORKING DRAFT J3/07-007 1The letters "xyz" stand for any syntactic class phrase. An explicit syntax rule for a term overrides an 2assumed rule. 1.7.6 Syntax conventions and characteristics 3 4 (1) Any syntactic class name ending in "-stmt" follows the source form statement rules: it shall 5 be delimited by end-of-line or semicolon, and may be labeled unless it forms part of another 6 statement (such as an IF or WHERE statement). Conversely, everything considered to be 7 a source form statement is given a "-stmt" ending in the syntax rules. 8 (2) The rules on statement ordering are described rigorously in the definition of program-unit (R202). Expression hierarchy is described rigorously in the definition of expr (R722). 9 10 (3) The suffix "-spec" is used consistently for specifiers, such as input/output statement speci- 11 fiers. It also is used for type declaration attribute specifications (for example, "array-spec" in R510), and in a few other cases. 12 13 (4) Where reference is made to a type parameter, including the surrounding parentheses, the 14 suffix "-selector" is used. See, for example, "kind-selector" (R405) and "length-selector" (R421). 15 16 (5) The term "subscript" (for example, R619, R620, and R621) is used consistently in array 17 definitions. 181.7.7 Text conventions 19In the descriptive text, an equivalent English word is frequently used in place of a syntactic term. 20Particular statements and attributes are identified in the text by an upper-case keyword, e.g., "END 21statement". Boldface words are used in the text where they are first defined with a specialized meaning. 22The descriptions of obsolescent features appear in a smaller type size. NOTE 1.3 This sentence is an example of the type size used for obsolescent features. 231.8 Deleted and obsolescent features 241.8.1 General 25This part of ISO/IEC 1539 protects the users' investment in existing software by including all but five 26of the language elements of Fortran 90 that are not processor dependent. This part of ISO/IEC 1539 27identifies two categories of outmoded features. There are five in the first category, deleted features, 28which consists of features considered to have been redundant in Fortran 77 and largely unused in 29Fortran 90. Those in the second category, obsolescent features, are considered to have been redundant 30in Fortran 90 and Fortran 95, but are still frequently used. 311.8.2 Nature of deleted features 32Better methods existed in Fortran 77 for each deleted feature. These features were not included in 33Fortran 95 or Fortran 2003, and are not included in this revision of Fortran. 341.8.3 Nature of obsolescent features 35Better methods existed in Fortran 90 and Fortran 95 for each obsolescent feature. It is recommended 36that programmers use these better methods in new programs and convert existing code to these methods. 37The obsolescent features are identified in the text of this part of ISO/IEC 1539 by a distinguishing type font (1.7.7). 38 7 J3/07-007 WORKING DRAFT 2006/01/05 1A future revision of this part of ISO/IEC 1539 might delete an obscolescent feature if its use has become 2insignificant. 31.9 Normative references 4The following referenced standards are indispensable for the application of this part of ISO/IEC 1539. 5For dated references, only the edition cited applies. For undated references, the latest edition of the referenced standard (including any amendments) applies. 6 ISO/IEC 646:1991, Information technology--ISO 7-bit coded character set for information interchange. 7 8ISO 8601:1988, Data elements and interchange formats--Information interchange-- 9Representation of dates and times. ISO/IEC 9899:1999, Information technology--Programming languages--C. 10 11ISO/IEC 10646-1:2000, Information technology--Universal multiple-octet coded character set (UCS)-- 12Part 1: Architecture and basic multilingual plane. IEC 60559 (1989-01), Binary floating-point arithmetic for microprocessor systems. 13 14ISO/IEC 646:1991 (International Reference Version) is the international equivalent of ANSI X3.4-1986, 15commonly known as ASCII. This part of ISO/IEC 1539 refers to ISO/IEC 9899:1999 as the C International Standard. 16 17Because IEC 60559 (1989-01) was originally IEEE 754-1985, Standard for binary floating-point arith- 18metic, and is widely known by this name, this part of ISO/IEC 1539 refers to it as the IEEE International 19Standard. 8 2006/01/05 WORKING DRAFT J3/07-007 2 Fortran terms and concepts 1 2.1 High level syntax 2 3This clause introduces the terms associated with program units and other Fortran concepts above the 4construct, statement, and expression levels and illustrates their relationships. The notation used in this part of ISO/IEC 1539 is described in 1.7. 5 NOTE 2.1 Constraints and other information related to the rules that do not begin with R2 appear in the appropriate clause. 6R201 program is program-unit [ program-unit ] ... 7 8A program shall contain exactly one main-program program-unit or a main program defined by means 9other than Fortran, but not both. 10R202 program-unit is main-program 11 or external-subprogram 12 or module 13 or submodule 14 or block-data 15R1101 main-program is [ program-stmt ] 16 [ specification-part ] 17 [ execution-part ] 18 [ internal-subprogram-part ] 19 end-program-stmt 20R203 external-subprogram is function-subprogram 21 or subroutine-subprogram 22R1227 function-subprogram is function-stmt 23 [ specification-part ] 24 [ execution-part ] 25 [ internal-subprogram-part ] 26 end-function-stmt 27R1233 subroutine-subprogram is subroutine-stmt 28 [ specification-part ] 29 [ execution-part ] 30 [ internal-subprogram-part ] 31 end-subroutine-stmt 32R1104 module is module-stmt 33 [ specification-part ] 34 [ module-subprogram-part ] 35 end-module-stmt 36R1116 submodule is submodule-stmt 9 J3/07-007 WORKING DRAFT 2006/01/05 1 [ specification-part ] 2 [ module-subprogram-part ] 3 end-submodule-stmt 4R1120 block-data is block-data-stmt 5 [ specification-part ] 6 end-block-data-stmt 7R204 specification-part is [ use-stmt ] ... 8 [ import-stmt ] ... 9 [ implicit-part ] [ declaration-construct ] ... 10 11R205 implicit-part is [ implicit-part-stmt ] ... 12 implicit-stmt 13R206 implicit-part-stmt is implicit-stmt 14 or parameter-stmt 15 or format-stmt 16 or entry-stmt 17R207 declaration-construct is derived-type-def 18 or entry-stmt 19 or enum-def 20 or format-stmt 21 or interface-block 22 or macro-definition 23 or parameter-stmt 24 or procedure-declaration-stmt 25 or specification-stmt 26 or type-declaration-stmt 27 or stmt-function-stmt 28R208 execution-part is executable-construct [ execution-part-construct ] ... 29 30R209 execution-part-construct is executable-construct 31 or format-stmt 32 or entry-stmt 33 or data-stmt 34R210 internal-subprogram-part is contains-stmt [ internal-subprogram ] ... 35 36R211 internal-subprogram is function-subprogram 37 or subroutine-subprogram 38R1107 module-subprogram-part is contains-stmt [ module-subprogram ] ... 39 40R1108 module-subprogram is function-subprogram 41 or subroutine-subprogram 42 or separate-module-subprogram 43R1237 separate-module-subprogram is mp-subprogram-stmt 44 [ specification-part ] 45 [ execution-part ] 10 2006/01/05 WORKING DRAFT J3/07-007 1 [ internal-subprogram-part ] 2 end-mp-subprogram-stmt 3R212 specification-stmt is access-stmt 4 or allocatable-stmt 5 or asynchronous-stmt 6 or bind-stmt 7 or common-stmt 8 or data-stmt 9 or dimension-stmt 10 or equivalence-stmt 11 or external-stmt 12 or intent-stmt 13 or intrinsic-stmt 14 or namelist-stmt 15 or optional-stmt 16 or pointer-stmt 17 or protected-stmt 18 or save-stmt 19 or target-stmt 20 or volatile-stmt 21 or value-stmt 22R213 executable-construct is action-stmt 23 or associate-construct 24 or block-construct 25 or case-construct 26 or critical-construct 27 or do-construct 28 or forall-construct 29 or if-construct 30 or select-type-construct 31 or where-construct 32R214 action-stmt is allocate-stmt 33 or assignment-stmt 34 or backspace-stmt 35 or call-stmt 36 or close-stmt 37 or continue-stmt 38 or cycle-stmt 39 or deallocate-stmt 40 or end-function-stmt 41 or end-mp-subprogram-stmt 42 or end-program-stmt 43 or end-subroutine-stmt 44 or endfile-stmt 45 or exit-stmt 46 or flush-stmt 47 or forall-stmt 48 or goto-stmt 49 or if-stmt 50 or inquire-stmt 51 or notify-stmt 52 or nullify-stmt 11 J3/07-007 WORKING DRAFT 2006/01/05 1 or open-stmt 2 or pointer-assignment-stmt 3 or print-stmt 4 or query-stmt 5 or read-stmt 6 or return-stmt 7 or rewind-stmt 8 or stop-stmt 9 or sync-all-stmt 10 or sync-images-stmt 11 or sync-memory-stmt 12 or sync-team-stmt 13 or wait-stmt 14 or where-stmt 15 or write-stmt 16 or arithmetic-if-stmt 17 or computed-goto-stmt 18C201 (R208) An execution-part shall not contain an end-function-stmt, end-mp-subprogram-stmt, end- 19 program-stmt, or end-subroutine-stmt. 20Additionally, an EXPAND statement may occur anywhere that any statement may occur other than 21as the first statement of a program unit. The syntax rules are applied to the program after macro 22expansion, i.e. with each EXPAND statement replaced by the statements it produces. 2.2 Program unit concepts 23 2.2.1 Program units and scoping units 24 25Program units are the fundamental components of a Fortran program. A program unit may be 26a main program, an external subprogram, a module, a submodule, or a block data program unit. A 27subprogram may be a function subprogram or a subroutine subprogram. A module contains definitions 28that are to be made accessible to other program units. A submodule is a extension of a module; it may 29contain the definitions of procedures declared in a module or another submodule. A block data program 30unit is used to specify initial values for data objects in named common blocks. Each type of program 31unit is described in Clause 11 or 12. An external subprogram is a subprogram that is not in a main 32program, a module, a submodule, or another subprogram. An internal subprogram is a subprogram 33that is in a main program or another subprogram. A module subprogram is a subprogram that is in 34a module or submodule but is not an internal subprogram. 35A program unit consists of a set of nonoverlapping scoping units. A scoping unit is (1) a program unit or subprogram, excluding any scoping units in it, 36 (2) a derived-type definition (4.5.2), or 37 (3) an interface body, excluding any scoping units in it. 38 39A scoping unit that immediately surrounds another scoping unit is called the host scoping unit (often abbreviated to host). A module or submodule is also the host scoping unit of its child submodules. 40 2.2.2 Program 41 42A program consists of exactly one main program, any number (including zero) of other kinds of program 43units, any number (including zero) of external procedures, and any number (including zero) of other 44entities defined by means other than Fortran. 12 2006/01/05 WORKING DRAFT J3/07-007 NOTE 2.2 There is a restriction that there shall be no more than one unnamed block data program unit (11.3). This part of ISO/IEC 1539 places no ordering requirement on the program units that constitute a program, but because the public portions of a module are required to be available by the time a module reference (11.2.2) is processed, a processor may require a particular order of processing of the program units. 2.2.3 Main program 1 2The Fortran main program is described in 11.1. 32.2.4 Procedure 4A procedure encapsulates an arbitrary sequence of actions that may be invoked directly during program 5execution. Procedures are either functions or subroutines. A function is a procedure that is invoked 6in an expression; its invocation causes a value to be computed which is then used in evaluating the 7expression. The variable that returns the value of a function is called the result variable. A subroutine 8is a procedure that is invoked in a CALL statement, by a defined assignment statement, or by some 9operations on derived-type entities. Unless it is a pure procedure, a subroutine may be used to change 10the program state by changing the values of any of the data objects accessible to the subroutine; unless 11it is a pure procedure, a function may do this in addition to computing the function value. 12Procedures are described further in Clause 12. 132.2.4.1 External procedure 14An external procedure is a procedure that is defined by an external subprogram or by means other 15than Fortran. An external procedure may be invoked by the main program or by any procedure of a 16program. 172.2.4.2 Module procedure 18A module procedure is a procedure that is defined by a module subprogram (R1108). The module or 19submodule containing the subprogram is the host scoping unit of the module procedure. 202.2.4.3 Internal procedure 21An internal procedure is a procedure that is defined by an internal subprogram (R211). The containing 22main program or subprogram is the host scoping unit of the internal procedure. An internal procedure 23is local to its host in the sense that its name is accessible within the host scoping unit and all its other 24internal procedures but is not accessible elsewhere. 252.2.4.4 Interface block 26An interface body describes an abstract interface or the interface of a dummy procedure, external 27procedure, procedure pointer, or separate module procedure. 28An interface block is a specific interface block, an abstract interface block, or a generic interface block. 29A specific interface block is a collection of interface bodies. A generic interface block can also be used 30to specify that a procedure can be invoked (1) by using a generic name, 31 (2) by using a defined operator, 32 13 J3/07-007 WORKING DRAFT 2006/01/05 (3) by using a defined assignment, or 1 (4) for derived-type input/output. 2 32.2.5 Module 4A module contains (or accesses from other modules) definitions that are to be made accessible to other 5program units. These definitions include data object declarations, type definitions, procedure definitions, 6and interface blocks. A scoping unit in another program unit may access the definitions in a module. 7Modules are further described in Clause 11. 82.2.6 Submodule 9A submodule is a program unit that extends a module or another submodule. It may provide definitions 10(12.6) for procedures whose interfaces are declared (12.4.3.2) in an ancestor module or submodule. It 11may also contain declarations and definitions of other entities, which are accessible in its descendants. 12An entity declared in a submodule is not accessible by use association unless it is a module procedure 13whose interface is declared in the ancestor module. Submodules are further described in Clause 11. NOTE 2.3 The scoping unit of a submodule accesses the scoping unit of its parent module or submodule by host association. 2.3 Execution concepts 14 152.3.1 Statement classification 16Each Fortran statement is classified as either an executable statement or a nonexecutable statement. 17There are restrictions on the order in which statements may appear in a program unit, and not all 18executable statements may appear in all contexts. 2.3.2 Program execution 19 20An instance of a Fortran program is an image. Execution of a program consists of the asynchronous 21execution of a fixed number (which may be one) of its images. Each image has its own execution state, 22floating-point status (14.6), and set of data objects and procedure pointers. Whether a file is available 23on any image or only on a specific image is processor dependent. Each image is identified by an image 24index, which is an integer value in the range one to the number of images. NOTE 2.4 The programmer controls the progress of execution in each image through explicit use of Fortran control constructs (8.1, 8.2). Image control statements (8.5.1) affect the relative progress of exe- cution between images. Co-arrays (2.4.6) provide a mechanism for accessing data on one image from another image. NOTE 2.5 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. Portable programs should not make assumptions about the exact number of images. The maximum number of images may be limited due to architectural constraints. A team is a set of images identified by a scalar object of type IMAGE TEAM (13.8.2.7). 25 14 2006/01/05 WORKING DRAFT J3/07-007 2.3.3 Executable/nonexecutable statements 1 2Image execution is a sequence, in time, of actions. An executable statement is an instruction to 3perform or control one or more of these actions. Thus, the executable statements of a program unit 4determine the behavior of the program unit. The executable statements are all of those that make up 5the syntactic class executable-construct, excluding those in the specification-part of a BLOCK executable 6construct. 7Nonexecutable statements do not specify actions; they are used to configure the program environment 8in which actions take place. The nonexecutable statements are all those not classified as executable. 92.3.4 Statement order 10The syntax rules of clause 2.1 specify the statement order within program units and subprograms. These 11rules are illustrated in Table 2.1 and Table 2.2. Table 2.1 shows the ordering rules for statements and 12applies to all program units, subprograms, and interface bodies. Vertical lines delineate varieties of 13statements that may be interspersed and horizontal lines delineate varieties of statements that shall not 14be interspersed. Internal or module subprograms shall follow a CONTAINS statement. Between USE 15and CONTAINS statements in a subprogram, nonexecutable statements generally precede executable 16statements, although the ENTRY statement, FORMAT statement, and DATA statement may appear 17among the executable statements. Table 2.2 shows which statements are allowed in a scoping unit. Table 2.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 statements constructs CONTAINS statement Internal subprograms or module subprograms END statement Table 2.2: Statements allowed in scoping units Kind of scoping unit1 Main Module or Block External Module Internal Interface Statement type program submodule data subprog subprog subprog body USE Yes Yes Yes Yes Yes Yes Yes IMPORT No No No No No No Yes 15 J3/07-007 WORKING DRAFT 2006/01/05 Statements allowed in scoping units Kind of scoping unit1 Main Module or Block External Module Internal Interface Statement type program submodule data subprog subprog subprog body ENTRY No No No Yes Yes No No FORMAT Yes No No Yes Yes Yes No Misc. decl.s 2 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 (1) The scoping unit of a module or submodule does not include any module subprograms that it contains. (2) Miscellaneous declarations are PARAMETER statements, IMPLICIT statements, type declaration statements, enumeration definitions, procedure declaration statements, and spec- ification statements. 12.3.5 The END statement 2An end-program-stmt, end-function-stmt, end-subroutine-stmt, end-mp-subprogram-stmt, end-module- 3stmt, end-submodule-stmt, or end-block-data-stmt is an END statement. Each program unit, module 4subprogram, and internal subprogram shall have exactly one END statement. The end-program-stmt, 5end-function-stmt, end-subroutine-stmt, and end-mp-subprogram-stmt statements are executable, and 6may be branch target statements (8.2). Executing an end-program-stmt causes normal termination of 7execution of the program. Executing an end-function-stmt, end-subroutine-stmt, or end-mp-subprogram- 8stmt is equivalent to executing a return-stmt with no scalar-int-expr. 9The end-module-stmt, end-submodule-stmt, and end-block-data-stmt statements are nonexecutable. 2.3.6 Execution sequence 10 11If a program contains a Fortran main program, execution of the program begins by creating a fixed 12number of instances of the program; each image begins execution with the first executable construct of 13the main program. The execution of a main program or subprogram involves execution of the executable 14constructs within its scoping unit. When a Fortran procedure is invoked, the specification expressions 15within the specification-part of the invoked procedure, if any, are evaluated in a processor dependent 16order. Thereafter, execution proceeds to the first executable construct appearing within the scoping unit 17of the procedure after the invoked entry point. With the following exceptions, the effect of execution is 18as if the executable constructs are executed in the order in which they appear in the main program or 19subprogram until a STOP, RETURN, or END statement is executed. 20 (1) Execution of a branching statement (8.2) changes the execution sequence. These statements 21 explicitly specify a new starting place for the execution sequence. 22 (2) CASE constructs, DO constructs, IF constructs, and SELECT TYPE constructs contain 23 an internal statement structure and execution of these constructs involves implicit internal 24 branching. See Clause 8 for the detailed semantics of each of these constructs. 25 (3) BLOCK constructs may contain specification expressions; see 8.1.4 for detailed semantics 26 of this construct. 16 2006/01/05 WORKING DRAFT J3/07-007 (4) END=, ERR=, and EOR= specifiers may result in a branch. 1 (5) 2 Alternate returns may result in a branch. 3Internal subprograms may precede the END statement of a main program or a subprogram. The 4execution sequence excludes all such definitions. 5The relative ordering of the exeuction sequences of different images can be affected by image control statements (8.5.1). 6 7Normal termination of execution of an image occurs if a STOP statement is executed on that image. Ex- 8ecution of an end-program-stmt results in a synchronization of all images followed by normal termination 9of execution of all images. Normal termination of execution of an image also may occur during execution 10of a procedure defined by a companion processor (C International Standard 5.1.2.2.3 and 7.20.4.3). If 11normal termination of execution occurs within a Fortran program unit and the program incorporates 12procedures defined by a companion processor, the process of execution termination shall include the effect of executing the C exit() function (C International Standard 7.20.4.3). 13 2.4 Data concepts 14 15Nonexecutable statements are used to specify the characteristics of the data environment. This includes 16typing variables, declaring arrays, and defining new types. 2.4.1 Type 17 18A type is a named category of data that is characterized by a set of values, a syntax for denoting 19these values, and a set of operations that interpret and manipulate the values. This central concept is 20described in 4.1. 21A type may be parameterized, in which case the set of data values, the syntax for denoting them, and 22the set of operations depend on the values of one or more parameters. Such a parameter is called a type parameter (4.2). 23 24There are two categories of types: intrinsic types and derived types. 252.4.1.1 Intrinsic type 26An intrinsic type is a type that is defined by the language, along with operations, and is always 27accessible. The intrinsic types are integer, real, complex, character, logical, and bits. The properties of 28intrinsic types are described in 4.4. The intrinsic type parameters are KIND and LEN. 29The kind type parameter indicates the representation method for the specified type. 302.4.1.2 Derived type 31A derived type is a type that is defined by a type definition or by an intrinsic module. A scalar object of 32derived type is called a structure (4.5). Derived types may be parameterized. Assignment of structures 33is defined intrinsically (7.2.1.3), but there are no intrinsic operations for structures. For each derived 34type, a structure constructor is available to provide values (4.5.10). In addition, data objects of derived 35type may be used as procedure arguments and function results, and may appear in input/output lists. 36If additional operations are needed for a derived type, they shall be supplied as procedure definitions. 37Derived types are described further in 4.5. 382.4.2 Data value 17 J3/07-007 WORKING DRAFT 2006/01/05 1Each intrinsic type has associated with it a set of values that a datum of that type may take, depending 2on the values of the type parameters. The values for each intrinsic type are described in 4.4. The values 3that objects of a derived type may assume are determined by the type definition, type parameter values, 4and the sets of values of its components. 2.4.3 Data entity 5 6A data entity is a data object, the result of the evaluation of an expression, or the result of the execution 7of a function reference (called the function result). A data entity has a type and type parameters; it 8may have a data value (an exception is an undefined variable). Every data entity has a rank and is thus 9either a scalar or an array. 102.4.3.1 Data object 11A data object (often abbreviated to object) is a constant (4.1.2), a variable (6), or a subobject of a 12constant. The type and type parameters of a named data object may be specified explicitly (5.2) or implicitly (5.5). 13 14Subobjects are portions of certain objects that may be referenced and defined (variables only) inde- 15pendently of the other portions. These include portions of arrays (array elements and array sections), 16portions of character strings (substrings), portions of complex objects (real and imaginary parts), and 17portions of structures (components). Subobjects are themselves data objects, but subobjects are refer- 18enced only by object designators or intrinsic functions. A subobject of a variable is a variable. Subobjects 19are described in Clause 6. 20Objects referenced by a name are: a named scalar (a scalar object) a named array (an array object) 21 22Subobjects referenced by an object designator are: an array element (a scalar subobject) an array section (an array subobject) a complex part designator (the real or imaginary part of a complex object) a structure component (a scalar or an array subobject) a substring (a scalar subobject) 23 242.4.3.1.1 Variable 25A variable may have a value and may be defined and redefined during execution of a program. 26A named local variable of the scoping unit of a module, submodule, main program, or subprogram, is a 27named variable that is a local entity of the scoping unit, is not a dummy argument, is not in COMMON, 28does not have the BIND attribute, and is not accessed by use or host association. A named local variable 29of a BLOCK construct is a named variable that is declared in that construct, is not in COMMON, does 30not have the BIND attribute, and is not accessed by use association. A subobject of a named local 31variable is also a local variable. 322.4.3.1.2 Constant 33A constant has a value and cannot become defined, redefined, or undefined during execution of a 34program. A constant with a name is called a named constant and has the PARAMETER attribute (5.3.12). A constant without a name is called a literal constant (4.4). 35 362.4.3.1.3 Subobject of a constant 18 2006/01/05 WORKING DRAFT J3/07-007 1A subobject of a constant is a portion of a constant. The portion referenced may depend on the 2value of a variable. NOTE 2.6 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. 32.4.3.2 Expression 4An expression (7.1) produces a data entity when evaluated. An expression represents either a data 5reference or a computation; it is formed from operands, operators, and parentheses. The type, type 6parameters, value, and rank of an expression result are determined by the rules in Clause 7. 72.4.3.3 Function reference 8A function reference (12.5.3) produces a data entity when the function is executed during expression 9evaluation. The type, type parameters, and rank of a function result are determined by the interface of the function (12.3.3). The value of a function result is determined by execution of the function. 10 112.4.4 Scalar 12A scalar (2.4.4) is a data entity that can be represented by a single value of the type and that is not an array (6.2). Its value, if defined, is a single element from the set of values that characterize its type. 13 NOTE 2.7 A structure is scalar even if it has arrays as components. A scalar object of derived type has a single value that consists of the values of its components (4.5.8). 14The rank of a scalar is zero. The shape of a scalar is represented by a rank-one array of size zero. 2.4.5 Array 15 16An array is a set of scalar data, all of the same type and type parameters, whose individual elements 17are arranged in a rectangular pattern. An array element is one of the individual elements in the array 18and is a scalar. An array section is a subset of the elements of an array and is itself an array. 19An array may have up to fifteen dimensions, and any extent (number of elements) in any dimension. 20The rank of the array is the number of dimensions; its size is the total number of elements, which is 21equal to the product of the extents. An array may have zero size. The shape of an array is determined 22by its rank and its extent in each dimension, and may be represented as a rank-one array whose elements 23are the extents. All named arrays shall be declared, and the rank of a named array is specified in its 24declaration. The rank of a named array, once declared, is constant; the extents may be constant or may 25vary during execution. 26Two arrays are conformable if