WORKING DRAFT J3/06-007 July 11, 2006 18:25 This is an internal working document of J3. 2006/07/11 WORKING DRAFT J3/06-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 . . . . . . . . . . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.2 Main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.3 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.2.4 Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.2.5 Submodule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.3 Execution concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.1 Executable/nonexecutable statements . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.2 Statement order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.3.3 The END statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3.4 Execution sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.3.5 Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.4 Data concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.4.1 Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.4.2 Data value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.4.3 Data entity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.4.4 Scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2.4.5 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 i J3/06-007 WORKING DRAFT 2006/07/11 2.4.6 Co-array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.4.7 Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.4.8 Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5 Fundamental terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.1 Name and designator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.2 Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.5.3 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.4 Declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.5 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.6 Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.7 Intrinsic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.5.8 Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.5.9 Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 2.5.10 Companion processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 3 Characters, lexical tokens, and source form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1 Processor character set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.1 Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.2 Digits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.1.3 Underscore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.1.4 Special characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.1.5 Other characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2 Low-level syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.1 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.5.1 Macro definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 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 ob jects . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.3.1 Type specifiers and type compatibility . . . . . . . . . . . . . . . . . . . . . . . 43 4.4 Intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.4.1 Classification and specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.4.2 Integer type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.4.3 Real type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.4.4 Complex type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 4.4.5 Character type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 4.4.6 Logical type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.4.7 Bits type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 4.5 Derived types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4.5.1 Derived type concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 ii 2006/07/11 WORKING DRAFT J3/06-007 4.5.2 Derived-type definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 4.5.3 Derived-type parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 4.5.4 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 4.5.5 Type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 4.5.6 Final subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4.5.7 Type extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 4.5.8 Derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.5.9 Derived-type specifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 4.5.10 Construction of derived-type values . . . . . . . . . . . . . . . . . . . . . . . . . 76 4.5.11 Derived-type operations and assignment . . . . . . . . . . . . . . . . . . . . . . 78 4.6 Enumerations and enumerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 4.7 Construction of array values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 5 Attribute declarations and specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.2 Type declaration statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.2.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 5.2.2 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 5.2.3 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 5.3.10 INTRINSIC attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 5.3.11 OPTIONAL attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 5.3.12 PARAMETER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.13 POINTER attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.3.14 PROTECTED attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 5.3.15 SAVE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 5.3.16 TARGET attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 5.3.17 VALUE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.3.18 VOLATILE attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.4 Attribute specification statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.4.1 Accessibility statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 5.4.2 ALLOCATABLE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.3 ASYNCHRONOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.4 BIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 5.4.5 CONTIGUOUS statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.4.6 DATA statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 5.4.7 DIMENSION statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.4.8 INTENT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 5.4.9 OPTIONAL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 5.4.10 PARAMETER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 5.4.11 POINTER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 5.4.12 PROTECTED statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5.4.13 SAVE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5.4.14 TARGET statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5.4.15 VALUE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 iii J3/06-007 WORKING DRAFT 2006/07/11 5.4.16 VOLATILE statement . . . ....... . . . . . . . . . . . . . . . . . . . . . . 105 5.5 IMPLICIT statement . . . . . . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 106 5.6 NAMELIST statement . . . . . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 108 5.7 Storage association of data ob jects . ....... . . . . . . . . . . . . . . . . . . . . . . 108 5.7.1 EQUIVALENCE statement ....... . . . . . . . . . . . . . . . . . . . . . . 108 5.7.2 COMMON statement . . . . ....... . . . . . . . . . . . . . . . . . . . . . . 111 5.7.3 Restrictions on common and equivalence . . . . . . . . . . . . . . . . . . . . . . 114 6 Use of data ob jects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 6.1 Scalars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 6.1.1 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 6.1.2 Structure components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 6.1.3 Complex parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 6.1.4 Type parameter inquiry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.2 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.2.1 Whole arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 6.2.2 Array elements and array sections . . . . . . . . . . . . . . . . . . . . . . . . . . 120 6.2.3 Image selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 6.3 Dynamic association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 6.3.1 ALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 6.3.2 NULLIFY statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 6.3.3 DEALLOCATE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 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 of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 7.2 Interpretation of operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 7.2.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 7.2.2 Numeric intrinsic operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 8.1.3 IF construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 8.1.4 CASE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 8.1.5 ASSOCIATE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 iv 2006/07/11 WORKING DRAFT J3/06-007 8.1.6 SELECT TYPE construct . . . . . . . . . . . . . . . ........... . . . . 182 8.1.7 DO construct . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 185 8.1.8 EXIT statement . . . . . . . . . . . . . . . . . . . . . ........... . . . . 191 8.1.9 BLOCK construct . . . . . . . . . . . . . . . . . . . . ........... . . . . 191 8.1.10 CRITICAL construct . . . . . . . . . . . . . . . . . . ........... . . . . 192 8.2 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 193 8.2.1 GO TO statement . . . . . . . . . . . . . . . . . . . . ........... . . . . 193 8.2.2 Computed GO TO statement . . . . . . . . . . . . . ........... . . . . 193 8.2.3 Arithmetic IF statement . . . . . . . . . . . . . . . . ........... . . . . 193 8.3 CONTINUE statement . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 194 8.4 STOP statement . . . . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 194 8.5 Image execution control . . . . . . . . . . . . . . . . . . . . . . ........... . . . . 196 8.5.1 Image control statements . . . . . . . . . . . . . . . . ........... . . . . 196 8.5.2 SYNC ALL statement . . . . . . . . . . . . . . . . . ........... . . . . 198 8.5.3 SYNC TEAM statement . . . . . . . . . . . . . . . . ........... . . . . 199 8.5.4 SYNC IMAGES statement . . . . . . . . . . . . . . . ........... . . . . 201 8.5.5 NOTIFY and QUERY statements . . . . . . . . . . . ........... . . . . 202 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 9.4.5 OPEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 9.4.6 NEWUNIT= specifier in the OPEN statement . . . . . . . . . . . . . . . . . . . 220 9.4.7 CLOSE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 9.5 Data transfer statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 9.5.1 Control information list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 9.5.2 Data transfer input/output list . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 9.5.3 Execution of a data transfer input/output statement . . . . . . . . . . . . . . . 232 9.5.4 Termination of data transfer statements . . . . . . . . . . . . . . . . . . . . . . 243 9.6 Waiting on pending data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.6.1 WAIT statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.6.2 Wait operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 9.7 File positioning statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 9.7.1 BACKSPACE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 9.7.2 ENDFILE statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 9.7.3 REWIND statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 9.8 FLUSH statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 9.9 File inquiry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 9.9.1 Inquiry specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 v J3/06-007 WORKING DRAFT 2006/07/11 9.9.2 Restrictions on inquiry specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 9.9.3 Inquire by output list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 9.10 Error, end-of-record, and end-of-file conditions . . . . . . . . . . . . . . . . . . . . . . . . 255 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 . . . . . . . . . . . . . . . . . . 256 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 10.7.4 Character editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 10.7.5 Generalized editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 10.7.6 User-defined derived-type editing . . . . . . . . . . . . . . . . . . . . . . . . . . 274 10.8 Control edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.9 Character string edit descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.10 List-directed formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 10.10.1 List-directed input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 10.10.2 List-directed output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 10.11 Namelist formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 10.11.1 Namelist input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 10.11.2 Namelist output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 11 Program units . . . . . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 289 11.1 Main program . . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 289 11.2 Modules . . . . . . . . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 290 11.2.1 The USE statement and use association . . . . . . . . . . . . . . . . . . . . . . . 291 11.2.2 Submodules . . . . ............ . . . . . . . . . . . . . . . . . . . . . . 293 11.3 Block data program units . . ............ . . . . . . . . . . . . . . . . . . . . . . 294 12 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 vi 2006/07/11 WORKING DRAFT J3/06-007 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 of procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298 12.3.1 Characteristics of dummy arguments . . . . . . . . . . . . . . . . . . . . . . . . 298 12.3.2 Characteristics of function results . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4 Procedure interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4.1 Implicit and explicit interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 12.4.2 Specification of the procedure interface . . . . . . . . . . . . . . . . . . . . . . . 300 12.5 Procedure reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 12.5.1 Actual arguments, dummy arguments, and argument association . . . . . . . . . 311 12.5.2 Function reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 12.5.3 Subroutine reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 12.5.4 Resolving named procedure references . . . . . . . . . . . . . . . . . . . . . . . . 323 12.5.5 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 . . . . . . . . . . . . . . . . . . . . . . . . . 325 12.6.3 Definition and invocation of procedures by means other than Fortran . . . . . . 332 12.6.4 Statement function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 12.7 Pure procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 12.8 Elemental procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 12.8.1 Elemental procedure declaration and interface . . . . . . . . . . . . . . . . . . . 335 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 13.2.1 General rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 13.2.2 The shape of array arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.2.3 Mask arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.2.4 Arguments of collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.3 Bit model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 13.4 Numeric models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 13.5 Standard generic intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.5.1 Numeric functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.5.2 Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 13.5.3 Character functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 13.5.4 Kind functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.5 Miscellaneous type conversion functions . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.6 Numeric inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.7 Array inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.8 Other inquiry functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 13.5.9 Bit manipulation procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.10 Floating-point manipulation functions . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.11 Vector and matrix multiply functions . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.12 Array reduction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 13.5.13 Array construction functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.14 Array location functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.15 Collective subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347 13.5.16 Null function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.5.17 Allocation transfer procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 vii J3/06-007 WORKING DRAFT 2006/07/11 13.5.18 Random number subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.5.19 System environment procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 13.6 Specific names for standard intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . 349 13.7 Specifications of the standard intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . 350 13.8 Standard intrinsic modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 13.8.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 13.8.2 The IEEE modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 13.8.3 The ISO FORTRAN ENV intrinsic module . . . . . . . . . . . . . . . . . . . . 437 13.8.4 The ISO C BINDING module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 14 Exceptions and IEEE arithmetic . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 443 14.1 Derived types and constants defined in the modules . . . . . . . . . . . . . . . . . . . . . 444 14.2 The exceptions . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 445 14.3 The rounding modes . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 446 14.4 Underflow mode . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 447 14.5 Halting . . . . . . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 447 14.6 The floating point status . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 448 14.7 Exceptional values . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 448 14.8 IEEE arithmetic . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 448 14.9 Tables of the procedures . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 449 14.9.1 Inquiry functions . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 449 14.9.2 Elemental functions . . . . ......... . . . . . . . . . . . . . . . . . . . . . 450 14.9.3 Kind function . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 450 14.9.4 Elemental subroutines . . ......... . . . . . . . . . . . . . . . . . . . . . 450 14.9.5 Nonelemental subroutines ......... . . . . . . . . . . . . . . . . . . . . . 450 14.10 Specifications of the procedures . . ......... . . . . . . . . . . . . . . . . . . . . . 451 14.11 Examples . . . . . . . . . . . . . . . ......... . . . . . . . . . . . . . . . . . . . . . 466 15 Interoperability with C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 15.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 15.2 The ISO C BINDING intrinsic module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 15.2.1 Summary of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 15.2.2 Named constants and derived types in the module . . . . . . . . . . . . . . . . . 471 15.2.3 Procedures in the module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473 15.3 Interoperability between Fortran and C entities . . . . . . . . . . . . . . . . . . . . . . . 476 15.3.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476 15.3.2 Interoperability of intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . 477 15.3.3 Interoperability with C pointer types . . . . . . . . . . . . . . . . . . . . . . . . 479 15.3.4 Interoperability of derived types and C struct types . . . . . . . . . . . . . . . . 480 15.3.5 Interoperability of scalar variables . . . . . . . . . . . . . . . . . . . . . . . . . . 481 15.3.6 Interoperability of array variables . . . . . . . . . . . . . . . . . . . . . . . . . . 481 15.3.7 Interoperability of procedures and procedure interfaces . . . . . . . . . . . . . . 482 15.4 Interoperation with C global variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 15.4.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 15.4.2 Binding labels for common blocks and variables . . . . . . . . . . . . . . . . . . 485 15.5 Interoperation with C functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 15.5.1 Definition and reference of interoperable procedures . . . . . . . . . . . . . . . . 485 15.5.2 Binding labels for procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 15.5.3 Exceptions and IEEE arithmetic procedures . . . . . . . . . . . . . . . . . . . . 486 16 Scope, association, and definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 16.1 Identifiers and entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 16.2 Scope of global identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 16.3 Scope of local identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488 viii 2006/07/11 WORKING DRAFT J3/06-007 16.3.1 Classes of local identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488 16.3.2 Local identifiers that are the same as common block names . . . . . . . . . . . . 489 16.3.3 Function results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489 16.3.4 Restrictions on generic declarations . . . . . . . . . . . . . . . . . . . . . . . . . 489 16.3.5 Components, type parameters, and bindings . . . . . . . . . . . . . . . . . . . . 491 16.3.6 Argument keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 16.4 Statement and construct entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 16.5 Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492 16.5.1 Name association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492 16.5.2 Pointer association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496 16.5.3 Storage association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 16.5.4 Inheritance association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502 16.5.5 Establishing associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502 16.6 Definition and undefinition of variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 16.6.1 Definition of ob jects and subob jects . . . . . . . . . . . . . . . . . . . . . . . . . 503 16.6.2 Variables that are always defined . . . . . . . . . . . . . . . . . . . . . . . . . . 503 16.6.3 Variables that are initially defined . . . . . . . . . . . . . . . . . . . . . . . . . . 503 16.6.4 Variables that are initially undefined . . . . . . . . . . . . . . . . . . . . . . . . 504 16.6.5 Events that cause variables to become defined . . . . . . . . . . . . . . . . . . . 504 16.6.6 Events that cause variables to become undefined . . . . . . . . . . . . . . . . . . 506 16.6.7 Variable definition context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508 16.6.8 Pointer association context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508 Annex A (informative)Glossary of technical terms . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Annex B (informative)Decremental features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 B.1 Deleted features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 B.2 Obsolescent features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 B.2.1 Alternate return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 B.2.2 Computed GO TO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 B.2.3 Statement functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 B.2.4 DATA statements among executables . . . . . . . . . . . . . . . . . . . . . . . . 525 B.2.5 Assumed character length functions . . . . . . . . . . . . . . . . . . . . . . . . . 525 B.2.6 Fixed form source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 B.2.7 CHARACTER* form of CHARACTER declaration . . . . . . . . . . . . . . . . 525 Annex C (informative)Extended notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 C.1 Clause 4 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 C.1.1 Selection of the approximation methods (4.4.3) . . . . . . . . . . . . . . . . . . 527 C.1.2 Type extension and component accessibility (4.5.2.2, 4.5.4) . . . . . . . . . . . . 527 C.1.3 Abstract types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 C.1.4 Pointers (4.5.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 C.1.5 Structure constructors and generic names . . . . . . . . . . . . . . . . . . . . . . 530 C.1.6 Generic type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 532 C.1.7 Final subroutines (4.5.6, 4.5.6.2, 4.5.6.3, 4.5.6.4) . . . . . . . . . . . . . . . . . . 533 C.2 Clause 5 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 C.2.1 The POINTER attribute (5.3.13) . . . . . . . . . . . . . . . . . . . . . . . . . . 535 C.2.2 The TARGET attribute (5.3.16) . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 C.2.3 The VOLATILE attribute (5.3.18) . . . . . . . . . . . . . . . . . . . . . . . . . . 536 C.3 Clause 6 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 C.3.1 Structure components (6.1.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 C.3.2 Allocation with dynamic type (6.3.1) . . . . . . . . . . . . . . . . . . . . . . . . 538 C.3.3 Pointer allocation and association . . . . . . . . . . . . . . . . . . . . . . . . . . 539 C.4 Clause 7 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 ix J3/06-007 WORKING DRAFT 2006/07/11 C.4.1 Character assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 C.4.2 Evaluation of function references . . . . . . . . . . . . . . . . . . . . . . . . . . 540 C.4.3 Pointers in expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 C.4.4 Pointers on the left side of an assignment . . . . . . . . . . . . . . . . . . . . . . 540 C.4.5 An example of a FORALL construct containing a WHERE construct . . . . . . 541 C.4.6 Examples of FORALL statements . . . . . . . . . . . . . . . . . . . . . . . . . . 542 C.5 Clause 8 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 C.5.1 Loop control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 C.5.2 The CASE construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 C.5.3 Examples of DO constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 C.5.4 Examples of invalid DO constructs . . . . . . . . . . . . . . . . . . . . . . . . . 545 C.6 Clause 9 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546 C.6.1 External files (9.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546 C.6.2 Nonadvancing input/output (9.2.3.1) . . . . . . . . . . . . . . . . . . . . . . . . 548 C.6.3 Asynchronous input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549 C.6.4 OPEN statement (9.4.5) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550 C.6.5 Connection properties (9.4.3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551 C.6.6 CLOSE statement (9.4.7) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552 C.7 Clause 10 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552 C.7.1 Number of records (10.4, 10.5, 10.8.2) . . . . . . . . . . . . . . . . . . . . . . . . 552 C.7.2 List-directed input (10.10.1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553 C.8 Clause 11 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553 C.8.1 Main program and block data program unit (11.1, 11.3) . . . . . . . . . . . . . 553 C.8.2 Dependent compilation (11.2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 C.8.3 Examples of the use of modules . . . . . . . . . . . . . . . . . . . . . . . . . . . 556 C.8.4 Modules with submodules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562 C.9 Clause 12 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 C.9.1 Portability problems with external procedures (12.4.2.2) . . . . . . . . . . . . . 567 C.9.2 Procedures defined by means other than Fortran (12.6.3) . . . . . . . . . . . . . 567 C.9.3 Procedure interfaces (12.4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 C.9.4 Abstract interfaces (12.4) and procedure pointer components (4.5) . . . . . . . . 568 C.9.5 Argument association and evaluation (12.5.1.4) . . . . . . . . . . . . . . . . . . 570 C.9.6 Pointers and targets as arguments (12.5.1.4) . . . . . . . . . . . . . . . . . . . . 571 C.9.7 Polymorphic Argument Association (12.5.1.6) . . . . . . . . . . . . . . . . . . . 572 C.10 Clause 13 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573 C.10.1 Module for THIS IMAGE and IMAGE INDEX . . . . . . . . . . . . . . . . . . 573 C.10.2 Collective co-array subroutine variations . . . . . . . . . . . . . . . . . . . . . . 574 C.11 Clause 15 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575 C.11.1 Runtime environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575 C.11.2 Examples of Interoperation between Fortran and C Functions . . . . . . . . . . 575 C.12 Clause 16 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 C.12.1 Examples of host association (16.5.1.4) . . . . . . . . . . . . . . . . . . . . . . . 580 C.12.2 Rules ensuring unambiguous generics (16.3.4) . . . . . . . . . . . . . . . . . . . 581 C.13 Array feature notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586 C.13.1 Summary of features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586 C.13.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588 C.13.3 FORmula TRANslation and array processing . . . . . . . . . . . . . . . . . . . 592 C.13.4 Sum of squared residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 C.13.5 Vector norms: infinity-norm and one-norm . . . . . . . . . . . . . . . . . . . . . 593 C.13.6 Matrix norms: infinity-norm and one-norm . . . . . . . . . . . . . . . . . . . . . 593 C.13.7 Logical queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 C.13.8 Parallel computations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 C.13.9 Example of element-by-element computation . . . . . . . . . . . . . . . . . . . . 595 C.13.10 Bit manipulation and inquiry procedures . . . . . . . . . . . . . . . . . . . . . . 595 x 2006/07/11 WORKING DRAFT J3/06-007 Annex D (informative)Syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597 D.1 Extract of all syntax rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597 D.2 Syntax rule cross-reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641 Annex E (informative)Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657 xi J3/06-007 WORKING DRAFT 2006/07/11 xii 2006/07/11 WORKING DRAFT J3/06-007 List of Tables 2.1 Requirements on statement ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 Statements allowed in scoping units . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.1 Sp ecial characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6.1 Subscript order value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 7.1 Typ e of op erands and results for intrinsic op erators . . . . . . . . . . . . . . . . . 137 7.2 Interpretation of the numeric intrinsic op erators . . . . . . . . . . . . . . . . . . . 151 7.3 Interpretation of the character intrinsic op erator // . . . . . . . . . . . . . . . . . 151 7.4 Interpretation of the relational intrinsic op erators . . . . . . . . . . . . . . . . . . 152 7.5 Interpretation of the logical intrinsic op erators . . . . . . . . . . . . . . . . . . . . 153 7.6 The values of op erations involving logical intrinsic op erators . . . . . . . . . . . . 153 7.7 Interpretation of the bits intrinsic op erators . . . . . . . . . . . . . . . . . . . . . . 154 7.8 The values of bitwise op erations involving bits intrinsic op erators . . . . . . . . 154 7.9 Categories of op erations and relative precedence . . . . . . . . . . . . . . . . . . . 154 7.10 Typ e conformance for the intrinsic assignment statement . . . . . . . . . . . . . . 158 7.11 Numeric conversion and the assignment statement . . . . . . . . . . . . . . . . . . 160 7.12 Bits conversion and the assignment statement . . . . . . . . . . . . . . . . . . . . . 160 13.1 Characteristics of the result of NULL ( ) . . . . . . . . . . . . . . . . . . . . . . . . 413 15.1 Names of C characters with sp ecial semantics . . . . . . . . . . . . . . . . . . . . . 472 15.2 Interop erability b etween Fortran and C typ es . . . . . . . . . . . . . . . . . . . . . 477 xiii J3/06-007 WORKING DRAFT 2006/07/11 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 sub ject 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/07/11 WORKING DRAFT J3/06-007 Intro duction 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. 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 xv J3/06-007 WORKING DRAFT 2006/07/11 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/07/11 WORKING DRAFT J3/06-007 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. The third part, ISO/IEC 1539-3, defines a stan- 12 dard conditional compilation facility for Fortran. A processor conforming to part 1 need not conform to 13 ISO/IEC 1539-2 or ISO/IEC 1539-3; however, conformance to either assumes conformance to this part. 14 Throughout this publication, the term "this standard" refers to ISO/IEC 1539-1. 15 1.2 Processor 16 The combination of a computing system and the mechanism by which programs are transformed for use 17 on that computing system is called a pro cessor in this part of ISO/IEC 1539. 18 1.3 Inclusions 19 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 1.4 Exclusions 25 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 (3) the method of transcription of programs or their input or output data to or from a storage 29 medium, 30 (4) the program and processor behavior when this part of ISO/IEC 1539 fails to establish an 31 interpretation except for the processor detection and reporting requirements in items (2) to 32 1 J3/06-007 WORKING DRAFT 2006/07/11 (8) of 1.5, 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, 3 (6) the physical properties of the representation of quantities and the method of rounding, 4 approximating, or computing numeric values on a particular processor, 5 (7) the physical properties of input/output records, files, and units, or 6 (8) the physical properties and implementation of storage. 7 1.5 Conformance 8 A program (2.2.1) is a standard-conforming program if it uses only those forms and relationships 9 described herein and if the program has an interpretation according to this part of ISO/IEC 1539. A 10 program unit (2.2) conforms to this part of ISO/IEC 1539 if it can be included in a program in a manner 11 that allows the program to be standard conforming. 12 A processor conforms to this part of ISO/IEC 1539 if: 13 (1) it executes any standard-conforming program in a manner that fulfills the interpretations 14 herein, sub ject to any limits that the processor may impose on the size and complexity of 15 the program; 16 (2) it contains the capability to detect and report the use within a submitted program unit of 17 a form designated herein as obsolescent, insofar as such use can be detected by reference to 18 the numbered syntax rules and constraints; 19 (3) it contains the capability to detect and report the use within a submitted program unit of 20 an additional form or relationship that is not permitted by the numbered syntax rules or 21 constraints, including the deleted features described in Annex B; 22 (4) it contains the capability to detect and report the use within a submitted program unit of 23 an intrinsic type with a kind type parameter value not supported by the processor (4.4); 24 (5) it contains the capability to detect and report the use within a submitted program unit of 25 source form or characters not permitted by Clause 3; 26 (6) it contains the capability to detect and report the use within a submitted program of name 27 usage not consistent with the scope rules for names, labels, operators, and assignment 28 symbols in Clause 16; 29 (7) it contains the capability to detect and report the use within a submitted program unit of 30 intrinsic procedures whose names are not defined in Clause 13; and 31 (8) it contains the capability to detect and report the reason for rejecting a submitted program. 32 However, in a format specification that is not part of a FORMAT statement (10.2.1), a processor need not 33 detect or report the use of deleted or obsolescent features, or the use of additional forms or relationships. 34 A standard-conforming processor may allow additional forms and relationships provided that such ad- 35 ditions do not conflict with the standard forms and relationships. However, a standard-conforming 36 processor may allow additional intrinsic procedures even though this could cause a conflict with the 37 name of a procedure in a standard-conforming program. If such a conflict occurs and involves the name 38 of an external procedure, the processor is permitted to use the intrinsic procedure unless the name is 39 given the EXTERNAL attribute (5.3.8) in the scoping unit (16). A standard-conforming program shall 40 not use nonstandard intrinsic procedures or modules that have been added by the processor. 41 Because a standard-conforming program may place demands on a processor that are not within the 42 scope of this part of ISO/IEC 1539 or may include standard items that are not portable, such as 43 external procedures defined by means other than Fortran, conformance to this part of ISO/IEC 1539 44 does not ensure that a program will execute consistently on all or any standard-conforming processors. 45 2 2006/07/11 WORKING DRAFT J3/06-007 In some cases, this part of ISO/IEC 1539 allows the provision of facilities that are not completely specified 1 in the standard. These facilities are identified as pro cessor dep endent. They shall be provided, with 2 methods or semantics determined by the processor. 3 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 4 1.6.1 New intrinsic pro cedures 5 Each Fortran International Standard since ISO 1539:1980 (informally referred to as Fortran 77), defines 6 more intrinsic procedures than the previous one. Therefore, a Fortran program conforming to an older 7 standard may have a different interpretation under a newer standard if it invokes an external procedure 8 having the same name as one of the new standard intrinsic procedures, unless that procedure is specified 9 to have the EXTERNAL attribute. 10 1.6.2 New intrinsic data typ e and op erator 11 This part of ISO/IEC 1539 specifies a new intrinsic type, BITS, which will conflict with a derived type 12 of the same name. 13 This part of ISO/IEC 1539 specifies a new intrinsic operator, .XOR., which might conflict with a user- 14 defined operator of the same name, and has a different precedence than in previous revisions of this part 15 of ISO/IEC 1539. 16 1.6.3 Fortran 2003 compatibility 17 Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension 18 to the preceding Fortran International Standard, ISO/IEC 1539-1:2004 (Fortran 2003). Any standard- 19 conforming Fortran 2003 program that does not use a derived type called BITS, and does not use a 20 user-defined operator called .XOR., remains standard-conforming under this part of ISO/IEC 1539. 21 1.6.4 Fortran 95 compatibility 22 Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension to 23 ISO/IEC 1539-1:1997 (Fortran 95). Any standard-conforming Fortran 95 program remains standard- 24 conforming under this part of ISO/IEC 1539. The following Fortran 95 features may have different 25 interpretations in this part of ISO/IEC 1539. 26 (1) Earlier Fortran standards had the concept of printing, meaning that column one of formatted 27 output had special meaning for a processor-dependent (possibly empty) set of external 28 files. This could be neither detected nor specified by a standard-specified means. The 29 interpretation of the first column is not specified by this part of ISO/IEC 1539. 30 (2) This part of ISO/IEC 1539 specifies a different output format for real zero values in list- 31 directed and namelist output. 32 3 J3/06-007 WORKING DRAFT 2006/07/11 (3) If the processor can distinguish between positive and negative real zero, this part of ISO/IEC 1 1539 requires different returned values for ATAN2(Y,X) when X < 0 and Y is negative real 2 zero and for LOG(X) and SQRT(X) when X is complex with REAL(X) < 0 and negative 3 zero imaginary part. 4 1.6.5 Fortran 90 compatibility 5 Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this 6 part of ISO/IEC 1539 is an upward compatible extension to ISO/IEC 1539:1991 (Fortran 90). Any 7 standard-conforming Fortran 90 program that does not use one of the deleted features remains standard- 8 conforming under this part of ISO/IEC 1539. 9 The PAD= specifier in the INQUIRE statement in this part of ISO/IEC 1539 returns the value UNDE- 10 FINED if there is no connection or the connection is for unformatted input/output. Fortran 90 specified 11 YES. 12 Fortran 90 specified that if the second argument to MOD or MODULO was zero, the result was processor 13 dependent. this part of ISO/IEC 1539 specifies that the second argument shall not be zero. 14 1.6.6 FORTRAN 77 compatibility 15 Except for the deleted features noted in Annex B.1, and except as identified in this subclause, this part 16 of ISO/IEC 1539 is an upward compatible extension to ISO 1539:1980 (Fortran 77). Any standard- 17 conforming Fortran 77 program that does not use one of the deleted features noted in Annex B.1 and 18 that does not depend on the differences specified here remains standard-conforming under this part of 19 ISO/IEC 1539. This part of ISO/IEC 1539 restricts the behavior for some features that were processor 20 dependent in Fortran 77. Therefore, a standard-conforming Fortran 77 program that uses one of 21 these processor-dependent features may have a different interpretation under this part of ISO/IEC 1539, 22 yet remain a standard-conforming program. The following Fortran 77 features may have different 23 interpretations in this part of ISO/IEC 1539. 24 (1) Fortran 77 permitted a processor to supply more precision derived from a real constant 25 than can be represented in a real datum when the constant is used to initialize a data ob ject 26 of type double precision real in a DATA statement. This part of ISO/IEC 1539 does not 27 permit a processor this option. 28 (2) If a named variable that was not in a common block was initialized in a DATA statement and 29 did not have the SAVE attribute specified, Fortran 77 left its SAVE attribute processor 30 dependent. This part of ISO/IEC 1539 specifies (5.4.6) that this named variable has the 31 SAVE attribute. 32 (3) Fortran 77 specified that the number of characters required by the input list was to be 33 less than or equal to the number of characters in the record during formatted input. This 34 part of ISO/IEC 1539 specifies (9.5.3.4.2) that the input record is logically padded with 35 blanks if there are not enough characters in the record, unless the PAD= specifier with the 36 value 'NO' is specified in an appropriate OPEN or READ statement. 37 (4) A value of 0 for a list item in a formatted output statement will be formatted in a different 38 form for some G edit descriptors. In addition, this part of ISO/IEC 1539 specifies how 39 rounding of values will affect the output field form, but Fortran 77 did not address this 40 issue. Therefore, some Fortran 77 processors may produce an output form different from 41 the output form produced by Fortran 2003 processors for certain combinations of values and 42 G edit descriptors. 43 (5) If the processor can distinguish between positive and negative real zero, the behavior of the 44 SIGN intrinsic function when the second argument is negative real zero is changed by this 45 part of ISO/IEC 1539. 46 4 2006/07/11 WORKING DRAFT J3/06-007 1.7 Notation used in this part of ISO/IEC 1539 1 1.7.1 Applicability of requirements 2 In this part of ISO/IEC 1539, "shall" is to be interpreted as a requirement; conversely, "shall not" is 3 to be interpreted as a prohibition. Except where stated otherwise, such requirements and prohibitions 4 apply to programs rather than processors. 5 1.7.2 Informative notes 6 Informative notes of explanation, rationale, examples, and other material are interspersed with the 7 normative body of this part of ISO/IEC 1539. The informative material is nonnormative; it is identified 8 by being in shaded, framed boxes that have numbered headings beginning with "NOTE." 9 1.7.3 Syntax rules 10 Syntax rules describe the forms that Fortran lexical tokens, statements, and constructs may take. These 11 syntax rules are expressed in a variation of Backus-Naur form (BNF) with the following conventions. 12 (1) Characters from the Fortran character set (3.1) are interpreted literally as shown, except 13 where otherwise noted. 14 (2) Lower-case italicized letters and words (often hyphenated and abbreviated) represent gen- 15 eral syntactic classes for which particular syntactic entities shall be substituted in actual 16 statements. 17 Common abbreviations used in syntactic terms are: 18 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: 19 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 20 one- or two-digit clause number and nn is a two-digit sequence number within that clause. 21 The syntax rules are distributed as appropriate throughout the text, and are referenced by 22 number as needed. Some rules in Clauses 2 and 3 are more fully described in later clauses; in 23 such cases, the clause number s is the number of the later clause where the rule is repeated. 24 (5) The syntax rules are not a complete and accurate syntax description of Fortran, and cannot 25 be used to generate a Fortran parser automatically; where a syntax rule is incomplete, it is 26 restricted by corresponding constraints and text. 27 NOTE 1.2 An example of the use of the syntax rules is: digit-string is digit [ digit ] ... 5 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 1.2 (cont.) 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 Csnn, where s is a one- or two-digit 2 clause number and nn is a two-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. 27 (2) The rules on statement ordering are described rigorously in the definition of program-unit 28 (R202). Expression hierarchy is described rigorously in the definition of expr (R722). 29 6 2006/07/11 WORKING DRAFT J3/06-007 (3) The suffix "-spec " is used consistently for specifiers, such as input/output statement speci- 1 fiers. It also is used for type declaration attribute specifications (for example, "array-spec " 2 in R510), and in a few other cases. 3 (4) Where reference is made to a type parameter, including the surrounding parentheses, the 4 suffix "-selector " is used. See, for example, "kind-selector " (R405) and "length-selector " 5 (R421). 6 (5) The term "subscript " (for example, R619, R620, and R621) is used consistently in array 7 definitions. 8 1.7.7 Text conventions 9 In the descriptive text, an equivalent English word is frequently used in place of a syntactic term. 10 Particular statements and attributes are identified in the text by an upper-case keyword, e.g., "END 11 statement". Boldface words are used in the text where they are first defined with a specialized meaning. 12 The descriptions of obsolescent features appear in a smaller type size. 13 NOTE 1.3 This sentence is an example of the type size used for obsolescent features. 1.8 Deleted and obsolescent features 14 1.8.1 General 15 This part of ISO/IEC 1539 protects the users' investment in existing software by including all but five 16 of the language elements of Fortran 90 that are not processor dependent. This part of ISO/IEC 1539 17 identifies two categories of outmoded features. There are five in the first category, deleted features, 18 which consists of features considered to have been redundant in Fortran 77 and largely unused in 19 Fortran 90. Those in the second category, obsolescent features, are considered to have been redundant 20 in Fortran 90 and Fortran 95, but are still frequently used. 21 1.8.2 Nature of deleted features 22 Better methods existed in Fortran 77 for each deleted feature. These features were not included in 23 Fortran 95 or Fortran 2003, and are not included in this revision of Fortran. 24 1.8.3 Nature of obsolescent features 25 Better methods existed in Fortran 90 and Fortran 95 for each obsolescent feature. It is recommended 26 that programmers use these better methods in new programs and convert existing code to these methods. 27 The obsolescent features are identified in the text of this part of ISO/IEC 1539 by a distinguishing type 28 font (1.7.7). 29 A future revision of this part of ISO/IEC 1539 might delete an obscolescent feature if its use has become 30 insignificant. 31 1.9 Normative references 32 The following referenced standards are indispensable for the application of this part of ISO/IEC 1539. 33 For dated references, only the edition cited applies. For undated references, the latest edition of the 34 referenced standard (including any amendments) applies. 35 ISO/IEC 646:1991, Information technology--ISO 7-bit coded character set for information interchange. 36 7 J3/06-007 WORKING DRAFT 2006/07/11 ISO 8601:1988, Data elements and interchange formats--Information interchange-- 1 Representation of dates and times. 2 ISO/IEC 9899:1999, Information technology--Programming languages--C. 3 ISO/IEC 10646-1:2000, Information technology--Universal multiple-octet coded character set (UCS)-- 4 Part 1: Architecture and basic multilingual plane. 5 IEC 60559 (1989-01), Binary floating-point arithmetic for microprocessor systems. 6 ISO/IEC 646:1991 (International Reference Version) is the international equivalent of ANSI X3.4-1986, 7 commonly known as ASCII. 8 This part of ISO/IEC 1539 refers to ISO/IEC 9899:1999 as the C International Standard. 9 Because IEC 60559 (1989-01) was originally IEEE 754-1985, Standard for binary floating-point arith- 10 metic, and is widely known by this name, this standard refers to it as the IEEE International Standard. 11 8 2006/07/11 WORKING DRAFT J3/06-007 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 standard 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. 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-007 WORKING DRAFT 2006/07/11 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 al locatable-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/07/11 WORKING DRAFT J3/06-007 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 foral l-construct 9 or if-construct 10 or select-type-construct 11 or where-construct 12 R214 action-stmt is al locate-stmt 13 or assignment-stmt 14 or backspace-stmt 15 or cal l-stmt 16 or close-stmt 17 or continue-stmt 18 or cycle-stmt 19 or deal locate-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 foral l-stmt 27 or goto-stmt 28 or if-stmt 29 or inquire-stmt 30 or notify-stmt 31 or nul lify-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-al l-stmt 41 or sync-images-stmt 42 or sync-memory-stmt 43 or sync-team-stmt 44 or wait-stmt 45 or where-stmt 46 or write-stmt 47 or 48 arithmetic-if-stmt or 49 computed-goto-stmt C201 (R208) An execution-part shall not contain an end-function-stmt , end-program-stmt , or end- 50 subroutine-stmt . 51 Additionally, an EXPAND statement may occur anywhere that any statement may occur other than 52 11 J3/06-007 WORKING DRAFT