WORKING DRAFT J3/06-007r1 25th September 2006 18:59 This is an internal working document of J3. 2006/09/25 WORKING DRAFT J3/06-007r1 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 . . . . . . . . . . . . . . . . . . . . . . . 6 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.4 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.5 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.2.6 Submodule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.3 Execution concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.1 Statement classification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.2 Program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.3 Executable/nonexecutable statements . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.4 Statement order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.4.3 Data entity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 i J3/06-007r1 WORKING DRAFT 2006/09/25 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.5 Fundamental terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.1 Name and designator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.2 Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.3 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.4 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.5.5 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.6 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.7 Intrinsic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.8 Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.9 Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2 Low-level syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.1 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2.3 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 3.2.4 Statement labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.2.5 Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.3 Source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.3.1 Free source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.3.2 Fixed source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 3.4 Including source text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.5 Macro processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.5.1 Macro definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.5.2 Macro expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.1 The concept of type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.1.1 Set of values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.1.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.1.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.2 Type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.3 Relationship of types and values to objects . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.3.1 Type specifiers and type compatibility . . . . . . . . . . . . . . . . . . . . . . . 43 4.4 Intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.4.1 Classification and specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.4.2 Integer type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.4.3 Real type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.4.4 Complex type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 4.4.5 Character type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 4.4.6 Logical type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 4.4.7 Bits type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 ii 2006/09/25 WORKING DRAFT J3/06-007r1 4.5 Derived types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.5.1 Derived type concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.5.2 Derived-type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 4.5.3 Derived-type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 4.5.4 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 4.5.5 Type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 4.5.6 Final subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 4.5.7 Type extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 4.5.8 Derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.5.9 Derived-type specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.5.10 Construction of derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.5.11 Derived-type operations and assignment . . . . . . . . . . . . . . . . . . . . . . 77 4.6 Enumerations and enumerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 4.7 Construction of array values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 5 Attribute declarations and specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.2 Type declaration statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.2.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.2.2 Automatic data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 5.2.3 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.2.4 Examples of type declaration statements . . . . . . . . . . . . . . . . . . . . . . 85 5.3 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.3.1 Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.3.2 Accessibility attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 5.3.3 ALLOCATABLE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 5.3.4 ASYNCHRONOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 5.3.5 BIND attribute for data entities . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.3.6 CONTIGUOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.3.7 DIMENSION attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5.3.8 EXTERNAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 5.3.9 INTENT attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 5.3.10 INTRINSIC attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.11 OPTIONAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.12 PARAMETER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 5.3.13 POINTER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 5.3.14 PROTECTED attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 5.3.15 SAVE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 5.3.16 TARGET attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3.17 VALUE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3.18 VOLATILE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.4 Attribute specification statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.4.1 Accessibility statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.4.2 ALLOCATABLE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.3 ASYNCHRONOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.4 BIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.5 CONTIGUOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.6 DATA statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.7 DIMENSION statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.4.8 INTENT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.4.9 OPTIONAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.4.10 PARAMETER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 5.4.11 POINTER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 5.4.12 PROTECTED statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 iii J3/06-007r1 WORKING DRAFT 2006/09/25 5.4.13 SAVE statement . . . . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 104 5.4.14 TARGET statement . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 105 5.4.15 VALUE statement . . . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 105 5.4.16 VOLATILE statement . . . ....... . . . . . . . . . . . . . . . . . . . . . . 105 5.5 IMPLICIT statement . . . . . . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 105 5.6 NAMELIST statement . . . . . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 107 5.7 Storage association of data objects . ....... . . . . . . . . . . . . . . . . . . . . . . 108 5.7.1 EQUIVALENCE statement ....... . . . . . . . . . . . . . . . . . . . . . . 108 5.7.2 COMMON statement . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 111 5.7.3 Restrictions on common and equivalence . . . . . . . . . . . . . . . . . . . . . . 113 6 Use of data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 6.1 Scalars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 6.1.1 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 6.1.2 Structure components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 6.1.3 Complex parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.1.4 Type parameter inquiry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.2.1 Whole arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.2.2 Array elements and array sections . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.2.3 Image selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.3 Dynamic association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.3.1 ALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.3.2 NULLIFY statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.3.3 DEALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 7 Expressions and assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1.1 Form of an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 7.1.2 Intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 7.1.3 Defined operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 7.1.4 Type, type parameters, and shape of an expression . . . . . . . . . . . . . . . . 139 7.1.5 Conformability rules for elemental operations . . . . . . . . . . . . . . . . . . . 141 7.1.6 Specification expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 7.1.7 Initialization expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 7.1.8 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 7.2 Interpretation of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 7.2.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 7.2.2 Numeric intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 7.2.3 Character intrinsic operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 7.2.4 Relational intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 7.2.5 Logical intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 7.2.6 Bits intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 7.3 Precedence of operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 7.4 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 7.4.1 Assignment statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 7.4.2 Pointer assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 7.4.3 Masked array assignment ­ WHERE . . . . . . . . . . . . . . . . . . . . . . . . 166 7.4.4 FORALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 8 Execution control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 8.1 Executable constructs containing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 8.1.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 8.1.2 Rules governing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 iv 2006/09/25 WORKING DRAFT J3/06-007r1 8.1.3 ASSOCIATE construct . . . . . . . . . . . . . . . . . ........... . . . . 176 8.1.4 BLOCK construct . . . . . . . . . . . . . . . . . . . . ........... . . . . 177 8.1.5 CASE construct . . . . . . . . . . . . . . . . . . . . . ........... . . . . 178 8.1.6 CRITICAL construct . . . . . . . . . . . . . . . . . . ........... . . . . 180 8.1.7 DO construct . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 182 8.1.8 IF construct and statement . . . . . . . . . . . . . . . ........... . . . . 188 8.1.9 SELECT TYPE construct . . . . . . . . . . . . . . . ........... . . . . 189 8.1.10 EXIT statement . . . . . . . . . . . . . . . . . . . . . ........... . . . . 192 8.2 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 192 8.2.1 GO TO statement . . . . . . . . . . . . . . . . . . . . ........... . . . . 192 8.2.2 Computed GO TO statement . . . . . . . . . . . . . ........... . . . . 193 8.2.3 Arithmetic IF statement . . . . . . . . . . . . . . . . ........... . . . . 193 8.3 CONTINUE statement . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 193 8.4 STOP statement . . . . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 193 8.5 Image execution control . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 195 8.5.1 Image control statements . . . . . . . . . . . . . . . . ........... . . . . 195 8.5.2 SYNC ALL statement . . . . . . . . . . . . . . . . . ........... . . . . 197 8.5.3 SYNC TEAM statement . . . . . . . . . . . . . . . . ........... . . . . 197 8.5.4 SYNC IMAGES statement . . . . . . . . . . . . . . . ........... . . . . 199 8.5.5 NOTIFY and QUERY statements . . . . . . . . . . . ........... . . . . 200 8.5.6 SYNC MEMORY statement . . . . . . . . . . . . . . ........... . . . . 202 8.5.7 STAT= and ERRMSG= specifiers in image execution control statements . . . . 203 9 Input/output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 9.1 Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 9.1.1 Formatted record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 9.1.2 Unformatted record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 9.1.3 Endfile record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 9.2 External files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 9.2.1 File existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 9.2.2 File access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 9.2.3 File position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 9.2.4 File storage units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 9.3 Internal files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 9.4 File connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 9.4.1 Connection modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 9.4.2 Unit existence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 9.4.3 Connection of a file to a unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 9.4.4 Preconnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 9.4.5 OPEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 9.4.6 CLOSE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 9.5 Data transfer statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 9.5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 9.5.2 Control information list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 9.5.3 Data transfer input/output list . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 9.5.4 Execution of a data transfer input/output statement . . . . . . . . . . . . . . . 229 9.5.5 Termination of data transfer statements . . . . . . . . . . . . . . . . . . . . . . 241 9.6 Waiting on pending data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 9.6.1 Wait operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 9.6.2 WAIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 9.7 File positioning statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 9.7.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 9.7.2 BACKSPACE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 9.7.3 ENDFILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 v J3/06-007r1 WORKING DRAFT 2006/09/25 9.7.4 REWIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.8 FLUSH statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.9 File inquiry statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 9.9.1 Forms of the INQUIRE statement . . . . . . . . . . . . . . . . . . . . . . . . . . 245 9.9.2 Inquiry specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 9.9.3 Inquire by output list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 9.10 Error, end-of-record, and end-of-file conditions . . . . . . . . . . . . . . . . . . . . . . . . 252 9.10.1 Error conditions and the ERR= specifier . . . . . . . . . . . . . . . . . . . . . . 253 9.10.2 End-of-file condition and the END= specifier . . . . . . . . . . . . . . . . . . . . 253 9.10.3 End-of-record condition and the EOR= specifier . . . . . . . . . . . . . . . . . . 254 9.10.4 IOSTAT= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 9.10.5 IOMSG= specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 9.11 Restrictions on input/output statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 10 Input/output editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10.1 Format specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10.2 Explicit format specification methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10.2.1 FORMAT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10.2.2 Character format specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 10.3 Form of a format item list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 10.3.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 10.3.2 Edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 10.3.3 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 10.4 Interaction between input/output list and format . . . . . . . . . . . . . . . . . . . . . . 260 10.5 Positioning by format control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 10.6 Decimal symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 10.7 Data edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 10.7.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 10.7.2 Numeric and bits editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 10.7.3 Logical editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 10.7.4 Character editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 10.7.5 Generalized editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 10.7.6 User-defined derived-type editing . . . . . . . . . . . . . . . . . . . . . . . . . . 272 10.8 Control edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 10.8.1 Position editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 10.8.2 Slash editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8.3 Colon editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8.4 SS, SP, and S editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8.5 P editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8.6 BN and BZ editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 10.8.7 RU, RD, RZ, RN, RC, and RP editing . . . . . . . . . . . . . . . . . . . . . . . 275 10.8.8 DC and DP editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 10.9 Character string edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.10 List-directed formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.10.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.10.2 Values and value separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 10.10.3 List-directed input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 10.10.4 List-directed output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 10.11 Namelist formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 10.11.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 10.11.2 Name-value subsequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 10.11.3 Namelist input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 10.11.4 Namelist output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 vi 2006/09/25 WORKING DRAFT J3/06-007r1 11 Program units . . . . . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 287 11.1 Main program . . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 287 11.2 Modules . . . . . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 288 11.2.1 General . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 288 11.2.2 The USE statement and use association . . . . . . . . . . . . . . . . . . . . . . . 289 11.2.3 Submodules . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 291 11.3 Block data program units . . ............ . . . . . . . . . . . . . . . . . . . . . . 292 12 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 12.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 12.2 Procedure classifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 12.2.1 Procedure classification by reference . . . . . . . . . . . . . . . . . . . . . . . . . 295 12.2.2 Procedure classification by means of definition . . . . . . . . . . . . . . . . . . . 295 12.3 Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 12.3.1 Characteristics of procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 12.3.2 Characteristics of dummy arguments . . . . . . . . . . . . . . . . . . . . . . . . 296 12.3.3 Characteristics of function results . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.4 Procedure interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.4.2 Implicit and explicit interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 12.4.3 Specification of the procedure interface . . . . . . . . . . . . . . . . . . . . . . . 298 12.5 Procedure reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 12.5.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308 12.5.2 Actual arguments, dummy arguments, and argument association . . . . . . . . . 310 12.5.3 Function reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 12.5.4 Subroutine reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 12.5.5 Resolving named procedure references . . . . . . . . . . . . . . . . . . . . . . . . 323 12.5.6 Resolving type-bound procedure references . . . . . . . . . . . . . . . . . . . . . 325 12.6 Procedure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 12.6.1 Intrinsic procedure definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 12.6.2 Procedures defined by subprograms . . . . . . . . . . . . . . . . . . . . . . . . . 326 12.6.3 Definition and invocation of procedures by means other than Fortran . . . . . . 333 12.6.4 Statement function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 12.7 Pure procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 12.8 Elemental procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 12.8.1 Elemental procedure declaration and interface . . . . . . . . . . . . . . . . . . . 336 12.8.2 Elemental function actual arguments and results . . . . . . . . . . . . . . . . . . 336 12.8.3 Elemental subroutine actual arguments . . . . . . . . . . . . . . . . . . . . . . . 337 13 Intrinsic procedures and modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 13.1 Classes of intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 13.2 Arguments to intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 13.2.1 General rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 13.2.2 The shape of array arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 13.2.3 Mask arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 13.2.4 Arguments to collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . 340 13.3 Bit model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 13.4 Numeric models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.5 Standard generic intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.5.1 Numeric functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.5.2 Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.5.3 Character functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.5.4 Kind functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13.5.5 Miscellaneous type conversion functions . . . . . . . . . . . . . . . . . . . . . . . 344 vii J3/06-007r1 WORKING DRAFT 2006/09/25 13.5.6 Numeric inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13.5.7 Array inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13.5.8 Other inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.9 Bit manipulation procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.10 Floating-point manipulation functions . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.11 Vector and matrix multiply functions . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.12 Array reduction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.13 Array construction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.14 Array location functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.15 Collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.16 Null function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.17 Allocation transfer procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.18 Random number subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.19 System environment procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.6 Specific names for standard intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . 348 13.7 Specifications of the standard intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . 349 13.8 Standard intrinsic modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 13.8.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434 13.8.2 The IEEE intrinsic modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 13.8.3 The ISO FORTRAN ENV intrinsic module . . . . . . . . . . . . . . . . . . . . 435 13.8.4 The ISO C BINDING intrinsic module . . . . . . . . . . . . . . . . . . . . . . . 438 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 . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 442 14.4 Underflow mode . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 443 14.5 Halting . . . . . . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 443 14.6 The floating point status . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 444 14.7 Exceptional values . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 444 14.8 IEEE arithmetic . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 444 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 ......... . . . . . . . . . . . . . . . . . . . . . 446 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 viii 2006/09/25 WORKING DRAFT J3/06-007r1 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 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 16.5.4 Inheritance association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 16.5.5 Establishing associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 16.6 Definition and undefinition of variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 16.6.1 Definition of objects and subobjects . . . . . . . . . . . . . . . . . . . . . . . . . 498 16.6.2 Variables that are always defined . . . . . . . . . . . . . . . . . . . . . . . . . . 499 16.6.3 Variables that are initially defined . . . . . . . . . . . . . . . . . . . . . . . . . . 499 16.6.4 Variables that are initially undefined . . . . . . . . . . . . . . . . . . . . . . . . 499 16.6.5 Events that cause variables to become defined . . . . . . . . . . . . . . . . . . . 499 16.6.6 Events that cause variables to become undefined . . . . . . . . . . . . . . . . . . 501 16.6.7 Variable definition context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 16.6.8 Pointer association context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504 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 ix J3/06-007r1 WORKING DRAFT 2006/09/25 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 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.4) . . . . . . . . . . . . . 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.3.4) . . . . . . . . . . . . . . . . . 578 C.13 Array feature notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 x 2006/09/25 WORKING DRAFT J3/06-007r1 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 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)Syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 D.1 Extract of all syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 D.2 Syntax rule cross-reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638 Annex E (informative)Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651 xi J3/06-007r1 WORKING DRAFT 2006/09/25 xii 2006/09/25 WORKING DRAFT J3/06-007r1 List of Tables 2.1 Requirements on statement ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.2 Statements allowed in scoping units . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.1 Special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6.1 Subscript order value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 7.1 Type of operands and results for intrinsic operators . . . . . . . . . . . . . . . . . 137 7.3 Interpretation of the numeric intrinsic operators . . . . . . . . . . . . . . . . . . . 151 7.4 Interpretation of the character intrinsic operator // . . . . . . . . . . . . . . . . . 151 7.5 Interpretation of the relational intrinsic operators . . . . . . . . . . . . . . . . . . 152 7.6 Interpretation of the logical intrinsic operators . . . . . . . . . . . . . . . . . . . . 153 7.7 The values of operations involving logical intrinsic operators . . . . . . . . . . . . 153 7.8 Interpretation of the bits intrinsic operators . . . . . . . . . . . . . . . . . . . . . . 154 7.9 The values of bits intrinsic operations other than // . . . . . . . . . . . . . . . . . 154 7.10 Categories of operations and relative precedence . . . . . . . . . . . . . . . . . . . 154 7.11 Type conformance for the intrinsic assignment statement . . . . . . . . . . . . . . 157 7.12 Numeric conversion and the assignment statement . . . . . . . . . . . . . . . . . . 160 7.13 Bits conversion and the assignment statement . . . . . . . . . . . . . . . . . . . . . 160 10.1 E and D exponent forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266 10.2 EN exponent forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 10.3 ES exponent forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 13.1 Characteristics of the result of NULL ( ) . . . . . . . . . . . . . . . . . . . . . . . . 410 15.1 Names of C characters with special semantics . . . . . . . . . . . . . . . . . . . . . 468 15.2 Interoperability between Fortran and C types . . . . . . . . . . . . . . . . . . . . . 472 xiii J3/06-007r1 WORKING DRAFT 2006/09/25 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/09/25 WORKING DRAFT J3/06-007r1 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 the standard. 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 BOZ constants. (18) The G0 edit descriptor. (19) Additional mathematical intrinsic functions for computing Bessel functions, the error func- tion, 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/06-007r1 WORKING DRAFT 2006/09/25 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/09/25 WORKING DRAFT J3/06-007r1 Information technology -- Programming languages -- 1 Fortran -- 2 Part 1: 3 Base Language 4 1 Overview 5 1.1 Scope 6 ISO/IEC 1539 is a multipart International Standard; the parts are published separately. This publi- 7 cation, ISO/IEC 1539-1, which is the first part, specifies the form and establishes the interpretation 8 of programs expressed in the base Fortran language. The purpose of this part of ISO/IEC 1539 is to 9 promote portability, reliability, maintainability, and efficient execution of Fortran programs for use on 10 a variety of computing systems. The second part, ISO/IEC 1539-2, defines additional facilities for the 11 manipulation of character strings of variable length; this has been largely subsumed by allocatable char- 12 acters with deferred length parameters. The third part, ISO/IEC 1539-3, defines a standard conditional 13 compilation facility for Fortran. A processor conforming to part 1 need not conform to ISO/IEC 1539-2 14 or ISO/IEC 1539-3; however, conformance to either assumes conformance to this part. Throughout this 15 publication, the term "this standard" refers to ISO/IEC 1539-1. 16 1.2 Processor 17 The combination of a computing system and the mechanism by which programs are transformed for use 18 on that computing system is called a processor in this part of ISO/IEC 1539. 19 1.3 Inclusions 20 This part of ISO/IEC 1539 specifies 21 (1) the forms that a program written in the Fortran language may take, 22 (2) the rules for interpreting the meaning of a program and its data, 23 (3) the form of the input data to be processed by such a program, and 24 (4) the form of the output data resulting from the use of such a program. 25 1.4 Exclusions 26 This part of ISO/IEC 1539 does not specify 27 (1) the mechanism by which programs are transformed for use on computing systems, 28 (2) the operations required for setup and control of the use of programs on computing systems, 29 (3) the method of transcription of programs or their input or output data to or from a storage 30 medium, 31 1 J3/06-007r1 WORKING DRAFT 2006/09/25 (4) the program and processor behavior when this part of ISO/IEC 1539 fails to establish an 1 interpretation except for the processor detection and reporting requirements in items (2) to 2 (8) of 1.5, 3 (5) the size or complexity of a program and its data that will exceed the capacity of any 4 particular computing system or the capability of a particular processor, 5 (6) the physical properties of the representation of quantities and the method of rounding, 6 approximating, or computing numeric values on a particular processor, 7 (7) the physical properties of input/output records, files, and units, or 8 (8) the physical properties and implementation of storage. 9 1.5 Conformance 10 A program (2.2.2) is a standard-conforming program if it uses only those forms and relationships 11 described herein and if the program has an interpretation according to this part of ISO/IEC 1539. A 12 program unit (2.2.1) conforms to this part of ISO/IEC 1539 if it can be included in a program in a 13 manner that allows the program to be standard conforming. 14 A processor conforms to this part of ISO/IEC 1539 if: 15 (1) it executes any standard-conforming program in a manner that fulfills the interpretations 16 herein, subject to any limits that the processor may impose on the size and complexity of 17 the program; 18 (2) it contains the capability to detect and report the use within a submitted program unit of 19 a form designated herein as obsolescent, insofar as such use can be detected by reference to 20 the numbered syntax rules and constraints; 21 (3) it contains the capability to detect and report the use within a submitted program unit of 22 an additional form or relationship that is not permitted by the numbered syntax rules or 23 constraints, including the deleted features described in Annex B; 24 (4) it contains the capability to detect and report the use within a submitted program unit of 25 an intrinsic type with a kind type parameter value not supported by the processor (4.4); 26 (5) it contains the capability to detect and report the use within a submitted program unit of 27 source form or characters not permitted by Clause 3; 28 (6) it contains the capability to detect and report the use within a submitted program of name 29 usage not consistent with the scope rules for names, labels, operators, and assignment 30 symbols in Clause 16; 31 (7) it contains the capability to detect and report the use within a submitted program unit of 32 intrinsic procedures whose names are not defined in Clause 13; and 33 (8) it contains the capability to detect and report the reason for rejecting a submitted program. 34 However, in a format specification that is not part of a FORMAT statement (10.2.1), a processor need not 35 detect or report the use of deleted or obsolescent features, or the use of additional forms or relationships. 36 A standard-conforming processor may allow additional forms and relationships provided that such ad- 37 ditions do not conflict with the standard forms and relationships. However, a standard-conforming 38 processor may allow additional intrinsic procedures even though this could cause a conflict with the 39 name of a procedure in a standard-conforming program. If such a conflict occurs and involves the name 40 of an external procedure, the processor is permitted to use the intrinsic procedure unless the name is 41 given the EXTERNAL attribute (5.3.8) in the scoping unit (2.2.1). A standard-conforming program 42 shall not use nonstandard intrinsic procedures or modules that have been added by the processor. 43 Because a standard-conforming program may place demands on a processor that are not within the 44 scope of this part of ISO/IEC 1539 or may include standard items that are not portable, such as 45 external procedures defined by means other than Fortran, conformance to this part of ISO/IEC 1539 46 2 2006/09/25 WORKING DRAFT J3/06-007r1 does not ensure that a program will execute consistently on all or any standard-conforming processors. 1 In some cases, this part of ISO/IEC 1539 allows the provision of facilities that are not completely specified 2 in the standard. These facilities are identified as processor dependent. They shall be provided, with 3 methods or semantics determined by the processor. 4 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 5 1.6.1 New intrinsic procedures 6 Each Fortran International Standard since ISO 1539:1980 (informally referred to as Fortran 77), defines 7 more intrinsic procedures than the previous one. Therefore, a Fortran program conforming to an older 8 standard may have a different interpretation under a newer standard if it invokes an external procedure 9 having the same name as one of the new standard intrinsic procedures, unless that procedure is specified 10 to have the EXTERNAL attribute. 11 1.6.2 New intrinsic data type and operator 12 This part of ISO/IEC 1539 specifies a new intrinsic type, BITS, which will conflict with a derived type 13 of the same name. 14 This part of ISO/IEC 1539 specifies a new intrinsic operator, .XOR., which might conflict with a user- 15 defined operator of the same name, has a different precedence from that of a user-defined operator, and 16 a different syntax from that of a user-defined unary operator. 17 1.6.3 Fortran 2003 compatibility 18 Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension 19 to the preceding Fortran International Standard, ISO/IEC 1539-1:2004 (Fortran 2003). Any standard- 20 conforming Fortran 2003 program that does not use a derived type called BITS, and does not use a 21 user-defined operator called .XOR., remains standard-conforming under this part of ISO/IEC 1539. 22 1.6.4 Fortran 95 compatibility 23 Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension to 24 ISO/IEC 1539-1:1997 (Fortran 95). Any standard-conforming Fortran 95 program that does not use a 25 derived type called BITS or a user-defined operator called .XOR. remains standard-conforming under 26 this part of ISO/IEC 1539. The following Fortran 95 features may have different interpretations in this 27 part of ISO/IEC 1539. 28 (1) Earlier Fortran standards had the concept of printing, meaning that column one of formatted 29 output had special meaning for a processor-dependent (possibly empty) set of external 30 files. This could be neither detected nor specified by a standard-specified means. The 31 interpretation of the first column is not specified by this part of ISO/IEC 1539. 32 3 J3/06-007r1 WORKING DRAFT 2006/09/25 (2) This part of ISO/IEC 1539 specifies a different output format for real zero values in list- 1 directed and namelist output. 2 (3) If the processor can distinguish between positive and negative real zero, this part of ISO/IEC 3 1539 requires different returned values for ATAN2(Y,X) when X < 0 and Y is negative real 4 zero and for LOG(X) and SQRT(X) when X is complex with REAL(X) < 0 and negative 5 zero imaginary part. 6 1.6.5 Fortran 90 compatibility 7 Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this part 8 of ISO/IEC 1539 is an upward compatible extension to ISO/IEC 1539:1991 (Fortran 90). Any standard- 9 conforming Fortran 90 program that does not use a derived type called BITS, a user-defined operator 10 called .XOR., or one of the deleted features remains standard-conforming under this part of ISO/IEC 11 1539. 12 The PAD= specifier in the INQUIRE statement in this part of ISO/IEC 1539 returns the value UNDE- 13 FINED if there is no connection or the connection is for unformatted input/output. Fortran 90 specified 14 YES. 15 Fortran 90 specified that if the second argument to MOD or MODULO was zero, the result was processor 16 dependent. this part of ISO/IEC 1539 specifies that the second argument shall not be zero. 17 1.6.6 FORTRAN 77 compatibility 18 Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this part 19 of ISO/IEC 1539 is an upward compatible extension to ISO 1539:1980 (Fortran 77). Any standard- 20 conforming Fortran 77 program that does not use one of the deleted features noted in Annex B.1 and 21 that does not depend on the differences specified here remains standard-conforming under this part of 22 ISO/IEC 1539. This part of ISO/IEC 1539 restricts the behavior for some features that were processor 23 dependent in Fortran 77. Therefore, a standard-conforming Fortran 77 program that uses one of 24 these processor-dependent features may have a different interpretation under this part of ISO/IEC 1539, 25 yet remain a standard-conforming program. The following Fortran 77 features may have different 26 interpretations in this part of ISO/IEC 1539. 27 (1) Fortran 77 permitted a processor to supply more precision derived from a real constant 28 than can be represented in a real datum when the constant is used to initialize a data object 29 of type double precision real in a DATA statement. This part of ISO/IEC 1539 does not 30 permit a processor this option. 31 (2) If a named variable that was not in a common block was initialized in a DATA statement and 32 did not have the SAVE attribute specified, Fortran 77 left its SAVE attribute processor 33 dependent. This part of ISO/IEC 1539 specifies (5.4.6) that this named variable has the 34 SAVE attribute. 35 (3) Fortran 77 specified that the number of characters required by the input list was to be 36 less than or equal to the number of characters in the record during formatted input. This 37 part of ISO/IEC 1539 specifies (9.5.4.4.2) that the input record is logically padded with 38 blanks if there are not enough characters in the record, unless the PAD= specifier with the 39 value 'NO' is specified in an appropriate OPEN or READ statement. 40 (4) A value of 0 for a list item in a formatted output statement will be formatted in a different 41 form for some G edit descriptors. In addition, this part of ISO/IEC 1539 specifies how 42 rounding of values will affect the output field form, but Fortran 77 did not address this 43 issue. Therefore, some Fortran 77 processors may produce an output form different from 44 the output form produced by Fortran 2003 processors for certain combinations of values and 45 G edit descriptors. 46 (5) If the processor can distinguish between positive and negative real zero, the behavior of the 47 4 2006/09/25 WORKING DRAFT J3/06-007r1 SIGN intrinsic function when the second argument is negative real zero is changed by this 1 part of ISO/IEC 1539. 2 1.7 Notation used in this part of ISO/IEC 1539 3 1.7.1 Applicability of requirements 4 In this part of ISO/IEC 1539, "shall" is to be interpreted as a requirement; conversely, "shall not" is 5 to be interpreted as a prohibition. Except where stated otherwise, such requirements and prohibitions 6 apply to programs rather than processors. 7 1.7.2 Informative notes 8 Informative notes of explanation, rationale, examples, and other material are interspersed with the 9 normative body of this part of ISO/IEC 1539. The informative material is nonnormative; it is identified 10 by being in shaded, framed boxes that have numbered headings beginning with "NOTE." 11 1.7.3 Syntax rules 12 Syntax rules describe the forms that Fortran lexical tokens, statements, and constructs may take. These 13 syntax rules are expressed in a variation of Backus-Naur form (BNF) with the following conventions. 14 (1) Characters from the Fortran character set (3.1) are interpreted literally as shown, except 15 where otherwise noted. 16 (2) Lower-case italicized letters and words (often hyphenated and abbreviated) represent gen- 17 eral syntactic classes for which particular syntactic entities shall be substituted in actual 18 statements. 19 Common abbreviations used in syntactic terms are: 20 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: 21 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 (4) Each syntax rule is given a unique identifying number of the form Rsnn, where s is a 22 one- or two-digit clause number and nn is a two-digit sequence number within that clause. 23 The syntax rules are distributed as appropriate throughout the text, and are referenced by 24 number as needed. Some rules in Clauses 2 and 3 are more fully described in later clauses; in 25 such cases, the clause number s is the number of the later clause where the rule is repeated. 26 (5) The syntax rules are not a complete and accurate syntax description of Fortran, and cannot 27 be used to generate a Fortran parser automatically; where a syntax rule is incomplete, it is 28 restricted by corresponding constraints and text. 29 5 J3/06-007r1 WORKING DRAFT 2006/09/25 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 1.7.4 Constraints 1 Each constraint is given a unique identifying number of the form Csn, where s is a one or two digit clause 2 number and nn is a two or three digit sequence number within that clause. 3 Often a constraint is associated with a particular syntax rule. Where that is the case, the constraint is 4 annotated with the syntax rule number in parentheses. A constraint that is associated with a syntax 5 rule constitutes part of the definition of the syntax term defined by the rule. It thus applies in all places 6 where the syntax term appears. 7 Some constraints are not associated with particular syntax rules. The effect of such a constraint is similar 8 to that of a restriction stated in the text, except that a processor is required to have the capability to 9 detect and report violations of constraints (1.5). In some cases, a broad requirement is stated in text 10 and a subset of the same requirement is also stated as a constraint. This indicates that a standard- 11 conforming program is required to adhere to the broad requirement, but that a standard-conforming 12 processor is required only to have the capability of diagnosing violations of the constraint. 13 1.7.5 Assumed syntax rules 14 In order to minimize the number of additional syntax rules and convey appropriate constraint informa- 15 tion, the following rules are assumed. 16 R101 xyz-list is xyz [ , xyz ] ... 17 R102 xyz-name is name 18 R103 scalar-xyz is xyz 19 C101 (R103) scalar-xyz shall be scalar. 20 The letters "xyz " stand for any syntactic class phrase. An explicit syntax rule for a term overrides an 21 assumed rule. 22 1.7.6 Syntax conventions and characteristics 23 (1) Any syntactic class name ending in "-stmt" follows the source form statement rules: it shall 24 be delimited by end-of-line or semicolon, and may be labeled unless it forms part of another 25 statement (such as an IF or WHERE statement). Conversely, everything considered to be 26 a source form statement is given a "-stmt" ending in the syntax rules. 6 2006/09/25 WORKING DRAFT J3/06-007r1 (2) The rules on statement ordering are described rigorously in the definition of program-unit 1 (R202). Expression hierarchy is described rigorously in the definition of expr (R722). 2 (3) The suffix "-spec" is used consistently for specifiers, such as input/output statement speci- 3 fiers. It also is used for type declaration attribute specifications (for example, "array-spec" 4 in R510), and in a few other cases. 5 (4) Where reference is made to a type parameter, including the surrounding parentheses, the 6 suffix "-selector " is used. See, for example, "kind-selector " (R405) and "length-selector " 7 (R421). 8 (5) The term "subscript" (for example, R619, R620, and R621) is used consistently in array 9 definitions. 10 1.7.7 Text conventions 11 In the descriptive text, an equivalent English word is frequently used in place of a syntactic term. 12 Particular statements and attributes are identified in the text by an upper-case keyword, e.g., "END 13 statement". Boldface words are used in the text where they are first defined with a specialized meaning. 14 The descriptions of obsolescent features appear in a smaller type size. 15 NOTE 1.3 This sentence is an example of the type size used for obsolescent features. 1.8 Deleted and obsolescent features 16 1.8.1 General 17 This part of ISO/IEC 1539 protects the users' investment in existing software by including all but five 18 of the language elements of Fortran 90 that are not processor dependent. This part of ISO/IEC 1539 19 identifies two categories of outmoded features. There are five in the first category, deleted features, 20 which consists of features considered to have been redundant in Fortran 77 and largely unused in 21 Fortran 90. Those in the second category, obsolescent features, are considered to have been redundant 22 in Fortran 90 and Fortran 95, but are still frequently used. 23 1.8.2 Nature of deleted features 24 Better methods existed in Fortran 77 for each deleted feature. These features were not included in 25 Fortran 95 or Fortran 2003, and are not included in this revision of Fortran. 26 1.8.3 Nature of obsolescent features 27 Better methods existed in Fortran 90 and Fortran 95 for each obsolescent feature. It is recommended 28 that programmers use these better methods in new programs and convert existing code to these methods. 29 The obsolescent features are identified in the text of this part of ISO/IEC 1539 by a distinguishing type 30 font (1.7.7). 31 A future revision of this part of ISO/IEC 1539 might delete an obscolescent feature if its use has become 32 insignificant. 33 1.9 Normative references 34 The following referenced standards are indispensable for the application of this part of ISO/IEC 1539. 35 For dated references, only the edition cited applies. For undated references, the latest edition of the 36 7 J3/06-007r1 WORKING DRAFT 2006/09/25 referenced standard (including any amendments) applies. 1 ISO/IEC 646:1991, Information technology--ISO 7-bit coded character set for information interchange. 2 ISO 8601:1988, Data elements and interchange formats--Information interchange-- 3 Representation of dates and times. 4 ISO/IEC 9899:1999, Information technology--Programming languages--C. 5 ISO/IEC 10646-1:2000, Information technology--Universal multiple-octet coded character set (UCS)-- 6 Part 1: Architecture and basic multilingual plane. 7 IEC 60559 (1989-01), Binary floating-point arithmetic for microprocessor systems. 8 ISO/IEC 646:1991 (International Reference Version) is the international equivalent of ANSI X3.4-1986, 9 commonly known as ASCII. 10 This part of ISO/IEC 1539 refers to ISO/IEC 9899:1999 as the C International Standard. 11 Because IEC 60559 (1989-01) was originally IEEE 754-1985, Standard for binary floating-point arith- 12 metic, and is widely known by this name, this standard refers to it as the IEEE International Standard. 13 8 2006/09/25 WORKING DRAFT J3/06-007r1 2 Fortran terms and concepts 1 2.1 High level syntax 2 This clause introduces the terms associated with program units and other Fortran concepts above the 3 construct, statement, and expression levels and illustrates their relationships. The notation used in this 4 part of ISO/IEC 1539is 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. R201 program is program-unit 6 [ program-unit ] ... 7 A program shall contain exactly one main-program program-unit or a main program defined by means 8 other than Fortran, but not both. 9 R202 program-unit is main-program 10 or external-subprogram 11 or module 12 or submodule 13 or block-data 14 R1101 main-program is [ program-stmt ] 15 [ specification-part ] 16 [ execution-part ] 17 [ internal-subprogram-part ] 18 end-program-stmt 19 R203 external-subprogram is function-subprogram 20 or subroutine-subprogram 21 R1225 function-subprogram is function-stmt 22 [ specification-part ] 23 [ execution-part ] 24 [ internal-subprogram-part ] 25 end-function-stmt 26 R1233 subroutine-subprogram is subroutine-stmt 27 [ specification-part ] 28 [ execution-part ] 29 [ internal-subprogram-part ] 30 end-subroutine-stmt 31 R1104 module is module-stmt 32 [ specification-part ] 33 [ module-subprogram-part ] 34 end-module-stmt 35 R1116 submodule is submodule-stmt 36 [ specification-part ] 37 [ module-subprogram-part ] 38 end-submodule-stmt 39 R1120 block-data is block-data-stmt 40 [ specification-part ] 41 9 J3/06-007r1 WORKING DRAFT 2006/09/25 end-block-data-stmt 1 R204 specification-part is [ use-stmt ] ... 2 [ import-stmt ] ... 3 [ implicit-part ] 4 [ declaration-construct ] ... 5 R205 implicit-part is [ implicit-part-stmt ] ... 6 implicit-stmt 7 R206 implicit-part-stmt is implicit-stmt 8 or parameter-stmt 9 or format-stmt 10 or entry-stmt 11 R207 declaration-construct is derived-type-def 12 or entry-stmt 13 or enum-def 14 or format-stmt 15 or interface-block 16 or macro-definition 17 or parameter-stmt 18 or procedure-declaration-stmt 19 or specification-stmt 20 or type-declaration-stmt 21 or stmt-function-stmt 22 R208 execution-part is executable-construct 23 [ execution-part-construct ] ... 24 R209 execution-part-construct is executable-construct 25 or format-stmt 26 or entry-stmt 27 or data-stmt 28 R210 internal-subprogram-part is contains-stmt 29 [ internal-subprogram ] ... 30 R211 internal-subprogram is function-subprogram 31 or subroutine-subprogram 32 R1107 module-subprogram-part is contains-stmt 33 [ module-subprogram ] ... 34 R1108 module-subprogram is function-subprogram 35 or subroutine-subprogram 36 or separate-module-subprogram 37 R212 specification-stmt is access-stmt 38 or allocatable-stmt 39 or asynchronous-stmt 40 or bind-stmt 41 or common-stmt 42 or data-stmt 43 or dimension-stmt 44 or equivalence-stmt 45 or external-stmt 46 or intent-stmt 47 or intrinsic-stmt 48 or namelist-stmt 49 or optional-stmt 50 or pointer-stmt 51 or protected-stmt 52 or save-stmt 53 or target-stmt 54 10 2006/09/25 WORKING DRAFT J3/06-007r1 or volatile-stmt 1 or value-stmt 2 R213 executable-construct is action-stmt 3 or associate-construct 4 or block-construct 5 or case-construct 6 or critical-construct 7 or do-construct 8 or forall-construct 9 or if-construct 10 or select-type-construct 11 or where-construct 12 R214 action-stmt is allocate-stmt 13 or assignment-stmt 14 or backspace-stmt 15 or call-stmt 16 or close-stmt 17 or continue-stmt 18 or cycle-stmt 19 or deallocate-stmt 20 or endfile-stmt 21 or end-function-stmt 22 or end-program-stmt 23 or end-subroutine-stmt 24 or exit-stmt 25 or flush-stmt 26 or forall-stmt 27 or goto-stmt 28 or if-stmt 29 or inquire-stmt 30 or notify-stmt 31 or nullify-stmt 32 or open-stmt 33 or pointer-assignment-stmt 34 or print-stmt 35 or query-stmt 36 or read-stmt 37 or return-stmt 38 or rewind-stmt 39 or stop-stmt 40 or sync-all-stmt 41 or