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 2006/07/11 as the first statement of a program unit. The syntax rules are applied to the program after macro 1 expansion, i.e. with each EXPAND statement replaced by the statements it produces. 2 2.2 Program unit concepts 3 Program units are the fundamental components of a Fortran program. A program unit may be a main 4 program, an external subprogram, a module, a submodule, or a block data program unit. A subprogram 5 may be a function subprogram or a subroutine subprogram. A module contains definitions that are to 6 be made accessible to other program units. A submodule is a extension of a module; it may contain 7 the definitions of procedures declared in a module or another submodule. A block data program unit is 8 used to specify initial values for data ob jects in named common blocks. Each type of program unit is 9 described in Clause 11 or 12. An external subprogram is a subprogram that is not in a main program, 10 a module, a submodule, or another subprogram. An internal subprogram is a subprogram that is in 11 a main program or another subprogram. A mo dule subprogram is a subprogram that is in a module 12 or submodule but is not an internal subprogram. 13 A program unit consists of a set of nonoverlapping scoping units. A scoping unit is 14 (1) a program unit or subprogram, excluding any scoping units in it, 15 (2) a derived-type definition (4.5.2), or 16 (3) an interface body, excluding any scoping units in it. 17 A scoping unit that immediately surrounds another scoping unit is called the host scoping unit (often 18 abbreviated to host). A module or submodule is also the host scoping unit of its child submodules. 19 2.2.1 Program 20 A program consists of exactly one main program, any number (including zero) of other kinds of program 21 units, and any number (including zero) of external procedures and other entities defined by means other 22 than Fortran. 23 NOTE 2.2 There is a restriction that there shall be no more than one unnamed block data program unit (11.3). This standard places no ordering requirement on the program units that constitute a program, but because the public portions of a module are required to be available by the time a module reference (11.2.1) is processed, a processor may require a particular order of processing of the program units. 2.2.2 Main program 24 The Fortran main program is described in 11.1. 25 2.2.3 Pro cedure 26 A pro cedure encapsulates an arbitrary sequence of actions that may be invoked directly during program 27 execution. Procedures are either functions or subroutines. A function is a procedure that is invoked 28 in an expression; its invocation causes a value to be computed which is then used in evaluating the 29 expression. The variable that returns the value of a function is called the result variable. A subroutine 30 is a procedure that is invoked in a CALL statement, by a defined assignment statement, or by some 31 operations on derived-type entities. Unless it is a pure procedure, a subroutine may be used to change 32 the program state by changing the values of any of the data ob jects accessible to the subroutine; unless 33 it is a pure procedure, a function may do this in addition to computing the function value. 34 12 2006/07/11 WORKING DRAFT J3/06-007 Procedures are described further in Clause 12. 1 2.2.3.1 External pro cedure 2 An external pro cedure is a procedure that is defined by an external subprogram or by means other 3 than Fortran. An external procedure may be invoked by the main program or by any procedure of a 4 program. 5 2.2.3.2 Mo dule pro cedure 6 A mo dule pro cedure is a procedure that is defined by a module subprogram (R1108). The module or 7 submodule containing the subprogram is the host scoping unit of the module procedure. 8 2.2.3.3 Internal pro cedure 9 An internal pro cedure is a procedure that is defined by an internal subprogram (R211). The containing 10 main program or subprogram is the host scoping unit of the internal procedure. An internal procedure 11 is local to its host in the sense that the internal procedure is accessible within the host scoping unit and 12 all its other internal procedures but is not accessible elsewhere. 13 2.2.3.4 Interface blo ck 14 An interface b o dy describes an abstract interface or the interface of a dummy procedure, external 15 procedure, procedure pointer, or type-bound procedure. 16 An interface blo ck is a specific interface block, an abstract interface block, or a generic interface block. 17 A specific interface block is a collection of interface bodies. A generic interface block can also be used 18 to specify that a procedure can be invoked 19 (1) by using a generic name, 20 (2) by using a defined operator, 21 (3) by using a defined assignment, or 22 (4) for derived-type input/output. 23 2.2.4 Module 24 A mo dule contains (or accesses from other modules) definitions that are to be made accessible to other 25 program units. These definitions include data ob ject declarations, type definitions, procedure definitions, 26 and interface blocks. A scoping unit in another program unit may access the definitions in a module. 27 Modules are further described in Clause 11. 28 2.2.5 Submo dule 29 A submo dule is a program unit that extends a module or another submodule. It may provide definitions 30 (12.6) for procedures whose interfaces are declared (12.4.2.1) in an ancestor module or submodule. It 31 may also contain declarations and definitions of other entities, which are accessible in its descendants. 32 An entity declared in a submodule is not accessible by use association unless it is a module procedure 33 whose interface is declared in the ancestor module. Submodules are further described in Clause 11. 34 NOTE 2.3 The scoping unit of a submodule accesses the scoping unit of its parent module or submodule by host association. 13 J3/06-007 WORKING DRAFT 2006/07/11 2.3 Execution concepts 1 Each Fortran statement is classified as either an executable statement or a nonexecutable statement. 2 There are restrictions on the order in which statements may appear in a program unit, and not all 3 executable statements may appear in all contexts. 4 2.3.1 Executable/nonexecutable statements 5 Program execution is a sequence, in time, of actions. An executable statement is an instruction to 6 perform or control one or more of these actions. Thus, the executable statements of a program unit 7 determine the behavior of the program unit. The executable statements are all of those that make up 8 the syntactic class executable-construct . 9 Nonexecutable statements do not specify actions; they are used to configure the program environment 10 in which actions take place. The nonexecutable statements are all those not classified as executable. 11 2.3.2 Statement order 12 The syntax rules of clause 2.1 specify the statement order within program units and subprograms. These 13 rules are illustrated in Table 2.1 and Table 2.2. Table 2.1 shows the ordering rules for statements and 14 applies to all program units, subprograms, and interface bodies. Vertical lines delineate varieties of 15 statements that may be interspersed and horizontal lines delineate varieties of statements that shall not 16 be interspersed. Internal or module subprograms shall follow a CONTAINS statement. Between USE 17 and CONTAINS statements in a subprogram, nonexecutable statements generally precede executable 18 statements, although the ENTRY statement, FORMAT statement, and DATA statement may appear 19 among the executable statements. Table 2.2 shows which statements are allowed in a scoping unit. 20 Table 2.1: Requirements on statement ordering PROGRAM, FUNCTION, SUBROUTINE, MODULE, SUBMODULE, or BLOCK DATA statement USE statements IMPORT statements IMPLICIT NONE PARAMETER IMPLICIT statements statements Derived-type definitions, FORMAT interface blocks, and PARAMETER type declaration statements, ENTRY and DATA enumeration definitions, statements statements procedure declarations, specification statements, and statement function statements Executable DATA constructs statements CONTAINS statement Internal subprograms or module subprograms END statement 14 2006/07/11 WORKING DRAFT J3/06-007 Table 2.2: Statements allowed in scoping units Kind of scoping unit: Main Module or Block External Module Internal Interface program submodule data subprog subprog subprog body USE statement Yes Yes Yes Yes Yes Yes Yes IMPORT statement No No No No No No Yes ENTRY statement No No No Yes Yes No No FORMAT statement Yes No No Yes Yes Yes No Misc. decls (see note) Yes Yes Yes Yes Yes Yes Yes DATA statement Yes Yes Yes Yes Yes Yes No Derived-type definition Yes Yes Yes Yes Yes Yes Yes Interface block Yes Yes No Yes Yes Yes Yes Executable statement Yes No No Yes Yes Yes No CONTAINS statement Yes Yes No Yes Yes No No Statement function stmt. Yes No No Yes Yes Yes No Notes for Table 2.2: 1) Misc. declarations are PARAMETER statements, IMPLICIT statements, type declaration statements, enumeration definitions, procedure declaration statements, and specification statements. 2) The scoping unit of a module or submodule does not include any module sub- programs that it contains. 2.3.3 The END statement 1 An end-program-stmt , end-function-stmt , end-subroutine-stmt , end-sep-subprogram-stmt , end-module- 2 stmt , end-submodule-stmt , or end-block-data-stmt is an END statement. Each program unit, module 3 subprogram, and internal subprogram shall have exactly one END statement. The end-program-stmt , 4 end-function-stmt , end-subroutine-stmt , and end-sep-subprogram-stmt statements are executable, and 5 may be branch target statements (8.2). Executing an end-program-stmt causes normal termination of 6 execution of the program. Executing an end-function-stmt , end-subroutine-stmt , or end-sep-subprogram- 7 stmt is equivalent to executing a return-stmt with no scalar-int-expr . 8 The end-module-stmt , end-submodule-stmt , and end-block-data-stmt statements are nonexecutable. 9 2.3.4 Execution sequence 10 If a program contains a Fortran main program, execution of the program begins with the first executable 11 construct of the main program. The execution of a main program or subprogram involves execution of 12 the executable constructs within its scoping unit. When a procedure is invoked, execution begins with 13 the first executable construct appearing after the invoked entry point. With the following exceptions, 14 the effect of execution is as if the executable constructs are executed in the order in which they appear 15 in the main program or subprogram until a STOP, RETURN, or END statement is executed. 16 (1) Execution of a branching statement (8.2) changes the execution sequence. These statements 17 explicitly specify a new starting place for the execution sequence. 18 (2) CASE constructs, DO constructs, IF constructs, and SELECT TYPE constructs contain 19 an internal statement structure and execution of these constructs involves implicit internal 20 branching. See Clause 8 for the detailed semantics of each of these constructs. 21 (3) END=, ERR=, and EOR= specifiers may result in a branch. 22 (4) 23 Alternate returns may result in a branch. Internal subprograms may precede the END statement of a main program or a subprogram. The 24 execution sequence excludes all such definitions. 25 15 J3/06-007 WORKING DRAFT 2006/07/11 The relative ordering of the exeuction sequences of different images can be affected by image control 1 statements (8.5.1). 2 Normal termination of execution of the program occurs on all images if a STOP statement or end- 3 program-stmt is executed immediately after a SYNC ALL (8.5.2) statement on all images. The stop 4 code, if any, and warnings of any exceptions that are signaling (8.4) shall be made available only for 5 image 1. 6 J3 internal note Unresolved Technical Issue 3 Since there is only one program, I do not see how "Normal termination of execution" can be qualified by "occurs on all images". If execution of the program is terminated, since that execution is all of the image executions, each image is terminated. This is straightforward from the first sentence of 2.3.5. It was suggested to me that the issue was whether termination was "normal" on all images; well, if it is normal for the whole program, it is normal on all images. J3 internal note Unresolved Technical Issue 4 "shall be made available only for image 1" is problematic since after normal termination no images exist. I do not understand what is meant here. Maybe (?) it is that any signalling exception on any image other than 1 is not reported?" Subgroup says "This is in direct response to complaints about MPI programs printing "Fortran STOP" to the screen 10000 times." The editor says: There is nothing in the standard which prevents a processor from printing "Fortran STOP" to the screen 10000 times even in single-process Fortran 77. I think that is purely and simply a matter of QoI (or possibly even outwith the scope). If we want to say something here it should almost certainly be *a note* along the lines that since a program is a program, however many "images" it contains, that processors should be circumspect about reporting identical statuses multiple times on image termination. Anyway, failure to report signalling exceptions just because they are on images other than the image numbered "1" is poor design. The consequences of overflow and invalid operations are just as potentially serious whether the computation takes part on image 1 or some other image. It would be preferable not to disallow a conscientious processor from reporting such problems. Finally, this is a small detail. There is currently no mention of what happens with signalling exceptions in clause 2, and so no need to mention how it differs with co-arrays. Therefore the second sentence should be deleted. When a STOP or end-program-stmt that does not immediately follow a SYNC ALL statement is executed 7 on an image, normal termination occurs on that image. The stop code, if any, and warnings of any 8 exceptions that are signaling shall be made available only for that image. The executions of all other 9 images are terminated. 10 16 2006/07/11 WORKING DRAFT J3/06-007 J3 internal note Unresolved Technical Issue 5 This is inconsistent with the behaviour after SYNC ALL (unless image 1 always restarts first after a SYNC ALL). This is going to cause headaches for the implementors (STOP has multiple meanings, and does different things according to context - ugh). There seems to be two competing theories for what STOP is for here: (1) a programmer-initiated error termination (2) a normal termination and the decision as to which STOP is which kind is being determined by whether it is preceded by SYNC ALL (not that this is adequately defined, see J3 notes in the STOP statement section). In previous Fortrans, STOP is normal termination. That's it. It is not "CALL ABORT". If we want a second kind of STOP, perhaps we should consider adding a second kind of STOP, perhaps spelled QUICKSTOP or something. And of course the wording is bad ("made available") but wordsmithing can wait until the text is fixed or deleted. NOTE 2.4 When a STOP or end-program-stmt statement is executed on an image, how soon termination takes place on another image is processor dependent. J3 internal note Unresolved Technical Issue 6 Presumably this is referring to the "error STOP" (or the "STOP not after a SYNC ALL") situation, since it does not appear to be processor-dependent in the "normal STOP" case. Or perhaps it is... again, this doesn't seem to be well-defined.". 2.3.5 Images 1 A Fortran program executes as if it were replicated a number of times (which may be one), the number 2 of replications remaining fixed during execution of the program. 3 J3 internal note Unresolved Technical Issue 1 In post-draft discussions it has been variously and contradictorily contended that the concept of program does not include all the images. It is certainly contradictory in the edits. Look, if we *have* a definition of single-threaded Fortran (like we used to) then we can layer ***SOMETHING ELSE*** on top of it and replicate as we please without affecting the single- threaded concepts. But tightly integrating them does not give us this ability. If "program" is meant to include only the execution and data entities of a single image, we still need a name for the concept that is the "Co-Fortran program" providing the semantics for the whole "Co-Fortran" thing. Each copy is called an image and has its own set of data ob jects and procedure pointers. Each image 4 executes asynchronously. 5 NOTE 2.5 The programmer controls the progress of execution in each image through explicit use of Fortran control constructs (8.1, 8.2). The image control statements (8.5.1) affect the relative progress of execution between images. Co-arrays (2.4.6) provide a mechanism for accessing data on one image from another image. 17 J3/06-007 WORKING DRAFT 2006/07/11 J3 internal note Unresolved Technical Issue 2 Missing from the "own set" is execution state, however we say it. It has been contended that all of that is implicit in "executes asynchronously", but since there are many points of non-asychronous behaviour - e.g. in image termination effects - just how far that extends is emphatically NOT obvious. IEEE modes, external units, file system, we all need to know. Otherwise it is not standardised (a situation we should all hope to avoid). Either we should say that "All other entities are shared between the images" (after putting execution state into the "own" set!), or we should specify the entities that are shared; at least then any entity that does not fall into either list can be seen to be a problem... I suppose I recommend the latter course. Once this is fixed the edit at [178:36] can be turned into a note instead. (Actually, I think the whole paragraph at 178:35-36 should probably be inside the note, since we already say this under "scoping".) Each image is identified by an image index, which is an integer value in the range one to the number 1 of images. 2 A processor shall contain the capability of executing a program on a single image. 3 NOTE 2.6 A processor might allow the number of images to be chosen at compile time, link time, or run time. It might be the same as the number of CPUs but this is not required. Compiling for a single image might permit the optimizer to eliminate overhead associated with parallel execution. Portable programs should not make assumptions about the exact number of images. The maximum number of images may be limited due to architectural constraints. A team is a set of images formed by invoking the intrinsic collective subroutine FORM TEAM (13.7.69) 4 for the purposes of collaboration. A team is identified by a scalar variable of type IMAGE TEAM 5 (13.8.3.5). 6 2.4 Data concepts 7 Nonexecutable statements are used to specify the characteristics of the data environment. This includes 8 typing variables, declaring arrays, and defining new types. 9 2.4.1 Type 10 A typ e is a named category of data that is characterized by a set of values, a syntax for denoting 11 these values, and a set of operations that interpret and manipulate the values. This central concept is 12 described in 4.1. 13 A type may be parameterized, in which case the set of data values, the syntax for denoting them, and 14 the set of operations depend on the values of one or more parameters. Such a parameter is called a typ e 15 parameter (4.2). 16 There are two categories of types: intrinsic types and derived types. 17 2.4.1.1 Intrinsic typ e 18 An intrinsic typ e is a type that is defined by the language, along with operations, and is always 19 accessible. The intrinsic types are integer, real, complex, character, logical, and bits. The properties of 20 intrinsic types are described in 4.4. The intrinsic type parameters are KIND and LEN. 21 The kind typ e parameter indicates the representation method for the specified type. 22 18 2006/07/11 WORKING DRAFT J3/06-007 2.4.1.2 Derived typ e 1 A derived typ e is a type that is defined by a type definition or by an intrinsic module. A scalar ob ject of 2 derived type is called a structure (4.5). Derived types may be parameterized. Assignment of structures 3 is defined intrinsically (7.4.1.3), but there are no intrinsic operations for structures. For each derived 4 type, a structure constructor is available to provide values (4.5.10). In addition, data ob jects of derived 5 type may be used as procedure arguments and function results, and may appear in input/output lists. 6 If additional operations are needed for a derived type, they shall be supplied as procedure definitions. 7 Derived types are described further in 4.5. 8 2.4.2 Data value 9 Each intrinsic type has associated with it a set of values that a datum of that type may take, depending 10 on the values of the type parameters. The values for each intrinsic type are described in 4.4. The values 11 that ob jects of a derived type may assume are determined by the type definition, type parameter values, 12 and the sets of values of its components. 13 2.4.3 Data entity 14 A data entity is a data ob ject, the result of the evaluation of an expression, or the result of the execution 15 of a function reference (called the function result). A data entity has a type and type parameters; it 16 may have a data value (an exception is an undefined variable). Every data entity has a rank and is thus 17 either a scalar or an array. 18 2.4.3.1 Data object 19 A data ob ject (often abbreviated to ob ject) is a constant (4.1.2), a variable (6), or a subob ject of a 20 constant. The type and type parameters of a named data ob ject may be specified explicitly (5.2) or 21 implicitly (5.5). 22 Sub ob jects are portions of certain ob jects that may be referenced and defined (variables only) inde- 23 pendently of the other portions. These include portions of arrays (array elements and array sections), 24 portions of character strings (substrings), portions of complex ob jects (real and imaginary parts), and 25 portions of structures (components). Subob jects are themselves data ob jects, but subob jects are refer- 26 enced only by ob ject designators or intrinsic functions. A subob ject of a variable is a variable. Subob jects 27 are described in Clause 6. 28 Ob jects referenced by a name are: 29 a named scalar (a scalar ob ject) 30 a named array (an array ob ject) Subob jects referenced by an ob ject designator are: 31 an array element (a scalar subob ject) an array section (an array subob ject) a structure component (a scalar or an array subob ject) 32 a substring (a scalar subob ject) 2.4.3.1.1 Variable 33 A variable may have a value and may be defined and redefined during execution of a program. 34 A named lo cal variable of the scoping unit of a module, submodule, main program, or subprogram, is a 35 named variable that is a local entity of the scoping unit, is not a dummy argument, is not in COMMON, 36 19 J3/06-007 WORKING DRAFT 2006/07/11 does not have the BIND attribute, and is not accessed by use or host association. A named local variable 1 of a BLOCK construct is a named variable that is declared in that construct, is not in COMMON, does 2 not have the BIND attribute, and is not accessed by use association. A subob ject of a named local 3 variable is also a local variable. 4 2.4.3.1.2 Constant 5 A constant has a value and cannot become defined, redefined, or undefined during execution of a 6 program. A constant with a name is called a named constant and has the PARAMETER attribute 7 (5.3.12). A constant without a name is called a literal constant (4.4). 8 2.4.3.1.3 Sub object of a constant 9 A sub ob ject of a constant is a portion of a constant. The portion referenced may depend on the 10 value of a variable. 11 NOTE 2.7 For example, given: CHARACTER (LEN = 10), PARAMETER :: DIGITS = '0123456789' CHARACTER (LEN = 1) :: DIGIT INTEGER :: I ... DIGIT = DIGITS (I:I) DIGITS is a named constant and DIGITS (I:I) designates a subob ject of the constant DIGITS. 2.4.3.2 Expression 12 An expression (7.1) produces a data entity when evaluated. An expression represents either a data 13 reference or a computation; it is formed from operands, operators, and parentheses. The type, type 14 parameters, value, and rank of an expression result are determined by the rules in Clause 7. 15 2.4.3.3 Function reference 16 A function reference (12.5.2) produces a data entity when the function is executed during expression 17 evaluation. The type, type parameters, and rank of a function result are determined by the interface of 18 the function (12.3.2). The value of a function result is determined by execution of the function. 19 2.4.4 Scalar 20 A scalar is a datum that is not an array. Scalars may be of any type. 21 NOTE 2.8 A structure is scalar even if it has arrays as components. The rank of a scalar is zero. The shape of a scalar is represented by a rank-one array of size zero. 22 2.4.5 Array 23 An array is a set of scalar data, all of the same type and type parameters, whose individual elements 24 are arranged in a rectangular pattern. An array element is one of the individual elements in the array 25 and is a scalar. An array section is a subset of the elements of an array and is itself an array. 26 20 2006/07/11 WORKING DRAFT J3/06-007 An array may have up to fifteen dimensions, and any extent (number of elements) in any dimension. 1 The rank of the array is the number of dimensions; its size is the total number of elements, which is 2 equal to the product of the extents. An array may have zero size. The shap e of an array is determined 3 by its rank and its extent in each dimension, and may be represented as a rank-one array whose elements 4 are the extents. All named arrays shall be declared, and the rank of a named array is specified in its 5 declaration. The rank of a named array, once declared, is constant; the extents may be constant or may 6 vary during execution. 7 Two arrays are conformable if they have the same shape. A scalar is conformable with any array. Any 8 intrinsic operation defined for scalar ob jects may be applied to conformable ob jects. Such operations 9 are performed element-by-element to produce a resultant array conformable with the array operands. 10 Element-by-element operation means corresponding elements of the operand arrays are involved in a 11 scalar operation to produce the corresponding element in the result array. Such an operation is described 12 as elemental. 13 NOTE 2.9 If an elemental operation is intrinsically pure or is implemented by a pure elemental function (12.8), the element operations may be performed simultaneously or in any order. A rank-one array may be constructed from scalars and other arrays and may be reshaped into any 14 allowable array shape (4.7). 15 Arrays may be of any type and are described further in 6.2. 16 2.4.6 Co-array 17 A co-array is a data entity that is declared with nonzero co-rank and may be referenced or defined by 18 any image. It may be a scalar or an array. For each co-array on an image, there is a corresponding 19 co-array with the same type, type parameters, and bounds on every other image. The co-array on any 20 image may be accessed by using co-subscript s. On its own image, a co-array may be accessed without 21 use of co-subscripts. 22 The co-rank of a co-array is the number of co-dimensions. The co-size of a co-array is always equal to 23 the number of images. 24 J3 internal note Unresolved Technical Issue 7 The term "co-dimension" is not defined. It might be better to define co-array in terms of being a rectangular set of ob jects in co-rank "co-dimensions" etc., similarly to how we define arrays. An ob ject whose designator includes an image-selector is a co-indexed ob ject. For each co-array, 25 co-subscripts are mapped to image indices in the same way as Fortran array subscripts are mapped to 26 the position of the array element in array element order (6.2.2.2). 27 Intrinsic procedures are provided for mapping between an image index and a list of co-subscripts. 28 NOTE 2.10 The mechanism for an image to reference and define a co-array on another image might vary according to the hardware. On a shared-memory machine, a co-array could be implemented as a section of an array of higher rank. On a distributed-memory machine with separate physical memory for each image, a processor might store a co-array at the same virtual address in each physical memory. 21 J3/06-007 WORKING DRAFT 2006/07/11 2.4.7 Pointer 1 A data p ointer is a data entity that has the POINTER attribute. A pro cedure p ointer is a procedure 2 entity that has the POINTER attribute. A p ointer is either a data pointer or a procedure pointer. 3 A pointer is asso ciated with a target by pointer assignment (7.4.2). A data pointer may also be 4 associated with a target by allocation (6.3.1). A pointer is disasso ciated following execution of a 5 NULLIFY statement, following pointer assignment with a disassociated pointer, by default initialization, 6 or by explicit initialization. A data pointer may also be disassociated by execution of a DEALLOCATE 7 statement. A disassociated pointer is not associated with a target (16.5.2). 8 A pointer that is not associated shall not be referenced or defined. 9 If a data pointer is an array, the rank is declared, but the extents are determined when the pointer is 10 associated with a target. 11 2.4.8 Storage 12 Many of the facilities of this standard make no assumptions about the physical storage characteristics of 13 data ob jects. However, program units that include storage association dependent features shall observe 14 the storage restrictions described in 16.5.3. 15 2.5 Fundamental terms 16 For the purposes of this standard, the definitions of terms in this subclause apply. 17 2.5.1 Name and designator 18 A name is used to identify a program constituent, such as a program unit, named variable, named 19 constant, dummy argument, or derived type. The rules governing the construction of names are given 20 in 3.2.1. A designator is a name followed by zero or more component selectors, complex part selectors, 21 array section selectors, array element selectors, image selectors, and substring selectors. 22 An ob ject designator is a designator for a data ob ject. A pro cedure designator is a designator for 23 a procedure. 24 NOTE 2.11 An ob ject name is a special case of an ob ject designator. 2.5.2 Keyword 25 The term keyword is used in two ways. 26 (1) It is used to describe a word that is part of the syntax of a statement. These keywords are 27 not reserved words; that is, names with the same spellings are allowed. In the syntax rules, 28 such keywords appear literally. In descriptive text, this meaning is denoted by the term 29 "keyword" without any modifier. Examples of statement keywords are: IF, READ, UNIT, 30 KIND, and INTEGER. 31 (2) It is used to denote names that identify items in a list. In actual argument lists, type 32 parameter lists, and structure constructors, items may be identified by a preceding keyword = 33 rather than their position within the list. An argument keyword is the name of a dummy 34 argument in the interface for the procedure being referenced, a typ e parameter keyword 35 is the name of a type parameter in the type being specified, and a comp onent keyword 36 is the name of a component in a structure constructor. 37 22 2006/07/11 WORKING DRAFT J3/06-007 R215 keyword is name 1 NOTE 2.12 Use of keywords rather than position to identify items in a list can make such lists more readable and allows them to be reordered. This facilitates specification of a list in cases where optional items are omitted. 2.5.3 Association 2 Asso ciation is name association (16.5.1), pointer association (16.5.2), storage association (16.5.3), 3 or inheritance association (16.5.4). Name association is argument association, host association, use 4 association, linkage association, or construct association. 5 Storage association causes different entities to use the same storage. Any association permits an entity 6 to be identified by different names in the same scoping unit or by the same name or different names in 7 different scoping units. 8 2.5.4 Declaration 9 The term declaration refers to the specification of attributes for various program entities. Often this 10 involves specifying the type of a named data ob ject or specifying the shape of a named array ob ject. 11 2.5.5 Definition 12 The term definition is used in two ways. 13 (1) It refers to the specification of derived types and procedures. 14 (2) When an ob ject is given a valid value during program execution, it is said to become 15 defined. This is often accomplished by execution of an assignment or input statement. 16 When a variable does not have a predictable value, it is said to be undefined. Similarly, 17 when a pointer is associated with a target or nullified, its pointer association status is said 18 to become defined. When the association status of a pointer is not predictable, its pointer 19 association status is said to be undefined. 20 Clause 16 describes the ways in which variables may become defined and undefined. 21 2.5.6 Reference 22 A data ob ject reference is the appearance of the data ob ject designator in a context requiring its 23 value at that point during execution. 24 A pro cedure reference is the appearance of the procedure designator, operator symbol, or assignment 25 symbol in a context requiring execution of the procedure at that point. An occurrence of user-defined 26 derived-type input/output (10.7.6) or derived-type finalization (4.5.6.2) is also a procedure reference. 27 The appearance of a data ob ject designator or procedure designator in an actual argument list does not 28 constitute a reference to that data ob ject or procedure unless such a reference is necessary to complete 29 the specification of the actual argument. 30 A mo dule reference is the appearance of a module name in a USE statement (11.2.1). 31 2.5.7 Intrinsic 32 The qualifier intrinsic has two meanings. 33 23 J3/06-007 WORKING DRAFT 2006/07/11 (1) The qualifier signifies that the term to which it is applied is defined in this standard. In- 1 trinsic applies to types, procedures, modules, assignment statements, and operators. All 2 intrinsic types, procedures, assignments, and operators may be used in any scoping unit 3 without further definition or specification. Intrinsic modules may be accessed by use as- 4 sociation. Intrinsic procedures and modules defined in this standard are called standard 5 intrinsic procedures and standard intrinsic modules, respectively. 6 (2) The qualifier applies to procedures or modules that are provided by a processor but are not 7 defined in this standard (13, 14, 15.2). Such procedures and modules are called nonstandard 8 intrinsic procedures and nonstandard intrinsic modules, respectively. 9 2.5.8 Operator 10 An op erator specifies a computation involving one (unary operator) or two (binary operator) data values 11 (op erands). This standard specifies a number of intrinsic operators (e.g., the arithmetic operators +, ­, 12 *, /, and ** with numeric operands and the logical operators .AND., .OR., etc. with logical operands). 13 Additional operators may be defined within a program (7.1.3). 14 2.5.9 Sequence 15 A sequence is a set ordered by a one-to-one correspondence with the numbers 1, 2, through n. The 16 number of elements in the sequence is n. A sequence may be empty, in which case it contains no elements. 17 The elements of a nonempty sequence are referred to as the first element, second element, etc. The 18 nth element, where n is the number of elements in the sequence, is called the last element. An empty 19 sequence has no first or last element. 20 2.5.10 Companion processors 21 A processor has one or more companion processors. A companion pro cessor is a processor-dependent 22 mechanism by which global data and procedures may be referenced or defined. A companion processor 23 may be a mechanism that references and defines such entities by a means other than Fortran (12.6.3), 24 it may be the Fortran processor itself, or it may be another Fortran processor. If there is more than 25 one companion processor, the means by which the Fortran processor selects among them are processor 26 dependent. 27 If a procedure is defined by means of a companion processor that is not the Fortran processor itself, 28 this standard refers to the C function that defines the procedure, although the procedure need not be 29 defined by means of the C programming language. 30 NOTE 2.13 A companion processor might or might not be a mechanism that conforms to the requirements of the C International Standard. For example, a processor may allow a procedure defined by some language other than Fortran or C to be invoked if it can be described by a C prototype as defined in 6.5.5.3 of the C International Standard. 24 2006/07/11 WORKING DRAFT J3/06-007 3 Characters, lexical tokens, and source form 1 This clause describes the Fortran character set and the various lexical tokens such as names and operators. 2 This clause also describes the rules for the forms that Fortran programs may take. 3 3.1 Processor character set 4 The processor character set is processor dependent. Each character in a processor character set is either 5 a control character or a graphic character. The set of graphics characters is further divided into 6 letters (3.1.1), digits (3.1.2), underscore (3.1.3), special characters (3.1.4), and other characters (3.1.5). 7 The letters, digits, underscore, and special characters make up the Fortran character set. 8 R301 character is alphanumeric-character 9 or special-character 10 R302 alphanumeric-character is letter 11 or digit 12 or underscore 13 Except for the currency symbol, the graphics used for the characters shall be as given in 3.1.1, 3.1.2, 14 3.1.3, and 3.1.4. However, the style of any graphic is not specified. 15 The default character type shall support a character set that includes the Fortran character set. By sup- 16 plying nondefault character types, the processor may support additional character sets. The characters 17 available in the ASCII and ISO 10646 character sets are specified by ISO/IEC 646:1991 (International 18 Reference Version) and ISO/IEC 10646-1:2000 UCS-4, respectively; the characters available in other non- 19 default character types are not specified by this standard, except that one character in each nondefault 20 character type shall be designated as a blank character to be used as a padding character. 21 3.1.1 Letters 22 The twenty-six letters are: 23 ABCDEFGHIJKLMNOPQRSTUVWXYZ 24 The set of letters defines the syntactic class letter . The processor character set shall include lower- 25 case and upper-case letters. A lower-case letter is equivalent to the corresponding upper-case letter in 26 program units except in a character context (3.3). 27 NOTE 3.1 The following statements are equivalent: CALL BIG_COMPLEX_OPERATION (NDATE) call big_complex_operation (ndate) Call Big_Complex_Operation (NDate) 3.1.2 Digits 28 The ten digits are: 29 25 J3/06-007 WORKING DRAFT 2006/07/11 0123456789 1 The ten digits define the syntactic class digit . 2 3.1.3 Underscore 3 R303 underscore is 4 The underscore may be used as a significant character in a name. 5 3.1.4 Sp ecial characters 6 The sp ecial characters are shown in Table 3.1. 7 Table 3.1: Sp ecial characters Character Name of character Character Name of character Blank ; Semicolon = Equals ! Exclamation point + Plus Quotation mark or quote " - Minus % Percent * Asterisk & Ampersand / Slash Tilde ~ Backslash < Less than \ ( Left parenthesis > Greater than ) Right parenthesis ? Question mark [ Left square bracket Apostrophe ' ] Right square bracket ` Grave accent { Left curly bracket Circumflex accent ^ } | Right curly bracket Vertical line , Comma $ Currency symbol . Decimal point or period Number sign # : Colon @ Commercial at The special characters define the syntactic class special-character . Some of the special characters are 8 used for operator symbols, bracketing, and various forms of separating and delimiting other lexical 9 tokens. 10 3.1.5 Other characters 11 Additional characters may be representable in the processor, but may appear only in comments (3.3.1.1, 12 3.3.2.1), character constants (4.4.5), input/output records (9.1.1), and character string edit descriptors 13 (10.3.2). 14 3.2 Low-level syntax 15 The low-level syntax describes the fundamental lexical tokens of a program unit. Lexical tokens are 16 sequences of characters that constitute the building blocks of a program. They are keywords, names, 17 literal constants other than complex literal constants, operators, labels, delimiters, comma, =, =>, :, ::, 18 ;, and %. 19 26 2006/07/11 WORKING DRAFT J3/06-007 3.2.1 Names 1 Names are used for various entities such as variables, program units, dummy arguments, named con- 2 stants, and derived types. 3 R304 name is letter [ alphanumeric-character ] ... 4 C301 (R304) The maximum length of a name is 63 characters. 5 NOTE 3.2 Examples of names: A1 NAME LENGTH (single underscore) SPREAD OUT (two consecutive underscores) TRAILER (trailing underscore) NOTE 3.3 The word "name" always denotes this particular syntactic form. The word "identifier" is used where entities may be identified by other syntactic forms or by values; its particular meaning depends on the context in which it is used. 3.2.2 Constants 6 R305 constant is literal-constant 7 or named-constant 8 R306 literal-constant is int-literal-constant 9 or real-literal-constant 10 or complex-literal-constant 11 or logical-literal-constant 12 or char-literal-constant 13 or boz-literal-constant 14 R307 named-constant is name 15 R308 int-constant is constant 16 C302 (R308) int-constant shall be of type integer. 17 R309 char-constant is constant 18 C303 (R309) char-constant shall be of type character. 19 3.2.3 Operators 20 R310 intrinsic-operator is power-op 21 or mult-op 22 or add-op 23 or concat-op 24 or rel-op 25 or not-op 26 or and-op 27 or or-op 28 or equiv-op 29 R707 power-op is ** 30 R708 mult-op is * 31 27 J3/06-007 WORKING DRAFT 2006/07/11 or / 1 R709 add-op is + 2 or ­ 3 R711 concat-op is // 4 R713 rel-op is .EQ. 5 or .NE. 6 or .LT. 7 or .LE. 8 or .GT. 9 or .GE. 10 or == 11 or /= 12 or < 13 or <= 14 or > 15 or >= 16 R718 not-op is .NOT. 17 R719 and-op is .AND. 18 R720 or-op is .OR. 19 R721 equiv-op is .EQV. 20 or .NEQV. 21 or .XOR. 22 R311 defined-operator is defined-unary-op 23 or defined-binary-op 24 or extended-intrinsic-op 25 R703 defined-unary-op is . letter [ letter ] ... . 26 R723 defined-binary-op is . letter [ letter ] ... . 27 R312 extended-intrinsic-op is intrinsic-operator 28 3.2.4 Statement lab els 29 A statement lab el provides a means of referring to an individual statement. 30 R313 label is digit [ digit [ digit [ digit [ digit ] ] ] ] 31 C304 (R313) At least one digit in a label shall be nonzero. 32 If a statement is labeled, the statement shall contain a nonblank character. The same statement label 33 shall not be given to more than one statement in a scoping unit. Leading zeros are not significant in 34 distinguishing between statement labels. 35 NOTE 3.4 For example: 99999 10 010 are all statement labels. The last two are equivalent. There are 99999 unique statement labels and a processor shall accept any of them as a statement label. However, a processor may have a limit on the total number of unique statement labels in one program unit. 28 2006/07/11 WORKING DRAFT J3/06-007 Any statement may have a statement label, but the labels are used only in the following ways. 1 (1) The label on a branch target statement (8.2) is used to identify that statement as the 2 possible destination of a branch. 3 (2) The label on a FORMAT statement (10.2.1) is used to identify that statement as the format 4 specification for a data transfer statement (9.5). 5 (3) In some forms of the DO construct (8.1.7), the range of the DO construct is identified by 6 the label on the last statement in that range. 7 3.2.5 Delimiters 8 Delimiters are used to enclose syntactic lists. The following pairs are delimiters: 9 ( ... ) 10 / ... / 11 [ ... ] 12 (/ ... /) 13 3.3 Source form 14 A Fortran program unit is a sequence of one or more lines, organized as Fortran statements, comments, 15 and INCLUDE lines. A line is a sequence of zero or more characters. Lines following a program unit 16 END statement are not part of that program unit. A Fortran statement is a sequence of one or more 17 complete or partial lines. 18 A character context means characters within a character literal constant (4.4.5) or within a character 19 string edit descriptor (10.3.2). 20 A comment may contain any character that may occur in any character context. 21 There are two source forms: free and fixed. Free form and fixed form shall not be mixed in the same program unit. 22 23 The means for sp ecifying the source form of a program unit are pro cessor dep endent. 3.3.1 Free source form 24 In free source form there are no restrictions on where a statement (or portion of a statement) may 25 appear within a line. A line may contain zero characters. If a line consists entirely of characters of 26 default kind (4.4.5), it may contain at most 132 characters. If a line contains any character that is not 27 of default kind, the maximum number of characters allowed on the line is processor dependent. 28 Blank characters shall not appear within lexical tokens other than in a character context or in a format 29 specification. Blanks may be inserted freely between tokens to improve readability; for example, blanks 30 may occur between the tokens that form a complex literal constant. A sequence of blank characters 31 outside of a character context is equivalent to a single blank character. 32 A blank shall be used to separate names, constants, or labels from adjacent keywords, names, constants, 33 or labels. 34 NOTE 3.5 For example, the blanks after REAL, READ, 30, and DO are required in the following: REAL X 29 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 3.5 (cont.) READ 10 30 DO K=1,3 One or more blanks shall be used to separate adjacent keywords except in the following cases, where 1 blanks are optional: 2 Adjacent keywords where separating blanks are optional BLOCK DATA END MODULE DOUBLE PRECISION END INTERFACE ELSE IF END PROCEDURE ELSE WHERE END PROGRAM END ASSOCIATE END SELECT END BLOCK END SUBMODULE END BLOCK DATA END SUBROUTINE END CRITICAL END TYPE END DO END WHERE END ENUM GO TO END FILE IN OUT END FORALL SELECT CASE END FUNCTION SELECT TYPE END IF 3.3.1.1 Free form commentary 3 The character "!" initiates a comment except where it appears within a character context. The 4 comment extends to the end of the line. If the first nonblank character on a line is an "!", the line 5 is a comment line. Lines containing only blanks or containing no characters are also comment lines. 6 Comments may appear anywhere in a program unit and may precede the first statement of a program 7 unit or may follow the last statement of a program unit. Comments have no effect on the interpretation 8 of the program unit. 9 NOTE 3.6 The standard does not restrict the number of consecutive comment lines. 3.3.1.2 Free form statement continuation 10 The character "&" is used to indicate that the current statement is continued on the next line that is not 11 a comment line. Comment lines cannot be continued; an "&" in a comment has no effect. Comments may 12 occur within a continued statement. When used for continuation, the "&" is not part of the statement. 13 No line shall contain a single "&" as the only nonblank character or as the only nonblank character 14 before an "!" that initiates a comment. 15 If a noncharacter context is to be continued, an "&" shall be the last nonblank character on the line, 16 or the last nonblank character before an "!". There shall be a later line that is not a comment; the 17 statement is continued on the next such line. If the first nonblank character on that line is an "&", the 18 statement continues at the next character position following that "&"; otherwise, it continues with the 19 first character position of that line. 20 If a lexical token is split across the end of a line, the first nonblank character on the first following 21 noncomment line shall be an "&" immediately followed by the successive characters of the split token. 22 30 2006/07/11 WORKING DRAFT J3/06-007 If a character context is to be continued, an "&" shall be the last nonblank character on the line and 1 shall not be followed by commentary. There shall be a later line that is not a comment; an "&" shall be 2 the first nonblank character on the next such line and the statement continues with the next character 3 following that "&". 4 3.3.1.3 Free form statement termination 5 If a statement is not continued, a comment or the end of the line terminates the statement. 6 A statement may alternatively be terminated by a ";" character that appears other than in a character 7 context or in a comment. The ";" is not part of the statement. After a ";" terminator, another statement 8 may appear on the same line, or begin on that line and be continued. A sequence consisting only of zero 9 or more blanks and one or more ";" terminators, in any order, is equivalent to a single ";" terminator. 10 3.3.1.4 Free form statements 11 A label may precede any statement not forming part of another statement. 12 NOTE 3.7 No Fortran statement begins with a digit. A statement shall not have more than 255 continuation lines. 13 3.3.2 Fixed source form 14 15 In fixed source form, there are restrictions on where a statement may app ear within a line. If a source line contains only 16 default kind characters, it shall contain exactly 72 characters; otherwise, its maximum numb er of characters is pro cessor 17 dependent. 18 Except in a character context, blanks are insignificant and may b e used freely throughout the program. 3.3.2.1 Fixed form commentary 19 20 The character "!" initiates a comment except where it app ears within a character context or in character p osition 6. The 21 comment extends to the end of the line. If the first nonblank character on a line is an "!" in any character p osition other 22 than character p osition 6, the line is a comment line. Lines b eginning with a "C" or "*" in character p osition 1 and lines 23 containing only blanks are also comment lines. Comments may app ear anywhere in a program unit and may precede the 24 first statement of the program unit or may follow the last statement of a program unit. Comments have no effect on the 25 interpretation of the program unit. NOTE 3.8 The standard do es not restrict the numb er of consecutive comment lines. 3.3.2.2 Fixed form statement continuation 26 27 Except within commentary, character p osition 6 is used to indicate continuation. If character position 6 contains a blank 28 or zero, the line is the initial line of a new statement, which b egins in character p osition 7. If character p osition 6 contains 29 any character other than blank or zero, character p ositions 7­72 of the line constitute a continuation of the preceding 30 noncomment line. NOTE 3.9 An "!" or ";" in character p osition 6 is interpreted as a continuation indicator unless it app ears within commentary indicated by a "C" or "*" in character p osition 1 or by an "!" in character positions 1­5. 31 Comment lines cannot be continued. Comment lines may o ccur within a continued statement. 31 J3/06-007 WORKING DRAFT 2006/07/11 3.3.2.3 Fixed form statement termination 1 2 If a statement is not continued, a comment or the end of the line terminates the statement. 3 A statement may alternatively b e terminated by a ";" character that app ears other than in a character context, in a 4 comment, or in character p osition 6. The ";" is not part of the statement. After a ";" terminator, another statement may 5 b egin on the same line, or b egin on that line and be continued. A ";" shall not app ear as the first nonblank character 6 on an initial line. A sequence consisting only of zero or more blanks and one or more ";" terminators, in any order, is 7 equivalent to a single ";" terminator. 3.3.2.4 Fixed form statements 8 9 A lab el, if present, shall occur in character positions 1 through 5 of the first line of a statement; otherwise, p ositions 1 10 through 5 shall b e blank. Blanks may app ear anywhere within a lab el. A statement following a ";" on the same line shall 11 not b e labeled. Character p ositions 1 through 5 of any continuation lines shall b e blank. A statement shall not have more 12 than 255 continuation lines. The program unit END statement shall not b e continued. A statement whose initial line 13 appears to b e a program unit END statement shall not b e continued. 3.4 Including source text 14 Additional text may be incorporated into the source text of a program unit during processing. This is 15 accomplished with the INCLUDE line, which has the form 16 INCLUDE char-literal-constant 17 The char-literal-constant shall not have a kind type parameter value that is a named-constant . 18 An INCLUDE line is not a Fortran statement. 19 An INCLUDE line shall appear on a single source line where a statement may appear; it shall be the 20 only nonblank text on this line other than an optional trailing comment. Thus, a statement label is not 21 allowed. 22 The effect of the INCLUDE line is as if the referenced source text physically replaced the INCLUDE line 23 prior to program processing. Included text may contain any source text, including additional INCLUDE 24 lines; such nested INCLUDE lines are similarly replaced with the specified source text. The maximum 25 depth of nesting of any nested INCLUDE lines is processor dependent. Inclusion of the source text 26 referenced by an INCLUDE line shall not, at any level of nesting, result in inclusion of the same source 27 text. 28 When an INCLUDE line is resolved, the first included statement line shall not be a continuation line 29 and the last included statement line shall not be continued. 30 The interpretation of char-literal-constant is processor dependent. An example of a possible valid inter- 31 pretation is that char-literal-constant is the name of a file that contains the source text to be included. 32 NOTE 3.10 In some circumstances, for example where source co de is maintained in an INCLUDE file for use in programs whose source form might b e either fixed or free, observing the following rules allows the co de to b e used with either source form: (1) Confine statement lab els to character p ositions 1 to 5 and statements to character p ositions 7 to 72; (2) Treat blanks as b eing significant; (3) Use only the exclamation mark (!) to indicate a comment, but do not start the comment in character p osition 6; 32 2006/07/11 WORKING DRAFT J3/06-007 NOTE 3.10 (cont.) (4) For continued statements, place an amp ersand (&) in b oth character p osition 73 of a continued line and character p osition 6 of a continuing line. 3.5 Macro processing 1 3.5.1 Macro definition 2 A macro definition defines a macro. A defined macro shall only be referenced by a USE statement, 3 IMPORT statement, or macro expansion statement. A defined macro shall not be redefined. 4 R314 macro-definition is define-macro-stmt 5 [ macro-declaration-stmt ] ... 6 macro-body-block 7 end-macro-stmt 8 R315 define-macro-stmt is DEFINE MACRO [ , macro-attribute -list ] :: macro-name 9 [ ( [ macro-dummy-arg-name-list ] ) ] 10 C305 (R315) A macro-dummy-arg-name shall not appear more than once in a macro-dummy-arg- 11 name-list . 12 R316 macro-attribute is access-spec 13 The DEFINE MACRO statement begins the definition of the macro macro-name . Appearance of an 14 access-spec in the DEFINE MACRO statement explicitly gives the macro the specified attribute. Each 15 macro-dummy-arg-name is a macro dummy argument. A macro dummy argument is a macro local 16 variable. 17 R317 macro-declaration-stmt is macro-type-declaration-stmt 18 or macro-optional-decl-stmt 19 R318 macro-type-declaration-stmt is MACRO macro-type-spec :: macro-local-variable-name-list 20 R319 macro-optional-decl-stmt is MACRO OPTIONAL :: macro-dummy-arg-name-list 21 R320 macro-type-spec is INTEGER [ ( [ KIND= ] macro-expr ) ] 22 C306 (R318) A macro-local-variable-name shall not be the same as the name of a dummy argument 23 of the macro being defined. 24 C307 (R319) A macro-dummy-arg-name shall be the name of a dummy argument of the macro being 25 defined. 26 C308 (R320) If macro-expr appears, when the macro is expanded it shall be of type integer, and have 27 a non-negative value that specifies a representation method that exists on the processor. 28 A macro type declaration statement specifies that the named entities are macro local variables of the 29 specified type. If the kind is not specified, they are of default kind. A macro local variable that is not a 30 macro dummy argument shall appear in a macro type declaration statement. 31 R321 macro-body-block is [ macro-body-construct ] ... 32 R322 macro-body-construct is macro-definition 33 or expand-stmt 34 33 J3/06-007 WORKING DRAFT 2006/07/11 or macro-body-stmt 1 or macro-do-construct 2 or macro-if-construct 3 C309 A statement in a macro definition that is not a macro-body-construct or macro-definition shall 4 not appear on a line with any other statement. 5 R323 macro-do-construct is macro-do-stmt 6 macro-body-block 7 macro-end-do-stmt 8 R324 macro-do-stmt is MACRO DO macro-do-variable-name = macro-do-limit , 9 macro-do-limit [ , macro-do-limit ] 10 C310 (R324) A macro-do-variable-name shall be a local variable of the macro being defined, and shall 11 not be a macro dummy argument. 12 R325 macro-do-limit is macro-expr 13 C311 (R325) A macro-do-limit shall expand to an expression of type integer. 14 R326 macro-end-do-stmt is MACRO END DO 15 A macro DO construct iterates the expansion of its enclosed macro body block at macro expansion time. 16 The number of iterations is determined by the values of the expanded macro expressions in the MACRO 17 DO statement. 18 R327 macro-if-construct is macro-if-then-stmt 19 macro-body-block 20 [ macro-else-if-stmt 21 macro-body-block ] ... 22 [ macro-else-stmt 23 macro-body-block ] 24 macro-end-if-stmt 25 R328 macro-if-then-stmt is MACRO IF ( macro-condition ) THEN 26 R329 macro-else-if-stmt is MACRO ELSE IF ( macro-condition ) THEN 27 R330 macro-else-stmt is MACRO ELSE 28 R331 macro-end-if-stmt is MACRO END IF 29 R332 macro-condition is macro-expr 30 C312 (R332) A macro condition shall expand to an expression of type logical. 31 A macro IF construct provides conditional expansion of its enclosed macro body blocks at macro expan- 32 sion time. Whether the enclosed macro body blocks contribute to the macro expansion is determined by 33 the logical value of the expanded macro expressions in the MACRO IF and MACRO ELSE IF statements. 34 R333 macro-body-stmt is result-token [ result-token ] ... [ && ] 35 C313 (R333) The first result-token shall not be MACRO unless the second result-token is not a keyword 36 or name. 37 R334 result-token is token [ %% token ] ... 38 C314 (R334) The concatenated textual token s in a result-token shall have the form of a lexical token. 39 34 2006/07/11 WORKING DRAFT J3/06-007 R335 token is any lexical token including labels, keywords, and semi-colon. 1 C315 && shall not appear in the last macro-body-stmt of a macro definition. 2 C316 When a macro is expanded, the last macro-body-stmt processed shall not end with &&. 3 R336 end-macro-stmt is END MACRO [ macro-name ] 4 C317 (R314) The macro-name in the END MACRO statement shall be the same as the macro-name 5 in the DEFINE MACRO statement. 6 R337 macro-expr is basic-token-sequence 7 C318 (R337) A macro-expr shall expand to a scalar initialization expression. 8 Macro expressions are used to control the behavior of the MACRO DO and MACRO IF constructs when 9 a macro is being expanded. The type, type parameters, and value of a macro expression are determined 10 when that macro expression is expanded. 11 3.5.2 Macro expansion 12 3.5.2.1 General 13 Macro expansion is the conceptual replacement of the EXPAND statement with the Fortran statements 14 that it produces. The semantics of an EXPAND statement are those of the Fortran statements that it 15 produces. It is recommended that a processor be capable of displaying the results of macro expansion. It 16 is processor-dependent whether comments in a macro definition appear in the expansion. It is processor- 17 dependent whether continuations and consecutive blanks that are not part of a token are preserved. 18 The process of macro expansion produces Fortran statements consisting of tokens. The combined length 19 of the tokens for a single statement, plus inter-token spacing, shall not be greater than 33280 characters. 20 If a statement contains any character that is not of default kind, the maximum number of characters 21 allowed is processor dependent. 22 NOTE 3.11 This length is so that the result of macro expansion can be formed into valid free form Fortran source, consisting of an initial line and 255 continuation lines, times 130 which allows for beginning and ending continuation characters (&) on each line. Also, breaking tokens across continuation lines in macro definitions and in EXPAND statements does not affect macro expansion: it is as if they were joined together before replacement. R338 expand-stmt is EXPAND macro-name [ ( macro-actual-arg -list ) ] 23 C319 (R338) macro-name shall be the name of a macro that was previously defined or accessed via 24 use or host association. 25 C320 (R338) The macro shall expand to a sequence or zero or more complete Fortran statements. 26 C321 (R338) The statements produced by a macro expansion shall conform to the syntax rules and 27 constraints as if they physically replaced the EXPAND statement prior to program processing. 28 C322 (R338) The statements produced by a macro expansion shall not include a statement which 29 ends the scoping unit containing the EXPAND statement. 30 C323 (R338) If a macro expansion produces a statement which begins a new scoping unit, it shall also 31 35 J3/06-007 WORKING DRAFT 2006/07/11 produce a statement which ends that scoping unit. 1 C324 (R338) If the EXPAND statement appears as the action-stmt of an if-stmt , it shall expand to 2 exactly one action-stmt that is not an if-stmt , end-program-stmt , end-function-stmt , or end- 3 subroutine-stmt . 4 5 C325 (R338) If the EXPAND statement app ears as a do-term-action-stmt , it shall expand to exactly one action-stmt 6 that is not a continue-stmt , a goto-stmt , a return-stmt , a stop-stmt , an exit-stmt , a cycle-stmt , an end-function-stmt , an 7 end-subroutine-stmt , an end-program-stmt , or an arithmetic-if-stmt . C326 (R338) If the EXPAND statement has a label, the expansion of the macro shall produce at least 8 one statement, and the first statement produced shall not have a label. 9 C327 (R338) A macro-actual-arg shall appear corresponding to each nonoptional macro dummy ar- 10 gument. 11 C328 (R338) At most one macro-actual-arg shall appear corresponding to each optional macro dummy 12 argument. 13 Expansion of a macro is performed by the EXPAND statement. If the EXPAND statement has a label, 14 the label is interpreted after expansion as belonging to the first statement of the expansion. 15 R339 macro-actual-arg is [ macro-dummy-name = ] macro-actual-arg-value 16 C329 (R339) macro-dummy-name shall be the name of a macro dummy argument of the macro being 17 expanded. 18 C330 (R338) The macro-dummy-name = shall not be omitted unless it has been omitted from each 19 preceding macro-actual-arg in the expand-stmt . 20 R340 macro-actual-arg-value is basic-token-sequence 21 R341 basic-token-sequence is basic-token 22 or [ basic-token-sequence ] nested-token-sequence 23 [ basic-token-sequence ] 24 or basic-token basic-token-sequence 25 R342 basic-token is any lexical token except comma, parentheses, array 26 constructor delimiters, and semi-colon. 27 R343 nested-token-sequence is ( [ arg-token ] ... ) 28 or (/ [ arg-token ] ... /) 29 or lbracket [ arg-token ] ... rbracket 30 R344 arg-token is basic-token 31 or , 32 Macro expansion processes any macro declarations of the macro definition, and then expands its macro 33 body block. Any macro expressions in macro-type-spec s are evaluated and the kinds of the macro 34 variables thereby declared are determined for that particular expansion. 35 Macro expansion of a macro body block processes each macro body construct of the macro body block 36 in turn, starting with the first macro body construct and ending with the last macro body construct. 37 Expansion of a statement within a macro body construct consists of three steps: 38 (1) token replacement, 39 (2) token concatenation, and 40 36 2006/07/11 WORKING DRAFT J3/06-007 (3) statement-dependent processing. 1 Token replacement replaces each token of a macro body statement or macro expression that is a macro 2 local variable with the value of that variable. In a macro expression, a reference to the PRESENT 3 intrinsic function with a macro dummy argument name as its actual argument is replaced by the token 4 .TRUE. if the specified macro dummy argument is present, and the token .FALSE. if the specified macro 5 dummy argument is not present. Otherwise, the value of a macro dummy argument that is present is 6 the sequence of tokens from the corresponding actual argument. The value of a macro dummy argument 7 that is not present is a zero-length token sequence. The value of an integer macro variable is its minimal- 8 length decimal representation; if negative this will produce two tokens, a minus sign and an unsigned 9 integer literal constant. 10 Token concatenation is performed with the %% operator, which is only permitted inside a macro defini- 11 tion. After expansion, each sequence of single tokens separated by %% operators is replaced by a single 12 token consisting of the concatenated text of the sequence of tokens. The result of a concatenation shall 13 be a valid Fortran token, and may be a different kind of token from one or more of the original sequence 14 of tokens. 15 NOTE 3.12 For example, the sequence 3 %% .14159 %% E %% + %% 0 forms the single real literal constant 3.14159E+0. 3.5.2.2 Macro b o dy statements 16 Processing a macro body statement produces a whole or partial Fortran statement. A macro body 17 statement that is either the first macro body statement processed by this macro expansion or the next 18 macro body statement processed after a macro body statement that did not end with the continuation 19 generation operator &&, is an initial macro body statement. The next macro body statement processed 20 after a macro body statement that ends with && is a continuation macro body statement. An initial 21 macro body statement that does not end with && produces a whole Fortran statement consisting of its 22 token sequence. All other macro body statements produce partial Fortran statements, and the sequence 23 of tokens starting with those produced by the initial macro body statement and appending the tokens 24 produced by each subsequent continuation macro body statement form a Fortran statement. The && 25 operators are not included in the token sequence. 26 3.5.2.3 The macro DO construct 27 The macro DO construct specifies the repeated expansion of a macro body block. Processing the macro 28 DO statement performs the following steps in sequence. 29 (1) The initial parameter m1 , the terminal parameter m2 , and the incrementation parameter 30 m3 are of type integer with the same kind type parameter as the macro-do-variable-name . 31 Their values are given by the first macro-expr , the second macro-expr , and the third macro- 32 expr of the macro-do-stmt respectively, including, if necessary, conversion to the kind type 33 parameter of the macro-do-variable-name according to the rules for numeric conversion 34 (Table 7.11). If the third macro-expr does not appear, m3 has the value 1. The value of m3 35 shall not be zero. 36 (2) The macro DO variable becomes defined with the value of the initial parameter m1 . 37 The iteration count is established and is the value of the expression (m2 - m1 + m3 )/m3 , (3) 38 unless that value is negative, in which case the iteration count is 0. 39 37 J3/06-007 WORKING DRAFT 2006/07/11 After this, the following steps are performed repeatedly until processing of the macro DO construct is 1 finished. 2 (1) The iteration count is tested. If it is zero, the loop terminates and processing of the macro 3 DO construct is finished. 4 (2) If the iteration count is nonzero, the macro body block of the macro DO construct is 5 expanded. 6 (3) The iteration count is decremented by one. The macro DO variable is incremented by the 7 value of the incrementation parameter m3 . 8 3.5.2.4 The MACRO IF construct 9 The MACRO IF construct provides conditional expansion of macro body blocks. At most one of the 10 macro body blocks of the macro IF construct is expanded. The macro conditions of the construct are 11 evaluated in order until a true value is found or a MACRO ELSE or MACRO END IF statement is 12 encountered. If a true value or a MACRO ELSE statement is found, the macro body block immediately 13 following is expanded and this completes the processing of the construct. If none of the evaluated 14 conditions is true and there is no MACRO ELSE statement, the processing of the construct is completed 15 without expanding any of the macro body blocks within the construct. 16 3.5.2.5 Macro definitions 17 Processing a macro definition defines a new macro. If a macro definition is produced by a macro expan- 18 sion, all of the statements of the produced macro definition have token replacement and concatenation 19 applied to them before the new macro is defined. 20 3.5.2.6 Examples 21 NOTE 3.13 This is a macro which loops over an array of any rank and processes each array element. DEFINE MACRO loop_over(array,rank,traceinfo) MACRO INTEGER :: i BLOCK MACRO DO i=1,rank INTEGER loop_over_temp_%%i MACRO END DO MACRO DO i=1,rank DO loop_over_temp_%%i=1,size(array,i) MACRO END DO CALL impure_scalar_procedure(array(loop_over_temp_%%1 && MACRO DO i=2,rank ,loop_over_temp%i && MACRO END DO ),traceinfo) MACRO DO i=1,rank END DO MACRO END DO END BLOCK END MACRO 38 2006/07/11 WORKING DRAFT J3/06-007 NOTE 3.14 One can effectively pass macro names as macro arguments, since expansion of arguments occurs before analysis of each macro body statement. For example: DEFINE MACRO :: iterator(count,operation) DO i=1,count EXPAND operation(i) END DO END MACRO DEFINE MACRO :: process_element(j) READ *,a(j) result(j) = process(a(j)) IF (j>1) PRINT *,'difference =',result(j)-result(j-1) END MACRO EXPAND iterator(17,process_element) This expands into 17 sets of 3 statements: READ *,a(1) result(1) = process(a(1)) IF (1>1) PRINT *,'difference =',result(1)-result(1-1) READ *,a(2) result(2) = process(a(2)) IF (2>1) PRINT *,'difference =',result(2)-result(2-1) ... READ *,a(17) result(17) = process(a(17)) IF (17>1) PRINT *,'difference =',result(17)-result(17-1) NOTE 3.15 Using the ability to evaluate initialization expressions under macro control and test them, one can create interfaces and procedures for all kinds of a type, for example: DEFINE MACRO :: i_square_procs() MACRO INTEGER i MACRO DO i=1,1000 MACRO IF (SELECTED_INT_KIND(i)>=0 .AND. (i==1 .OR. SELECTED_INT_KIND(i)/=SELECTED_INT_KIND(i-1))) THEN FUNCTION i_square_range_%%i(a) RESULT(r) INTEGER(SELECTED_INT_KIND(i)) a,r r = a**2 END FUNCTION MACRO END IF MACRO END DO END MACRO 39 J3/06-007 WORKING DRAFT 2006/07/11 40 2006/07/11 WORKING DRAFT J3/06-007 4 Typ es 1 4.1 The concept of typ e 2 Fortran provides an abstract means whereby data may be categorized without relying on a particular 3 physical representation. This abstract means is the concept of type. 4 A type has a name, a set of valid values, a means to denote such values (constants), and a set of 5 operations to manipulate the values. 6 A type is either an intrinsic type or a derived type. 7 This part of ISO/IEC 1539 defines six intrinsic types: integer, real, complex, character, logical, and bits. 8 A derived type is one that is defined by a derived-type definition (4.5.2) or by an intrinsic module. It 9 shall be used only where it is accessible (4.5.2.2). An intrinsic type is always accessible. 10 4.1.1 Set of values 11 For each type, there is a set of valid values. The set of valid values may be completely determined, 12 as is the case for logical and bits, or may be determined by a processor-dependent method, as is the 13 case for integer, character, and real. For complex, the set of valid values consists of the set of all the 14 combinations of the values of the individual components. For derived types, the set of valid values is as 15 defined in 4.5.8. 16 4.1.2 Constants 17 The syntax for literal constants of each intrinsic type is specified in 4.4. 18 The syntax for denoting a value indicates the type, type parameters, and the particular value. 19 A constant value may be given a name (5.3.12, 5.4.10). 20 A structure constructor (4.5.10) may be used to construct a constant value of derived type from an 21 appropriate sequence of initialization expressions (7.1.7). Such a constant value is considered to be a 22 scalar even though the value may have components that are arrays. 23 4.1.3 Operations 24 For each of the intrinsic types, a set of operations and corresponding operators is defined intrinsically. 25 These are described in Clause 7. The intrinsic set may be augmented with operations and operators 26 defined by functions with the OPERATOR interface (12.4.2.1). Operator definitions are described in 27 Clauses 7 and 12. 28 For derived types, there are no intrinsic operations. Operations on derived types may be defined by the 29 program (4.5.11). 30 4.2 Typ e parameters 31 A type may be parameterized. In this case, the set of values, the syntax for denoting the values, and 32 the set of operations on the values of the type depend on the values of the parameters. 33 41 J3/06-007 WORKING DRAFT 2006/07/11 The intrinsic types are all parameterized. Derived types may be defined to be parameterized. 1 A type parameter is either a kind type parameter or a length type parameter. 2 A kind type parameter may be used in initialization and specification expressions within the derived-type 3 definition (4.5.2) for the type; it participates in generic resolution (16.3.4). Each of the intrinsic types 4 has a kind type parameter named KIND, which is used to distinguish multiple representations of the 5 intrinsic type. 6 NOTE 4.1 By design, the value of a kind type parameter is known at compile time. Some parameterizations that involve multiple representation forms need to be distinguished at compile time for practical implementation and performance. Examples include the multiple precisions of the intrinsic real type and the possible multiple character sets of the intrinsic character type. A type parameter of a derived type may be specified to be a kind type parameter in order to allow generic resolution based on the parameter; that is to allow a single generic to include two specific procedures that have interfaces distinguished only by the value of a kind type parameter of a dummy argument. Generics are designed to be resolvable at compile time. A length type parameter may be used in specification expressions within the derived-type definition for 7 the type, but it shall not be used in initialization expressions. The intrinsic character type has a length 8 type parameter named LEN, which is the length of the string. 9 NOTE 4.2 The adjective "length" is used for type parameters other than kind type parameters because they often specify a length, as for intrinsic character type. However, they may be used for other purposes. The important difference from kind type parameters is that their values need not be known at compile time and might change during execution. A type parameter value may be specified with a type specification (4.4, 4.5.9). 10 R401 type-param-value is scalar-int-expr 11 or * 12 or : 13 C401 (R401) The type-param-value for a kind type parameter shall be an initialization expression. 14 C402 (R401) A colon may be used as a type-param-value only in the declaration of an entity or 15 component that has the POINTER or ALLOCATABLE attribute. 16 A deferred typ e parameter is a length type parameter whose value can change during execution of 17 the program. A colon as a type-param-value specifies a deferred type parameter. 18 The values of the deferred type parameters of an ob ject are determined by successful execution of an 19 ALLOCATE statement (6.3.1), execution of an intrinsic assignment statement (7.4.1.3), execution of a 20 pointer assignment statement (7.4.2), or by argument association (12.5.1.4). 21 NOTE 4.3 Deferred type parameters of functions, including function procedure pointers, have no values. Instead, they indicate that those type parameters of the function result will be determined by execution of the function, if it returns an allocated allocatable result or an associated pointer result. An assumed typ e parameter is a length type parameter for a dummy argument that assumes the 22 42 2006/07/11 WORKING DRAFT J3/06-007 type parameter value from the corresponding actual argument; it is also used for an associate name in a 1 SELECT TYPE construct that assumes the type parameter value from the corresponding selector. An 2 asterisk as a type-param-value specifies an assumed type parameter. 3 4.3 Relationship of typ es and values to objects 4 The name of a type serves as a type specifier and may be used to declare ob jects of that type. A 5 declaration specifies the type of a named ob ject. A data ob ject may be declared explicitly or implicitly. 6 Data ob jects may have attributes in addition to their types. Clause 5 describes the way in which a data 7 ob ject is declared and how its type and other attributes are specified. 8 Scalar data of any intrinsic or derived type may be shaped in a rectangular pattern to compose an array 9 of the same type and type parameters. An array ob ject has a type and type parameters just as a scalar 10 ob ject does. 11 A variable is a data ob ject. The type and type parameters of a variable determine which values that 12 variable may take. Assignment provides one means of defining or redefining the value of a variable of 13 any type. Assignment is defined intrinsically for all types where the type, type parameters, and shape 14 of both the variable and the value to be assigned to it are identical. Assignment between ob jects of 15 certain differing intrinsic types, type parameters, and shapes is described in Clause 7. A subroutine and 16 a generic interface (4.5.2, 12.4.2.1) whose generic specifier is ASSIGNMENT (=) define an assignment 17 that is not defined intrinsically or redefine an intrinsic derived-type assignment (7.4.1.4). 18 NOTE 4.4 For example, assignment of a real value to an integer variable is defined intrinsically. The type of a variable determines the operations that may be used to manipulate the variable. 19 4.3.1 Type sp ecifiers and typ e compatibility 20 4.3.1.1 General 21 A type is specified by a typ e sp ecifier. In an executable statement, or in an expression within a nonex- 22 ecutable statement, a type-spec is used. In a nonexecutable statement other than within an expression, 23 a declaration-type-spec is used. 24 R402 type-spec is intrinsic-type-spec 25 or derived-type-spec 26 C403 (R402) The derived-type-spec shall not specify an abstract type (4.5.7). 27 R403 declaration-type-spec is intrinsic-type-spec 28 or TYPE ( intrinsic-type-spec ) 29 or TYPE ( derived-type-spec ) 30 or CLASS ( derived-type-spec ) 31 or CLASS ( * ) 32 C404 (R403) In a declaration-type-spec , every type-param-value that is not a colon or an asterisk shall 33 be a specification-expr . 34 C405 (R403) In a declaration-type-spec that uses the CLASS keyword, derived-type-spec shall specify 35 43 J3/06-007 WORKING DRAFT 2006/07/11 an extensible type. 1 C406 (R403) The TYPE(derived-type-spec ) shall not specify an abstract type (4.5.7). 2 C407 An entity declared with the CLASS keyword shall be a dummy argument or have the ALLO- 3 CATABLE or POINTER attribute. It shall not have the VALUE attribute. 4 An intrinsic-type-spec specifies the named intrinsic type and its type parameter values. A derived-type- 5 spec specifies the named derived type and its type parameter values. 6 NOTE 4.5 A type-spec is used in an array constructor, a SELECT TYPE construct, or an ALLOCATE statement. Elsewhere, a declaration-type-spec is used. 4.3.1.2 TYPE 7 A TYPE type specifier is used to declare entities of an intrinsic or derived type. 8 Where a data entity is declared explicitly using the TYPE type specifier to be of derived type, the 9 specified derived type shall have been defined previously in the scoping unit or be accessible there by 10 use or host association. If the data entity is a function result, the derived type may be specified in 11 the FUNCTION statement provided the derived type is defined within the body of the function or is 12 accessible there by use or host association. If the derived type is specified in the FUNCTION statement 13 and is defined within the body of the function, it is as if the function result variable was declared with 14 that derived type immediately following the derived-type-def of the specified derived type. 15 4.3.1.3 CLASS 16 A p olymorphic entity is a data entity that is able to be of differing types during program execution. 17 The type of a data entity at a particular point during execution of a program is its dynamic typ e. The 18 declared typ e of a data entity is the type that it is declared to have, either explicitly or implicitly. 19 A CLASS type specifier is used to declare polymorphic entities. The declared type of a polymorphic 20 entity is the specified type if the CLASS type specifier contains a type name. 21 An entity declared with the CLASS(*) specifier is an unlimited p olymorphic entity. An unlimited 22 polymorphic entity is not declared to have a type. It is not considered to have the same declared type 23 as any other entity, including another unlimited polymorphic entity. 24 A nonpolymorphic entity is typ e compatible only with entities of the same declared type. A poly- 25 morphic entity that is not an unlimited polymorphic entity is type compatible with entities of the same 26 declared type or any of its extensions. Even though an unlimited polymorphic entity is not considered 27 to have a declared type, it is type compatible with all entities. An entity is said to be type compatible 28 with a type if it is type compatible with entities of that type. 29 Two entities are typ e incompatible if neither is type compatible with the other. 30 A scalar entity of type bits is bits compatible with a scalar entity of type bits, integer, real, complex, 31 or logical if and only if both entities have the same size expressed in bits. 32 J3 internal note Unresolved Technical Issue 14 This might belong in the BITS subclause, or somewhere else. TKR compatibility belongs in c12 (the only place it is used), maybe this should go there? Or maybe split this subclause into one which handles type compabilities of all kinds, and one which handles polymorphism? Anyway, it doesn't have anything to do with CLASS (title of subclause). 44 2006/07/11 WORKING DRAFT J3/06-007 J3 internal note Unresolved Technical Issue 15 This leaves undefined whether entities of other types are bits compatible. Also, this term is often (always?) used as if it were symmetric, but like the other compatibility terms, it is not. It has been suggested that (1) the definition is meant to be symmetric, and (2) complete. Perhaps something like: An entity is bits compatible with another entity if and only if one is of type bits, the other is of type bits, integer, real, complex, or logical, and scalar entities of these types have the same size expressed in bits. It is not entirely obvious that this is correct, since the terms it is modelled on are not symmetric (and it is then used in those terms). The other terms are deliberately assymmetric in part to allow only safe associations, whereas it appears that a substantial point of BITS is perhaps to permit unsafe associations... if that is not the purpose of BITS, then making bits compatible symmetric is almost certainly incorrect. J3 internal note Unresolved Technical Issue 16 It is unclear whether the term "bits compatible" is useful or necessary. It is (mostly?) being used where otherwise we would be saying "type compatible with the same kind type parameters" (so-called TK compatibility). If that really is the only use, we should write the "TK compatibility" definition in one place and use it everywhere; otherwise, this extra complication is likely to lead to questions. (Alternative names for TK compatible are "kind compatible" and "type and kind compatible". The latter is probably the best.) An entity is type, kind, and rank compatible, or TKR compatible, with another entity if both entities 1 have the same rank, and either the first entity is type compatible with the second and the kind type 2 parameters of the first entity have the same values as corresponding kind type parameters of the second, 3 or the two entities are bits compatible. 4 J3 internal note Unresolved Technical Issue 17 This has wrecked generic resolution. It allows ambiguous procedures to be added to a generic set. BAD BAD BAD. Fixable by making bits only match bits in a generic setting, i.e. disable bits compatibility the same way we already disable sequence association. Other fixes possible. Note: If people want to use bits as a poor man's CLASS(*), for purposes of describing some MPI routines in a shorter "clever" way, it is certainly not going to be straight-forward to fix this in any sort of consistent way. Oh, and did I mention that the paragraph is getting harder to read? J3 internal note Unresolved Technical Issue 18 Since the "kind" type parameter of bits is inherently a length type parameter (being the number of bits), it behooves us not to arbitrarily prevent variable length bits in the future. (FWIW, it does not look substantially more difficult to implement variable-length bits than fixed-length ones to me, and without adversely affecting the performance of known-length bit operations too.) This should be borne in mind while considering how to fix generics, for example. 45 J3/06-007 WORKING DRAFT 2006/07/11 J3 internal note Unresolved Technical Issue 19 Given that having a "bits dummy" is semi-polymorphic, we should probably make "having a bits dummy argument" require an explicit interface, like we do with polymorphics. Given the arguments (from the same people) that in order to avoid errors in co-arrays, one should have an explicit interface merely to *pass* a co-indexed ob ject as an actual argument, it is hard to avoid the conclusion that it is warranted in this case too. Furthermore, requiring an explicit interface would facilitate future extension should that ever be contemplated. A polymorphic allocatable ob ject may be allocated to be of any type with which it is type compatible. 1 A polymorphic pointer or dummy argument may, during program execution, be associated with ob jects 2 with which it is type compatible. 3 The dynamic type of an allocated allocatable polymorphic ob ject is the type with which it was allocated. 4 The dynamic type of an associated polymorphic pointer is the dynamic type of its target. The dynamic 5 type of a nonallocatable nonpointer polymorphic dummy argument is the dynamic type of its associated 6 actual argument. The dynamic type of an unallocated allocatable or a disassociated pointer is the same 7 as its declared type. The dynamic type of an entity identified by an associate name (8.1.5) is the dynamic 8 type of the selector with which it is associated. The dynamic type of an ob ject that is not polymorphic 9 is its declared type. 10 NOTE 4.6 Only components of the declared type of a polymorphic ob ject may be designated by component selection (6.1.2). 4.4 Intrinsic types 11 4.4.1 Classification and sp ecification 12 Each intrinsic type is classified as a numeric type or a nonnumeric type. The numeric typ es are integer, 13 real, and complex. The nonnumeric intrinsic types are character, logical, and bits. 14 The numeric types are provided for numerical computation. The normal operations of arithmetic, 15 addition (+), subtraction (­), multiplication (*), division (/), exponentiation (**), identity (unary +), 16 and negation (unary ­), are defined intrinsically for the numeric types. 17 R404 intrinsic-type-spec is INTEGER [ kind-selector ] 18 or REAL [ kind-selector ] 19 or DOUBLE PRECISION 20 or COMPLEX [ kind-selector ] 21 or CHARACTER [ char-selector ] 22 or LOGICAL [ kind-selector ] 23 or BITS [ kind-selector ] 24 R405 kind-selector is ( [ KIND = ] scalar-int-initialization-expr ) 25 C408 (R405) The value of scalar-int-initialization-expr shall be nonnegative and shall specify a rep- 26 resentation method that exists on the processor. 27 4.4.2 Integer type 28 The set of values for the integer typ e is a subset of the mathematical integers. The processor shall 29 provide one or more representation metho ds that define sets of values for data of type integer. Each 30 46 2006/07/11 WORKING DRAFT J3/06-007 such method is characterized by a value for a type parameter called the kind type parameter; this kind 1 type parameter is of type default integer. The kind type parameter of a representation method is returned 2 by the intrinsic inquiry function KIND (13.7.96). The decimal exponent range of a representation method 3 is returned by the intrinsic function RANGE (13.7.143). The intrinsic function SELECTED INT KIND 4 (13.7.153) returns a kind value based on a specified decimal range requirement. The integer type includes 5 a zero value, which is considered to be neither negative nor positive. The value of a signed integer zero 6 is the same as the value of an unsigned integer zero. 7 The processor shall provide at least one representation method with a decimal exponent range greater 8 than or equal to 18. 9 The type specifier for the integer type uses the keyword INTEGER. 10 If the kind type parameter is not specified, the default kind value is KIND (0) and the type specified is 11 default integer. The decimal exponent range of default integer shall be at least 5. 12 Any integer value may be represented as a signed-int-literal-constant . 13 R406 signed-int-literal-constant is [ sign ] int-literal-constant 14 R407 int-literal-constant is digit-string [ kind-param ] 15 R408 kind-param is digit-string 16 or scalar-int-constant-name 17 R409 signed-digit-string is [ sign ] digit-string 18 R410 digit-string is digit [ digit ] ... 19 R411 sign is + 20 or ­ 21 C409 (R408) A scalar-int-constant-name shall be a named constant of type integer. 22 C410 (R408) The value of kind-param shall be nonnegative. 23 C411 (R407) The value of kind-param shall specify a representation method that exists on the pro- 24 cessor. 25 The optional kind type parameter following digit-string specifies the kind type parameter of the integer 26 constant; if it is not present, the constant is of type default integer. 27 An integer constant is interpreted as a decimal value. 28 NOTE 4.7 Examples of signed integer literal constants are: 473 +56 -101 21_2 21_SHORT 1976354279568241_8 where SHORT is a scalar integer named constant. 4.4.3 Real typ e 29 The real typ e has values that approximate the mathematical real numbers. The processor shall provide 30 two or more approximation metho ds that define sets of values for data of type real. Each such method 31 has a representation metho d and is characterized by a value for a type parameter called the kind 32 47 J3/06-007 WORKING DRAFT 2006/07/11 type parameter; this kind type parameter is of type default integer. The kind type parameter of an 1 approximation method is returned by the intrinsic inquiry function KIND (13.7.96). 2 The decimal precision, decimal exponent range, and radix of an approximation method are returned by 3 the intrinsic functions PRECISION (13.7.137), RANGE (13.7.143), and RADIX (D13:RADIX (X)). The 4 intrinsic function SELECTED REAL KIND (13.7.154) returns a kind value based on specified precision, 5 range, and radix requirements. 6 NOTE 4.8 See C.1.1 for remarks concerning selection of approximation methods. The real type includes a zero value. Processors that distinguish between positive and negative zeros 7 shall treat them as mathematically equivalent 8 (1) in all relational operations, 9 (2) as actual arguments to intrinsic procedures other than those for which it is explicitly specified 10 that negative zero is distinguished, and 11 (3) 12 as the scalar-numeric-expr in an arithmetic IF. NOTE 4.9 On a processor that can distinguish between 0.0 and -0.0, ( X >= 0.0 ) evaluates to true if X = 0.0 or if X = -0.0, ( X < 0.0 ) evaluates to false for X = -0.0, and IF (X) 1,2,3 causes a transfer of control to the branch target statement with the statement lab el "2" for b oth X = 0.0 and X = - 0 .0 . In order to distinguish between 0.0 and -0.0, a program should use the SIGN function. SIGN(1.0,X) will return -1.0 if X < 0.0 or if the processor distinguishes between 0.0 and -0.0 and X has the value -0.0. The type specifier for the real type uses the keyword REAL. The keyword DOUBLE PRECISION is an 13 alternate specifier for one kind of real type. 14 If the type keyword REAL is specified and the kind type parameter is not specified, the default kind 15 value is KIND (0.0) and the type specified is default real. If the type keyword DOUBLE PRECISION 16 is specified, the kind value is KIND (0.0D0) and the type specified is double precision real. The 17 decimal precision of the double precision real approximation method shall be greater than that of the 18 default real method. 19 The decimal precision of double precision real shall be at least 10, and its decimal exponent range shall 20 be at least 37. It is recommended that the decimal precision of default real be at least 6, and that its 21 decimal exponent range be at least 37. 22 R412 signed-real-literal-constant is [ sign ] real-literal-constant 23 R413 real-literal-constant is significand [ exponent-letter exponent ] [ kind-param ] 24 or digit-string exponent-letter exponent [ kind-param ] 25 48 2006/07/11 WORKING DRAFT J3/06-007 R414 significand is digit-string . [ digit-string ] 1 or . digit-string 2 R415 exponent-letter is E 3 or D 4 R416 exponent is signed-digit-string 5 C412 (R413) If both kind-param and exponent-letter are present, exponent-letter shall be E. 6 C413 (R413) The value of kind-param shall specify an approximation method that exists on the 7 processor. 8 A real literal constant without a kind type parameter is a default real constant if it is without an 9 exponent part or has exponent letter E, and is a double precision real constant if it has exponent letter 10 D. A real literal constant written with a kind type parameter is a real constant with the specified kind 11 type parameter. 12 The exponent represents the power of ten scaling to be applied to the significand or digit string. The 13 meaning of these constants is as in decimal scientific notation. 14 The significand may be written with more digits than a processor will use to approximate the value of 15 the constant. 16 NOTE 4.10 Examples of signed real literal constants are: -12.78 +1.6E3 2.1 -16.E4_8 0.45D-4 10.93E7_QUAD .123 3E4 where QUAD is a scalar integer named constant. 4.4.4 Complex type 17 The complex typ e has values that approximate the mathematical complex numbers. The values of a 18 complex type are ordered pairs of real values. The first real value is called the real part, and the second 19 real value is called the imaginary part. 20 Each approximation method used to represent data entities of type real shall be available for both the 21 real and imaginary parts of a data entity of type complex. A kind type parameter may be specified for 22 a complex entity and selects for both parts the real approximation method characterized by this kind 23 type parameter value; this kind type parameter is of type default integer. The kind type parameter of 24 an approximation method is returned by the intrinsic inquiry function KIND (13.7.96). 25 The type specifier for the complex type uses the keyword COMPLEX. There is no keyword for double 26 precision complex. If the type keyword COMPLEX is specified and the kind type parameter is not 27 specified, the default kind value is the same as that for default real, the type of both parts is default 28 real, and the type specified is default complex. 29 R417 complex-literal-constant is ( real-part , imag-part ) 30 R418 real-part is signed-int-literal-constant 31 49 J3/06-007 WORKING DRAFT 2006/07/11 or signed-real-literal-constant 1 or named-constant 2 R419 imag-part is signed-int-literal-constant 3 or signed-real-literal-constant 4 or named-constant 5 C414 (R417) Each named constant in a complex literal constant shall be of type integer or real. 6 If the real part and the imaginary part of a complex literal constant are both real, the kind type 7 parameter value of the complex literal constant is the kind type parameter value of the part with the 8 greater decimal precision; if the precisions are the same, it is the kind type parameter value of one of the 9 parts as determined by the processor. If a part has a kind type parameter value different from that of 10 the complex literal constant, the part is converted to the approximation method of the complex literal 11 constant. 12 If both the real and imaginary parts are integer, they are converted to the default real approximation 13 method and the constant is of type default complex. If only one of the parts is an integer, it is converted 14 to the approximation method selected for the part that is real and the kind type parameter value of the 15 complex literal constant is that of the part that is real. 16 NOTE 4.11 Examples of complex literal constants are: (1.0, -1.0) (3, 3.1E6) (4.0_4, 3.6E7_8) ( 0., PI) where PI is a previously declared named real constant. 4.4.5 Character typ e 17 4.4.5.1 Character sets 18 The character typ e has a set of values composed of character strings. A character string is a sequence 19 of characters, numbered from left to right 1, 2, 3, ... up to the number of characters in the string. The 20 number of characters in the string is called the length of the string. The length is a type parameter; its 21 value is greater than or equal to zero. The length type parameter is of type default integer. 22 The processor shall provide one or more representation metho ds that define sets of values for data 23 of type character. Each such method is characterized by a value for a type parameter called the kind 24 type parameter; this kind type parameter is of type default integer. The kind type parameter of a rep- 25 resentation method is returned by the intrinsic inquiry function KIND (13.7.96). The intrinsic function 26 SELECTED CHAR KIND (13.7.152) returns a kind value based on the name of a character type. Any 27 character of a particular representation method representable in the processor may occur in a character 28 string of that representation method. 29 The character set defined by ISO/IEC 646:1991 (International Reference Version) is referred to as the 30 ASCI I character set or the ASCI I character typ e. The character set defined by ISO/IEC 10646- 31 1:2000 UCS-4 is referred to as the ISO 10646 character set or the ISO 10646 character typ e. 32 4.4.5.2 Character typ e sp ecifier 33 The type specifier for the character type uses the keyword CHARACTER. 34 50 2006/07/11 WORKING DRAFT J3/06-007 If the kind type parameter is not specified, the default kind value is KIND ('A') and the type specified 1 is default character. 2 R420 char-selector is length-selector 3 or ( LEN = type-param-value , 4 KIND = scalar-int-initialization-expr ) 5 or ( type-param-value , 6 [ KIND = ] scalar-int-initialization-expr ) 7 or ( KIND = scalar-int-initialization-expr 8 [ , LEN =type-param-value ] ) 9 R421 length-selector is ( [ LEN = ] type-param-value ) 10 or * char-length [ , ] 11 R422 char-length is ( type-param-value ) 12 or scalar-int-literal-constant 13 C415 (R420) The value of scalar-int-initialization-expr shall be nonnegative and shall specify a rep- 14 resentation method that exists on the processor. 15 C416 (R422) The scalar-int-literal-constant shall not include a kind-param . 16 C417 (R422) A type-param-value in a char-length shall be a colon, asterisk, or specification-expr . 17 C418 (R420 R421 R422) A type-param-value of * shall be used only 18 (1) to declare a dummy argument, 19 (2) to declare a named constant, 20 (3) in the type-spec of an ALLOCATE statement wherein each al locate-object is a dummy 21 argument of type CHARACTER with an assumed character length, 22 (4) in the type-spec or derived-type-spec of a type guard statement (8.1.6), or 23 (5) in an external function, to declare the character length parameter of the function result. 24 C419 A function name shall not be declared with an asterisk type-param-value unless it is of type CHAR- 25 26 ACTER and is the name of the result of an external function or the name of a dummy function. C420 27 A function name declared with an asterisk type-param-value shall not b e an array, a p ointer, recursive, or pure. C421 28 (R421) The optional comma in a length-selector is permitted only in a declaration-type-spec in a type-declaration- 29 stmt . C422 30 (R421) The optional comma in a length-selector is p ermitted only if no double-colon separator app ears in the 31 type-declaration-stmt . C423 32 (R420) The length sp ecified for a character statement function or for a statement function dummy argument of 33 typ e character shall b e an initialization expression. The char-selector in a CHARACTER intrinsic-type-spec and the * char-length in an entity-decl or in 34 a component-decl of a type definition specify character length. The * char-length in an entity-decl or 35 a component-decl specifies an individual length and overrides the length specified in the char-selector , 36 if any. If a * char-length is not specified in an entity-decl or a component-decl , the length-selector or 37 type-param-value specified in the char-selector is the character length. If the length is not specified in a 38 char-selector or a * char-length , the length is 1. 39 If the character length parameter value evaluates to a negative value, the length of character entities 40 declared is zero. A character length parameter value of : indicates a deferred type parameter (4.2). A 41 char-length type parameter value of * has the following meanings. 42 (1) If used to declare a dummy argument of a procedure, the dummy argument assumes the 43 51 J3/06-007 WORKING DRAFT 2006/07/11 length of the associated actual argument. 1 (2) If used to declare a named constant, the length is that of the constant value. 2 (3) If used in the type-spec of an ALLOCATE statement, each al locate-object assumes its length 3 from the associated actual argument. 4 (4) If used in the type-spec of a type guard statement, the associating entity assumes its length 5 from the selector. 6 (5) 7 If used to sp ecify the character length parameter of a function result, any scoping unit invoking the function shall declare the function name with a character length parameter value other than * or access such a 8 9 definition by host or use asso ciation. When the function is invoked, the length of the result variable in the function is assumed from the value of this type parameter. 10 4.4.5.3 Character literal constant 11 A character literal constant is written as a sequence of characters, delimited by either apostrophes 12 or quotation marks. 13 R423 char-literal-constant is [ kind-param ] ' [ rep-char ] ... ' 14 or [ kind-param ] " [ rep-char ] ... " 15 C424 (R423) The value of kind-param shall specify a representation method that exists on the pro- 16 cessor. 17 The optional kind type parameter preceding the leading delimiter specifies the kind type parameter of 18 the character constant; if it is not present, the constant is of type default character. 19 For the type character with kind kind-param , if present, and for type default character otherwise, a 20 representable character, rep-char , is defined as follows. 21 (1) In free source form, it is any graphic character in the processor-dependent character set. 22 (2) 23 In fixed source form, it is any character in the pro cessor-dep endent character set. A pro cessor may restrict 24 the o ccurrence of some or all of the control characters. NOTE 4.12 Fortran 77 allowed any character to occur in a character context. This standard allows a source program to contain characters of more than one kind. Some processors may identify characters of nondefault kinds by control characters (called "escape" or "shift" characters). It is difficult, if not impossible, to process, edit, and print files where some occurences of control characters have their intended meaning and some occurrences might not. Almost all control characters have uses or effects that effectively preclude their use in character contexts and this is why free source form allows only graphic characters as representable characters. Nevertheless, for compatibility with Fortran 77, control characters remain p ermitted in principle in fixed source form. The delimiting apostrophes or quotation marks are not part of the value of the character literal constant. 25 An apostrophe character within a character constant delimited by apostrophes is represented by two 26 consecutive apostrophes (without intervening blanks); in this case, the two apostrophes are counted as 27 one character. Similarly, a quotation mark character within a character constant delimited by quotation 28 marks is represented by two consecutive quotation marks (without intervening blanks) and the two 29 quotation marks are counted as one character. 30 A zero-length character literal constant is represented by two consecutive apostrophes (without inter- 31 vening blanks) or two consecutive quotation marks (without intervening blanks) outside of a character 32 context. 33 The intrinsic operation concatenation (//) is defined between two data entities of type character (7.2.3) 34 52 2006/07/11 WORKING DRAFT J3/06-007 with the same kind type parameter. 1 NOTE 4.13 Examples of character literal constants are: "DON'T" 'DON''T' both of which have the value DON'T and '' which has the zero-length character string as its value. NOTE 4.14 An example of a nondefault character literal constant, where the processor supports the corre- sponding character set, is: ¡ ¢ £ ¤ ¢ ¥ ¦ § NIHONGO ' ' where NIHONGO is a named constant whose value is the kind type parameter for Nihongo (Japanese) characters. 4.4.5.4 Collating sequence 2 The processor defines a collating sequence for the character set of each kind of character. A collating 3 sequence is a one-to-one mapping of the characters into the nonnegative integers such that each charac- 4 ter corresponds to a different nonnegative integer. The intrinsic functions CHAR (13.7.30) and ICHAR 5 (13.7.84) provide conversions between the characters and the integers according to this mapping. 6 NOTE 4.15 For example: ICHAR ( 'X' ) returns the integer value of the character 'X' according to the collating sequence of the processor. The collating sequence of the default character type shall satisfy the following constraints. 7 (1) ICHAR ('A') < ICHAR ('B') < ... < ICHAR ('Z') for the twenty-six upper-case letters. 8 (2) ICHAR ('0') < ICHAR ('1') < ... < ICHAR ('9') for the ten digits. 9 (3) ICHAR (' ') < ICHAR ('0') < ICHAR ('9') < ICHAR ('A') or 10 ICHAR (' ') < ICHAR ('A') < ICHAR ('Z') < ICHAR ('0'). 11 (4) ICHAR ('a') < ICHAR ('b') < ... < ICHAR ('z') for the twenty-six lower-case letters. 12 (5) ICHAR (' ') < ICHAR ('0') < ICHAR ('9') < ICHAR ('a') or 13 ICHAR (' ') < ICHAR ('a') < ICHAR ('z') < ICHAR ('0'). 14 Except for blank, there are no constraints on the location of the special characters and underscore in 15 the collating sequence, nor is there any specified collating sequence relationship between the upper-case 16 and lower-case letters. 17 The collating sequence for the ASCII character type is as defined by ISO/IEC 646:1991 (International 18 Reference Version); this collating sequence is called the ASCI I collating sequence in this standard. 19 53 J3/06-007 WORKING DRAFT 2006/07/11 The collating sequence for the ISO 10646 character type is as defined by ISO/IEC 10646-1:2000. 1 NOTE 4.16 The intrinsic functions ACHAR (13.7.2) and IACHAR (13.7.77) provide conversion between char- acters and corresponding integer values according to the ASCII collating sequence. The intrinsic functions LGT, LGE, LLE, and LLT (13.7.101-13.7.104) provide comparisons between 2 strings based on the ASCII collating sequence. International portability is guaranteed if the set of 3 characters used is limited to the letters, digits, underscore, and special characters. 4 4.4.6 Logical typ e 5 The logical typ e has two values, which represent true and false. 6 The processor shall provide one or more representation metho ds for data of type logical. Each such 7 method is characterized by a value for a type parameter called the kind type parameter; this kind type 8 parameter is of type default integer. The kind type parameter of a representation method is returned 9 by the intrinsic inquiry function KIND (13.7.96). 10 The type specifier for the logical type uses the keyword LOGICAL. 11 If the kind type parameter is not specified, the default kind value is KIND (.FALSE.) and the type 12 specified is default logical. 13 R424 logical-literal-constant is .TRUE. [ kind-param ] 14 or .FALSE. [ kind-param ] 15 C425 (R424) The value of kind-param shall specify a representation method that exists on the pro- 16 cessor. 17 The optional kind type parameter following the trailing delimiter specifies the kind type parameter of 18 the logical constant; if it is not present, the constant is of type default logical. 19 The intrinsic operations defined for data entities of logical type are: negation (.NOT.), conjunction 20 (.AND.), inclusive disjunction (.OR.), logical equivalence (.EQV.), and logical nonequivalence (.NEQV.) 21 as described in 7.2.5. There is also a set of intrinsically defined relational operators that compare the 22 values of data entities of other types and yield a value of type default logical. These operations are 23 described in 7.2.4. 24 4.4.7 Bits typ e 25 4.4.7.1 General 26 The bits typ e has a set of values composed of ordered sequences of bits. The number of bits in 27 the sequence is specified by the kind type parameter, which shall be greater than or equal to zero. 28 The processor shall provide representation methods with kind type parameter values equal to every 29 nonnegative integer less than or equal to a processor-determined limit. This limit shall be at least as 30 large as the storage size, expressed in bits, of every supported kind of type integer, real, complex, and 31 logical. Additional representation methods may be provided. 32 The type specifier for the bits type uses the keyword BITS. 33 If the kind type parameter is not specified for a bits variable, the default kind value is the size of a 34 numeric storage unit expressed in bits, and the type specified is default bits. 35 R425 boz-literal-constant is binary-constant [ kind-param ] 36 54 2006/07/11 WORKING DRAFT J3/06-007 or octal-constant [ kind-param ] 1 or hex-constant [ kind-param ] 2 R426 binary-constant is B ' digit [ digit ] ... ' 3 or B " digit [ digit ] ... " 4 C426 (R426) digit shall have one of the values 0 or 1. 5 R427 octal-constant is O ' digit [ digit ] ... ' 6 or O " digit [ digit ] ... " 7 C427 (R427) digit shall have one of the values 0 through 7. 8 R428 hex-constant is Z ' hex-digit [ hex-digit ] ... ' 9 or Z " hex-digit [ hex-digit ] ... " 10 R429 hex-digit is digit 11 or A 12 or B 13 or C 14 or D 15 or E 16 or F 17 The hex-digit s A through F represent the numbers ten through fifteen, respectively; they may be repre- 18 sented by their lower-case equivalents. 19 If the optional kind type parameter is not specified for a boz literal constant, the kind value is assumed 20 from the form of the constant. If the constant is a binary-constant the kind value is the number 21 of digit characters. If the constant is an octal-constant the kind value is three times the number of 22 digit characters. If the constant is a hex-constant the kind value is four times the number of hex-digit 23 characters. 24 NOTE 4.17 Even if a bits value is too large to fit into a single statement as a literal constant, it can be constructed by concatenation of bits named constants. Each digit of an octal constant represents three bits, and each hex digit of a hex constant represents 25 four bits, according to their numerical representations as binary integers, with leading zero bits where 26 needed. 27 If a kind-param is specified for a boz literal constant and has a value greater than the number of bits 28 specified by its digits, the constant is padded on the left (13.3) with enough zero bits to create a constant 29 of kind kind-param . If the kind-param specified has a value smaller the number of bits specified by its 30 digits, only the rightmost kind-param bits are used to determine the value of the constant. 31 NOTE 4.18 Though the processor is required to provide bit kinds only up to four times the size of a numeric storage unit, or up to the maximum intrinsic type size (whichever is larger), it is expected that the actual size limit will be much larger, based on system capacity constraints. Use of BITS ob jects with KIND values equal to small integer multiples of NUMERIC STORAGE SIZE should result in more efficient execution. 55 J3/06-007 WORKING DRAFT 2006/07/11 4.5 Derived typ es 1 4.5.1 Derived typ e concepts 2 Additional types may be derived from the intrinsic types and other derived types. A type definition is 3 required to define the name of the type and the names and attributes of its components and type-bound 4 procedures. 5 A derived type may be parameterized by multiple type parameters, each of which is defined to be either 6 a kind or length type parameter and may have a default value. 7 The ultimate comp onents of an ob ject of derived type are the components that are of intrinsic type 8 or have the POINTER or ALLOCATABLE attribute, plus the ultimate components of the components 9 of the ob ject that are of derived type and have neither the ALLOCATABLE nor POINTER attribute. 10 NOTE 4.19 The ultimate components of ob jects of the derived type kids defined below are name, age, and other kids. type :: person character(len=20) :: name integer :: age end type person type :: kids type(person) :: oldest_child type(person), allocatable, dimension(:) :: other_kids end type kids By default, no storage sequence is implied by the order of the component definitions. However, a storage 11 order is implied for a sequence type (4.5.2.3). If the derived type has the BIND attribute, the storage 12 sequence is that required by the companion processor (2.5.10, 15.3.4). 13 A scalar entity of derived type is a structure. If a derived type has the SEQUENCE property, a scalar 14 entity of the type is a sequence structure. 15 4.5.2 Derived-typ e definition 16 4.5.2.1 Syntax 17 R430 derived-type-def is derived-type-stmt 18 [ type-param-def-stmt ] ... 19 [ private-or-sequence ] ... 20 [ component-part ] 21 [ type-bound-procedure-part ] 22 end-type-stmt 23 R431 derived-type-stmt is TYPE [ [ , type-attr-spec -list ] :: ] type-name 24 [ ( type-param-name -list ) ] 25 R432 type-attr-spec is ABSTRACT 26 or access-spec 27 or BIND (C) 28 or EXTENDS ( parent-type-name ) 29 C428 (R431) A derived type type-name shall not be DOUBLEPRECISION or the same as the name 30 56 2006/07/11 WORKING DRAFT J3/06-007 of any intrinsic type defined in this part of ISO/IEC 1539. 1 C429 (R431) The same type-attr-spec shall not appear more than once in a given derived-type-stmt . 2 C430 (R432) A parent-type-name shall be the name of a previously defined extensible type (4.5.7). 3 C431 (R430) If the type definition contains or inherits (4.5.7.2) a deferred binding (4.5.5), ABSTRACT 4 shall appear. 5 C432 (R430) If ABSTRACT appears, the type shall be extensible. 6 C433 (R430) If EXTENDS appears, SEQUENCE shall not appear. 7 R433 private-or-sequence is private-components-stmt 8 or sequence-stmt 9 C434 (R430) The same private-or-sequence shall not appear more than once in a given derived-type- 10 def . 11 R434 end-type-stmt is END TYPE [ type-name ] 12 C435 (R434) If END TYPE is followed by a type-name , the type-name shall be the same as that in 13 the corresponding derived-type-stmt . 14 Derived types with the BIND attribute are sub ject to additional constraints as specified in 15.3.4. 15 NOTE 4.20 An example of a derived-type definition is: TYPE PERSON INTEGER AGE CHARACTER (LEN = 50) NAME END TYPE PERSON An example of declaring a variable CHAIRMAN of type PERSON is: TYPE (PERSON) :: CHAIRMAN 4.5.2.2 Accessibility 16 Types that are defined in a module or accessible in that module by use association have either the 17 PUBLIC or PRIVATE attribute. Types for which an access-spec is not explicitly specified in that 18 module have the default accessibility attribute for that module. The default accessibility attribute for a 19 module is PUBLIC unless it has been changed by a PRIVATE statement (5.4.1). Only types that have 20 the PUBLIC attribute in that module are available to be accessed from that module by use association. 21 The accessibility of a type does not affect, and is not affected by, the accessibility of its components and 22 bindings. 23 If a type definition is private, then the type name, and thus the structure constructor (4.5.10) for the 24 type, are accessible only within the module containing the definition, and within its descendants. 25 NOTE 4.21 An example of a type with a private name is: TYPE, PRIVATE :: AUXILIARY 57 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 4.21 (cont.) LOGICAL :: DIAGNOSTIC CHARACTER (LEN = 20) :: MESSAGE END TYPE AUXILIARY Such a type would be accessible only within the module in which it is defined, and within its descendants. 4.5.2.3 Sequence typ e 1 R435 sequence-stmt is SEQUENCE 2 C436 (R439) If SEQUENCE appears, each data component shall be declared to be of an intrinsic type 3 or of a sequence derived type. 4 C437 (R430) If SEQUENCE appears, a type-bound-procedure-part shall not appear. 5 If the SEQUENCE statement appears, the type is a sequence typ e. The order of the component 6 definitions in a sequence type specifies a storage sequence for ob jects of that type. The type is a 7 numeric sequence typ e if there are no type parameters, no pointer or allocatable components, and 8 each component is of type default integer, default real, double precision real, default complex, default 9 logical, default bits, or a numeric sequence type. The type is a character sequence typ e if there 10 are no type parameters, no pointer or allocatable components, and each component is of type default 11 character or a character sequence type. 12 NOTE 4.22 An example of a numeric sequence type is: TYPE NUMERIC_SEQ SEQUENCE INTEGER :: INT_VAL REAL :: REAL_VAL LOGICAL :: LOG_VAL END TYPE NUMERIC_SEQ NOTE 4.23 A structure resolves into a sequence of components. Unless the structure includes a SEQUENCE statement, the use of this terminology in no way implies that these components are stored in this, or any other, order. Nor is there any requirement that contiguous storage be used. The sequence merely refers to the fact that in writing the definitions there will necessarily be an order in which the components appear, and this will define a sequence of components. This order is of limited significance because a component of an ob ject of derived type will always be accessed by a component name except in the following contexts: the sequence of expressions in a derived-type value constructor, intrinsic assignment, the data values in namelist input data, and the inclusion of the structure in an input/output list of a formatted data transfer, where it is expanded to this sequence of components. Provided the processor adheres to the defined order in these cases, it is otherwise free to organize the storage of the components for any nonsequence structure in memory as best suited to the particular architecture. 4.5.2.4 Determination of derived typ es 13 Derived-type definitions with the same type name may appear in different scoping units, in which case 14 they may be independent and describe different derived types or they may describe the same type. 15 58 2006/07/11 WORKING DRAFT J3/06-007 Two data entities have the same type if they are declared with reference to the same derived-type 1 definition. The definition may be accessed from a module or from a host scoping unit. Data entities in 2 different scoping units also have the same type if they are declared with reference to different derived-type 3 definitions that specify the same type name, all have the SEQUENCE property or all have the BIND 4 attribute, have no components with PRIVATE accessibility, and have type parameters and components 5 that agree in order, name, and attributes. Otherwise, they are of different derived types. A data entity 6 declared using a type with the SEQUENCE property or with the BIND attribute is not of the same type 7 as an entity of a type declared to be PRIVATE or that has any components that are PRIVATE. 8 NOTE 4.24 An example of declaring two entities with reference to the same derived-type definition is: TYPE POINT REAL X, Y END TYPE POINT TYPE (POINT) :: X1 CALL SUB (X1) ... CONTAINS SUBROUTINE SUB (A) TYPE (POINT) :: A ... END SUBROUTINE SUB The definition of derived type POINT is known in subroutine SUB by host association. Because the declarations of X1 and A both reference the same derived-type definition, X1 and A have the same type. X1 and A also would have the same type if the derived-type definition were in a module and both SUB and its containing program unit referenced the module. NOTE 4.25 An example of data entities in different scoping units having the same type is: PROGRAM PGM TYPE EMPLOYEE SEQUENCE INTEGER ID_NUMBER CHARACTER (50) NAME END TYPE EMPLOYEE TYPE (EMPLOYEE) PROGRAMMER CALL SUB (PROGRAMMER) ... END PROGRAM PGM SUBROUTINE SUB (POSITION) TYPE EMPLOYEE SEQUENCE INTEGER ID_NUMBER CHARACTER (50) NAME END TYPE EMPLOYEE TYPE (EMPLOYEE) POSITION ... END SUBROUTINE SUB The actual argument PROGRAMMER and the dummy argument POSITION have the same type 59 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 4.25 (cont.) because they are declared with reference to a derived-type definition with the same name, the SEQUENCE property, and components that agree in order, name, and attributes. Suppose the component name ID NUMBER was ID NUM in the subroutine. Because all the component names are not identical to the component names in derived type EMPLOYEE in the main program, the actual argument PROGRAMMER would not be of the same type as the dummy argument POSITION. Thus, the program would not be standard-conforming. NOTE 4.26 The requirement that the two types have the same name applies to the type-name s of the respective derived-type-stmt s, not to local names introduced via renaming in USE statements. 4.5.3 Derived-typ e parameters 1 4.5.3.1 Declaration 2 R436 type-param-def-stmt is INTEGER [ kind-selector ] , type-param-attr-spec :: 3 type-param-decl -list 4 R437 type-param-decl is type-param-name [ = scalar-int-initialization-expr ] 5 C438 (R436) A type-param-name in a type-param-def-stmt in a derived-type-def shall be one of the 6 type-param-name s in the derived-type-stmt of that derived-type-def . 7 C439 (R436) Each type-param-name in the derived-type-stmt in a derived-type-def shall appear as a 8 type-param-name in a type-param-def-stmt in that derived-type-def . 9 R438 type-param-attr-spec is KIND 10 or LEN 11 The derived type is parameterized if the derived-type-stmt has any type-param-name s. 12 Each type parameter is itself of type integer. If its kind selector is omitted, the kind type parameter is 13 default integer. 14 The type-param-attr-spec explicitly specifies whether a type parameter is a kind parameter or a length 15 parameter. 16 If a type-param-decl has a scalar-int-initialization-expr , the type parameter has a default value which 17 is specified by the expression. If necessary, the value is converted according to the rules of intrinsic 18 assignment (7.4.1.3) to a value of the same kind as the type parameter. 19 A type parameter may be used as a primary in a specification expression (7.1.6) in the derived-type- 20 def . A kind type parameter may also be used as a primary in an initialization expression (7.1.7) in the 21 derived-type-def . 22 NOTE 4.27 The following example uses derived-type parameters. TYPE humongous_matrix(k, d) INTEGER, KIND :: k = kind(0.0) INTEGER(selected_int_kind(12)), LEN :: d !-- Specify a nondefault kind for d. REAL(k) :: element(d,d) 60 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.27 (cont.) END TYPE In the following example, dim is declared to be a kind parameter, allowing generic overloading of procedures distinguished only by dim. TYPE general_point(dim) INTEGER, KIND :: dim REAL :: coordinates(dim) END TYPE 4.5.3.2 Typ e parameter order 1 Typ e parameter order is an ordering of the type parameters of a derived type; it is used for derived- 2 type specifiers. 3 The type parameter order of a nonextended type is the order of the type parameter list in the derived- 4 type definition. The type parameter order of an extended type consists of the type parameter order of 5 its parent type followed by any additional type parameters in the order of the type parameter list in the 6 derived-type definition. 7 NOTE 4.28 Given TYPE :: t1(k1,k2) INTEGER,KIND :: k1,k2 REAL(k1) a(k2) END TYPE TYPE,EXTENDS(t1) :: t2(k3) INTEGER,KIND :: k3 LOGICAL(k3) flag END TYPE the type parameter order for type T1 is K1 then K2, and the type parameter order for type T2 is K1 then K2 then K3. 4.5.4 Components 8 4.5.4.1 Syntax 9 R439 component-part is [ component-def-stmt ] ... 10 R440 component-def-stmt is data-component-def-stmt 11 or proc-component-def-stmt 12 R441 data-component-def-stmt is declaration-type-spec [ [ , component-attr-spec -list ] :: ] 13 component-decl -list 14 R442 component-attr-spec is access-spec 15 or ALLOCATABLE 16 or component-dim-spec 17 or CONTIGUOUS 18 or POINTER 19 R443 component-decl is component-name [ ( component-array-spec ) ] 20 [ lbracket co-array-spec rbracket ] 21 [ * char-length ] [ component-initialization ] 22 61 J3/06-007 WORKING DRAFT 2006/07/11 R444 component-dim-spec is DIMENSION ( component-array-spec ) 1 or DIMENSION [ ( deferred-shape-spec -list ) ] 2 lbracket co-array-spec rbracket 3 R445 component-array-spec is explicit-shape-spec -list 4 or deferred-shape-spec -list 5 6 C440 (R441) No component-attr-spec shall appear more than once in a given component-def-stmt . 7 C441 (R441) If neither the POINTER nor ALLOCATABLE attribute is specified, the declaration-type- 8 spec in the component-def-stmt shall specify an intrinsic type or a previously defined derived 9 type. 10 C442 (R441) If the POINTER or ALLOCATABLE attribute is specified, the declaration-type-spec in 11 the component-def-stmt shall be CLASS(*) or shall specify an intrinsic type or any accessible 12 derived type including the type being defined. 13 C443 (R441) If the POINTER or ALLOCATABLE attribute is specified, each component-array-spec 14 shall be a deferred-shape-spec -list. 15 C444 (R441) If a co-array-spec appears, it shall be a deferred-shape-spec -list and the component shall 16 have the ALLOCATABLE attribute. 17 C445 A data component whose type has a co-array ultimate component shall be a nonpointer nonal- 18 locatable scalar and shall not be a co-array. 19 C446 (R441) If neither the POINTER attribute nor the ALLOCATABLE attribute is specified, each 20 component-array-spec shall be an explicit-shape-spec -list. 21 C447 (R445) Each bound in the explicit-shape-spec shall either be an initialization expression or be a 22 specification expression that does not contain references to specification functions or any ob ject 23 designators other than named constants or subob jects thereof. 24 C448 (R441) A component shall not have both the ALLOCATABLE and the POINTER attribute. 25 C449 (R441) If the CONTIGUOUS attribute is specified, the component shall be an array with the 26 POINTER attribute. 27 C450 (R443) The * char-length option is permitted only if the component is of type character. 28 C451 (R440) Each type-param-value within a component-def-stmt shall either be a colon, be an ini- 29 tialization expression, or be a specification expression that contains neither references to speci- 30 fication functions nor any ob ject designators other than named constants or subob jects thereof. 31 NOTE 4.29 Because a type parameter is not an ob ject, a type-param-value or a bound in an explicit-shape-spec may contain a type-param-name . R446 proc-component-def-stmt is PROCEDURE ( [ proc-interface ] ) , 32 proc-component-attr-spec -list :: proc-decl -list 33 NOTE 4.30 See 12.4.2.3 for definitions of proc-interface and proc-decl . R447 proc-component-attr-spec is POINTER 34 or PASS [ (arg-name ) ] 35 62 2006/07/11 WORKING DRAFT J3/06-007 or NOPASS 1 or access-spec 2 C452 (R446) The same proc-component-attr-spec shall not appear more than once in a given proc- 3 component-def-stmt . 4 C453 (R446) POINTER shall appear in each proc-component-attr-spec -list. 5 C454 (R446) If the procedure pointer component has an implicit interface or has no arguments, 6 NOPASS shall be specified. 7 C455 (R446) If PASS (arg-name ) appears, the interface shall have a dummy argument named arg- 8 name . 9 C456 (R446) PASS and NOPASS shall not both appear in the same proc-component-attr-spec -list. 10 4.5.4.2 Array comp onents 11 A data component is an array if its component-decl contains a component-array-spec or its data-compo- 12 nent-def-stmt contains the DIMENSION clause with a component-array-spec . If the component-decl 13 contains a component-array-spec , it specifies the array rank, and if the array is explicit shape (5.3.7.2), 14 the array bounds; otherwise, the component-array-spec in the DIMENSION clause specifies the array 15 rank, and if the array is explicit shape, the array bounds. 16 A data component is a co-array if its component-decl contains a co-array-spec or its data-component-def- 17 stmt contains a DIMENSION clause with a co-array-spec . If the component-decl contains a co-array-spec 18 it specifies the co-rank; otherwise, the co-array-spec in the DIMENSION clause specifies the co-rank. 19 NOTE 4.31 An example of a derived type definition with an array component is: TYPE LINE REAL, DIMENSION (2, 2) :: COORD ! ! COORD(:,1) has the value of (/X1, Y1/) ! COORD(:,2) has the value of (/X2, Y2/) REAL :: WIDTH ! Line width in centimeters INTEGER :: PATTERN ! 1 for solid, 2 for dash, 3 for dot END TYPE LINE An example of declaring a variable LINE SEGMENT to be of the type LINE is: TYPE (LINE) :: LINE_SEGMENT The scalar variable LINE SEGMENT has a component that is an array. In this case, the array is a subob ject of a scalar. The double colon in the definition for COORD is required; the double colon in the definition for WIDTH and PATTERN is optional. NOTE 4.32 An example of a derived type definition with an allocatable component is: TYPE STACK INTEGER :: INDEX INTEGER, ALLOCATABLE :: CONTENTS (:) END TYPE STACK 63 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 4.32 (cont.) For each scalar variable of type STACK, the shape of the component CONTENTS is determined by execution of an ALLOCATE statement or assignment statement, or by argument association. NOTE 4.33 Default initialization of an explicit-shape array component may be specified by an initialization expression consisting of an array constructor (4.7), or of a single scalar that becomes the value of each array element. 4.5.4.3 Pointer comp onents 1 A component is a pointer (2.4.7) if its component-attr-spec -list contains the POINTER attribute. A 2 pointer component may be a data pointer or a procedure pointer. 3 NOTE 4.34 An example of a derived type definition with a pointer component is: TYPE REFERENCE INTEGER :: VOLUME, YEAR, PAGE CHARACTER (LEN = 50) :: TITLE CHARACTER, DIMENSION (:), POINTER :: SYNOPSIS END TYPE REFERENCE Any ob ject of type REFERENCE will have the four nonpointer components VOLUME, YEAR, PAGE, and TITLE, plus a pointer to an array of characters holding SYNOPSIS. The size of this target array will be determined by the length of the abstract. The space for the target may be allocated (6.3.1) or the pointer component may be associated with a target by a pointer assignment statement (7.4.2). 4.5.4.4 The passed-object dummy argument 4 A passed-ob ject dummy argument is a distinguished dummy argument of a procedure pointer 5 component or type-bound procedure. It affects procedure overriding (4.5.7.3) and argument association 6 (12.5.1.2). 7 If NOPASS is specified, the procedure pointer component or type-bound procedure has no passed-ob ject 8 dummy argument. 9 If neither PASS nor NOPASS is specified or PASS is specified without arg-name , the first dummy argu- 10 ment of a procedure pointer component or type-bound procedure is its passed-ob ject dummy argument. 11 If PASS (arg-name ) is specified, the dummy argument named arg-name is the passed-ob ject dummy 12 argument of the procedure pointer component or named type-bound procedure. 13 C457 The passed-ob ject dummy argument shall be a scalar, nonpointer, nonallocatable dummy data 14 ob ject with the same declared type as the type being defined; all of its length type parameters 15 shall be assumed; it shall be polymorphic (4.3.1.3) if and only if the type being defined is 16 extensible (4.5.7). It shall not have the VALUE attribute. 17 64 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.35 If a procedure is bound to several types as a type-bound procedure, different dummy arguments might be the passed-ob ject dummy argument in different contexts. 4.5.4.5 Default initialization for comp onents 1 Default initialization provides a means of automatically initializing pointer components to be disasso- 2 ciated, and nonpointer nonallocatable components to have a particular value. Allocatable components 3 are always initialized to not allocated. 4 A pointer variable or component is data-p ointer-initialization compatible with a target if the pointer 5 is type compatible with the target, they have the same rank, and the values of corresponding nondeferred 6 type parameters are specified by initialization expressions that have the same value. 7 R448 component-initialization is = initialization-expr 8 or => nul l-init 9 or => initial-data-target 10 R449 initial-data-target is designator 11 C458 (R441) If component-initialization appears, a double-colon separator shall appear before the 12 component-decl -list. 13 C459 (R441) If component-initialization appears, every type parameter and array bound of the com- 14 ponent shall be an initialization expression. 15 C460 (R441) If => appears in component-initialization , POINTER shall appear in the component- 16 attr-spec -list. If = appears in component-initialization , POINTER or ALLOCATABLE shall 17 not appear in the component-attr-spec -list. 18 C461 (R448) If initial-data-target appears, component-name shall be data-pointer-initialization com- 19 patible with it. 20 C462 (R449) The designator shall designate a variable that is an initialization target. Every subscript, 21 section subscript, substring starting point, and substring ending point in designator shall be an 22 initialization expression. 23 If nul l-init appears for a pointer component, that component in any ob ject of the type has an initial 24 association status of disassociated (16.5.2.2) or becomes disassociated as specified in 16.5.2.2.2. 25 A variable is an initialization target if it has the TARGET attribute, either has the SAVE attribute 26 or is declared in the main program, does not have the ALLOCATABLE attribute. 27 If initial-data-target appears for a data pointer component, that component in any ob ject of the type is 28 initially associated with the target or becomes associated with the target as specified in 16.5.2.2.1. 29 If initial-proc-target appears in proc-decl for a procedure pointer component, that component in any 30 ob ject of the type is initially associated with the target or becomes associated with the target as specified 31 in 16.5.2.2.1. 32 If initialization-expr appears for a nonpointer component, that component in any ob ject of the type 33 is initially defined (16.6.3) or becomes defined as specified in 16.6.5 with the value determined from 34 initialization-expr . If necessary, the value is converted according to the rules of intrinsic assignment 35 (7.4.1.3) to a value that agrees in type, type parameters, and shape with the component. If the compo- 36 nent is of a type for which default initialization is specified for a component, the default initialization 37 specified by initialization-expr overrides the default initialization specified for that component. When 38 one initialization overrides another it is as if only the overriding initialization were specified (see Note 39 65 J3/06-007 WORKING DRAFT 2006/07/11 4.37). Explicit initialization in a type declaration statement (5.2) overrides default initialization (see 1 Note 4.36). Unlike explicit initialization, default initialization does not imply that the ob ject has the 2 SAVE attribute. 3 A subcomponent (6.1.2) is default-initialized if the type of the ob ject of which it is a component 4 specifies default initialization for that component, and the subcomponent is not a subob ject of an ob ject 5 that is default-initialized or explicitly initialized. 6 NOTE 4.36 It is not required that initialization be specified for each component of a derived type. For example: TYPE DATE INTEGER DAY CHARACTER (LEN = 5) MONTH INTEGER :: YEAR = 1994 ! Partial default initialization END TYPE DATE In the following example, the default initial value for the YEAR component of TODAY is overridden by explicit initialization in the type declaration statement: TYPE (DATE), PARAMETER :: TODAY = DATE (21, "Feb.", 1995) NOTE 4.37 The default initial value of a component of derived type may be overridden by default initialization specified in the definition of the type. Continuing the example of Note 4.36: TYPE SINGLE_SCORE TYPE(DATE) :: PLAY_DAY = TODAY INTEGER SCORE TYPE(SINGLE_SCORE), POINTER :: NEXT => NULL ( ) END TYPE SINGLE_SCORE TYPE(SINGLE_SCORE) SETUP The PLAY DAY component of SETUP receives its initial value from TODAY, overriding the initialization for the YEAR component. NOTE 4.38 Arrays of structures may be declared with elements that are partially or totally initialized by default. Continuing the example of Note 4.37 : TYPE MEMBER (NAME_LEN) INTEGER, LEN :: NAME_LEN CHARACTER (LEN = NAME_LEN) NAME = '' INTEGER :: TEAM_NO, HANDICAP = 0 TYPE (SINGLE_SCORE), POINTER :: HISTORY => NULL ( ) END TYPE MEMBER TYPE (MEMBER(9)) LEAGUE (36) ! Array of partially initialized elements TYPE (MEMBER(9)) :: ORGANIZER = MEMBER ("I. Manage",1,5,NULL ( )) ORGANIZER is explicitly initialized, overriding the default initialization for an ob ject of type MEMBER. 66 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.38 (cont.) Allocated ob jects may also be initialized partially or totally. For example: ALLOCATE (ORGANIZER % HISTORY) ! A partially initialized object of type ! SINGLE_SCORE is created. NOTE 4.39 A pointer component of a derived type may have as its target an ob ject of that derived type. The type definition may specify that in ob jects declared to be of this type, such a pointer is default initialized to disassociated. For example: TYPE NODE INTEGER :: VALUE = 0 TYPE (NODE), POINTER :: NEXT_NODE => NULL ( ) END TYPE A type such as this may be used to construct linked lists of ob jects of type NODE. See C.1.4 for an example. Linked lists can also be constructed using allocatable components. NOTE 4.40 A pointer component of a derived type may be default-initialized to have an initial target. TYPE NODE INTEGER :: VALUE = 0 TYPE (NODE), POINTER :: NEXT_NODE => SENTINEL END TYPE TYPE(NODE), SAVE, TARGET :: SENTINEL 4.5.4.6 Comp onent order 1 Comp onent order is an ordering of the nonparent components of a derived type; it is used for intrinsic 2 formatted input/output and structure constructors (where component keywords are not used). Parent 3 components are excluded from the component order of an extended type (4.5.7). 4 The component order of a nonextended type is the order of the declarations of the components in the 5 derived-type definition. The component order of an extended type consists of the component order of 6 its parent type followed by any additional components in the order of their declarations in the extended 7 derived-type definition. 8 NOTE 4.41 Given the same type definitions as in Note 4.28, the component order of type T1 is just A (there is only one component), and the component order of type T2 is A then FLAG. The parent component (T1) does not participate in the component order. 4.5.4.7 Comp onent accessibility 9 R450 private-components-stmt is PRIVATE 10 C463 (R450) A private-components-stmt is permitted only if the type definition is within the specifi- 11 cation part of a module. 12 67 J3/06-007 WORKING DRAFT 2006/07/11 The default accessibility for the components that are declared in a type's component-part is private 1 if the type definition contains a private-components-stmt , and public otherwise. The accessibility of a 2 component may be explicitly declared by an access-spec ; otherwise its accessibility is the default for the 3 type definition in which it is declared. 4 If a component is private, that component name is accessible only within the module containing the 5 definition, and within its descendants. 6 NOTE 4.42 Type parameters are not components. They are effectively always public. NOTE 4.43 The accessibility of the components of a type is independent of the accessibility of the type name. It is possible to have all four combinations: a public type name with a public component, a private type name with a private component, a public type name with a private component, and a private type name with a public component. NOTE 4.44 An example of a type with private components is: TYPE POINT PRIVATE REAL :: X, Y END TYPE POINT Such a type definition is accessible in any scoping unit accessing the module via a USE state- ment; however, the components X and Y are accessible only within the module, and within its descendants. NOTE 4.45 The following example illustrates the use of an individual component access-spec to override the default accessibility: TYPE MIXED PRIVATE INTEGER :: I INTEGER, PUBLIC :: J END TYPE MIXED TYPE (MIXED) :: M The component M%J is accessible in any scoping unit where M is accessible; M%I is accessible only within the module containing the TYPE MIXED definition, and within its descendants. 4.5.5 Type-b ound procedures 7 R451 type-bound-procedure-part is contains-stmt 8 [ binding-private-stmt ] 9 [ proc-binding-stmt ] ... 10 R452 binding-private-stmt is PRIVATE 11 C464 (R451) A binding-private-stmt is permitted only if the type definition is within the specification 12 68 2006/07/11 WORKING DRAFT J3/06-007 part of a module. 1 R453 proc-binding-stmt is specific-binding 2 or generic-binding 3 or final-binding 4 R454 specific-binding is PROCEDURE [ (interface-name ) ] 5 [ [ , binding-attr -list ] :: ] 6 binding-name [ => procedure-name ] 7 C465 (R454) If => procedure-name appears, the double-colon separator shall appear. 8 C466 (R454) If => procedure-name appears, interface-name shall not appear. 9 C467 (R454) The procedure-name shall be the name of an accessible module procedure or an external 10 procedure that has an explicit interface. 11 If neither => procedure-name nor interface-name appears, it is as though => procedure-name had 12 appeared with a procedure name the same as the binding name. 13 R455 generic-binding is GENERIC 14 [, access-spec ] :: generic-spec => binding-name -list 15 C468 (R455) Within the specification-part of a module, each generic-binding shall specify, either 16 implicitly or explicitly, the same accessibility as every other generic-binding with that generic- 17 spec in the same derived type. 18 C469 (R455) Each binding-name in binding-name -list shall be the name of a specific binding of the 19 type. 20 C470 (R455) If generic-spec is not generic-name , each of its specific bindings shall have a passed-ob ject 21 dummy argument (4.5.4.4). 22 C471 (R455) If generic-spec is OPERATOR ( defined-operator ), the interface of each binding shall 23 be as specified in 12.4.2.1.1. 24 C472 (R455) If generic-spec is ASSIGNMENT ( = ), the interface of each binding shall be as specified 25 in 12.4.2.1.2. 26 C473 (R455) If generic-spec is dtio-generic-spec , the interface of each binding shall be as specified in 27 9.5.3.7. The type of the dtv argument shall be type-name . 28 R456 binding-attr is PASS [ (arg-name ) ] 29 or NOPASS 30 or NON OVERRIDABLE 31 or DEFERRED 32 or access-spec 33 C474 (R456) The same binding-attr shall not appear more than once in a given binding-attr -list. 34 C475 (R454) If the interface of the binding has no dummy argument of the type being defined, 35 NOPASS shall appear. 36 C476 (R454) If PASS (arg-name ) appears, the interface of the binding shall have a dummy argument 37 named arg-name . 38 C477 (R456) PASS and NOPASS shall not both appear in the same binding-attr -list. 39 C478 (R456) NON OVERRIDABLE and DEFERRED shall not both appear in the same binding- 40 69 J3/06-007 WORKING DRAFT 2006/07/11 attr -list. 1 C479 (R456) DEFERRED shall appear if and only if interface-name appears. 2 C480 (R454) An overriding binding (4.5.7.3) shall have the DEFERRED attribute only if the binding 3 it overrides is deferred. 4 C481 (R454) A binding shall not override an inherited binding (4.5.7.2) that has the NON OVER- 5 RIDABLE attribute. 6 Each binding in a proc-binding-stmt specifies a typ e-b ound pro cedure. A type-bound procedure 7 may have a passed-ob ject dummy argument (4.5.4.4). A generic-binding specifies a type-bound generic 8 interface for its specific bindings. A binding that specifies the DEFERRED attribute is a deferred 9 binding. A deferred binding shall appear only in the definition of an abstract type. 10 A type-bound procedure may be identified by a binding name in the scope of the type definition. 11 This name is the binding-name for a specific binding, and the generic-name for a generic binding whose 12 generic-spec is generic-name . A final binding, or a generic binding whose generic-spec is not generic- 13 name , has no binding name. 14 The interface of a specific binding is that of the procedure specified by procedure-name or the interface 15 specified by interface-name . 16 NOTE 4.46 An example of a type and a type-bound procedure is: TYPE POINT REAL :: X, Y CONTAINS PROCEDURE, PASS :: LENGTH => POINT_LENGTH END TYPE POINT ... and in the module-subprogram-part of the same module: REAL FUNCTION POINT_LENGTH (A, B) CLASS (POINT), INTENT (IN) :: A, B POINT_LENGTH = SQRT ( (A%X - B%X)**2 + (A%Y - B%Y)**2 ) END FUNCTION POINT_LENGTH The same generic-spec may be used in several generic-binding s within a single derived-type definition. 17 Each additional generic-binding with the same generic-spec extends the generic interface. 18 NOTE 4.47 Unlike the situation with generic procedure names, a generic type-bound procedure name is not permitted to be the same as a specific type-bound procedure name in the same type (16.3). The default accessibility for the procedure bindings of a type is private if the type definition contains a 19 binding-private-stmt , and public otherwise. The accessibility of a procedure binding may be explicitly 20 declared by an access-spec ; otherwise its accessibility is the default for the type definition in which it is 21 declared. 22 A public type-bound procedure is accessible via any accessible ob ject of the type. A private type-bound 23 procedure is accessible only within the module containing the type definition, and within its descendants. 24 70 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.48 The accessibility of a type-bound procedure is not affected by a PRIVATE statement in the component-part ; the accessibility of a data component is not affected by a PRIVATE statement in the type-bound-procedure-part . 4.5.6 Final subroutines 1 4.5.6.1 Declaration 2 R457 final-binding is FINAL [ :: ] final-subroutine-name -list 3 C482 (R457) A final-subroutine-name shall be the name of a module procedure with exactly one 4 dummy argument. That argument shall be nonoptional and shall be a nonpointer, nonallocat- 5 able, nonpolymorphic variable of the derived type being defined. All length type parameters of 6 the dummy argument shall be assumed. The dummy argument shall not be INTENT(OUT). 7 C483 (R457) A final-subroutine-name shall not be one previously specified as a final subroutine for 8 that type. 9 C484 (R457) A final subroutine shall not have a dummy argument with the same kind type parameters 10 and rank as the dummy argument of another final subroutine of that type. 11 The FINAL keyword specifies a list of final subroutines. A final subroutine might be executed when 12 a data entity of that type is finalized (4.5.6.2). 13 A derived type is finalizable if it has any final subroutines or if it has any nonpointer, nonallocatable 14 component whose type is finalizable. A nonpointer data entity is finalizable if its type is finalizable. 15 NOTE 4.49 Final subroutines are effectively always "accessible". They are called for entity finalization re- gardless of the accessibility of the type, its other type-bound procedures, or the subroutine name itself. NOTE 4.50 Final subroutines are not inherited through type extension and cannot be overridden. The final subroutines of the parent type are called after any additional final subroutines of an extended type are called. 4.5.6.2 The finalization pro cess 16 Only finalizable entities are finalized. When an entity is finalized, the following steps are carried out 17 in sequence. 18 (1) If the dynamic type of the entity has a final subroutine whose dummy argument has the 19 same kind type parameters and rank as the entity being finalized, it is called with the entity 20 as an actual argument. Otherwise, if there is an elemental final subroutine whose dummy 21 argument has the same kind type parameters as the entity being finalized, it is called with 22 the entity as an actual argument. Otherwise, no subroutine is called at this point. 23 (2) Each finalizable component that appears in the type definition is finalized. If the entity 24 being finalized is an array, each finalizable component of each element of that entity is 25 finalized separately. 26 (3) If the entity is of extended type and the parent type is finalizable, the parent component is 27 finalized. 28 71 J3/06-007 WORKING DRAFT 2006/07/11 If several entities are to be finalized as a consequence of an event specified in 4.5.6.3, the order in which 1 they are finalized is processor-dependent. A final subroutine shall not reference or define an ob ject that 2 has already been finalized. 3 If an ob ject is not finalized, it retains its definition status and does not become undefined. 4 4.5.6.3 When finalization o ccurs 5 When a pointer is deallocated its target is finalized. When an allocatable entity is deallocated, it is 6 finalized. 7 A nonpointer, nonallocatable ob ject that is not a dummy argument or function result is finalized immedi- 8 ately before it would become undefined due to execution of a RETURN or END statement (16.6.6, item 9 (3)). If the ob ject is defined in a module or submodule, and there are no longer any active procedures 10 referencing the module or submodule, it is processor-dependent whether it is finalized. 11 A nonpointer nonallocatable local variable of a BLOCK construct is finalized immediately before it 12 would become undefined due to termination of the BLOCK construct (16.6.6, item (20)). 13 If an executable construct references a function, the result is finalized after execution of the innermost 14 executable construct containing the reference. 15 If an executable construct references a structure constructor or array constructor, the entity created by 16 the constructor is finalized after execution of the innermost executable construct containing the reference. 17 If a specification expression in a scoping unit references a function, the result is finalized before execution 18 of the executable constructs in the scoping unit. 19 If a specification expression in a scoping unit references a structure constructor or array constructor, the 20 entity created by the constructor is finalized before execution of the executable constructs in the scoping 21 unit. 22 When a procedure is invoked, a nonpointer, nonallocatable ob ject that is an actual argument associated 23 with an INTENT(OUT) dummy argument is finalized. 24 When an intrinsic assignment statement is executed, the variable is finalized after evaluation of expr 25 and before the definition of the variable. 26 NOTE 4.51 If finalization is used for storage management, it often needs to be combined with defined assign- ment. If an ob ject is allocated via pointer allocation and later becomes unreachable due to all pointers to that 27 ob ject having their pointer association status changed, it is processor dependent whether it is finalized. 28 If it is finalized, it is processor dependent as to when the final subroutines are called. 29 4.5.6.4 Entities that are not finalized 30 If program execution is terminated, either by an error (e.g. an allocation failure) or by execution of 31 a STOP or END PROGRAM statement, entities existing immediately prior to termination are not 32 finalized. 33 NOTE 4.52 A nonpointer, nonallocatable ob ject that has the SAVE attribute or that occurs in the main pro- gram is never finalized as a direct consequence of the execution of a RETURN or END statement. 72 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.52 (cont.) A variable in a module or submodule is not finalized if it retains its definition status and value, even when there is no active procedure referencing the module or submodule. 4.5.7 Type extension 1 4.5.7.1 Concepts 2 A nonsequence derived type that does not have the BIND attribute is an extensible typ e. 3 An extensible type that does not have the EXTENDS attribute is a base typ e. A type that has the 4 EXTENDS attribute is an extended typ e. The parent typ e of an extended type is the type named 5 in the EXTENDS attribute specification. 6 NOTE 4.53 The name of the parent type might be a local name introduced via renaming in a USE statement. A base type is an extension typ e of itself only. An extended type is an extension of itself and of all 7 types for which its parent type is an extension. 8 An abstract typ e is a type that has the ABSTRACT attribute. 9 NOTE 4.54 A deferred binding (4.5.5) defers the implementation of a type-bound procedure to extensions of the type; it may appear only in an abstract type. The dynamic type of an ob ject cannot be abstract; therefore, a deferred binding cannot be invoked. An extension of an abstract type need not be abstract if it has no deferred bindings. A short example of an abstract type is: TYPE, ABSTRACT :: FILE_HANDLE CONTAINS PROCEDURE(OPEN_FILE), DEFERRED, PASS(HANDLE) :: OPEN ... END TYPE For a more elaborate example see C.1.3. 4.5.7.2 Inheritance 10 An extended type includes all of the type parameters, all of the components, and the nonoverridden 11 (4.5.7.3) nonfinal procedure bindings of its parent type. These are said to be inherited by the extended 12 type from the parent type. They retain all of the attributes that they had in the parent type. Additional 13 type parameters, components, and procedure bindings may be declared in the derived-type definition of 14 the extended type. 15 NOTE 4.55 Inaccessible components and bindings of the parent type are also inherited, but they remain inac- cessible in the extended type. Inaccessible entities occur if the type being extended is accessed via use association and has a private entity. NOTE 4.56 A base type is not required to have any components, bindings, or parameters; an extended type is not required to have more components, bindings, or parameters than its parent type. 73 J3/06-007 WORKING DRAFT 2006/07/11 An extended type has a scalar, nonpointer, nonallocatable, parent comp onent with the type and 1 type parameters of the parent type. The name of this component is the parent type name. It has the 2 accessibility of the parent type. Components of the parent component are inheritance asso ciated 3 (16.5.4) with the corresponding components inherited from the parent type. An ancestor comp onent 4 of a type is the parent component of the type or an ancestor component of the parent component. 5 NOTE 4.57 A component or type parameter declared in an extended type shall not have the same name as any accessible component or type parameter of its parent type. NOTE 4.58 Examples: TYPE POINT ! A base type REAL :: X, Y END TYPE POINT TYPE, EXTENDS(POINT) :: COLOR_POINT ! An extension of TYPE(POINT) ! Components X and Y, and component name POINT, inherited from parent INTEGER :: COLOR END TYPE COLOR_POINT 4.5.7.3 Typ e-b ound pro cedure overriding 6 If a nongeneric binding specified in a type definition has the same binding name as a binding from the 7 parent type then the binding specified in the type definition overrides the one from the parent type. 8 The overriding binding and the overridden binding shall satisfy the following conditions. 9 (1) Either both shall have a passed-ob ject dummy argument or neither shall. 10 (2) If the overridden binding is pure then the overriding binding shall also be pure. 11 (3) Either both shall be elemental or neither shall. 12 (4) They shall have the same number of dummy arguments. 13 (5) Passed-ob ject dummy arguments, if any, shall correspond by name and position. 14 (6) Dummy arguments that correspond by position shall have the same names and characteris- 15 tics, except for the type of the passed-ob ject dummy arguments. 16 (7) Either both shall be subroutines or both shall be functions having the same result charac- 17 teristics (12.3.2). 18 (8) If the overridden binding is PUBLIC then the overriding binding shall not be PRIVATE. 19 NOTE 4.59 The following is an example of procedure overriding, expanding on the example in Note 4.46. TYPE, EXTENDS (POINT) :: POINT_3D REAL :: Z CONTAINS PROCEDURE, PASS :: LENGTH => POINT_3D_LENGTH END TYPE POINT_3D ... and in the module-subprogram-part of the same module: 74 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.59 (cont.) REAL FUNCTION POINT_3D_LENGTH ( A, B ) CLASS (POINT_3D), INTENT (IN) :: A CLASS (POINT), INTENT (IN) :: B SELECT TYPE(B) CLASS IS(POINT_3D) POINT_3D_LENGTH = SQRT( (A%X-B%X)**2 + (A%Y-B%Y)**2 + (A%Z-B%Z)**2 ) RETURN END SELECT PRINT *, 'In POINT_3D_LENGTH, dynamic type of argument is incorrect.' STOP END FUNCTION POINT_3D_LENGTH If a generic binding specified in a type definition has the same generic-spec as an inherited binding, it 1 extends the generic interface and shall satisfy the requirements specified in 16.3.4. 2 If a generic binding in a type definition has the same dtio-generic-spec as one inherited from the parent, it 3 extends the type-bound generic interface for dtio-generic-spec and shall satisfy the requirements specified 4 in 16.3.4. 5 A binding of a type and a binding of an extension of that type are said to correspond if the latter binding 6 is the same binding as the former, overrides a corresponding binding, or is an inherited corresponding 7 binding. 8 4.5.8 Derived-typ e values 9 The comp onent value of 10 (1) a pointer component is its pointer association, 11 (2) an allocatable component is its allocation status and, if it is allocated, its dynamic type and 12 type parameters, bounds and value, and 13 (3) a nonpointer nonallocatable component is its value. 14 The set of values of a particular derived type consists of all possible sequences of the component values 15 of its components. 16 4.5.9 Derived-typ e sp ecifier 17 A derived-type specifier is used in several contexts to specify a particular derived type and type param- 18 eters. 19 R458 derived-type-spec is type-name [ ( type-param-spec -list ) ] 20 R459 type-param-spec is [ keyword = ] type-param-value 21 C485 (R458) type-name shall be the name of an accessible derived type. 22 C486 (R458) type-param-spec -list shall appear only if the type is parameterized. 23 C487 (R458) There shall be at most one type-param-spec corresponding to each parameter of the type. 24 If a type parameter does not have a default value, there shall be a type-param-spec corresponding 25 to that type parameter. 26 C488 (R459) The keyword = may be omitted from a type-param-spec only if the keyword = has been 27 75 J3/06-007 WORKING DRAFT 2006/07/11 omitted from each preceding type-param-spec in the type-param-spec -list. 1 C489 (R459) Each keyword shall be the name of a parameter of the type. 2 C490 (R459) An asterisk may be used as a type-param-value in a type-param-spec only in the decla- 3 ration of a dummy argument or associate name or in the allocation of a dummy argument. 4 Type parameter values that do not have type parameter keywords specified correspond to type param- 5 eters in type parameter order (4.5.3.2). If a type parameter keyword is present, the value is assigned to 6 the type parameter named by the keyword. If necessary, the value is converted according to the rules of 7 intrinsic assignment (7.4.1.3) to a value of the same kind as the type parameter. 8 The value of a type parameter for which no type-param-value has been specified is its default value. 9 4.5.10 Construction of derived-typ e values 10 A derived-type definition implicitly defines a corresponding structure constructor that allows con- 11 struction of values of that derived type. The type and type parameters of a constructed value are 12 specified by a derived type specifier. 13 R460 structure-constructor is derived-type-spec ( [ component-spec -list ] ) 14 R461 component-spec is [ keyword = ] component-data-source 15 R462 component-data-source is expr 16 or data-target 17 or proc-target 18 C491 (R460) The derived-type-spec shall not specify an abstract type (4.5.7). 19 C492 (R460) At most one component-spec shall be provided for a component. 20 C493 (R460) If a component-spec is provided for an ancestor component, a component-spec shall not 21 be provided for any component that is inheritance associated with a subcomponent of that 22 ancestor component. 23 C494 (R460) A component-spec shall be provided for a nonallocatable component unless it has default 24 initialization or is inheritance associated with a subcomponent of another component for which 25 a component-spec is provided. 26 C495 (R461) The keyword = may be omitted from a component-spec only if the keyword = has been 27 omitted from each preceding component-spec in the constructor. 28 C496 (R461) Each keyword shall be the name of a component of the type. 29 C497 (R460) The type name and all components of the type for which a component-spec appears shall 30 be accessible in the scoping unit containing the structure constructor. 31 C498 (R460) If derived-type-spec is a type name that is the same as a generic name, the component- 32 spec -list shall not be a valid actual-arg-spec -list for a function reference that is resolvable as a 33 generic reference (12.5.4.1). 34 C499 (R462) A data-target shall correspond to a nonprocedure pointer component; a proc-target shall 35 correspond to a procedure pointer component. 36 C4100 (R462) A data-target shall have the same rank as its corresponding component. 37 76 2006/07/11 WORKING DRAFT J3/06-007 NOTE 4.60 The form 'name(...)' is interpreted as a generic function-reference if possible; it is interpreted as a structure-constructor only if it cannot be interpreted as a generic function-reference . In the absence of a component keyword, each component-data-source is assigned to the corresponding 1 component in component order (4.5.4.6). If a component keyword appears, the expr is assigned to the 2 component named by the keyword. For a nonpointer component, the declared type and type parameters 3 of the component and expr shall conform in the same way as for a variable and expr in an intrinsic 4 assignment statement (7.4.1.2), as specified in Table 7.10. If necessary, each value of intrinsic type is 5 converted according to the rules of intrinsic assignment (7.4.1.3) to a value that agrees in type and type 6 parameters with the corresponding component of the derived type. For a nonpointer nonallocatable 7 component, the shape of the expression shall conform with the shape of the component. 8 If a component with default initialization has no corresponding component-data-source , then the default 9 initialization is applied to that component. If an allocatable component has no corresponding component- 10 data-source , then that component has an allocation status of unallocated. 11 NOTE 4.61 Because no parent components appear in the defined component ordering, a value for a parent component may be specified only with a component keyword. Examples of equivalent values using types defined in Note 4.58: ! Create values with components x = 1.0, y = 2.0, color = 3. TYPE(POINT) :: PV = POINT(1.0, 2.0) ! Assume components of TYPE(POINT) ! are accessible here. ... COLOR_POINT( point=point(1,2), color=3) ! Value for parent component COLOR_POINT( point=PV, color=3) ! Available even if TYPE(point) ! has private components COLOR_POINT( 1, 2, 3) ! All components of TYPE(point) ! need to be accessible. A structure constructor shall not appear before the referenced type is defined. 12 NOTE 4.62 This example illustrates a derived-type constant expression using a derived type defined in Note 4.20: PERSON (21, 'JOHN SMITH') This could also be written as PERSON (NAME = 'JOHN SMITH', AGE = 21) NOTE 4.63 An example constructor using the derived type GENERAL POINT defined in Note 4.27 is general_point(dim=3) ( (/ 1., 2., 3. /) ) For a pointer component, the corresponding component-data-source shall be an allowable data-target or 13 proc-target for such a pointer in a pointer assignment statement (7.4.2). If the component data source is 14 77 J3/06-007 WORKING DRAFT 2006/07/11 a pointer, the association of the component is that of the pointer; otherwise, the component is pointer 1 associated with the component data source. 2 NOTE 4.64 For example, if the variable TEXT were declared (5.2) to be CHARACTER, DIMENSION (1:400), TARGET :: TEXT and BIBLIO were declared using the derived-type definition REFERENCE in Note 4.34 TYPE (REFERENCE) :: BIBLIO the statement BIBLIO = REFERENCE (1, 1987, 1, "This is the title of the referenced & &paper", TEXT) is valid and associates the pointer component SYNOPSIS of the ob ject BIBLIO with the target ob ject TEXT. If a component of a derived type is allocatable, the corresponding constructor expression shall either be 3 a reference to the intrinsic function NULL with no arguments, an allocatable entity of the same rank, 4 or shall evaluate to an entity of the same rank. If the expression is a reference to the intrinsic function 5 NULL, the corresponding component of the constructor has a status of unallocated. If the expression 6 is an allocatable entity, the corresponding component of the constructor has the same allocation status 7 as that allocatable entity and, if it is allocated, the same dynamic type, bounds, and value; if a length 8 parameter of the component is deferred, its value is the same as the corresponding parameter of the 9 expression. Otherwise the corresponding component of the constructor has an allocation status of 10 allocated and has the same bounds and value as the expression. 11 NOTE 4.65 When the constructor is an actual argument, the allocation status of the allocatable component is available through the associated dummy argument. 4.5.11 Derived-typ e op erations and assignment 12 Intrinsic assignment of derived-type entities is described in 7.4.1. This part of ISO/IEC 1539 does 13 not specify any intrinsic operations on derived-type entities. Any operation on derived-type entities 14 or defined assignment (7.4.1.4) for derived-type entities shall be defined explicitly by a function or a 15 subroutine, and a generic interface (4.5.2, 12.4.2.1). 16 4.6 Enumerations and enumerators 17 An enumeration is a set of enumerators. An enumerator is a named integer constant. An enumeration 18 definition specifies the enumeration and its set of enumerators of the corresponding integer kind. 19 R463 enum-def is enum-def-stmt 20 enumerator-def-stmt 21 [ enumerator-def-stmt ] ... 22 end-enum-stmt 23 R464 enum-def-stmt is ENUM, BIND(C) 24 R465 enumerator-def-stmt is ENUMERATOR [ :: ] enumerator -list 25 78 2006/07/11 WORKING DRAFT J3/06-007 R466 enumerator is named-constant [ = scalar-int-initialization-expr ] 1 R467 end-enum-stmt is END ENUM 2 C4101 (R465) If = appears in an enumerator , a double-colon separator shall appear before the enu- 3 merator -list. 4 For an enumeration, the kind is selected such that an integer type with that kind is interoperable (15.3.2) 5 with the corresponding C enumeration type. The corresponding C enumeration type is the type that 6 would be declared by a C enumeration specifier (6.7.2.2 of the C International Standard) that specified 7 C enumeration constants with the same values as those specified by the enum-def , in the same order as 8 specified by the enum-def . 9 The companion processor (2.5.10) shall be one that uses the same representation for the types declared 10 by all C enumeration specifiers that specify the same values in the same order. 11 NOTE 4.66 If a companion processor uses an unsigned type to represent a given enumeration type, the Fortran processor will use the signed integer type of the same width for the enumeration, even though some of the values of the enumerators cannot be represented in this signed integer type. The values of any such enumerators will be interoperable with the values declared in the C enumeration. NOTE 4.67 The C International Standard guarantees the enumeration constants fit in a C int (6.7.2.2 of the C International Standard). Therefore, the Fortran processor can evaluate all enumerator values using the integer type with kind parameter C INT, and then determine the kind parameter of the integer type that is interoperable with the corresponding C enumerated type. NOTE 4.68 The C International Standard specifies that two enumeration types are compatible only if they specify enumeration constants with the same names and same values in the same order. This part of ISO/IEC 1539 further requires that a C processor that is to be a companion processor of a Fortran processor use the same representation for two enumeration types if they both specify enumeration constants with the same values in the same order, even if the names are different. An enumerator is treated as if it were explicitly declared with the PARAMETER attribute. The enu- 12 merator is defined in accordance with the rules of intrinsic assignment (7.4) with the value determined 13 as follows. 14 (1) If scalar-int-initialization-expr is specified, the value of the enumerator is the result of 15 scalar-int-initialization-expr . 16 (2) If scalar-int-initialization-expr is not specified and the enumerator is the first enumerator 17 in enum-def , the enumerator has the value 0. 18 (3) If scalar-int-initialization-expr is not specified and the enumerator is not the first enumer- 19 ator in enum-def , its value is the result of adding 1 to the value of the enumerator that 20 immediately precedes it in the enum-def . 21 NOTE 4.69 Example of an enumeration definition: ENUM, BIND(C) ENUMERATOR :: RED = 4, BLUE = 9 ENUMERATOR YELLOW END ENUM 79 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 4.69 (cont.) The kind type parameter for this enumeration is processor dependent, but the processor is required to select a kind sufficient to represent the values 4, 9, and 10, which are the values of its enumerators. The following declaration might be equivalent to the above enumeration definition. INTEGER(SELECTED_INT_KIND(2)), PARAMETER :: RED = 4, BLUE = 9, YELLOW = 10 An entity of the same kind type parameter value can be declared using the intrinsic function KIND with one of the enumerators as its argument, for example INTEGER(KIND(RED)) :: X NOTE 4.70 There is no difference in the effect of declaring the enumerators in multiple ENUMERATOR statements or in a single ENUMERATOR statement. The order in which the enumerators in an enumeration definition are declared is significant, but the number of ENUMERATOR statements is not. 4.7 Construction of array values 1 An array constructor is defined as a sequence of scalar values and is interpreted as a rank-one array 2 where the element values are those specified in the sequence. 3 R468 array-constructor is (/ ac-spec /) 4 or lbracket ac-spec rbracket 5 R469 ac-spec is type-spec :: 6 or [type-spec ::] ac-value -list 7 R470 lbracket is [ 8 R471 rbracket is ] 9 R472 ac-value is expr 10 or ac-implied-do 11 R473 ac-implied-do is ( ac-value -list , ac-implied-do-control ) 12 R474 ac-implied-do-control is ac-do-variable = scalar-int-expr , scalar-int-expr 13 [ , scalar-int-expr ] 14 R475 ac-do-variable is do-variable 15 C4102 (R469) If type-spec is omitted, each ac-value expression in the array-constructor shall have the 16 same type and kind type parameters. 17 C4103 (R469) If type-spec specifies an intrinsic type, each ac-value expression in the array-constructor 18 shall be of an intrinsic type that is in type conformance with a variable of type type-spec as 19 specified in Table 7.10. 20 C4104 (R469) If type-spec specifies a derived type, all ac-value expressions in the array-constructor 21 shall be of that derived type and shall have the same kind type parameter values as specified by 22 type-spec . 23 C4105 (R473) The ac-do-variable of an ac-implied-do that is in another ac-implied-do shall not appear 24 as the ac-do-variable of the containing ac-implied-do . 25 If type-spec is omitted, each ac-value expression in the array constructor shall have the same length type 26 parameters; in this case, the type and type parameters of the array constructor are those of the ac-value 27 expressions. 28 80 2006/07/11 WORKING DRAFT J3/06-007 If type-spec appears, it specifies the type and type parameters of the array constructor. Each ac-value 1 expression in the array-constructor shall be compatible with intrinsic assignment to a variable of this 2 type and type parameters. Each value is converted to the type parameters of the array-constructor in 3 accordance with the rules of intrinsic assignment (7.4.1.3). 4 The character length of an ac-value in an ac-implied-do whose iteration count is zero shall not depend 5 on the value of the ac-do-variable and shall not depend on the value of an expression that is not an 6 initialization expression. 7 If an ac-value is a scalar expression, its value specifies an element of the array constructor. If an ac- 8 value is an array expression, the values of the elements of the expression, in array element order (6.2.2.2), 9 specify the corresponding sequence of elements of the array constructor. If an ac-value is an ac-implied- 10 do , it is expanded to form a sequence of elements under the control of the ac-do-variable , as in the DO 11 construct (8.1.7.5). 12 For an ac-implied-do , the loop initialization and execution is the same as for a DO construct. 13 An empty sequence forms a zero-sized rank-one array. 14 NOTE 4.71 A one-dimensional array may be reshaped into any allowable array shape using the RESHAPE intrinsic function (13.7.146). An example is: X = (/ 3.2, 4.01, 6.5 /) Y = RESHAPE (SOURCE = [ 2.0, [ 4.5, 4.5 ], X ], SHAPE = [ 3, 2 ]) This results in Y having the 3 × 2 array of values: 2.0 3.2 4.5 4.01 4.5 6.5 NOTE 4.72 Examples of array constructors containing an implied DO are: (/ (I, I = 1, 1075) /) and [ 3.6, (3.6 / I, I = 1, N) ] NOTE 4.73 Using the type definition for PERSON in Note 4.20, an example of the construction of a derived- type array value is: (/ PERSON (40, 'SMITH'), PERSON (20, 'JONES') /) NOTE 4.74 Using the type definition for LINE in Note 4.31, an example of the construction of a derived-type scalar value with a rank-2 array component is: LINE (RESHAPE ( (/ 0.0, 0.0, 1.0, 2.0 /), (/ 2, 2 /) ), 0.1, 1) 81 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 4.74 (cont.) The RESHAPE intrinsic function is used to construct a value that represents a solid line from (0, 0) to (1, 2) of width 0.1 centimeters. NOTE 4.75 Examples of zero-size array constructors are: (/ INTEGER :: /) (/ ( I, I = 1, 0) /) NOTE 4.76 An example of an array constructor that specifies a length type parameter: (/ CHARACTER(LEN=7) :: 'Takata', 'Tanaka', 'Hayashi' /) In this constructor, without the type specification, it would have been necessary to specify all of the constants with the same character length. 82 2006/07/11 WORKING DRAFT J3/06-007 5 Attribute declarations and sp ecifications 1 5.1 General 2 Every data ob ject has a type and rank and may have type parameters and other attributes that determine 3 the uses of the ob ject. Collectively, these properties are the attributes of the ob ject. The type of a 4 named data ob ject is either specified explicitly in a type declaration statement or determined implicitly 5 by the first letter of its name (5.5). All of its attributes may be specified in a type declaration statement 6 or individually in separate specification statements. 7 A function has a type and rank and may have type parameters and other attributes that determine the 8 uses of the function. The type, rank, and type parameters are the same as those of its result variable. 9 A subroutine does not have a type, rank, or type parameters, but may have other attributes that 10 determine the uses of the subroutine. 11 5.2 Typ e declaration statements 12 5.2.1 Syntax 13 R501 type-declaration-stmt is declaration-type-spec [ [ , attr-spec ] ... :: ] entity-decl -list 14 The type declaration statement specifies the type of the entities in the entity declaration list. The type 15 and type parameters are those specified by declaration-type-spec , except that the character length type 16 parameter may be overridden for an entity by the appearance of * char-length in its entity-decl . 17 R502 attr-spec is access-spec 18 or ALLOCATABLE 19 or ASYNCHRONOUS 20 or CONTIGUOUS 21 or dimension-spec 22 or EXTERNAL 23 or INTENT ( intent-spec ) 24 or INTRINSIC 25 or language-binding-spec 26 or OPTIONAL 27 or PARAMETER 28 or POINTER 29 or PROTECTED 30 or SAVE 31 or TARGET 32 or VALUE 33 or VOLATILE 34 35 C501 (R501) The same attr-spec shall not appear more than once in a given type-declaration-stmt . 36 C502 (R501) If a language-binding-spec with a NAME= specifier appears, the entity-decl -list shall 37 consist of a single entity-decl . 38 C503 (R501) If a language-binding-spec is specified, the entity-decl -list shall not contain any procedure 39 83 J3/06-007 WORKING DRAFT 2006/07/11 names. 1 The type declaration statement also specifies the attributes whose keywords appear in the attr-spec , 2 except that the DIMENSION attribute may be specified or overridden for an entity by the appearance 3 of array-spec in its entity-decl . 4 R503 entity-decl is object-name [( array-spec )] 5 [ lbracket co-array-spec rbracket ] 6 [ * char-length ] [ initialization ] 7 or function-name [ * char-length ] 8 C504 (R503) If the entity is not of type character, * char-length shall not appear. 9 C505 (R501) If initialization appears, a double-colon separator shall appear before the entity-decl -list. 10 C506 (R503) An initialization shall not appear if object-name is a dummy argument, a function result, 11 an ob ject in a named common block unless the type declaration is in a block data program unit, 12 an ob ject in blank common, an allocatable variable, an external function, an intrinsic function, 13 or an automatic ob ject. 14 C507 (R503) An initialization shall appear if the entity is a named constant (5.3.12). 15 C508 (R503) The function-name shall be the name of an external function, an intrinsic function, a 16 function dummy procedure, a procedure pointer, or a statement function. 17 R504 object-name is name 18 C509 (R504) The object-name shall be the name of a data ob ject. 19 R505 initialization is = initialization-expr 20 or => nul l-init 21 or => initial-data-target 22 R506 nul l-init is function-reference 23 C510 (R503) If => appears in initialization , the entity shall have the POINTER attribute. If = 24 appears in initialization , the entity shall not have the POINTER attribute. 25 C511 (R503) If initial-data-target appears, object-name shall be data-pointer-initialization compatible 26 with it (4.5.4.5). 27 C512 (R506) The function-reference shall be a reference to the NULL intrinsic function with no 28 arguments. 29 A name that identifies a specific intrinsic function in a scoping unit has a type as specified in 13.6. An 30 explicit type declaration statement is not required; however, it is permitted. Specifying a type for a 31 generic intrinsic function name in a type declaration statement is not sufficient, by itself, to remove the 32 generic properties from that function. 33 An automatic data ob ject is a nondummy data ob ject with a type parameter or array bound that 34 depends on the value of a specification-expr that is not an initialization expression. 35 NOTE 5.1 An automatic ob ject shall not have the SAVE attribute and shall not appear in a common block. If a type parameter in a declaration-type-spec or in a char-length in an entity-decl is defined by an 36 expression that is not an initialization expression, the type parameter value is established on entry to 37 the procedure and is not affected by any redefinition or undefinition of the variables in the expression 38 84 2006/07/11 WORKING DRAFT J3/06-007 during execution of the procedure. 1 5.2.2 Initialization 2 The appearance of initialization in an entity-decl for an entity without the PARAMETER attribute 3 specifies that the entity is a variable with explicit initialization. Explicit initialization alternatively 4 may be specified in a DATA statement unless the variable is of a derived type for which default initial- 5 ization is specified. If initialization is =initialization-expr , the variable is initially defined with the value 6 specified by the initialization-expr ; if necessary, the value is converted according to the rules of intrinsic 7 assignment (7.4.1.3) to a value that agrees in type, type parameters, and shape with the variable. A 8 variable, or part of a variable, shall not be explicitly initialized more than once in a program. If the 9 variable is an array, it shall have its shape specified in either the type declaration statement or a previous 10 attribute specification statement in the same scoping unit. 11 If nul l-init appears, the initial association status of the ob ject is disassociated. If initial-data-target 12 appears, the ob ject is initially associated with the target. 13 Explicit initialization of a variable that is not in a common block implies the SAVE attribute, which 14 may be confirmed by explicit specification. 15 5.2.3 Examples of typ e declaration statements 16 NOTE 5.2 REAL A (10) LOGICAL, DIMENSION (5, 5) :: MASK1, MASK2 COMPLEX :: CUBE_ROOT = (-0.5, 0.866) INTEGER, PARAMETER :: SHORT = SELECTED_INT_KIND (4) INTEGER (SHORT) K ! Range at least -9999 to 9999. REAL (KIND (0.0D0)) A REAL (KIND = 2) B COMPLEX (KIND = KIND (0.0D0)) :: C CHARACTER (LEN = 10, KIND = 2) A CHARACTER B, C *20 TYPE (PERSON) :: CHAIRMAN TYPE(NODE), POINTER :: HEAD => NULL ( ) TYPE (humongous_matrix (k=8, d=1000)) :: mat (The last line above uses a type definition from Note 4.27.) 5.3 Attributes 17 5.3.1 Constraints 18 An attribute may be explicitly specified by an attr-spec in a type declaration statement or by an attribute 19 specification statement (5.4). The following constraints apply to attributes. 20 C513 An entity shall not be explicitly given any attribute more than once in a scoping unit. 21 C514 An array-spec for a function result that does not have the ALLOCATABLE or POINTER 22 attribute shall be an explicit-shape-spec -list. 23 C515 The ALLOCATABLE, POINTER, or OPTIONAL attribute shall not be specified for a dummy 24 85 J3/06-007 WORKING DRAFT 2006/07/11 argument of a procedure that has a proc-language-binding-spec . 1 5.3.2 Accessibility attribute 2 The accessibility attribute specifies the accessibility of an entity via a particular identifier. 3 R507 access-spec is PUBLIC 4 or PRIVATE 5 C516 (R507) An access-spec shall appear only in the specification-part of a module. 6 Identifiers that are specified in a module or accessible in that module by use association have either 7 the PUBLIC or PRIVATE attribute. Identifiers for which an access-spec is not explicitly specified in 8 that module have the default accessibility attribute for that module. The default accessibility attribute 9 for a module is PUBLIC unless it has been changed by a PRIVATE statement (5.4.1). Only identifiers 10 that have the PUBLIC attribute in that module are available to be accessed from that module by use 11 association. 12 NOTE 5.3 In order for an identifier to be accessed by use association, it must have the PUBLIC attribute in the module from which it is accessed. It can nonetheless have the PRIVATE attribute in a module in which it is accessed by use association, and therefore not be available for use association from a module where it is PRIVATE. NOTE 5.4 An example of an accessibility specification is: REAL, PRIVATE :: X, Y, Z 5.3.3 ALLOCATABLE attribute 13 An entity with the ALLOCATABLE attribute is a variable for which space is allocated by an AL- 14 LOCATE statement (6.3.1) or by an intrinsic assignment statement (7.4.1.3). 15 5.3.4 ASYNCHRONOUS attribute 16 An entity with the ASYNCHRONOUS attribute is a variable that may be sub ject to asynchronous 17 input/output. 18 The base ob ject of a variable shall have the ASYNCHRONOUS attribute in a scoping unit if 19 (1) the variable appears in an executable statement or specification expression in that scoping 20 unit and 21 (2) any statement of the scoping unit is executed while the variable is a pending I/O storage 22 sequence affector (9.5.1.4). 23 Use of a variable in an asynchronous input/output statement can imply the ASYNCHRONOUS attribute; 24 see subclause (9.5.1.4). 25 An ob ject may have the ASYNCHRONOUS attribute in a particular scoping unit without necessarily 26 having it in other scoping units (11.2.1, 16.5.1.4). If an ob ject has the ASYNCHRONOUS attribute, 27 then all of its subob jects also have the ASYNCHRONOUS attribute. 28 86 2006/07/11 WORKING DRAFT J3/06-007 NOTE 5.5 The ASYNCHRONOUS attribute specifies the variables that might be associated with a pending input/output storage sequence (the actual memory locations on which asynchronous input/output is being performed) while the scoping unit is in execution. This information could be used by the compiler to disable certain code motion optimizations. The ASYNCHRONOUS attribute is similar to the VOLATILE attribute. It is intended to facilitate traditional code motion optimizations in the presence of asynchronous input/output. 5.3.5 BIND attribute for data entities 1 The BIND attribute for a variable or common block specifies that it is capable of interoperating with a 2 C variable that has external linkage (15.4). 3 R508 language-binding-spec is BIND (C [, NAME = scalar-char-initialization-expr ]) 4 C517 An entity with the BIND attribute shall be a common block, variable, or procedure. 5 C518 A variable with the BIND attribute shall be declared in the specification part of a module. 6 C519 A variable with the BIND attribute shall be interoperable (15.3). 7 C520 Each variable of a common block with the BIND attribute shall be interoperable. 8 C521 (R508) The scalar-char-initialization-expr shall be of default character kind. If the value of the 9 scalar-char-initialization-expr after discarding leading and trailing blanks has nonzero length, 10 it shall be valid as an identifier on the companion processor. 11 NOTE 5.6 The C International Standard provides a facility for creating C identifiers whose characters are not restricted to the C basic character set. Such a C identifier is referred to as a universal character name (6.4.3 of the C International Standard). The name of such a C identifier might include characters that are not part of the representation method used by the processor for type default character. If so, the C entity cannot be referenced from Fortran. The BIND attribute for a variable or common block implies the SAVE attribute, which may be confirmed 12 by explicit specification. 13 5.3.6 CONTIGUOUS attribute 14 C522 An entity that has the CONTIGUOUS attribute shall be an array pointer or an assumed-shape 15 array. 16 The CONTIGUOUS attribute specifies that an assumed-shape array can only be argument associated 17 with a contiguous ob ject, or that an array pointer can only be pointer associated with a contiguous target. 18 An ob ject is contiguous if it is not the real or imaginary part of an array of type complex, and is: 19 (1) an ob ject with the CONTIGUOUS attribute, 20 (2) a scalar ob ject, 21 (3) a nonpointer array that is not assumed-shape, 22 (4) an array allocated by an ALLOCATE statement, 23 (5) an assumed-shape array that is argument associated with an array that is contiguous, 24 (6) a pointer associated with a contiguous target, 25 87 J3/06-007 WORKING DRAFT 2006/07/11 (7) an array with at most one element, or 1 (8) a nonzero-sized array section (6.2.2) with the following properties: 2 (a) Its base ob ject is contiguous. 3 (b) It does not have a vector subscript. 4 (c) The elements of the section, in array element order, are a subset of the base ob ject 5 elements that are consecutive in array element order. 6 (d) If the array is of type character and a substring-range appears, the substring-range 7 specifies all of the characters of the parent-string (6.1.1). 8 (e) Only its final part-ref has nonzero rank. 9 J3 internal note Unresolved Technical Issue 11 The above list (CONTIGUOUS definition) does not conform to the ISO guidelines. An ob ject is not contiguous if it is an array subob ject, and 10 (1) the ob ject has two or more elements, 11 (2) the elements of the ob ject in array element order are not consecutive in the elements of the 12 base ob ject, 13 (3) the ob ject is not of type character with length zero, and 14 (4) the ob ject is not of a derived type that has no ultimate components other than zero-sized 15 arrays and characters with length zero. 16 It is processor-dependent whether any other ob ject is contiguous. 17 NOTE 5.7 If a derived type has only one component that is not zero-sized, it is processor-dependent whether a structure component of a contiguous array of that type is contiguous. That is, the derived type might contain padding on some processors. NOTE 5.8 The CONTIGUOUS attribute allows a processor to enable optimizations that depend on the memory layout of the ob ject occupying a contiguous block of memory. Examples of CONTIGUOUS attribute specifications are: REAL, POINTER, CONTIGUOUS :: SPTR(:) REAL, CONTIGUOUS, DIMENSION(:,:) :: D 5.3.7 DIMENSION attribute 18 5.3.7.1 General 19 The DIMENSION attribute specifies that an entity is an array, a co-array, or both. If an array-spec 20 appears, it is an array. If a co-array-spec appears, it is a co-array. 21 For an array, its array-spec specifies its rank or rank and shape. For a co-array, its co-array-spec specifies 22 its co-rank or co-rank and co-bounds. 23 The co-b ounds are given within square brackets in the co-array's declaration or allocation. If the co- 24 rank is r, the co-array has lower co-bounds li , i = 1, 2, ..., r, upper co-bounds ui , i = 1, 2, ..., r - 1, and 25 co-extents ui - li + 1, i = 1, 2, ..., r - 1. 26 88 2006/07/11 WORKING DRAFT J3/06-007 J3 internal note Unresolved Technical Issue 12 The last sentence "... the co-array has lower co-bounds ..." is meaningless gibberish. Whence came these li et al? Not from around here as far as I see... Furthermore, it probably belongs somewhere else. Why is there not a specific subclause for co- array declarations? Surely if assumed-size arrays warrant their own subclause, co-arrays ought not to be lumped in with the general part of arrays. NOTE 5.9 Unless it is a dummy argument, a co-array has the same bounds and co-bounds on every image. See Note 12.28 for further discussion of the bounds and co-bounds of dummy co-arrays. R509 dimension-spec is DIMENSION ( array-spec ) 1 or DIMENSION [ ( array-spec ) ] lbracket co-array-spec rbracket 2 C523 (R501) A co-array that has the ALLOCATABLE attribute shall be specified with a co-array-spec 3 that is a deferred-shape-spec -list. 4 C524 A co-array shall be a component or a variable that is not a function result. 5 C525 An entity whose type has a co-array ultimate component shall be a nonpointer nonallocatable 6 scalar, shall not be a co-array, and shall not be a function result. 7 NOTE 5.10 A co-array is permitted to be of a derived type with pointer or allocatable components. The target of such a pointer component is always on the same image. An allocatable component of a co-array need be allocated on an image only if it is referenced or defined. R510 array-spec is explicit-shape-spec -list 8 or assumed-shape-spec -list 9 or deferred-shape-spec -list 10 or assumed-size-spec 11 or implied-shape-spec -list 12 R511 co-array-spec is deferred-shape-spec -list 13 or assumed-size-spec 14 J3 internal note Unresolved Technical Issue 13 This does not work, because there are no semantics for the use of the syntax terms deferred-shape- spec -list and assumed-size-spec out of their array-spec context. (In so far as there are semantics, they specify array bounds not co-array co-bounds.) C526 The sum of the rank and co-rank of an entity shall not exceed fifteen. 15 NOTE 5.11 Examples of DIMENSION attribute specifications are: SUBROUTINE EX (N, A, B) REAL, DIMENSION (N, 10) :: W ! Automatic explicit-shape array REAL A (:), B (0:) ! Assumed-shape arrays 89 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 5.11 (cont.) REAL, POINTER :: D (:, :) ! Array pointer REAL, DIMENSION (:), POINTER :: P ! Array pointer REAL, ALLOCATABLE, DIMENSION (:) :: E ! Allocatable array REAL, PARAMETER :: V(0:*) = [0.1, 1.1] ! Implied-shape array 5.3.7.2 Explicit-shap e array 1 An explicit-shap e array is a named array that is declared with an explicit-shape-spec -list. This specifies 2 explicit values for the bounds in each dimension of the array. 3 R512 explicit-shape-spec is [ lower-bound : ] upper-bound 4 R513 lower-bound is specification-expr 5 R514 upper-bound is specification-expr 6 C527 (R512) An explicit-shape-spec whose bounds are not initialization expressions shall appear only 7 in a subprogram or interface body. 8 If an explicit-shape array has bounds that are not initialization expressions, the bounds, and hence 9 shape, are determined at entry to the procedure by evaluating the bounds expressions. The bounds of 10 such an array are unaffected by the redefinition or undefinition of any variable during execution of the 11 procedure. 12 The values of each lower-bound and upper-bound determine the bounds of the array along a particular 13 dimension and hence the extent of the array in that dimension. The value of a lower bound or an upper 14 bound may be positive, negative, or zero. The subscript range of the array in that dimension is the set 15 of integer values between and including the lower and upper bounds, provided the upper bound is not 16 less than the lower bound. If the upper bound is less than the lower bound, the range is empty, the 17 extent in that dimension is zero, and the array is of zero size. If the lower-bound is omitted, the default 18 value is 1. The rank is equal to the number of explicit-shape-spec s. 19 5.3.7.3 Assumed-shap e array 20 An assumed-shap e array is a nonpointer dummy argument array that takes its shape from the asso- 21 ciated actual argument array. 22 R515 assumed-shape-spec is [ lower-bound ] : 23 The rank is equal to the number of colons in the assumed-shape-spec -list. 24 The extent of a dimension of an assumed-shape array dummy argument is the extent of the corresponding 25 dimension of the associated actual argument array. If the lower bound value is d and the extent of the 26 corresponding dimension of the associated actual argument array is s, then the value of the upper bound 27 is s + d - 1. If lower-bound appears it specifies the lower bound; otherwise the lower bound is 1. 28 5.3.7.4 Deferred-shap e array 29 A deferred-shap e array is an allocatable array or an array pointer. 30 An allo catable array is an array that has the ALLOCATABLE attribute and a specified rank, but its 31 bounds, and hence shape, are determined by allocation or argument association. 32 An array p ointer is an array with the POINTER attribute and a specified rank. Its bounds, and hence 33 shape, are determined when it is associated with a target. 34 90 2006/07/11 WORKING DRAFT J3/06-007 R516 deferred-shape-spec is : 1 C528 An array that has the POINTER or ALLOCATABLE attribute shall have an array-spec that is 2 a deferred-shape-spec -list. 3 The rank is equal to the number of colons in the deferred-shape-spec -list. 4 The size, bounds, and shape of an unallocated allocatable array or a disassociated array pointer are 5 undefined. No part of such an array shall be referenced or defined; however, the array may appear as an 6 argument to an intrinsic inquiry function as specified in 13.1. 7 The bounds of each dimension of an allocatable array are those specified when the array is allocated. 8 The bounds of each dimension of an array pointer may be specified in two ways: 9 (1) in an ALLOCATE statement (6.3.1) when the target is allocated; 10 (2) by pointer assignment (7.4.2). 11 The bounds of the array pointer or allocatable array are unaffected by any subsequent redefinition or 12 undefinition of variables on which the bounds' expressions depend. 13 5.3.7.5 Assumed-size array 14 An assumed-size array is a dummy argument array whose size is assumed from that of an associated 15 actual argument. The rank and extents may differ for the actual and dummy arrays; only the size of the 16 actual array is assumed by the dummy array. An assumed-size array is declared with an assumed-size- 17 spec. 18 R517 assumed-size-spec is [ explicit-shape-spec -list , ] [ lower-bound : ] * 19 C529 An assumed-size-spec shall not appear except as the declaration of the array bounds of a dummy 20 data argument. 21 C530 An assumed-size array with INTENT (OUT) shall not be polymorphic, ofa finalizable type, of 22 a type with an ultimate allocatable component, or of a type for which default initialization is 23 specified. 24 The size of an assumed-size array is determined as follows. 25 (1) If the actual argument associated with the assumed-size dummy array is an array of any 26 type other than default character, the size is that of the actual array. 27 (2) If the actual argument associated with the assumed-size dummy array is an array element 28 of any type other than default character with a subscript order value of r (6.2.2.2) in an 29 array of size x, the size of the dummy array is x - r + 1. 30 (3) If the actual argument is a default character array, default character array element, or a 31 default character array element substring (6.1.1), and if it begins at character storage unit t 32 of an array with c character storage units, the size of the dummy array is MAX (INT ((c - 33 t + 1)/e), 0), where e is the length of an element in the dummy character array. 34 (4) If the actual argument is of type default character and is a scalar that is not an array element 35 or array element substring designator, the size of the dummy array is MAX (INT (l/e), 0), 36 where e is the length of an element in the dummy character array and l is the length of the 37 actual argument. 38 The rank is equal to one plus the number of explicit-shape-spec s. 39 An assumed-size array has no upper bound in its last dimension and therefore has no extent in its last 40 dimension and no shape. An assumed-size array name shall not be written as a whole array reference 41 except as an actual argument in a procedure reference for which the shape is not required. 42 91 J3/06-007 WORKING DRAFT 2006/07/11 If an explicit-shape-spec -list appears, it specifies the bounds of the first rank -1 dimensions. If lower- 1 bound appears it specifies the lower bound of the last dimension; otherwise that lower bound is 1. An 2 assumed-size array may be subscripted or sectioned (6.2.2.3). The upper bound shall not be omitted 3 from a subscript triplet in the last dimension. 4 If an assumed-size array has bounds that are not initialization expressions, the bounds are determined 5 at entry to the procedure. The bounds of such an array are unaffected by the redefinition or undefinition 6 of any variable during execution of the procedure. 7 5.3.7.6 Implied-shap e array 8 An implied-shap e array is a named constant that takes its shape from the initialization-expr in its 9 declaration. An implied-shape array is declared with an implied-shape-spec -list. 10 R518 implied-shape-spec is [ lower-bound : ] * 11 C531 An implied-shape array shall be a named constant. 12 The rank of an implied-shape array is the number of implied-shape-spec s in the implied-shape-spec -list. 13 The extent of each dimension of an implied-shape array is the same as the extent of the corresponding 14 dimension of the initialization-expr . The lower bound of each dimension is lower-bound , if it appears, 15 and 1 otherwise; the upper bound is one less than the sum of the lower bound and the extent. 16 5.3.8 EXTERNAL attribute 17 The EXTERNAL attribute specifies that an entity is an external procedure, dummy procedure, 18 procedure pointer, or block data subprogram. 19 C532 An entity shall not have both the EXTERNAL attribute and the INTRINSIC attribute. 20 In an external subprogram, the EXTERNAL attribute shall not be specified for a procedure defined by 21 the subprogram. 22 If an external procedure or dummy procedure is used as an actual argument or is the target of a procedure 23 pointer assignment, it shall be declared to have the EXTERNAL attribute. 24 A procedure that has both the EXTERNAL and POINTER attributes is a procedure pointer. 25 5.3.9 INTENT attribute 26 The INTENT attribute specifies the intended use of a dummy argument. An INTENT (IN) dummy 27 argument is suitable for receiving data from the invoking scoping unit, an INTENT (OUT) dummy 28 argument is suitable for returning data to the invoking scoping unit, and an INTENT (INOUT) dummy 29 argument is suitable for use both to receive data from and to return data to the invoking scoping unit. 30 R519 intent-spec is IN 31 or OUT 32 or INOUT 33 C533 An entity with the INTENT attribute shall be a dummy data ob ject or a dummy procedure 34 pointer. 35 C534 (R519) A nonpointer ob ject with the INTENT (IN) attribute shall not appear in a variable 36 definition context (16.6.7). 37 C535 A pointer with the INTENT (IN) attribute shall not appear in a pointer association context 38 92 2006/07/11 WORKING DRAFT J3/06-007 (16.6.8). 1 The INTENT (IN) attribute for a nonpointer dummy argument specifies that it shall neither be de- 2 fined nor become undefined during the execution of the procedure. The INTENT (IN) attribute for a 3 pointer dummy argument specifies that during the execution of the procedure its association shall not 4 be changed except that it may become undefined if the target is deallocated other than through the 5 pointer (16.5.2.2.3). 6 The INTENT (OUT) attribute for a nonpointer dummy argument specifies that the dummy argument 7 becomes undefined on invocation of the procedure, except for any subcomponents that are default- 8 initialized (4.5.4.5). Any actual argument that becomes associated with such a dummy argument shall 9 be definable. The INTENT (OUT) attribute for a pointer dummy argument specifies that on invocation 10 of the procedure the pointer association status of the dummy argument becomes undefined. Any actual 11 argument associated with such a pointer dummy shall be a pointer variable. 12 NOTE 5.12 If the actual argument is finalizable it will be finalized before undefinition and default initialization of the dummy argument (4.5.6). The INTENT (INOUT) attribute for a nonpointer dummy argument specifies that any actual argument 13 associated with the dummy argument shall be definable. The INTENT (INOUT) attribute for a pointer 14 dummy argument specifies that any actual argument associated with the dummy argument shall be a 15 pointer variable. 16 NOTE 5.13 The INTENT attribute for an allocatable dummy argument applies to both the allocation status and the definition status. An actual argument associated with an INTENT(OUT) allocatable dummy argument is deallocated on procedure invocation (6.3.3.1). If no INTENT attribute is specified for a dummy argument, its use is sub ject to the limitations of the 17 argument associated entity (12.5.1.4, 12.5.1.6, 12.5.1.7). 18 NOTE 5.14 An example of INTENT specification is: SUBROUTINE MOVE (FROM, TO) USE PERSON_MODULE TYPE (PERSON), INTENT (IN) :: FROM TYPE (PERSON), INTENT (OUT) :: TO If an ob ject has an INTENT attribute, then all of its subob jects have the same INTENT attribute. 19 NOTE 5.15 If a dummy argument is a derived-type ob ject with a pointer component, then the pointer as a pointer is a subob ject of the dummy argument, but the target of the pointer is not. Therefore, the restrictions on subob jects of the dummy ob ject apply to the pointer in contexts where it is used as a pointer, but not in contexts where it is dereferenced to indicate its target. For example, if X is a dummy argument of derived type with an integer pointer component P, and X has INTENT(IN), then the statement X%P => NEW_TARGET 93 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 5.15 (cont.) is prohibited, but X%P = 0 is allowed (provided that X%P is associated with a definable target). Similarly, the INTENT restrictions on pointer dummy arguments apply only to the association of the dummy argument; they do not restrict the operations allowed on its target. NOTE 5.16 Argument intent specifications serve several purposes in addition to documenting the intended use of dummy arguments. A processor can check whether an INTENT (IN) dummy argument is used in a way that could redefine it. A slightly more sophisticated processor could check to see whether an INTENT (OUT) dummy argument could possibly be referenced before it is defined. If the procedure's interface is explicit, the processor can also verify that actual arguments corresponding to INTENT (OUT) or INTENT (INOUT) dummy arguments are definable. A more sophisticated processor could use this information to optimize the translation of the referencing scoping unit by taking advantage of the fact that actual arguments corresponding to INTENT (IN) dummy arguments will not be changed and that any prior value of an actual argument corresponding to an INTENT (OUT) dummy argument will not be referenced and could thus be discarded. INTENT (OUT) means that the value of the argument after invoking the procedure is entirely the result of executing that procedure. If there is any possibility that an argument should retain its current value rather than being redefined, INTENT (INOUT) should be used rather than INTENT (OUT), even if there is no explicit reference to the value of the dummy argument. Because an INTENT(OUT) variable is considered undefined on entry to the procedure, any default initialization specified for its type will be applied. INTENT (INOUT) is not equivalent to omitting the INTENT attribute. The actual argument corresponding to an INTENT (INOUT) dummy argument is always required to be definable, while an argument corresponding to a dummy argument without an INTENT attribute need be definable only if the dummy argument is actually redefined. 5.3.10 INTRINSIC attribute 1 The INTRINSIC attribute specifies that the entity is an intrinsic procedure. It may be a generic 2 procedure (13.5), a specific procedure (13.6), or both. 3 If the specific name of an intrinsic procedure (13.6) is used as an actual argument, the name shall be 4 explicitly specified to have the INTRINSIC attribute. An intrinsic procedure whose specific name is 5 marked with a bullet (·) in 13.6 shall not be used as an actual argument. 6 C536 If the name of a generic intrinsic procedure is explicitly declared to have the INTRINSIC at- 7 tribute, and it is also the generic name of one or more generic interfaces (12.4.2.1) accessible in 8 the same scoping unit, the procedures in the interfaces and the specific intrinsic procedures shall 9 all be functions or all be subroutines, and the characteristics of the specific intrinsic procedures 10 and the procedures in the interfaces shall differ as specified in 16.3.4. 11 5.3.11 OPTIONAL attribute 12 The OPTIONAL attribute specifies that the dummy argument need not be associated with an actual 13 argument in a reference to the procedure (12.5.1.9). The PRESENT intrinsic function can be used to 14 94 2006/07/11 WORKING DRAFT J3/06-007 determine whether an optional dummy argument is associated with an actual argument. 1 C537 An entity with the OPTIONAL attribute shall be a dummy argument. 2 5.3.12 PARAMETER attribute 3 The PARAMETER attribute specifies that an entity is a named constant. The entity has the value 4 specified by its initialization-expr , converted, if necessary, to the type, type parameters and shape of the 5 entity. 6 C538 An entity with the PARAMETER attribute shall not be a variable, a co-array, or a procedure. 7 A named constant shall not be referenced unless it has been defined previously in the same statement, 8 defined in a prior statement, or made accessible by use or host association. 9 NOTE 5.17 Examples of declarations with a PARAMETER attribute are: REAL, PARAMETER :: ONE = 1.0, Y = 4.1 / 3.0 INTEGER, DIMENSION (3), PARAMETER :: ORDER = (/ 1, 2, 3 /) TYPE(NODE), PARAMETER :: DEFAULT = NODE(0, NULL ( )) 5.3.13 POINTER attribute 10 Entities with the POINTER attribute can be associated with different data ob jects or procedures 11 during execution of a program. A pointer is either a data pointer or a procedure pointer. Procedure 12 pointers are described in 12.4.2.3. 13 C539 An entity with the POINTER attribute shall not have the ALLOCATABLE, INTRINSIC, or 14 TARGET attribute. 15 C540 A procedure with the POINTER attribute shall have the EXTERNAL attribute. 16 C541 A co-array shall not have the POINTER attribute. 17 A data pointer shall not be referenced unless it is pointer associated with a target ob ject that is defined. 18 A data pointer shall not be defined unless it is pointer associated with a target ob ject that is definable. 19 If a data pointer is associated, the values of its deferred type parameters are the same as the values of 20 the corresponding type parameters of its target. 21 A procedure pointer shall not be referenced unless it is pointer associated with a target procedure. 22 NOTE 5.18 Examples of POINTER attribute specifications are: TYPE (NODE), POINTER :: CURRENT, TAIL REAL, DIMENSION (:, :), POINTER :: IN, OUT, SWAP For a more elaborate example see C.2.1. 95 J3/06-007 WORKING DRAFT 2006/07/11 5.3.14 PROTECTED attribute 1 The PROTECTED attribute imposes limitations on the usage of module entities. 2 C542 The PROTECTED attribute shall be specified only in the specification part of a module. 3 C543 An entity with the PROTECTED attribute shall be a procedure pointer or variable. 4 C544 An entity with the PROTECTED attribute shall not be in a common block. 5 C545 A nonpointer ob ject that has the PROTECTED attribute and is accessed by use association 6 shall not appear in a variable definition context (16.6.7) or as the data-target or proc-target in 7 a pointer-assignment-stmt . 8 C546 A pointer that has the PROTECTED attribute and is accessed by use association shall not 9 appear in a pointer association context (16.6.8). 10 Other than within the module in which an entity is given the PROTECTED attribute, or within any of 11 its descendants, 12 (1) if it is a nonpointer ob ject, it is not definable, and 13 (2) if it is a pointer, its association status shall not be changed except that it may become 14 undefined if its target is deallocated other than through the pointer (16.5.2.2.3) or if its 15 target becomes undefined by execution of a RETURN or END statement. 16 If an ob ject has the PROTECTED attribute, all of its subob jects have the PROTECTED attribute. 17 NOTE 5.19 An example of the PROTECTED attribute: MODULE temperature REAL, PROTECTED :: temp_c, temp_f CONTAINS SUBROUTINE set_temperature_c(c) REAL, INTENT(IN) :: c temp_c = c temp_f = temp_c*(9.0/5.0) + 32 END SUBROUTINE END MODULE The PROTECTED attribute ensures that the variables temp c and temp f cannot be modified other than via the set temperature c procedure, thus keeping them consistent with each other. 5.3.15 SAVE attribute 18 The SAVE attribute specifies that a variable retains its association status, allocation status, definition 19 status, and value after execution of a RETURN or END statement unless it is a pointer and its target 20 becomes undefined (16.5.2.2.3(4)). If it is a local variable of a subprogram it is shared by all instances 21 (12.6.2.3) of the subprogram. 22 Giving a common block the SAVE attribute confers the attribute on all variables in the common block. 23 C547 An entity with the SAVE attribute shall be a common block, variable, or procedure pointer. 24 C548 The SAVE attribute shall not be specified for a dummy argument, a function result, an automatic 25 96 2006/07/11 WORKING DRAFT J3/06-007 data ob ject, or an ob ject that is in a common block. 1 C549 The SAVE attribute shall be specified for a co-array unless it is a dummy argument, declared 2 in the main program, or allocatable and declared in a non-recursive procedure. 3 NOTE 5.20 An allocatable co-array is required to have the SAVE attribute in a recursive procedure because of the difficulties associated with defining the separate levels of recursion. Without the SAVE attribute, each would have a separate instance of the co-array and implicit synchronization would be required for each allocation and deallocation of each instance. Automatic co-arrays are not permitted; for example, the co-array WORK in the following code fragment is not valid. SUBROUTINE SOLVE3(N,A,B) INTEGER :: N REAL :: A(N)[*], B(N) REAL :: WORK(N)[*] ! Not permitted If this were permitted, it would require an implicit synchronization on entry to the procedure. Explicit-shape co-arrays that are not dummy arguments are required to have the SAVE attribute because otherwise they might be implemented as if they were automatic co-arrays. J3 internal note Unresolved Technical Issue 8 This text about about automatic co-arrays not being permitted because of putative implicit synchronisation absolutely does NOT belong here (in the SAVE attribute), nor did it belong where 06-174r3 said to insert it (in the middle of a 2-page list of constraints!). Co-arrays probably need their own subclause and it can go there. Pity they didn't use the CODIMENSION keyword instead of hijacking the DIMENSION keyword, then it would be a lot tidier with things having a rather obvious home. Furthermore, the last sentence is incorrect, because not all explicit-shape co-arrays are required to have the SAVE attribute, viz ones declared in the main program. J3 internal note Unresolved Technical Issue 9 The note says that allocatable co-arrays have to be (inconsistently) saved, "because of the diffi- culties associated with defining the separate levels of recursion". That is utter nonsense. 12.5.2.3 "Instances of a subprogram" was in F2003 already. If there were such difficulties, we wouldn't be able to have host association in recursive procedures (there since F90), or to pass internal procedures (of recursive procedures) as actual arguments (new in F2008). C550 (R501) If the type specified has a co-array ultimate component, each entity in the entity-decl -list 4 shall have the SAVE attribute unless it is a dummy argument, declared in the main program, 5 or declared in a non-recursive procedure. 6 97 J3/06-007 WORKING DRAFT 2006/07/11 J3 internal note Unresolved Technical Issue 10 This is inconsistent. (1) We require the user to SAVE variables in non-recursive procedures if he wants the value to persist. (2) ALLOCATABLE arrays that are unsaved get deallocated in non-recursive proce- dures, not saved. (3) It requires SAVE in a MODULE, but not in a non-recursive procedure!?! If you are going to special-case ANYTHING, doing it for modules must be top priority, but it's better to avoid it entirely. A saved entity is an entity that has the SAVE attribute. An unsaved entity is an entity that does not 1 have the SAVE attribute. 2 The SAVE attribute has no effect on entities declared in a main program. If a common block has the 3 SAVE attribute in any scoping unit that is not a main program, it shall have the SAVE attribute in 4 every scoping unit that is not a main program. 5 5.3.16 TARGET attribute 6 The TARGET attribute specifies that a data ob ject may have a pointer associated with it (7.4.2). 7 An ob ject without the TARGET attribute shall not have an accessible pointer associated with it. 8 C551 An entity with the TARGET attribute shall be a variable. 9 C552 An entity with the TARGET attribute shall not have the POINTER attribute. 10 NOTE 5.21 In addition to variables explicitly declared to have the TARGET attribute, the ob jects created by allocation of pointers (6.3.1.2) have the TARGET attribute. If an ob ject has the TARGET attribute, then all of its nonpointer subob jects also have the TARGET 11 attribute. 12 NOTE 5.22 Examples of TARGET attribute specifications are: TYPE (NODE), TARGET :: HEAD REAL, DIMENSION (1000, 1000), TARGET :: A, B For a more elaborate example see C.2.2. NOTE 5.23 Every ob ject designator that starts from a target ob ject will have either the TARGET or POINTER attribute. If pointers are involved, the designator might not necessarily be a subob ject of the original target ob ject, but because pointers may point only to targets, there is no way to end up at a nonpointer that is not a target. 98 2006/07/11 WORKING DRAFT J3/06-007 5.3.17 VALUE attribute 1 The VALUE attribute specifies a type of argument association (12.5.1.4) for a dummy argument. 2 C553 An entity with the VALUE attribute shall be a scalar dummy data ob ject. 3 C554 An entity with the VALUE attribute shall not have the ALLOCATABLE, INTENT(INOUT), 4 INTENT(OUT), POINTER, or VOLATILE attributes. 5 C555 If an entity has the VALUE attribute, any length type parameter value in its declaration shall 6 be omitted or specified by an initialization expression. 7 5.3.18 VOLATILE attribute 8 The VOLATILE attribute specifies that an ob ject may be referenced, defined, or become undefined, 9 by means not specified by the program, or by another image without synchronization. 10 C556 An entity with the VOLATILE attribute shall be a variable that is not an INTENT(IN) dummy 11 argument. 12 An ob ject may have the VOLATILE attribute in a particular scoping unit without necessarily having 13 it in other scoping units (11.2.1, 16.5.1.4). If an ob ject has the VOLATILE attribute, then all of its 14 subob jects also have the VOLATILE attribute. 15 NOTE 5.24 The Fortran processor should use the most recent definition of a volatile ob ject when a value is required. Likewise, it should make the most recent Fortran definition available. It is the programmer's responsibility to manage any interaction with non-Fortran processes. A pointer with the VOLATILE attribute may additionally have its association status, dynamic type and 16 type parameters, and array bounds changed by means not specified by the program. 17 NOTE 5.25 If the target of a pointer is referenced, defined, or becomes undefined, by means not specified by the program, while the pointer is associated with the target, then the pointer shall have the VOLATILE attribute. Usually a pointer should have the VOLATILE attribute if its target has the VOLATILE attribute. Similarly, all members of an EQUIVALENCE group should have the VOLATILE attribute if one member has the VOLATILE attribute. An allocatable ob ject with the VOLATILE attribute may additionally have its allocation status, dynamic 18 type and type parameters, and array bounds changed by means not specified by the program. 19 5.4 Attribute sp ecification statements 20 5.4.1 Accessibility statements 21 R520 access-stmt is access-spec [ [ :: ] access-id -list ] 22 R521 access-id is use-name 23 or generic-spec 24 C557 (R520) An access-stmt shall appear only in the specification-part of a module. Only one ac- 25 cessibility statement with an omitted access-id -list is permitted in the specification-part of a 26 99 J3/06-007 WORKING DRAFT 2006/07/11 module. 1 C558 (R521) Each use-name shall be the name of a named variable, procedure, derived type, named 2 constant, namelist group, or macro. 3 An access-stmt with an access-id -list specifies the accessibility attribute (5.3.2), PUBLIC or PRIVATE, 4 of each access-id in the list. An access-stmt without an access-id list specifies the default accessibility 5 that applies to all potentially accessible identifiers in the specification-part of the module. The statement 6 PUBLIC 7 specifies a default of public accessibility. The statement 8 PRIVATE 9 specifies a default of private accessibility. If no such statement appears in a module, the default is public 10 accessibility. 11 NOTE 5.26 Examples of accessibility statements are: MODULE EX PRIVATE PUBLIC :: A, B, C, ASSIGNMENT (=), OPERATOR (+) 5.4.2 ALLOCATABLE statement 12 R522 al locatable-stmt is ALLOCATABLE [ :: ] al locatable-decl -list 13 R523 al locatable-decl is object-name [ ( array-spec ) ] 14 [ lbracket co-array-spec rbracket ] 15 This statement specifies the ALLOCATABLE attribute (5.3.3) for a list of ob jects. 16 NOTE 5.27 An example of an ALLOCATABLE statement is: REAL A, B (:), SCALAR ALLOCATABLE :: A (:, :), B, SCALAR 5.4.3 ASYNCHRONOUS statement 17 R524 asynchronous-stmt is ASYNCHRONOUS [ :: ] object-name -list 18 The ASYNCHRONOUS statement specifies the ASYNCHRONOUS attribute (5.3.4) for a list of ob jects. 19 5.4.4 BIND statement 20 R525 bind-stmt is language-binding-spec [ :: ] bind-entity -list 21 R526 bind-entity is entity-name 22 or / common-block-name / 23 C559 (R525) If the language-binding-spec has a NAME= specifier, the bind-entity -list shall consist of 24 a single bind-entity . 25 The BIND statement specifies the BIND attribute (5.3.5) for a list of variables and common blocks. 26 100 2006/07/11 WORKING DRAFT J3/06-007 5.4.5 CONTIGUOUS statement 1 R527 contiguous-stmt is CONTIGUOUS [ :: ] object-name -list 2 The CONTIGUOUS statement specifies the CONTIGUOUS attribute (5.3.6) for a list of ob jects. 3 5.4.6 DATA statement 4 R528 data-stmt is DATA data-stmt-set [ [ , ] data-stmt-set ] ... 5 This statement specifies explicit initialization (5.2.2). 6 A variable, or part of a variable, shall not be explicitly initialized more than once in a program. If a 7 nonpointer ob ject has been specified with default initialization in a type definition, it shall not appear 8 in a data-stmt-object -list. 9 A variable that appears in a DATA statement and has not been typed previously may appear in a 10 subsequent type declaration only if that declaration confirms the implicit typing. An array name, 11 array section, or array element that appears in a DATA statement shall have had its array properties 12 established by a previous specification statement. 13 Except for variables in named common blocks, a named variable has the SAVE attribute if any part of 14 it is initialized in a DATA statement, and this may be confirmed by explicit specification. 15 R529 data-stmt-set is data-stmt-object -list / data-stmt-value -list / 16 R530 data-stmt-object is variable 17 or data-implied-do 18 R531 data-implied-do is ( data-i-do-object -list , data-i-do-variable = 19 scalar-int-initialization-expr , 20 scalar-int-initialization-expr 21 [ , scalar-int-initialization-expr ] ) 22 R532 data-i-do-object is array-element 23 or scalar-structure-component 24 or data-implied-do 25 R533 data-i-do-variable is do-variable 26 C560 A data-stmt-object or data-i-do-object shall not be a co-indexed variable. 27 C561 (R530) In a variable that is a data-stmt-object , any subscript, section subscript, substring start- 28 ing point, and substring ending point shall be an initialization expression. 29 C562 (R530) A variable whose designator appears as a data-stmt-object or a data-i-do-object shall 30 not be a dummy argument, made accessible by use association or host association, in a named 31 common block unless the DATA statement is in a block data program unit, in a blank common 32 block, a function name, a function result name, an automatic ob ject, or an allocatable variable. 33 C563 (R530) A data-i-do-object or a variable that appears as a data-stmt-object shall not be an ob ject 34 designator in which a pointer appears other than as the entire rightmost part-ref . 35 C564 (R532) The array-element shall be a variable. 36 C565 (R532) The scalar-structure-component shall be a variable. 37 C566 (R532) The scalar-structure-component shall contain at least one part-ref that contains a sub- 38 script -list. 39 C567 (R532) In an array-element or scalar-structure-component that is a data-i-do-object , any sub- 40 script shall be an initialization expression, and any primary within that subscript that is a 41 101 J3/06-007 WORKING DRAFT 2006/07/11 data-i-do-variable shall be a DO variable of this data-implied-do or of a containing data-implied- 1 do . 2 R534 data-stmt-value is [ data-stmt-repeat * ] data-stmt-constant 3 R535 data-stmt-repeat is scalar-int-constant 4 or scalar-int-constant-subobject 5 C568 (R535) The data-stmt-repeat shall be positive or zero. If the data-stmt-repeat is a named con- 6 stant, it shall have been declared previously in the scoping unit or made accessible by use 7 association or host association. 8 R536 data-stmt-constant is scalar-constant 9 or scalar-constant-subobject 10 or signed-int-literal-constant 11 or signed-real-literal-constant 12 or nul l-init 13 or initial-data-target 14 or structure-constructor 15 C569 (R536) If a DATA statement constant value is a named constant or a structure constructor, the 16 named constant or derived type shall have been declared previously in the scoping unit or made 17 accessible by use or host association. 18 C570 (R536) If a data-stmt-constant is a structure-constructor , it shall be an initialization expression. 19 R537 int-constant-subobject is constant-subobject 20 C571 (R537) int-constant-subobject shall be of type integer. 21 R538 constant-subobject is designator 22 C572 (R538) constant-subobject shall be a subob ject of a constant. 23 C573 (R538) Any subscript, substring starting point, or substring ending point shall be an initializa- 24 tion expression. 25 The data-stmt-object -list is expanded to form a sequence of pointers and scalar variables, referred to 26 as "sequence of variables" in subsequent text. A nonpointer array whose unqualified name appears 27 as a data-stmt-object or data-i-do-object is equivalent to a complete sequence of its array elements in 28 array element order (6.2.2.2). An array section is equivalent to the sequence of its array elements in 29 array element order. A data-implied-do is expanded to form a sequence of array elements and structure 30 components, under the control of the data-i-do-variable , as in the DO construct (8.1.7.5). 31 The data-stmt-value -list is expanded to form a sequence of data-stmt-constant s. A data-stmt-repeat 32 indicates the number of times the following data-stmt-constant is to be included in the sequence; omission 33 of a data-stmt-repeat has the effect of a repeat factor of 1. 34 A zero-sized array or a data-implied-do with an iteration count of zero contributes no variables to the 35 expanded sequence of variables, but a zero-length scalar character variable does contribute a variable 36 to the expanded sequence. A data-stmt-constant with a repeat factor of zero contributes no data-stmt- 37 constant s to the expanded sequence of scalar data-stmt-constant s. 38 The expanded sequences of variables and data-stmt-constant s are in one-to-one correspondence. Each 39 data-stmt-constant specifies the initial value, initial data target, or nul l-init for the corresponding vari- 40 able. The lengths of the two expanded sequences shall be the same. 41 A data-stmt-constant shall be nul l-init or initial-data-target if and only if the corresponding data-stmt- 42 object has the POINTER attribute. If data-stmt-constant is nul l-init , the initial association status of 43 102 2006/07/11 WORKING DRAFT J3/06-007 the corresponding data statement ob ject is disassociated. If data-stmt-constant is initial-data-target the 1 corresponding data statement ob ject shall be data-pointer-initialization compatible with the initial data 2 target; the data statement ob ject is initially associated with the target. 3 A data-stmt-constant other than nul l-init or initial-data-target shall be compatible with its corresponding 4 variable according to the rules of intrinsic assignment (7.4.1.2). The variable is initially defined with 5 the value specified by the data-stmt-constant ; if necessary, the value is converted according to the rules 6 of intrinsic assignment (7.4.1.3) to a value that agrees in type, type parameters, and shape with the 7 variable. 8 NOTE 5.28 Examples of DATA statements are: CHARACTER (LEN = 10) NAME INTEGER, DIMENSION (0:9) :: MILES REAL, DIMENSION (100, 100) :: SKEW TYPE (NODE), POINTER :: HEAD_OF_LIST TYPE (PERSON) MYNAME, YOURNAME DATA NAME / 'JOHN DOE' /, MILES / 10 * 0 / DATA ((SKEW (K, J), J = 1, K), K = 1, 100) / 5050 * 0.0 / DATA ((SKEW (K, J), J = K + 1, 100), K = 1, 99) / 4950 * 1.0 / DATA HEAD_OF_LIST / NULL() / DATA MYNAME / PERSON (21, 'JOHN SMITH') / DATA YOURNAME % AGE, YOURNAME % NAME / 35, 'FRED BROWN' / The character variable NAME is initialized with the value JOHN DOE with padding on the right because the length of the constant is less than the length of the variable. All ten elements of the integer array MILES are initialized to zero. The two-dimensional array SKEW is initialized so that the lower triangle of SKEW is zero and the strict upper triangle is one. The structures MYNAME and YOURNAME are declared using the derived type PERSON from Note 4.20. The pointer HEAD OF LIST is declared using the derived type NODE from Note 4.39; it is initially disassociated. MYNAME is initialized by a structure constructor. YOURNAME is initialized by supplying a separate value for each component. 5.4.7 DIMENSION statement 9 R539 dimension-stmt is DIMENSION [ :: ] dimension-decl -list 10 R540 dimension-decl is array-name ( array-spec ) 11 or co-array-name [ ( array-spec ) ] lbracket co-array-spec rbracket 12 13 This statement specifies the DIMENSION attribute (5.3.7) for a list of ob jects. 14 NOTE 5.29 An example of a DIMENSION statement is: DIMENSION A (10), B (10, 70), C (:) 5.4.8 INTENT statement 15 R541 intent-stmt is INTENT ( intent-spec ) [ :: ] dummy-arg-name -list 16 This statement specifies the INTENT attribute (5.3.9) for the dummy arguments in the list. 17 103 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 5.30 An example of an INTENT statement is: SUBROUTINE EX (A, B) INTENT (INOUT) :: A, B 5.4.9 OPTIONAL statement 1 R542 optional-stmt is OPTIONAL [ :: ] dummy-arg-name -list 2 This statement specifies the OPTIONAL attribute (5.3.11) for the dummy arguments in the list. 3 NOTE 5.31 An example of an OPTIONAL statement is: SUBROUTINE EX (A, B) OPTIONAL :: B 5.4.10 PARAMETER statement 4 The PARAMETER statement specifies the PARAMETER attribute (5.3.12) and the values for the 5 named constants in the list. 6 R543 parameter-stmt is PARAMETER ( named-constant-def -list ) 7 R544 named-constant-def is named-constant = initialization-expr 8 If a named constant is defined by a PARAMETER statement, it shall not be subsequently declared to 9 have a type or type parameter value that differs from the type and type parameters it would have if 10 declared implicitly (5.5). A named array constant defined by a PARAMETER statement shall have its 11 shape specified in a prior specification statement. 12 The value of each named constant is that specified by the corresponding initialization expression; if 13 necessary, the value is converted according to the rules of intrinsic assignment (7.4.1.3) to a value that 14 agrees in type, type parameters, and shape with the named constant. 15 NOTE 5.32 An example of a PARAMETER statement is: PARAMETER (MODULUS = MOD (28, 3), NUMBER_OF_SENATORS = 100) 5.4.11 POINTER statement 16 R545 pointer-stmt is POINTER [ :: ] pointer-decl -list 17 R546 pointer-decl is object-name [ ( deferred-shape-spec -list ) ] 18 or proc-entity-name 19 This statement specifies the POINTER attribute (5.3.13) for a list of entities. 20 NOTE 5.33 An example of a POINTER statement is: TYPE (NODE) :: CURRENT POINTER :: CURRENT, A (:, :) 104 2006/07/11 WORKING DRAFT J3/06-007 5.4.12 PROTECTED statement 1 R547 protected-stmt is PROTECTED [ :: ] entity-name -list 2 The PROTECTED statement specifies the PROTECTED attribute (5.3.14) for a list of entities. 3 5.4.13 SAVE statement 4 R548 save-stmt is SAVE [ [ :: ] saved-entity -list ] 5 R549 saved-entity is object-name 6 or proc-pointer-name 7 or / common-block-name / 8 R550 proc-pointer-name is name 9 C574 (R548) If a SAVE statement with an omitted saved entity list appears in a scoping unit, no 10 other appearance of the SAVE attr-spec or SAVE statement is permitted in that scoping unit. 11 A SAVE statement with a saved entity list specifies the SAVE attribute (5.3.15) for a list of entities. A 12 SAVE statement without a saved entity list is treated as though it contained the names of all allowed 13 items in the same scoping unit. 14 NOTE 5.34 An example of a SAVE statement is: SAVE A, B, C, / BLOCKA /, D 5.4.14 TARGET statement 15 R551 target-stmt is TARGET [ :: ] target-decl -list 16 R552 target-decl is object-name [ ( array-spec ) ] 17 [ lbracket co-array-spec rbracket ] 18 This statement specifies the TARGET attribute (5.3.16) for a list of ob jects. 19 NOTE 5.35 An example of a TARGET statement is: TARGET :: A (1000, 1000), B 5.4.15 VALUE statement 20 R553 value-stmt is VALUE [ :: ] dummy-arg-name -list 21 The VALUE statement specifies the VALUE attribute (5.3.17) for a list of dummy arguments. 22 5.4.16 VOLATILE statement 23 R554 volatile-stmt is VOLATILE [ :: ] object-name -list 24 The VOLATILE statement specifies the VOLATILE attribute (5.3.18) for a list of ob jects. 25 105 J3/06-007 WORKING DRAFT 2006/07/11 5.5 IMPLICIT statement 1 In a scoping unit, an IMPLICIT statement specifies a type, and possibly type parameters, for all 2 implicitly typed data entities whose names begin with one of the letters specified in the statement. 3 Alternatively, it may indicate that no implicit typing rules are to apply in a particular scoping unit. 4 R555 implicit-stmt is IMPLICIT implicit-spec -list 5 or IMPLICIT NONE 6 R556 implicit-spec is declaration-type-spec ( letter-spec -list ) 7 R557 letter-spec is letter [ ­ letter ] 8 C575 (R555) If IMPLICIT NONE is specified in a scoping unit, it shall precede any PARAMETER 9 statements that appear in the scoping unit and there shall be no other IMPLICIT statements 10 in the scoping unit. 11 C576 (R557) If the minus and second letter appear, the second letter shall follow the first letter 12 alphabetically. 13 A letter-spec consisting of two letter s separated by a minus is equivalent to writing a list containing all 14 of the letters in alphabetical order in the alphabetic sequence from the first letter through the second 15 letter. For example, A­C is equivalent to A, B, C. The same letter shall not appear as a single letter, or 16 be included in a range of letters, more than once in all of the IMPLICIT statements in a scoping unit. 17 In each scoping unit, there is a mapping, which may be null, between each of the letters A, B, ..., Z 18 and a type (and type parameters). An IMPLICIT statement specifies the mapping for the letters in 19 its letter-spec -list. IMPLICIT NONE specifies the null mapping for all the letters. If a mapping is not 20 specified for a letter, the default for a program unit or an interface body is default integer if the letter 21 is I, J, ..., or N and default real otherwise, and the default for an internal or module procedure is the 22 mapping in the host scoping unit. 23 Any data entity that is not explicitly declared by a type declaration statement, is not an intrinsic 24 function, and is not made accessible by use association or host association is declared implicitly to be of 25 the type (and type parameters) mapped from the first letter of its name, provided the mapping is not 26 null. The mapping for the first letter of the data entity shall either have been established by a prior 27 IMPLICIT statement or be the default mapping for the letter. The mapping may be to a derived type 28 that is inaccessible in the local scope if the derived type is accessible in the host scoping unit. The data 29 entity is treated as if it were declared in an explicit type declaration in the outermost scoping unit in 30 which it appears. An explicit type specification in a FUNCTION statement overrides an IMPLICIT 31 statement for the name of the result variable of that function subprogram. 32 NOTE 5.36 The following are examples of the use of IMPLICIT statements: MODULE EXAMPLE_MODULE IMPLICIT NONE ... INTERFACE FUNCTION FUN (I) ! Not all data entities need to INTEGER FUN ! be declared explicitly END FUNCTION FUN END INTERFACE CONTAINS FUNCTION JFUN (J) ! All data entities need to INTEGER JFUN, J ! be declared explicitly. ... 106 2006/07/11 WORKING DRAFT J3/06-007 NOTE 5.36 (cont.) END FUNCTION JFUN END MODULE EXAMPLE_MODULE SUBROUTINE SUB IMPLICIT COMPLEX (C) C = (3.0, 2.0) ! C is implicitly declared COMPLEX ... CONTAINS SUBROUTINE SUB1 IMPLICIT INTEGER (A, C) C = (0.0, 0.0) ! C is host associated and of ! type complex Z = 1.0 ! Z is implicitly declared REAL A=2 ! A is implicitly declared INTEGER CC = 1 ! CC is implicitly declared INTEGER ... END SUBROUTINE SUB1 SUBROUTINE SUB2 Z = 2.0 ! Z is implicitly declared REAL and ! is different from the variable of ! the same name in SUB1 ... END SUBROUTINE SUB2 SUBROUTINE SUB3 USE EXAMPLE_MODULE ! Accesses integer function FUN ! by use association Q = FUN (K) ! Q is implicitly declared REAL and ... ! K is implicitly declared INTEGER END SUBROUTINE SUB3 END SUBROUTINE SUB NOTE 5.37 The following is an example of a mapping to a derived type that is inaccessible in the local scope: PROGRAM MAIN IMPLICIT TYPE(BLOB) (A) TYPE BLOB INTEGER :: I END TYPE BLOB TYPE(BLOB) :: B CALL STEVE CONTAINS SUBROUTINE STEVE INTEGER :: BLOB .. AA = B .. END SUBROUTINE STEVE END PROGRAM MAIN In the subroutine STEVE, it is not possible to explicitly declare a variable to be of type BLOB because BLOB has been given a different meaning, but implicit mapping for the letter A still maps 107 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 5.37 (cont.) to type BLOB, so AA is of type BLOB. 5.6 NAMELIST statement 1 A NAMELIST statement specifies a group of named data ob jects, which may be referred to by a 2 single name for the purpose of data transfer (9.5, 10.11). 3 R558 namelist-stmt is NAMELIST 4 / namelist-group-name / namelist-group-object -list 5 [ [ , ] / namelist-group-name / 6 namelist-group-object -list ] . . . 7 C577 (R558) The namelist-group-name shall not be a name accessed by use association. 8 R559 namelist-group-object is variable-name 9 C578 (R559) A namelist-group-object shall not be an assumed-size array. 10 C579 (R558) A namelist-group-object shall not have the PRIVATE attribute if the namelist-group- 11 name has the PUBLIC attribute. 12 The order in which the variables are specified in the NAMELIST statement determines the order in 13 which the values appear on output. 14 Any namelist-group-name may occur more than once in the NAMELIST statements in a scoping unit. 15 The namelist-group-object -list following each successive appearance of the same namelist-group-name in 16 a scoping unit is treated as a continuation of the list for that namelist-group-name . 17 A namelist group ob ject may be a member of more than one namelist group. 18 A namelist group ob ject shall either be accessed by use or host association or shall have its type, type 19 parameters, and shape specified by previous specification statements or the procedure heading in the 20 same scoping unit or by the implicit typing rules in effect for the scoping unit. If a namelist group ob ject 21 is typed by the implicit typing rules, its appearance in any subsequent type declaration statement shall 22 confirm the implied type and type parameters. 23 NOTE 5.38 An example of a NAMELIST statement is: NAMELIST /NLIST/ A, B, C 5.7 Storage association of data objects 24 5.7.1 EQUIVALENCE statement 25 5.7.1.1 General 26 An EQUIVALENCE statement is used to specify the sharing of storage units by two or more ob jects 27 in a scoping unit. This causes storage association (16.5.3) of the ob jects that share the storage units. 28 108 2006/07/11 WORKING DRAFT J3/06-007 NOTE 5.39 The co-size of a co-array is not a constant, therefore co-arrays are not allowed in COMMON or EQUIVALENCE. If the equivalenced ob jects have differing type or type parameters, the EQUIVALENCE statement does 1 not cause type conversion or imply mathematical equivalence. If a scalar and an array are equivalenced, 2 the scalar does not have array properties and the array does not have the properties of a scalar. 3 R560 equivalence-stmt is EQUIVALENCE equivalence-set -list 4 R561 equivalence-set is ( equivalence-object , equivalence-object -list ) 5 R562 equivalence-object is variable-name 6 or array-element 7 or substring 8 C580 (R562) An equivalence-object shall not be a designator with a base ob ject that is a dummy 9 argument, a pointer, an allocatable variable, a derived-type ob ject that has an allocatable ulti- 10 mate component, an ob ject of a nonsequence derived type, an ob ject of a derived type that has 11 a pointer at any level of component selection, an automatic ob ject, a function name, an entry 12 name, a result name, a variable with the BIND attribute, a variable in a common block that 13 has the BIND attribute, or a named constant. 14 C581 (R562) An equivalence-object shall not be a designator that has more than one part-ref . 15 C582 (R562) An equivalence-object shall not be a co-array or a subob ject thereof. 16 C583 (R562) An equivalence-object shall not have the TARGET attribute. 17 C584 (R562) Each subscript or substring range expression in an equivalence-object shall be an integer 18 initialization expression (7.1.7). 19 C585 (R561) If an equivalence-object is of type default integer, default real, double precision real, 20 default complex, default logical, or numeric sequence type, all of the ob jects in the equivalence 21 set shall be of these types. 22 C586 (R561) If an equivalence-object is of type default character or character sequence type, all of the 23 ob jects in the equivalence set shall be of these types. 24 C587 (R561) If an equivalence-object is of a sequence derived type that is not a numeric sequence or 25 character sequence type, all of the ob jects in the equivalence set shall be of the same type with 26 the same type parameter values. 27 C588 (R561) If an equivalence-object is of an intrinsic type other than default integer, default real, 28 double precision real, default complex, default logical, or default character, all of the ob jects in 29 the equivalence set shall be of the same type with the same kind type parameter value. 30 C589 (R562) If an equivalence-object has the PROTECTED attribute, all of the ob jects in the equiv- 31 alence set shall have the PROTECTED attribute. 32 C590 (R562) The name of an equivalence-object shall not be a name made accessible by use association. 33 C591 (R562) A substring shall not have length zero. 34 NOTE 5.40 The EQUIVALENCE statement allows the equivalencing of sequence structures and the equiv- alencing of ob jects of intrinsic type with nondefault type parameters, but there are strict rules regarding the appearance of these ob jects in an EQUIVALENCE statement. 109 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 5.40 (cont.) A structure that appears in an EQUIVALENCE statement shall be a sequence structure. If a sequence structure is not of numeric sequence type or of character sequence type, it shall be equivalenced only to ob jects of the same type with the same type parameter values. A structure of a numeric sequence type shall be equivalenced only to another structure of a numeric sequence type, an ob ject of default integer type, default real type, double precision real type, default complex type, or default logical type such that components of the structure ultimately become associated only with ob jects of these types. A structure of a character sequence type shall be equivalenced only to an ob ject of default character type or another structure of a character sequence type. An ob ject of intrinsic type with nondefault kind type parameters shall not be equivalenced to ob jects of different type or kind type parameters. Further rules on the interaction of EQUIVALENCE statements and default initialization are given in 16.5.3.4. 5.7.1.2 Equivalence asso ciation 1 An EQUIVALENCE statement specifies that the storage sequences (16.5.3.2) of the data ob jects specified 2 in an equivalence-set are storage associated. All of the nonzero-sized sequences in the equivalence-set , if 3 any, have the same first storage unit, and all of the zero-sized sequences in the equivalence-set , if any, 4 are storage associated with one another and with the first storage unit of any nonzero-sized sequences. 5 This causes the storage association of the data ob jects in the equivalence-set and may cause storage 6 association of other data ob jects. 7 5.7.1.3 Equivalence of default character objects 8 A data ob ject of type default character shall not be equivalenced to an ob ject that is not of type default 9 character and not of a character sequence type. The lengths of the equivalenced character ob jects need 10 not be the same. 11 An EQUIVALENCE statement specifies that the storage sequences of all the default character data 12 ob jects specified in an equivalence-set are storage associated. All of the nonzero-sized sequences in the 13 equivalence-set , if any, have the same first character storage unit, and all of the zero-sized sequences in 14 the equivalence-set , if any, are storage associated with one another and with the first character storage 15 unit of any nonzero-sized sequences. This causes the storage association of the data ob jects in the 16 equivalence-set and may cause storage association of other data ob jects. 17 NOTE 5.41 For example, using the declarations: CHARACTER (LEN = 4) :: A, B CHARACTER (LEN = 3) :: C (2) EQUIVALENCE (A, C (1)), (B, C (2)) the association of A, B, and C can be illustrated graphically as: 1 2 3 4 5 6 7 |--- --- A --- ---| |--- --- B --- ---| |--- C(1) ---| |--- C(2) ---| 110 2006/07/11 WORKING DRAFT J3/06-007 5.7.1.4 Array names and array element designators 1 For a nonzero-sized array, the use of the array name unqualified by a subscript list as an equivalence- 2 object has the same effect as using an array element designator that identifies the first element of the 3 array. 4 5.7.1.5 Restrictions on EQUIVALENCE statements 5 An EQUIVALENCE statement shall not specify that the same storage unit is to occur more than once 6 in a storage sequence. 7 NOTE 5.42 For example: REAL, DIMENSION (2) :: A REAL :: B EQUIVALENCE (A (1), B), (A (2), B) ! Not standard-conforming is prohibited, because it would specify the same storage unit for A (1) and A (2). An EQUIVALENCE statement shall not specify that consecutive storage units are to be nonconsecutive. 8 NOTE 5.43 For example, the following is prohibited: REAL A (2) DOUBLE PRECISION D (2) EQUIVALENCE (A (1), D (1)), (A (2), D (2)) ! Not standard-conforming 5.7.2 COMMON statement 9 5.7.2.1 General 10 The COMMON statement specifies blocks of physical storage, called common blo cks, that can be 11 accessed by any of the scoping units in a program. Thus, the COMMON statement provides a global 12 data facility based on storage association (16.5.3). 13 The common blocks specified by the COMMON statement may be named and are called named com- 14 mon blo cks, or may be unnamed and are called blank common. 15 R563 common-stmt is COMMON 16 [ / [ common-block-name ] / ] common-block-object -list 17 [ [ , ] / [ common-block-name ] / 18 common-block-object -list ] ... 19 R564 common-block-object is variable-name [ ( array-spec ) ] 20 or proc-pointer-name 21 C592 (R564) An array-spec in a common-block-object shall be an explicit-shape-spec -list. 22 C593 (R564) Only one appearance of a given variable-name or proc-pointer-name is permitted in all 23 common-block-object -list s within a scoping unit. 24 C594 (R564) A common-block-object shall not be a dummy argument, an allocatable variable, a 25 derived-type ob ject with an ultimate component that is allocatable, an automatic ob ject, a 26 111 J3/06-007 WORKING DRAFT 2006/07/11 function name, an entry name, a variable with the BIND attribute, a co-array, or a result name. 1 C595 (R564) If a common-block-object is of a derived type, it shall be a sequence type (4.5.2) or a 2 type with the BIND attribute and it shall have no default initialization. 3 C596 (R564) A variable-name or proc-pointer-name shall not be a name made accessible by use 4 association. 5 In each COMMON statement, the data ob jects whose names appear in a common block ob ject list 6 following a common block name are declared to be in that common block. If the first common block 7 name is omitted, all data ob jects whose names appear in the first common block ob ject list are specified to 8 be in blank common. Alternatively, the appearance of two slashes with no common block name between 9 them declares the data ob jects whose names appear in the common block ob ject list that follows to be 10 in blank common. 11 Any common block name or an omitted common block name for blank common may occur more than 12 once in one or more COMMON statements in a scoping unit. The common block list following each 13 successive appearance of the same common block name in a scoping unit is treated as a continuation of 14 the list for that common block name. Similarly, each blank common block ob ject list in a scoping unit 15 is treated as a continuation of blank common. 16 The form variable-name (array-spec ) specifies the DIMENSION attribute for that variable. 17 If derived-type ob jects of numeric sequence type (4.5.2) or character sequence type (4.5.2) appear in 18 common, it is as if the individual components were enumerated directly in the common list. 19 NOTE 5.44 Examples of COMMON statements are: COMMON /BLOCKA/ A, B, D (10, 30) COMMON I, J, K 5.7.2.2 Common blo ck storage sequence 20 For each common block in a scoping unit, a common blo ck storage sequence is formed as follows: 21 (1) A storage sequence is formed consisting of the sequence of storage units in the storage 22 sequences (16.5.3.2) of all data ob jects in the common block ob ject lists for the common 23 block. The order of the storage sequences is the same as the order of the appearance of the 24 common block ob ject lists in the scoping unit. 25 (2) The storage sequence formed in (1) is extended to include all storage units of any storage 26 sequence associated with it by equivalence association. The sequence shall be extended only 27 by adding storage units beyond the last storage unit. Data ob jects associated with an entity 28 in a common block are considered to be in that common block. 29 Only COMMON statements and EQUIVALENCE statements appearing in the scoping unit contribute 30 to common block storage sequences formed in that scoping unit. 31 5.7.2.3 Size of a common blo ck 32 The size of a common blo ck is the size of its common block storage sequence, including any extensions 33 of the sequence resulting from equivalence association. 34 112 2006/07/11 WORKING DRAFT J3/06-007 5.7.2.4 Common asso ciation 1 Within a program, the common block storage sequences of all nonzero-sized common blocks with the 2 same name have the same first storage unit, and the common block storage sequences of all zero-sized 3 common blocks with the same name are storage associated with one another. Within a program, the 4 common block storage sequences of all nonzero-sized blank common blocks have the same first storage 5 unit and the storage sequences of all zero-sized blank common blocks are associated with one another and 6 with the first storage unit of any nonzero-sized blank common blocks. This results in the association of 7 ob jects in different scoping units. Use association or host association may cause these associated ob jects 8 to be accessible in the same scoping unit. 9 A nonpointer ob ject of default integer type, default real type, double precision real type, default complex 10 type, default logical type, or numeric sequence type shall be associated only with nonpointer ob jects of 11 these types. 12 A nonpointer ob ject of type default character or character sequence type shall be associated only with 13 nonpointer ob jects of these types. 14 A nonpointer ob ject of a derived type that is not a numeric sequence or character sequence type shall 15 be associated only with nonpointer ob jects of the same type with the same type parameter values. 16 A nonpointer ob ject of intrinsic type other than default integer, default real, double precision real, 17 default complex, default logical, or default character shall be associated only with nonpointer ob jects of 18 the same type and type parameters. 19 A data pointer shall be storage associated only with data pointers of the same type and rank. Data 20 pointers that are storage associated shall have deferred the same type parameters; corresponding non- 21 deferred type parameters shall have the same value. A procedure pointer shall be storage associated 22 only with another procedure pointer; either both interfaces shall be explicit or both interfaces shall be 23 implicit. If the interfaces are explicit, the characteristics shall be the same. If the interfaces are implicit, 24 either both shall be subroutines or both shall be functions with the same type and type parameters. 25 An ob ject with the TARGET attribute shall be storage associated only with another ob ject that has 26 the TARGET attribute and the same type and type parameters. 27 NOTE 5.45 A common block is permitted to contain sequences of different storage units, provided each scoping unit that accesses the common block specifies an identical sequence of storage units for the common block. For example, this allows a single common block to contain both numeric and character storage units. Association in different scoping units between ob jects of default type, ob jects of double precision real type, and sequence structures is permitted according to the rules for equivalence ob jects (5.7.1). 5.7.2.5 Differences b etween named common and blank common 28 A blank common block has the same properties as a named common block, except for the following. 29 (1) Execution of a RETURN or END statement may cause data ob jects in a named common 30 block to become undefined unless the common block has the SAVE attribute, but never 31 causes data ob jects in blank common to become undefined (16.6.6). 32 (2) Named common blocks of the same name shall be of the same size in all scoping units of a 33 program in which they appear, but blank common blocks may be of different sizes. 34 (3) A data ob ject in a named common block may be initially defined by means of a DATA 35 statement or type declaration statement in a block data program unit (11.3), but ob jects in 36 113 J3/06-007 WORKING DRAFT 2006/07/11 blank common shall not be initially defined. 1 5.7.3 Restrictions on common and equivalence 2 An EQUIVALENCE statement shall not cause the storage sequences of two different common blocks to 3 be associated. 4 Equivalence association shall not cause a derived-type ob ject with default initialization to be associated 5 with an ob ject in a common block. 6 Equivalence association shall not cause a common block storage sequence to be extended by adding 7 storage units preceding the first storage unit of the first ob ject specified in a COMMON statement for 8 the common block. 9 NOTE 5.46 For example, the following is not permitted: COMMON /X/ A REAL B (2) EQUIVALENCE (A, B (2)) ! Not standard-conforming 114 2006/07/11 WORKING DRAFT J3/06-007 6 Use of data objects 1 The appearance of a data ob ject designator in a context that requires its value is termed a reference. A 2 reference is permitted only if the data ob ject is defined. A reference to a pointer is permitted only if the 3 pointer is associated with a target ob ject that is defined. A data ob ject becomes defined with a value 4 when events described in 16.6.5 occur. 5 R601 variable is designator 6 or expr 7 C601 (R601) designator shall not be a constant or a subob ject of a constant. 8 C602 (R601) The expr shall be a reference to a function that has a pointer result. 9 A variable is either the data ob ject denoted by designator or the target of expr . 10 R602 variable-name is name 11 C603 (R602) A variable-name shall be the name of a variable. 12 R603 designator is object-name 13 or array-element 14 or array-section 15 or complex-part-designator 16 or structure-component 17 or substring 18 R604 logical-variable is variable 19 C604 (R604) logical-variable shall be of type logical. 20 R605 default-logical-variable is variable 21 C605 (R605) default-logical-variable shall be of type default logical. 22 R606 char-variable is variable 23 C606 (R606) char-variable shall be of type character. 24 R607 default-char-variable is variable 25 C607 (R607) default-char-variable shall be of type default character. 26 R608 int-variable is variable 27 C608 (R608) int-variable shall be of type integer. 28 NOTE 6.1 For example, given the declarations: CHARACTER (10) A, B (10) TYPE (PERSON) P ! See Note 4.20 then A, B, B (1), B (1:5), P % AGE, and A (1:1) are all variables. 115 J3/06-007 WORKING DRAFT 2006/07/11 A constant (3.2.2) is a literal constant or a named constant. A literal constant is a scalar denoted by a 1 syntactic form, which indicates its type, type parameters, and value. A named constant is a constant 2 that has a name; the name has the PARAMETER attribute (5.3.12, 5.4.10). A reference to a constant 3 is always permitted; redefinition of a constant is never permitted. 4 6.1 Scalars 5 A scalar (2.4.4) is a data entity that can be represented by a single value of the type and that is not an 6 array (6.2). Its value, if defined, is a single element from the set of values that characterize its type. 7 NOTE 6.2 A scalar ob ject of derived type has a single value that consists of the values of its components (4.5.8). A scalar has rank zero. 8 6.1.1 Substrings 9 A substring is a contiguous portion of a character string (4.4.5). The following rules define the forms 10 of a substring: 11 R609 substring is parent-string ( substring-range ) 12 R610 parent-string is scalar-variable-name 13 or array-element 14 or scalar-structure-component 15 or scalar-constant 16 R611 substring-range is [ scalar-int-expr ] : [ scalar-int-expr ] 17 C609 (R610) parent-string shall be of type character. 18 The value of the first scalar-int-expr in substring-range is called the starting p oint and the value of 19 the second one is called the ending p oint. The length of a substring is the number of characters in the 20 substring and is MAX (l - f + 1, 0), where f and l are the starting and ending points, respectively. 21 Let the characters in the parent string be numbered 1, 2, 3, ..., n, where n is the length of the parent 22 string. Then the characters in the substring are those from the parent string from the starting point and 23 proceeding in sequence up to and including the ending point. Both the starting point and the ending 24 point shall be within the range 1, 2, ..., n unless the starting point exceeds the ending point, in which 25 case the substring has length zero. If the starting point is not specified, the default value is 1. If the 26 ending point is not specified, the default value is n. 27 If the parent is a variable, the substring is also a variable. 28 NOTE 6.3 Examples of character substrings are: B(1)(1:5) array element as parent string P%NAME(1:1) structure component as parent string ID(4:9) scalar variable name as parent string '0123456789'(N:N) character constant as parent string 116 2006/07/11 WORKING DRAFT J3/06-007 6.1.2 Structure comp onents 1 A structure comp onent is part of an ob ject of derived type; it may be referenced by an ob ject 2 designator. A structure component may be a scalar or an array. 3 R612 data-ref is part-ref [ % part-ref ] ... 4 R613 part-ref is part-name [ ( section-subscript -list ) ] [ image-selector ] 5 C610 (R612) Each part-name except the rightmost shall be of derived type. 6 C611 (R612) Each part-name except the leftmost shall be the name of a component of the declared 7 type of the preceding part-name . 8 C612 (R612) If the rightmost part-name is of abstract type, data-ref shall be polymorphic. 9 C613 (R612) The leftmost part-name shall be the name of a data ob ject. 10 C614 (R613) If a section-subscript -list appears, the number of section-subscript s shall equal the rank 11 of part-name . 12 C615 (R613) If image-selector appears and part-name is an array, section-subscript -list shall appear. 13 C616 (R613) A data-ref that is a co-indexed ob ject shall not be of a type that has a pointer ultimate 14 component. 15 NOTE 6.4 This restriction is needed to avoid a disallowed pointer assignment for a component, such as Z[P] = Z ! Not allowed if Z has a pointer component Z = Z[P] ! Not allowed if Z has a pointer component J3 internal note Unresolved Technical Issue 20 Is "Z[P] = Z" allowed if Z has an allocatable component? This would imply remote (re)allocation, which I was told was bad when I asked why we were prohibiting "array[i]" forcing it to be "array(:)[i]". Also, constraint (C633a) in ALLOCATE prevents explicit remote allocation. If the answer is that remote reallocation is fine in this instance, we need to make that consistent (including allowing explicit remote allocation). Or if it is bad, we need to remove it consistently. Subgroup say they want to allow this, but require allocatable components in Z[P] to have the same shape as those in Z, removing the auto realloc. The editor disagrees that this is an obviously "good" technical fix; see discussion under assignment. The rank of a part-ref of the form part-name is the rank of part-name . The rank of a part-ref that has 16 a section subscript list is the number of subscript triplets and vector subscripts in the list. 17 C617 (R612) There shall not be more than one part-ref with nonzero rank. A part-name to the right 18 of a part-ref with nonzero rank shall not have the ALLOCATABLE or POINTER attribute. 19 The rank of a data-ref is the rank of the part-ref with nonzero rank, if any; otherwise, the rank is zero. 20 The base ob ject of a data-ref is the data ob ject whose name is the leftmost part name. 21 The type and type parameters, if any, of a data-ref are those of the rightmost part name. 22 A data-ref with more than one part-ref is a subob ject of its base ob ject if none of the part-name s, 23 except for possibly the rightmost, are pointers. If the rightmost part-name is the only pointer, then the 24 data-ref is a subob ject of its base ob ject in contexts that pertain to its pointer association status but 25 117 J3/06-007 WORKING DRAFT 2006/07/11 not in any other contexts. 1 NOTE 6.5 If X is an ob ject of derived type with a pointer component P, then the pointer X%P is a subob ject of X when considered as a pointer ­ that is in contexts where it is not dereferenced. However the target of X%P is not a subob ject of X. Thus, in contexts where X%P is dereferenced to refer to the target, it is not a subob ject of X. R614 structure-component is data-ref 2 C618 (R614) There shall be more than one part-ref and the rightmost part-ref shall be of the form 3 part-name . 4 A structure component shall be neither referenced nor defined before the declaration of the base ob ject. 5 A structure component is a pointer only if the rightmost part name is defined to have the POINTER 6 attribute. 7 NOTE 6.6 Examples of structure components are: SCALAR_PARENT%SCALAR_FIELD scalar component of scalar parent ARRAY_PARENT(J)%SCALAR_FIELD component of array element parent ARRAY_PARENT(1:N)%SCALAR_FIELD component of array section parent For a more elaborate example see C.3.1. NOTE 6.7 The syntax rules are structured such that a data-ref that ends in a component name without a following subscript list is a structure component, even when other component names in the data- ref are followed by a subscript list. A data-ref that ends in a component name with a following subscript list is either an array element or an array section. A data-ref of nonzero rank that ends with a substring-range is an array section. A data-ref of zero rank that ends with a substring-range is a substring. A sub comp onent of an ob ject of derived type is a component of that ob ject or of a subob ject of that 8 ob ject. 9 6.1.3 Complex parts 10 A complex part designator is used to designate the real or imaginary part of a complex data ob ject, 11 independently of the other part. 12 R615 complex-part-designator is designator % RE 13 or designator % IM 14 C619 (R615) The designator shall be of complex type. 15 If complex-part-designator is designator %RE it designates the real part of designator . If it is designa- 16 tor %IM it designates the imaginary part of designator . The type of a complex-part-designator is real, 17 and its kind and shape are those of the designator . 18 118 2006/07/11 WORKING DRAFT J3/06-007 NOTE 6.8 The following are examples of complex part designators: impedance%re !-- Same value as REAL(impedance) fft%im !-- Same value as AIMAG(fft) x%im = 0.0 !-- Sets the imaginary part of X to zero 6.1.4 Type parameter inquiry 1 A typ e parameter inquiry is used to inquire about a type parameter of a data ob ject. It applies to 2 both intrinsic and derived types. 3 R616 type-param-inquiry is designator % type-param-name 4 C620 (R616) The type-param-name shall be the name of a type parameter of the declared type of the 5 ob ject designated by the designator . 6 A deferred type parameter of a pointer that is not associated or of an unallocated allocatable variable 7 shall not be inquired about. 8 NOTE 6.9 A type-param-inquiry has a syntax like that of a structure component reference, but it does not have the same semantics. It is not a variable and thus can never be assigned to. It may be used only as a primary in an expression. It is scalar even if designator is an array. The intrinsic type parameters can also be inquired about by using the intrinsic functions KIND and LEN. NOTE 6.10 The following are examples of type parameter inquiries: a%kind !-- A is real. Same value as KIND(a). s%len !-- S is character. Same value as LEN(s). b(10)%kind !-- Inquiry about an array element. p%dim !-- P is of the derived type general_point. See Note 4.27 for the definition of the general point type used in the last example above. 6.2 Arrays 9 An array is a set of scalar data, all of the same type and type parameters, whose individual elements 10 are arranged in a rectangular pattern. The scalar data that make up an array are the array elements. 11 No order of reference to the elements of an array is indicated by the appearance of the array designator, 12 except where array element ordering (6.2.2.2) is specified. 13 6.2.1 Whole arrays 14 A whole array is a named array, which may be either a named constant (5.3.12, 5.4.10) or a variable; 15 no subscript list is appended to the name. 16 The appearance of a whole array variable in an executable construct specifies all the elements of the 17 array (2.4.5). An assumed-size array is permitted to appear as a whole array in an executable construct 18 119 J3/06-007 WORKING DRAFT 2006/07/11 only as an actual argument in a procedure reference that does not require the shape. 1 The appearance of a whole array name in a nonexecutable statement specifies the entire array except 2 for the appearance of a whole array name in an equivalence set (5.7.1.4). 3 6.2.2 Array elements and array sections 4 R617 array-element is data-ref 5 C621 (R617) Every part-ref shall have rank zero and the last part-ref shall contain a subscript -list. 6 R618 array-section is data-ref [ ( substring-range ) ] 7 or complex-part-designator 8 C622 (R618) Exactly one part-ref shall have nonzero rank, and either the final part-ref shall have a 9 section-subscript -list with nonzero rank, the array-section is a complex-part-designator that is 10 an array, or another part-ref shall have nonzero rank. 11 C623 (R618) If a substring-range appears, the rightmost part-name shall be of type character. 12 R619 subscript is scalar-int-expr 13 R620 section-subscript is subscript 14 or subscript-triplet 15 or vector-subscript 16 R621 subscript-triplet is [ subscript ] : [ subscript ] [ : stride ] 17 R622 stride is scalar-int-expr 18 R623 vector-subscript is int-expr 19 C624 (R623) A vector-subscript shall be an integer array expression of rank one. 20 C625 (R621) The second subscript shall not be omitted from a subscript-triplet in the last dimension 21 of an assumed-size array. 22 An array element is a scalar. An array section is an array. If a substring-range is present in an array- 23 section , each element is the designated substring of the corresponding element of the array section. 24 NOTE 6.11 For example, with the declarations: REAL A (10, 10) CHARACTER (LEN = 10) B (5, 5, 5) A (1, 2) is an array element, A (1:N:2, M) is a rank-one array section, and B (:, :, :) (2:3) is an array of shape (5, 5, 5) whose elements are substrings of length 2 of the corresponding elements of B. NOTE 6.12 Unless otherwise specified, an array element or array section does not have an attribute of the whole array. In particular, an array element or an array section does not have the POINTER or ALLOCATABLE attribute. NOTE 6.13 Examples of array elements and array sections are: ARRAY_A(1:N:2)%ARRAY_B(I, J)%STRING(K)(:) array section 120 2006/07/11 WORKING DRAFT J3/06-007 NOTE 6.13 (cont.) SCALAR_PARENT%ARRAY_FIELD(J) array element SCALAR_PARENT%ARRAY_FIELD(1:N) array section SCALAR_PARENT%ARRAY_FIELD(1:N)%SCALAR_FIELD array section 6.2.2.1 Array elements 1 The value of a subscript in an array element shall be within the bounds for that dimension. 2 6.2.2.2 Array element order 3 The elements of an array form a sequence known as the array element order. The position of an array 4 element in this sequence is determined by the subscript order value of the subscript list designating the 5 element. The subscript order value is computed from the formulas in Table 6.1. 6 Table 6.1: Subscript order value Rank Subscript bounds Subscript list Subscript order value 1 + (s1 - j1 ) 1 j1 :k1 s1 1 + (s1 - j1 ) 2 j1 :k1 ,j2 :k2 s1 , s2 + (s2 - j2 ) × d1 1 + (s1 - j1 ) + (s2 - j2 ) × d1 3 j1 :k1 , j2 :k2 , j3 :k3 s1 , s2 , s3 + (s3 - j3 ) × d2 × d1 · · · · · · · · · · · · 1 + (s1 - j1 ) + (s2 - j2 ) × d1 + (s3 - j3 ) × d2 × d1 15 j1 :k1 , . . . , j15 :k15 s1 , . . . , s15 + ... + (s15 - j15 ) × d14 × d13 × . . . × d1 Notes for Table 6.1: 1) di = max (ki - ji + 1, 0) is the size of the ith dimension. 2) If the size of the array is nonzero, ji si ki for all i = 1, 2, ..., 15. 6.2.2.3 Array sections 7 An array section is an array subob ject optionally followed by a substring range. 8 In an array-section having a section-subscript -list, each subscript-triplet and vector-subscript in the 9 section subscript list indicates a sequence of subscripts, which may be empty. Each subscript in such a 10 sequence shall be within the bounds for its dimension unless the sequence is empty. The array section is 11 the set of elements from the array determined by all possible subscript lists obtainable from the single 12 subscripts or sequences of subscripts specified by each section subscript. 13 In an array-section with no section-subscript -list, the rank and shape of the array is the rank and shape 14 of the part-ref with nonzero rank; otherwise, the rank of the array section is the number of subscript 15 triplets and vector subscripts in the section subscript list. The shape is the rank-one array whose ith 16 element is the number of integer values in the sequence indicated by the ith subscript triplet or vector 17 subscript. If any of these sequences is empty, the array section has size zero. The subscript order of the 18 elements of an array section is that of the array data ob ject that the array section represents. 19 121 J3/06-007 WORKING DRAFT 2006/07/11 6.2.2.3.1 Subscript triplet 1 A subscript triplet designates a regular sequence of subscripts consisting of zero or more subscript values. 2 The third expression in the subscript triplet is the increment between the subscript values and is called 3 the stride. The subscripts and stride of a subscript triplet are optional. An omitted first subscript in a 4 subscript triplet is equivalent to a subscript whose value is the lower bound for the array and an omitted 5 second subscript is equivalent to the upper bound. An omitted stride is equivalent to a stride of 1. 6 The stride shall not be zero. 7 When the stride is positive, the subscripts specified by a triplet form a regularly spaced sequence of 8 integers beginning with the first subscript and proceeding in increments of the stride to the largest such 9 integer not greater than the second subscript; the sequence is empty if the first subscript is greater than 10 the second. 11 NOTE 6.14 For example, suppose an array is declared as A (5, 4, 3). The section A (3 : 5, 2, 1 : 2) is the array of shape (3, 2): A (3, 2, 1) A (3, 2, 2) A (4, 2, 1) A (4, 2, 2) A (5, 2, 1) A (5, 2, 2) When the stride is negative, the sequence begins with the first subscript and proceeds in increments of 12 the stride down to the smallest such integer equal to or greater than the second subscript; the sequence 13 is empty if the second subscript is greater than the first. 14 NOTE 6.15 For example, if an array is declared B (10), the section B (9 : 1 : ­2) is the array of shape (5) whose elements are B (9), B (7), B (5), B (3), and B (1), in that order. NOTE 6.16 A subscript in a subscript triplet need not be within the declared bounds for that dimension if all values used in selecting the array elements are within the declared bounds. For example, if an array is declared as B (10), the array section B (3 : 11 : 7) is the array of shape (2) consisting of the elements B (3) and B (10), in that order. 6.2.2.3.2 Vector subscript 15 A vector subscript designates a sequence of subscripts corresponding to the values of the elements 16 of the expression. Each element of the expression shall be defined. A many-one array section is an 17 array section with a vector subscript having two or more elements with the same value. A many-one 18 array section shall appear neither on the left of the equals in an assignment statement nor as an input 19 item in a READ statement. 20 An array section with a vector subscript shall not be argument associated with a dummy array that 21 is defined or redefined. An array section with a vector subscript shall not be the target in a pointer 22 assignment statement. An array section with a vector subscript shall not be an internal file. 23 NOTE 6.17 For example, suppose Z is a two-dimensional array of shape (5, 7) and U and V are one-dimensional arrays of shape (3) and (4), respectively. Assume the values of U and V are: 122 2006/07/11 WORKING DRAFT J3/06-007 NOTE 6.17 (cont.) U = (/ 1, 3, 2 /) V = (/ 2, 1, 1, 3 /) Then Z (3, V) consists of elements from the third row of Z in the order: Z (3, 2) Z (3, 1) Z (3, 1) Z (3, 3) and Z (U, 2) consists of the column elements: Z (1, 2) Z (3, 2) Z (2, 2) and Z (U, V) consists of the elements: Z (1, 2) Z (1, 1) Z (1, 1) Z (1, 3) Z (3, 2) Z (3, 1) Z (3, 1) Z (3, 3) Z (2, 2) Z (2, 1) Z (2, 1) Z (2, 3) Because Z (3, V) and Z (U, V) contain duplicate elements from Z, the sections Z (3, V) and Z (U, V) shall not be redefined as sections. 6.2.3 Image selectors 1 An image selector specifies the image index for co-array data. 2 R624 image-selector is lbracket co-subscript -list rbracket 3 R625 co-subscript is scalar-int-expr 4 The number of co-subscripts shall be equal to the co-rank of the ob ject. The value of a co-subscript in 5 an image selector shall be within the bounds for its co-dimension. An image selector shall specify an 6 image index value that is not greater than the number of images. 7 NOTE 6.18 For example, if there are 16 images and the co-array A is declared REAL :: A(10)[5,*] A(:)[1,4] is valid because it specifies image 16, but A(:)[2,4] is invalid because it specifies image 17. J3 internal note Unresolved Technical Issue 21 This does not appear to be adequately specified. The mapping between co-subscripts (or rather, co-subscript lists) and image indexes is done by handwaving analogy. It is probably not necessary to repeat the formulae, but we need to say exactly how we use those formulae in a more rigorous way. (For a start, "Subscript bounds" clearly does not apply to co-subscripts.) 6.3 Dynamic asso ciation 8 Dynamic control over the allocation, association, and deallocation of pointer targets is provided by 9 the ALLOCATE, NULLIFY, and DEALLOCATE statements and pointer assignment. ALLOCATE 10 (6.3.1) creates targets for pointers; pointer assignment (7.4.2) associates pointers with existing targets; 11 NULLIFY (6.3.2) disassociates pointers from targets, and DEALLOCATE (6.3.3) deallocates targets. 12 123 J3/06-007 WORKING DRAFT 2006/07/11 Dynamic association applies to scalars and arrays of any type. 1 The ALLOCATE and DEALLOCATE statements also are used to create and deallocate variables with 2 the ALLOCATABLE attribute. 3 NOTE 6.19 Detailed remarks regarding pointers and dynamic association are in C.3.3. 6.3.1 ALLOCATE statement 4 The ALLOCATE statement dynamically creates pointer targets and allocatable variables. 5 R626 al locate-stmt is ALLOCATE ( [ type-spec :: ] al location -list 6 [, al loc-opt -list ] ) 7 R627 al loc-opt is ERRMSG = errmsg-variable 8 or MOLD = source-expr 9 or SOURCE = source-expr 10 or STAT = stat-variable 11 R628 stat-variable is scalar-int-variable 12 R629 errmsg-variable is scalar-default-char-variable 13 R630 source-expr is expr 14 R631 al location is al locate-object [ ( al locate-shape-spec -list ) ] 15 [ lbracket al locate-co-array-spec rbracket ] 16 R632 al locate-object is variable-name 17 or structure-component 18 R633 al locate-shape-spec is [ lower-bound-expr : ] upper-bound-expr 19 R634 lower-bound-expr is scalar-int-expr 20 R635 upper-bound-expr is scalar-int-expr 21 R636 al locate-co-array-spec is [ al locate-co-shape-spec -list , ] [ lower-bound-expr : ] * 22 R637 al locate-co-shape-spec is [ lower-bound-expr : ] upper-bound-expr 23 C626 (R632) Each al locate-object shall be a nonprocedure pointer or an allocatable variable. 24 C627 (R626) If any al locate-object in the statement has a deferred type parameter, either type-spec or 25 SOURCE= shall appear. 26 C628 (R626) If a type-spec appears, it shall specify a type with which each al locate-object is type 27 compatible. 28 C629 (R626) If any al locate-object is unlimited polymorphic or is of abstract type, either type-spec or 29 SOURCE= shall appear. 30 C630 (R626) A type-param-value in a type-spec shall be an asterisk if and only if each al locate-object 31 is a dummy argument for which the corresponding type parameter is assumed. 32 C631 (R626) If a type-spec appears, the kind type parameter values of each al locate-object shall be 33 the same as the corresponding type parameter values of the type-spec . 34 C632 (R631) An al locate-shape-spec -list shall appear if and only if the al locate-object is an array. An 35 al locate-co-array-spec shall appear if and only if the al locate-object is a co-array. 36 C633 (R631) The number of al locate-shape-spec s in an al locate-shape-spec -list shall be the same as the 37 rank of the al locate-object . The number of al locate-co-shape-spec s in an al locate-co-array-spec 38 124 2006/07/11 WORKING DRAFT J3/06-007 shall be one less than the co-rank of the al locate-object . 1 C634 (R627) No al loc-opt shall appear more than once in a given al loc-opt -list. 2 C635 (R626) At most one of SOURCE=, MOLD=, and type-spec shall appear. 3 C636 (R626) Each al locate-object shall be type compatible (4.3.1.3) with source-expr . If SOURCE= 4 appears, source-expr shall be a scalar or have the same rank as each al locate-object . 5 C637 (R626) Corresponding kind type parameters of al locate-object and source-expr shall have the 6 same values. 7 C638 (R632) An al locate-object shall not be a co-indexed ob ject. 8 NOTE 6.20 If a co-array is of a derived type that has an allocatable component, the component shall be allocated by its own image: TYPE(SOMETHING), ALLOCATABLE :: T[:] ... ALLOCATE(T[*]) ! Allowed - implies synchronization ALLOCATE(T%AAC(N)) ! Allowed - allocated by its own image ALLOCATE(T[Q]%AAC(N)) ! Not allowed, because it is not ! necessarily executed on image Q. An al locate-object or a bound or type parameter of an al locate-object shall not depend on the value of 9 stat-variable , the value of errmsg-variable , or on the value, bounds, length type parameters, allocation 10 status, or association status of any al locate-object in the same ALLOCATE statement. 11 Neither stat-variable , source-expr , nor errmsg-variable shall be allocated within the ALLOCATE state- 12 ment in which it appears; nor shall they depend on the value, bounds, length type parameters, allocation 13 status, or association status of any al locate-object in the same ALLOCATE statement. 14 If type-spec is specified, each al locate-object is allocated with the specified dynamic type and type pa- 15 rameter values; if source-expr is specified, each al locate-object is allocated with the dynamic type and 16 type parameter values of source-expr ; otherwise, each al locate-object is allocated with its dynamic type 17 the same as its declared type. The dynamic type shall not have a co-array ultimate component. 18 J3 internal note Unresolved Technical Issue 22 (minor) It is worth considering how this dynamic type could ever have a co-array subcomponent. In particular, we should constrain this type-spec against being such a type. (ma jor) This is a runtime problem which cannot be avoided by the user in any systematic way. It is a very bad idea to design the language so that "bad things happen" when the user is not in any position to detect that a bad thing might happen. The easy solution is (1) to prohibit type extension from adding co-array components, and (2) to constrain the declared type of source-expr from having any co-array ultimate components. Since co-array components are really really special (like, something with a co-array component cannot be pointed to) it does not seem too unreasonable for them not to be includable via type extension. If type-spec appears and the value of a type parameter it specifies differs from the value of the corre- 19 125 J3/06-007 WORKING DRAFT 2006/07/11 sponding nondeferred type parameter specified in the declaration of any al locate-object , an error condition 1 occurs. If the value of a nondeferred length type parameter of an al locate-object differs from the value 2 of the corresponding type parameter of source-expr , an error condition occurs. 3 If a type-param-value in a type-spec in an ALLOCATE statement is an asterisk, it denotes the current 4 value of that assumed type parameter. If it is an expression, subsequent redefinition or undefinition of 5 any entity in the expression does not affect the type parameter value. 6 NOTE 6.21 An example of an ALLOCATE statement is: ALLOCATE (X (N), B (-3 : M, 0:9), STAT = IERR_ALLOC) When an ALLOCATE statement is executed for an array, the values of the lower bound and upper 7 bound expressions determine the bounds of the array. Subsequent redefinition or undefinition of any 8 entities in the bound expressions do not affect the array bounds. If the lower bound is omitted, the 9 default value is 1. If the upper bound is less than the lower bound, the extent in that dimension is zero 10 and the array has zero size. 11 NOTE 6.22 An al locate-object may be of type character with zero character length. If SOURCE= appears, source-expr shall be conformable (2.4.5) with al location . If the value of a non- 12 deferred length type parameter of al locate-object is different from the value of the corresponding type 13 parameter of source-expr , an error condition occurs. If the allocation is successful, the value of al locate- 14 object becomes that of source-expr . 15 If MOLD= appears and source-expr is a variable, its value need not be defined. 16 NOTE 6.23 The source-expr can be an array or scalar independently of whether an al locate-object is an array or a scalar. For MOLD=source-expr , only the dynamic type and type parameter values of source-expr are relevant; its rank, shape, and value are not. NOTE 6.24 An example of an ALLOCATE statement in which the value and dynamic type are determined by reference to another ob ject is: CLASS(*), ALLOCATABLE :: NEW CLASS(*), POINTER :: OLD ! ... ALLOCATE (NEW, SOURCE=OLD) ! Allocate NEW with the value and dynamic type of OLD A more extensive example is given in C.3.2. If the STAT= specifier appears, successful execution of the ALLOCATE statement causes the stat- 17 variable to become defined with a value of zero. If an error condition occurs during the execution 18 of the ALLOCATE statement, the stat-variable becomes defined with a processor-dependent positive 19 integer value and each al locate-object will have a processor-dependent status; each al locate-object that 20 was successfully allocated shall have an allocation status of allocated or a pointer association status of 21 associated; each al locate-object that was not successfully allocated shall retain its previous allocation 22 status or pointer association status. 23 126 2006/07/11 WORKING DRAFT J3/06-007 If an error condition occurs during execution of an ALLOCATE statement that does not contain the 1 STAT= specifier, execution of the program is terminated. 2 The ERRMSG= specifier is described in 6.3.1.3. 3 6.3.1.1 Allo cation of allo catable variables 4 The allocation status of an allocatable entity is one of the following at any time during the execution of 5 a program. 6 (1) The status of an allocatable variable becomes allo cated if it is allocated by an ALLOCATE 7 statement, if it is allocated during assignment, or if it is given that status by the allocation 8 transfer procedure (13.7.124). An allocatable variable with this status may be referenced, 9 defined, or deallocated; allocating it causes an error condition in the ALLOCATE statement. 10 The intrinsic function ALLOCATED (13.7.10) returns true for such a variable. 11 (2) An allocatable variable has a status of unallo cated if it is not allocated. The status of 12 an allocatable variable becomes unallocated if it is deallocated (6.3.3) or if it is given that 13 status by the allocation transfer procedure. An allocatable variable with this status shall 14 not be referenced or defined. It shall not be supplied as an actual argument corresponding 15 to a nonallocatable dummy argument, except to certain intrinsic inquiry functions. It may 16 be allocated with the ALLOCATE statement. Deallocating it causes an error condition in 17 the DEALLOCATE statement. The intrinsic function ALLOCATED (13.7.10) returns false 18 for such a variable. 19 At the beginning of execution of a program, allocatable variables are unallocated. 20 A saved allocatable ob ject has an initial status of unallocated. The status may change during the 21 execution of the program. 22 When the allocation status of an allocatable variable changes, the allocation status of any associated 23 allocatable variable changes accordingly. Allocation of an allocatable variable establishes values for the 24 deferred type parameters of all associated allocatable variables. 25 An unsaved allocatable ob ject that is a local variable of a procedure has a status of unallocated at the 26 beginning of each invocation of the procedure. The status may change during execution of the procedure. 27 An unsaved allocatable ob ject that is a local variable of a module or submodule, or a subob ject thereof, 28 has an initial status of unallocated. The status may change during execution of the program. 29 When an ob ject of derived type is created by an ALLOCATE statement, any allocatable ultimate 30 components have an allocation status of unallocated. 31 The value of each lower-bound-expr and each upper-bound-expr in an al locate-co-array-spec shall be the 32 same on each image. 33 If an al location specifies a co-array, its dynamic type and the values of each length type parameter shall 34 be the same on each image. 35 There is implicit synchronization of all images in association with each ALLOCATE statement that 36 involves one or more co-arrays. On each image, execution of the segment (8.5.1) following the statement 37 is delayed until all other images have executed the same statement the same number of times. 38 NOTE 6.25 When an image executes an ALLOCATE statement, communication is not necessarily involved apart from any required for synchronization. The image allocates its co-array and records how the corresponding co-arrays on other images are to be addressed. The processor is not required to detect violations of the rule that the bounds are the same on all images, nor is it responsible 127 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 6.25 (cont.) for detecting or resolving deadlock problems (such as two images waiting on different ALLOCATE statements). 6.3.1.2 Allo cation of p ointer targets 1 Allocation of a pointer creates an ob ject that implicitly has the TARGET attribute. Following successful 2 execution of an ALLOCATE statement for a pointer, the pointer is associated with the target and may 3 be used to reference or define the target. Additional pointers may become associated with the pointer 4 target or a part of the pointer target by pointer assignment. It is not an error to allocate a pointer 5 that is already associated with a target. In this case, a new pointer target is created as required by the 6 attributes of the pointer and any array bounds, type, and type parameters specified by the ALLOCATE 7 statement. The pointer is then associated with this new target. Any previous association of the pointer 8 with a target is broken. If the previous target had been created by allocation, it becomes inaccessible 9 unless other pointers are associated with it. The ASSOCIATED intrinsic function (13.7.15) may be used 10 to determine whether a pointer that does not have undefined association status is associated. 11 At the beginning of execution of a function whose result is a pointer, the association status of the result 12 pointer is undefined. Before such a function returns, it shall either associate a target with this pointer 13 or cause the association status of this pointer to become defined as disassociated. 14 6.3.1.3 ERRMSG= sp ecifier 15 If an error condition occurs during execution of an ALLOCATE or DEALLOCATE statement, the 16 processor shall assign an explanatory message to errmsg-variable . If no such condition occurs, the 17 processor shall not change the value of errmsg-variable . 18 6.3.2 NULLIFY statement 19 The NULLIFY statement causes pointers to be disassociated. 20 R638 nul lify-stmt is NULLIFY ( pointer-object -list ) 21 R639 pointer-object is variable-name 22 or structure-component 23 or proc-pointer-name 24 C639 (R639) Each pointer-object shall have the POINTER attribute. 25 A pointer-object shall not depend on the value, bounds, or association status of another pointer-object 26 in the same NULLIFY statement. 27 NOTE 6.26 When a NULLIFY statement is applied to a polymorphic pointer (4.3.1.3), its dynamic type becomes the declared type. 6.3.3 DEALLOCATE statement 28 The DEALLOCATE statement causes allocatable variables to be deallocated; it causes pointer tar- 29 gets to be deallocated and the pointers to be disassociated. 30 R640 deal locate-stmt is DEALLOCATE ( al locate-object -list [ , deal loc-opt -list ] ) 31 C640 (R640) Each al locate-object shall be a nonprocedure pointer or an allocatable variable. 32 128 2006/07/11 WORKING DRAFT J3/06-007 R641 deal loc-opt is STAT = stat-variable 1 or ERRMSG = errmsg-variable 2 C641 (R641) No deal loc-opt shall appear more than once in a given deal loc-opt -list. 3 An al locate-object shall not depend on the value, bounds, allocation status, or association status of 4 another al locate-object in the same DEALLOCATE statement; it also shall not depend on the value of 5 the stat-variable or errmsg-variable in the same DEALLOCATE statement. 6 Neither stat-variable nor errmsg-variable shall be deallocated within the same DEALLOCATE state- 7 ment; they also shall not depend on the value, bounds, allocation status, or association status of any 8 al locate-object in the same DEALLOCATE statement. 9 If the STAT= specifier appears, successful execution of the DEALLOCATE statement causes the stat- 10 variable to become defined with a value of zero. If an error condition occurs during the execution of 11 the DEALLOCATE statement, the stat-variable becomes defined with a processor-dependent positive 12 integer value and each al locate-object that was successfully deallocated shall have an allocation status of 13 unallocated or a pointer association status of disassociated. Each al locate-object that was not successfully 14 deallocated shall retain its previous allocation status or pointer association status. 15 NOTE 6.27 The status of ob jects that were not successfully deallocated can be individually checked with the ALLOCATED or ASSOCIATED intrinsic functions. If an error condition occurs during execution of a DEALLOCATE statement that does not contain the 16 STAT= specifier, execution of the program is terminated. 17 The ERRMSG= specifier is described in 6.3.1.3. 18 NOTE 6.28 An example of a DEALLOCATE statement is: DEALLOCATE (X, B) 6.3.3.1 Deallo cation of allo catable variables 19 Deallocating an unallocated allocatable variable causes an error condition in the DEALLOCATE state- 20 ment. Deallocating an allocatable variable with the TARGET attribute causes the pointer association 21 status of any pointer associated with it to become undefined. 22 When the execution of a procedure is terminated by execution of a RETURN or END statement, an 23 allocatable variable that is a named local variable of the procedure retains its allocation and definition 24 status if it has the SAVE attribute or is a function result variable or a subob ject thereof; otherwise, it 25 is deallocated. 26 When a BLOCK construct terminates, an allocatable variable that is a named local variable of the con- 27 struct retains its allocation and definition status if it has the SAVE attribute; otherwise it is deallocated. 28 NOTE 6.29 The ALLOCATED intrinsic function may be used to determine whether a variable is allocated or unallocated. If an unsaved allocatable ob ject is a local variable of a module or submodule, and it is allocated when 29 execution of a RETURN or END statement results in no active scoping unit referencing the module or 30 129 J3/06-007 WORKING DRAFT 2006/07/11 submodule, it is processor-dependent whether the ob ject retains its allocation status or is deallocated. 1 NOTE 6.30 The following example illustrates the effects of SAVE on allocation status. MODULE MOD1 TYPE INITIALIZED_TYPE INTEGER :: I = 1 ! Default initialization END TYPE INITIALIZED_TYPE SAVE :: SAVED1, SAVED2 INTEGER :: SAVED1, UNSAVED1 TYPE(INITIALIZED_TYPE) :: SAVED2, UNSAVED2 ALLOCATABLE :: SAVED1(:), SAVED2(:), UNSAVED1(:), UNSAVED2(:) END MODULE MOD1 PROGRAM MAIN CALL SUB1 ! The values returned by the ALLOCATED intrinsic calls ! in the PRINT statement are: ! .FALSE., .FALSE., .FALSE., and .FALSE. ! Module MOD1 is used, and its variables are allocated. ! After return from the subroutine, whether the variables ! which were not specified with the SAVE attribute ! retain their allocation status is processor dependent. CALL SUB1 ! The values returned by the first two ALLOCATED intrinsic ! calls in the PRINT statement are: ! .TRUE., .TRUE. ! The values returned by the second two ALLOCATED ! intrinsic calls in the PRINT statement are ! processor dependent and each could be either ! .TRUE. or .FALSE. CONTAINS SUBROUTINE SUB1 USE MOD1 ! Brings in saved and unsaved variables. PRINT *, ALLOCATED(SAVED1), ALLOCATED(SAVED2), & ALLOCATED(UNSAVED1), ALLOCATED(UNSAVED2) IF (.NOT. ALLOCATED(SAVED1)) ALLOCATE(SAVED1(10)) IF (.NOT. ALLOCATED(SAVED2)) ALLOCATE(SAVED2(10)) IF (.NOT. ALLOCATED(UNSAVED1)) ALLOCATE(UNSAVED1(10)) IF (.NOT. ALLOCATED(UNSAVED2)) ALLOCATE(UNSAVED2(10)) END SUBROUTINE SUB1 END PROGRAM MAIN If an executable construct references a function whose result is either allocatable or a structure with 2 a subob ject that is allocatable, and the function reference is executed, an allocatable result and any 3 subob ject that is an allocated allocatable entity in the result returned by the function is deallocated 4 after execution of the innermost executable construct containing the reference. 5 If a specification expression in a scoping unit references a function whose result is either allocatable or 6 a structure with a subob ject that is allocatable, and the function reference is executed, an allocatable 7 result and any subob ject that is an allocated allocatable entity in the result returned by the function is 8 deallocated before execution of the first executable statement in the scoping unit. 9 When a procedure is invoked, any allocated allocatable ob ject that is an actual argument associated with 10 an INTENT(OUT) allocatable dummy argument is deallocated; any allocated allocatable ob ject that is 11 a subob ject of an actual argument associated with an INTENT(OUT) dummy argument is deallocated. 12 130 2006/07/11 WORKING DRAFT J3/06-007 When an intrinsic assignment statement (7.4.1.3) is executed, any allocated allocatable subob ject of the 1 variable is deallocated before the assignment takes place. 2 When a variable of derived type is deallocated, any allocated allocatable subob ject is deallocated. 3 If an allocatable component is a subob ject of a finalizable ob ject, that ob ject is finalized before the 4 component is automatically deallocated. 5 The effect of automatic deallocation is the same as that of a DEALLOCATE statement without a 6 deal loc-opt -list. 7 NOTE 6.31 In the following example: SUBROUTINE PROCESS REAL, ALLOCATABLE :: TEMP(:) REAL, ALLOCATABLE, SAVE :: X(:) ... END SUBROUTINE PROCESS on return from subroutine PROCESS, the allocation status of X is preserved because X has the SAVE attribute. TEMP does not have the SAVE attribute, so it will be deallocated. On the next invocation of PROCESS, TEMP will have an allocation status of unallocated. There is implicit synchronization of all images in association with each DEALLOCATE statement that 8 involves one or more co-arrays. On each image, execution of the segment (8.5.1) following the statement 9 is delayed until all other images have executed the same statement the same number of times. 10 There is also an implicit synchronization of all images in association with the deallocation of a co-array 11 or co-array subcomponent caused by the execution of a RETURN or END statement or the termination 12 of a BLOCK construct. 13 6.3.3.2 Deallo cation of p ointer targets 14 If a pointer appears in a DEALLOCATE statement, its association status shall be defined. Deallocating 15 a pointer that is disassociated or whose target was not created by an ALLOCATE statement causes an 16 error condition in the DEALLOCATE statement. If a pointer is associated with an allocatable entity, 17 the pointer shall not be deallocated. 18 If a pointer appears in a DEALLOCATE statement, it shall be associated with the whole of an ob ject 19 that was created by allocation. Deallocating a pointer target causes the pointer association status of 20 any other pointer that is associated with the target or a portion of the target to become undefined. 21 131 J3/06-007 WORKING DRAFT 2006/07/11 132 2006/07/11 WORKING DRAFT J3/06-007 7 Expressions and assignment 1 This clause describes the formation, interpretation, and evaluation rules for expressions, intrinsic and 2 defined assignment, pointer assignment, masked array assignment (WHERE), and FORALL. 3 7.1 Expressions 4 An expression represents either a data reference or a computation, and its value is either a scalar or 5 an array. An expression is formed from operands, operators, and parentheses. 6 An operand is either a scalar or an array. An operation is either intrinsic or defined (7.2). More 7 complicated expressions can be formed using operands which are themselves expressions. 8 Evaluation of an expression produces a value, which has a type, type parameters (if appropriate), and a 9 shape (7.1.4). 10 7.1.1 Form of an expression 11 An expression is defined in terms of several categories: primary, level-1 expression, level-2 expression, 12 level-3 expression, level-4 expression, and level-5 expression. 13 These categories are related to the different operator precedence levels and, in general, are defined in 14 terms of other categories. The simplest form of each expression category is a primary . The rules given 15 below specify the syntax of an expression. The semantics are specified in 7.2. 16 7.1.1.1 Primary 17 R701 primary is constant 18 or designator 19 or array-constructor 20 or structure-constructor 21 or function-reference 22 or type-param-inquiry 23 or type-param-name 24 or ( expr ) 25 C701 (R701) The type-param-name shall be the name of a type parameter. 26 C702 (R701) The designator shall not be a whole assumed-size array. 27 NOTE 7.1 Examples of a primary are: Example Syntactic class constant 1.0 designator 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' (I:I) array-constructor (/ 1.0, 2.0 /) structure-constructor PERSON (12, 'Jones') function-reference F (X, Y) type-param-inquiry X%KIND 133 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.1 (cont.) type-param-name KIND (expr ) (S + T) 7.1.1.2 Level-1 expressions 1 Defined unary operators have the highest operator precedence (Table 7.9). Level-1 expressions are 2 primaries optionally operated on by defined unary operators: 3 R702 level-1-expr is [ defined-unary-op ] primary 4 R703 defined-unary-op is . letter [ letter ] ... . 5 C703 (R703) A defined-unary-op shall not contain more than 63 letters and shall not be the same as 6 any intrinsic-operator or logical-literal-constant . 7 NOTE 7.2 Simple examples of a level-1 expression are: Example Syntactic class primary (R701) A level-1-expr (R702) .INVERSE. B A more complicated example of a level-1 expression is: .INVERSE. (A + B) 7.1.1.3 Level-2 expressions 8 Level-2 expressions are level-1 expressions optionally involving the numeric operators power-op , mult-op , 9 and add-op . 10 R704 mult-operand is level-1-expr [ power-op mult-operand ] 11 R705 add-operand is [ add-operand mult-op ] mult-operand 12 R706 level-2-expr is [ [ level-2-expr ] add-op ] add-operand 13 R707 power-op is ** 14 R708 mult-op is * 15 or / 16 R709 add-op is + 17 or ­ 18 NOTE 7.3 Simple examples of a level-2 expression are: Example Syntactic class Remarks level-1-expr A is a primary . (R702) A mult-operand B is a level-1-expr , ** is a power-op , B ** C and C is a mult-operand . (R704) add-operand D is an add-operand , * is a mult-op , D*E and E is a mult-operand . (R705) level-2-expr + is an add-op +1 and 1 is an add-operand . (R706) level-2-expr F is a level-2-expr , ­ is an add-op , F-I and I is an add-operand . (R706) 134 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.3 (cont.) A more complicated example of a level-2 expression is: - A + D * E + B ** C 7.1.1.4 Level-3 expressions 1 Level-3 expressions are level-2 expressions optionally involving the character operator and bits concate- 2 nation operator concat-op . 3 R710 level-3-expr is [ level-3-expr concat-op ] level-2-expr 4 R711 concat-op is // 5 NOTE 7.4 Simple examples of a level-3 expression are: Example Syntactic class level-2-expr (R706) A level-3-expr (R710) B // C A more complicated example of a level-3 expression is: X // Y // 'ABCD' 7.1.1.5 Level-4 expressions 6 Level-4 expressions are level-3 expressions optionally involving the relational operators rel-op . 7 R712 level-4-expr is [ level-3-expr rel-op ] level-3-expr 8 R713 rel-op is .EQ. 9 or .NE. 10 or .LT. 11 or .LE. 12 or .GT. 13 or .GE. 14 or == 15 or /= 16 or < 17 or <= 18 or > 19 or >= 20 NOTE 7.5 Simple examples of a level-4 expression are: Example Syntactic class level-3-expr (R710) A level-4-expr (R712) B == C D, >=, <, <= C C L .NOT. L, B L, B L L L .AND., .OR., .EQV., .NEQV. B B,I B I B B Note: The symbols I, R, Z, C, L, and B stand for the types integer, real, complex, character, logical, and bits, respectively. Where more than one type for x2 is given, the type of the result of the operation is given in the same relative position in the next column. For the intrinsic operators with operands of type character, the kind type parameters of the operands shall be the same. A numeric intrinsic op eration is an intrinsic operation for which the intrinsic-operator is a numeric 8 operator (+, ­, *, /, or **). A numeric intrinsic op erator is the operator in a numeric intrinsic 9 operation. 10 For numeric intrinsic binary operations, the two operands may be of different numeric types or different 11 kind type parameters. Except for a value raised to an integer power, if the operands have different types 12 or kind type parameters, the effect is as if each operand that differs in type or kind type parameter from 13 those of the result is converted to the type and kind type parameter of the result before the operation 14 is performed. When a value of type real or complex is raised to an integer power, the integer operand 15 137 J3/06-007 WORKING DRAFT 2006/07/11 need not be converted. 1 The character intrinsic op eration is the intrinsic operation for which the intrinsic-operator is (//) 2 and both operands are of type character. The operands shall have the same kind type parameter. The 3 character intrinsic op erator is the operator in a character intrinsic operation. 4 A logical intrinsic op eration is an intrinsic operation for which the intrinsic-operator is .AND., .OR., 5 .XOR., .NOT., .EQV., or .NEQV. and both operands are of type logical. A logical intrinsic op erator 6 is the operator in a logical intrinsic operation. 7 A bits intrinsic op eration is an intrinsic operation for which the intrinsic-operator is //, .AND., .OR., 8 .XOR., .NOT., .EQV., or .NEQV. and at least one operand is of type bits. A bits intrinsic op erator 9 is the operator in a bits intrinsic operation. 10 For bits intrinsic operations other than concatenation (//), the two operands may be of different types 11 or different kind type parameters. The effect is as if each operand that differs in type or kind type 12 parameter from those of the result is converted to the type and kind type parameter of the result before 13 the operation is performed. 14 A relational intrinsic op erator is an intrinsic-operator that is .EQ., .NE., .GT., .GE., .LT., .LE., 15 ==, /=, >, >=, <, or <=. A relational intrinsic op eration is an intrinsic operation for which the 16 intrinsic-operator is a relational intrinsic operator. A numeric relational intrinsic op eration is a 17 relational intrinsic operation for which both operands are of numeric type. A character relational 18 intrinsic op eration is a relational intrinsic operation for which both operands are of type character. 19 The kind type parameters of the operands of a character relational intrinsic operation shall be the same. 20 A bits relational intrinsic op eration is a relational intrinsic operation for which at least one of the 21 operands is of type bits. 22 If both operands of a bits relational operation do not have the same kind type parameter, the operand 23 with the smaller kind type parameter is converted to the same kind as the other operand. If one operand 24 of a bits relational operation is not of type bits, it is converted to type bits with the same kind type 25 parameter as the other operand. Any conversion takes place before the operation is evaluated. 26 7.1.3 Defined operations 27 A defined op eration is either a defined unary operation or a defined binary operation. A defined 28 unary op eration is an operation that has the form defined-unary-op x2 or intrinsic-operator x2 and 29 that is defined by a function and a generic interface (4.5.2, 12.4.2.1). 30 A function defines the unary operation op x2 if 31 (1) the function is specified with a FUNCTION (12.6.2.1) or ENTRY (12.6.2.5) statement that 32 specifies one dummy argument d2 , 33 (2) either 34 (a) a generic interface (12.4.2.1) provides the function with a generic-spec of OPERA- 35 TOR (op ), or 36 (b) there is a generic binding (4.5.2) in the declared type of x2 with a generic-spec of 37 OPERATOR (op ) and there is a corresponding binding to the function in the dynamic 38 type of x2 , 39 the type of d2 is compatible with the dynamic type of x2 , (3) 40 (4) the type parameters, if any, of d2 match the corresponding type parameters of x2 , and 41 (5) either 42 (a) the rank of x2 matches that of d2 or 43 (b) the function is elemental and there is no other function that defines the operation. 44 138 2006/07/11 WORKING DRAFT J3/06-007 If d2 is an array, the shape of x2 shall match the shape of d2 . 1 A defined binary op eration is an operation that has the form x1 defined-binary-op x2 or x1 intrinsic- 2 operator x2 and that is defined by a function and a generic interface. 3 A function defines the binary operation x1 op x2 if 4 (1) the function is specified with a FUNCTION (12.6.2.1) or ENTRY (12.6.2.5) statement that 5 specifies two dummy arguments, d1 and d2 , 6 (2) either 7 (a) a generic interface (12.4.2.1) provides the function with a generic-spec of OPERA- 8 TOR (op ), or 9 (b) there is a generic binding (4.5.2) in the declared type of x1 or x2 with a generic- 10 spec of OPERATOR (op ) and there is a corresponding binding to the function in the 11 dynamic type of x1 or x2 , respectively, 12 (3) the types of d1 and d2 are compatible with the dynamic types of x1 and x2 , respectively, 13 (4) the type parameters, if any, of d1 and d2 match the corresponding type parameters of x1 14 and x2 , respectively, and 15 (5) either 16 (a) the ranks of x1 and x2 match those of d1 and d2 or 17 (b) the function is elemental, x1 and x2 are conformable, and there is no other function 18 that defines the operation. 19 If d1 or d2 is an array, the shapes of x1 and x2 shall match the shapes of d1 and d2 , respectively. 20 NOTE 7.8 An intrinsic operator may be used as the operator in a defined operation. In such a case, the generic properties of the operator are extended. An extension op eration is a defined operation in which the operator is of the form defined-unary-op 21 or defined-binary-op . Such an operator is called an extension op erator. The operator used in an 22 extension operation may be such that a generic interface for the operator may specify more than one 23 function. 24 A defined elemental op eration is a defined operation for which the function is elemental (12.8). 25 7.1.4 Type, typ e parameters, and shap e of an expression 26 The type, type parameters, and shape of an expression depend on the operators and on the types, type 27 parameters, and shapes of the primaries used in the expression, and are determined recursively from 28 the syntactic form of the expression. The type of an expression is one of the intrinsic types (4.4) or a 29 derived type (4.5). 30 If an expression is a polymorphic primary or defined operation, the type parameters and the declared and 31 dynamic types of the expression are the same as those of the primary or defined operation. Otherwise 32 the type parameters and dynamic type of the expression are the same as its declared type and type 33 parameters; they are referred to simply as the type and type parameters of the expression. 34 R724 logical-expr is expr 35 C705 (R724) logical-expr shall be of type logical. 36 139 J3/06-007 WORKING DRAFT 2006/07/11 R725 char-expr is expr 1 C706 (R725) char-expr shall be of type character. 2 R726 default-char-expr is expr 3 C707 (R726) default-char-expr shall be of type default character. 4 R727 int-expr is expr 5 C708 (R727) int-expr shall be of type integer. 6 R728 numeric-expr is expr 7 C709 (R728) numeric-expr shall be of type integer, real, or complex. 8 7.1.4.1 Typ e, typ e parameters, and shap e of a primary 9 The type, type parameters, and shape of a primary are determined according to whether the primary is a 10 constant, variable, array constructor, structure constructor, function reference, type parameter inquiry, 11 type parameter name, or parenthesized expression. If a primary is a constant, its type, type parameters, 12 and shape are those of the constant. If it is a structure constructor, it is scalar and its type and type 13 parameters are as described in 4.5.10. If it is an array constructor, its type, type parameters, and shape 14 are as described in 4.7. If it is a variable or function reference, its type, type parameters, and shape are 15 those of the variable (5.2, 5.3) or the function reference (12.5.2), respectively. If the function reference 16 is generic (12.4.2.1, 13.5) then its type, type parameters, and shape are those of the specific function 17 referenced, which is determined by the types, type parameters, and ranks of its actual arguments as 18 specified in 12.5.4.1. If it is a type parameter inquiry or type parameter name, it is a scalar integer with 19 the kind of the type parameter. 20 If a primary is a parenthesized expression, its type, type parameters, and shape are those of the expres- 21 sion. 22 The associated target ob ject is referenced if a pointer appears as 23 (1) a primary in an intrinsic or defined operation, 24 (2) the expr of a parenthesized primary, or 25 (3) the only primary on the right-hand side of an intrinsic assignment statement. 26 The type, type parameters, and shape of the primary are those of the current target. If the pointer is 27 not associated with a target, it may appear as a primary only as an actual argument in a reference to 28 a procedure whose corresponding dummy argument is declared to be a pointer, or as the target in a 29 pointer assignment statement. 30 A disassociated array pointer or an unallocated allocatable array has no shape but does have rank. 31 The type, type parameters, and rank of the result of the NULL intrinsic function depend on context 32 (13.7.131). 33 7.1.4.2 Typ e, typ e parameters, and shap e of the result of an op eration 34 The type of the result of an intrinsic operation [x1 ] op x2 is specified by Table 7.1. The shape of the 35 result of an intrinsic operation is the shape of x2 if op is unary or if x1 is scalar, and is the shape of x1 36 otherwise. 37 The type, type parameters, and shape of the result of a defined operation [x1 ] op x2 are specified by the 38 function defining the operation (7.2). 39 An expression of an intrinsic type has a kind type parameter. An expression of type character also has 40 140 2006/07/11 WORKING DRAFT J3/06-007 a character length parameter. 1 The type parameters of the result of an intrinsic operation are as follows. 2 (1) For an expression x1 // x2 where // is the character intrinsic operator and x1 and x2 are 3 of type character, the character length parameter is the sum of the lengths of the operands 4 and the kind type parameter is the kind type parameter of x1 , which shall be the same as 5 the kind type parameter of x2 . 6 (2) For an expression op x2 where op is an intrinsic unary operator and x2 is of type integer, 7 real, complex, logical, or bits, the kind type parameter of the expression is that of the 8 operand. 9 (3) For an expression x1 op x2 where op is a numeric intrinsic binary operator with one operand 10 of type integer and the other of type real or complex, the kind type parameter of the 11 expression is that of the real or complex operand. 12 (4) For an expression x1 op x2 where op is a numeric intrinsic binary operator with both 13 operands of the same type and kind type parameters, or with one real and one complex 14 with the same kind type parameters, the kind type parameter of the expression is identical 15 to that of each operand. In the case where both operands are integer with different kind type 16 parameters, the kind type parameter of the expression is that of the operand with the greater 17 decimal exponent range if the decimal exponent ranges are different; if the decimal exponent 18 ranges are the same, the kind type parameter of the expression is processor dependent, but 19 it is the same as that of one of the operands. In the case where both operands are any 20 of type real or complex with different kind type parameters, the kind type parameter of 21 the expression is that of the operand with the greater decimal precision if the decimal 22 precisions are different; if the decimal precisions are the same, the kind type parameter of 23 the expression is processor dependent, but it is the same as that of one of the operands. 24 (5) For an expression x1 op x2 where op is a logical intrinsic binary operator with both operands 25 of the same kind type parameter, the kind type parameter of the expression is identical to 26 that of each operand. In the case where both operands are of type logical with different 27 kind type parameters, the kind type parameter of the expression is processor dependent, 28 but it is the same as that of one of the operands. 29 (6) For an expression x1 // x2 where both operands are of type bits, the kind type parameter 30 of the result is the sum of the kind type parameters of the operands. 31 (7) For an expression x1 op x2 where op is a bits intrinsic binary operator other than //, the 32 type of the expression is bits and the kind type parameter of the expression is the maximum 33 of the kind type parameters of x1 and x2 . 34 (8) For an expression x1 op x2 where op is a relational intrinsic operator, the expression has 35 the default logical kind type parameter. 36 C710 The kind type parameter for the result of a bits concatenation operation expression shall be a 37 bits kind type parameter value supported by the processor. 38 7.1.5 Conformability rules for elemental op erations 39 An elemental op eration is an intrinsic operation or a defined elemental operation. Two entities are 40 in shap e conformance if both are arrays of the same shape, or one or both are scalars. 41 For all elemental binary operations, the two operands shall be in shape conformance. In the case where 42 one is a scalar and the other an array, the scalar is treated as if it were an array of the same shape as 43 the array operand with every element, if any, of the array equal to the value of the scalar. 44 141 J3/06-007 WORKING DRAFT 2006/07/11 7.1.6 Sp ecification expression 1 A sp ecification expression is an expression with limitations that make it suitable for use in speci- 2 fications such as length type parameters (C404) and array bounds (R513, R514). A specification-expr 3 shall be an initialization expression unless it is in an interface body (12.4.2.1), the specification part of 4 a subprogram, or the declaration-type-spec of a FUNCTION statement (12.6.2.1). 5 R729 specification-expr is scalar-int-expr 6 C711 (R729) The scalar-int-expr shall be a restricted expression. 7 A restricted expression is an expression in which each operation is intrinsic and each primary is 8 (1) a constant or subob ject of a constant, 9 (2) an ob ject designator with a base ob ject that is a dummy argument that has neither the 10 OPTIONAL nor the INTENT (OUT) attribute, 11 (3) an ob ject designator with a base ob ject that is in a common block, 12 (4) an ob ject designator with a base ob ject that is made accessible by use association or host 13 association, 14 (5) an array constructor where each element and each scalar-int-expr of each ac-implied-do- 15 control is a restricted expression, 16 (6) a structure constructor where each component is a restricted expression, 17 (7) a specification inquiry where each designator or function argument is 18 (a) a restricted expression or 19 (b) a variable whose properties inquired about are not 20 (i) dependent on the upper bound of the last dimension of an assumed-size array, 21 (ii) deferred, or 22 (iii) defined by an expression that is not a restricted expression, 23 (8) a reference to any other standard intrinsic function where each argument is a restricted 24 expression, 25 (9) a reference to a specification function where each argument is a restricted expression, 26 (10) a type parameter of the derived type being defined, 27 (11) an ac-do-variable within an array constructor where each scalar-int-expr of the correspond- 28 ing ac-implied-do-control is a restricted expression, or 29 (12) a restricted expression enclosed in parentheses, 30 where each subscript, section subscript, substring starting point, substring ending point, and type pa- 31 rameter value is a restricted expression, and where any final subroutine that is invoked is pure. 32 A sp ecification inquiry is a reference to 33 (1) an array inquiry function (13.5.7), 34 (2) the bit inquiry function BIT SIZE, 35 (3) the character inquiry function LEN, 36 (4) the kind inquiry function KIND, 37 (5) the bits kind inquiry function BITS KIND, 38 (6) the character inquiry function NEW LINE, 39 (7) a numeric inquiry function (13.5.6), 40 (8) a type parameter inquiry (6.1.4), 41 (9) an IEEE inquiry function (14.9.1), 42 (10) the function C SIZEOF from the intrinsic module ISO C BINDING (15.2.3.6) , or 43 142 2006/07/11 WORKING DRAFT J3/06-007 (11) the COMPILER VERSION or COMPILER OPTIONS inquiry functions from the intrinsic 1 module ISO FORTRAN ENV (13.8.3.3, 13.8.3.4). 2 A function is a sp ecification function if it is a pure function, is not a standard intrinsic function, is 3 not an internal function, is not a statement function, and does not have a dummy procedure argument. 4 Evaluation of a specification expression shall not directly or indirectly cause a procedure defined by the 5 subprogram in which it appears to be invoked. 6 NOTE 7.9 Specification functions are nonintrinsic functions that may be used in specification expressions to determine the attributes of data ob jects. The requirement that they be pure ensures that they cannot have side effects that could affect other ob jects being declared in the same specification-part . The requirement that they not be internal ensures that they cannot inquire, via host association, about other ob jects being declared in the same specification-part . The prohibition against recursion avoids the creation of a new instance of a procedure while construction of one is in progress. A variable in a specification expression shall have its type and type parameters, if any, specified by a 7 previous declaration in the same scoping unit, by the implicit typing rules in effect for the scoping unit, 8 or by host or use association. If a variable in a specification expression is typed by the implicit typing 9 rules, its appearance in any subsequent type declaration statement shall confirm the implied type and 10 type parameters. 11 If a specification expression includes a specification inquiry that depends on a type parameter or an 12 array bound of an entity specified in the same specification-part , the type parameter or array bound 13 shall be specified in a prior specification of the specification-part . The prior specification may be to the 14 left of the specification inquiry in the same statement, but shall not be within the same entity-decl . If a 15 specification expression includes a reference to the value of an element of an array specified in the same 16 specification-part , the array shall be completely specified in prior declarations. 17 NOTE 7.10 The following are examples of specification expressions: LBOUND (B, 1) + 5 ! B is an assumed-shape dummy array M + LEN (C) ! M and C are dummy arguments 2 * PRECISION (A) ! A is a real variable made accessible ! by a USE statement 7.1.7 Initialization expression 18 An initialization expression is an expression with limitations that make it suitable for use as a kind 19 type parameter, initializer, or named constant. It is an expression in which each operation is intrinsic, 20 and each primary is 21 (1) a constant or subob ject of a constant, 22 (2) an array constructor where each element and each scalar-int-expr of each ac-implied-do- 23 control is an initialization expression, 24 (3) a structure constructor where each component-spec corresponding to 25 (a) an allocatable component is a reference to the intrinsic function NULL, 26 (b) a pointer component is a reference to the intrinsic function NULL or an initialization 27 target, and 28 (c) any other component is an initialization expression, 29 143 J3/06-007 WORKING DRAFT 2006/07/11 (4) a reference to an elemental standard intrinsic function, where each argument is an initial- 1 ization expression, 2 (5) a reference to a transformational standard intrinsic function other than NULL, where each 3 argument is an initialization expression, 4 (6) A reference to the transformational intrinsic function NULL that does not have an argu- 5 ment with a type parameter that is assumed or is defined by an expression that is not an 6 initialization expression, 7 (7) a reference to the transformational function IEEE SELECTED REAL KIND from the in- 8 trinsic module IEEE ARITHMETIC (14), where each argument is an initialization expres- 9 sion. 10 (8) a specification inquiry where each designator or function argument is 11 (a) an initialization expression or 12 (b) a variable whose properties inquired about are not 13 (i) assumed, 14 (ii) deferred, or 15 (iii) defined by an expression that is not an initialization expression, 16 (9) a kind type parameter of the derived type being defined, 17 (10) a data-i-do-variable within a data-implied-do , 18 (11) an ac-do-variable within an array constructor where each scalar-int-expr of the correspond- 19 ing ac-implied-do-control is an initialization expression, or 20 (12) an initialization expression enclosed in parentheses, 21 and where each subscript, section subscript, substring starting point, substring ending point, and type 22 parameter value is an initialization expression. 23 R730 initialization-expr is expr 24 C712 (R730) initialization-expr shall be an initialization expression. 25 R731 char-initialization-expr is char-expr 26 C713 (R731) char-initialization-expr shall be an initialization expression. 27 R732 int-initialization-expr is int-expr 28 C714 (R732) int-initialization-expr shall be an initialization expression. 29 R733 logical-initialization-expr is logical-expr 30 C715 (R733) logical-initialization-expr shall be an initialization expression. 31 If an initialization expression includes a specification inquiry that depends on a type parameter or an 32 array bound of an entity specified in the same specification-part , the type parameter or array bound 33 shall be specified in a prior specification of the specification-part . The prior specification may be to the 34 left of the specification inquiry in the same statement, but shall not be within the same entity-decl . 35 NOTE 7.11 The following are examples of initialization expressions: 3 -3 + 4 'AB' 'AB' // 'CD' 144 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.11 (cont.) ('AB' // 'CD') // 'EF' SIZE (A) DIGITS (X) + 4 4.0 * atan(1.0) ceiling(number_of_decimal_digits / log10(radix(0.0))) where A is an explicit-shaped array with constant bounds and X is of type default real. 7.1.8 Evaluation of operations 1 An intrinsic operation requires the values of its operands. 2 The execution of any numeric operation whose result is not defined by the arithmetic used by the 3 processor is prohibited. Raising a negative-valued primary of type real to a real power is prohibited. 4 The evaluation of a function reference shall neither affect nor be affected by the evaluation of any other 5 entity within the statement. If a function reference causes definition or undefinition of an actual argument 6 of the function, that argument or any associated entities shall not appear elsewhere in the same statement. 7 However, execution of a function reference in the logical expression in an IF statement (8.1.3.4), the mask 8 expression in a WHERE statement (7.4.3.1), or the subscripts and strides in a FORALL statement (7.4.4) 9 is permitted to define variables in the statement that is conditionally executed. 10 NOTE 7.12 For example, the statements A (I) = F (I) Y = G (X) + X are prohibited if the reference to F defines or undefines I or the reference to G defines or undefines X. However, in the statements IF (F (X)) A = X WHERE (G (X)) B = X F or G may define X. The declared type of an expression in which a function reference appears does not affect, and is not 11 affected by, the evaluation of the actual arguments of the function. 12 Execution of an array element reference requires the evaluation of its subscripts. The type of an expres- 13 sion in which the array element reference appears does not affect, and is not affected by, the evaluation 14 of its subscripts. Execution of an array section reference requires the evaluation of its section subscripts. 15 The type of an expression in which an array section appears does not affect, and is not affected by, the 16 evaluation of the array section subscripts. Execution of a substring reference requires the evaluation of 17 its substring expressions. The type of an expression in which a substring appears does not affect, and 18 is not affected by, the evaluation of the substring expressions. It is not necessary for a processor to 19 evaluate any subscript expressions or substring expressions for an array of zero size or a character entity 20 of zero length. 21 The appearance of an array constructor requires the evaluation of each scalar-int-expr of the ac-implied- 22 do-control in any ac-implied-do it may contain. The type of an expression in which an array constructor 23 145 J3/06-007 WORKING DRAFT 2006/07/11 appears does not affect, and is not affected by, the evaluation of such bounds and stride expressions. 1 When an elemental binary operation is applied to a scalar and an array or to two arrays of the same 2 shape, the operation is performed element-by-element on corresponding array elements of the array 3 operands. 4 NOTE 7.13 For example, the array expression A+B produces an array of the same shape as A and B. The individual array elements of the result have the values of the first element of A added to the first element of B, the second element of A added to the second element of B, etc. When an elemental unary operator operates on an array operand, the operation is performed element- 5 by-element, and the result is the same shape as the operand. 6 NOTE 7.14 If an elemental operation is intrinsically pure or is implemented by a pure elemental function (12.8), the element operations may be performed simultaneously or in any order. 7.1.8.1 Evaluation of op erands 7 It is not necessary for a processor to evaluate all of the operands of an expression, or to evaluate entirely 8 each operand, if the value of the expression can be determined otherwise. 9 NOTE 7.15 This principle is most often applicable to logical expressions, zero-sized arrays, and zero-length strings, but it applies to all expressions. For example, in evaluating the expression X > Y .OR. L (Z) where X, Y, and Z are real and L is a function of type logical, the function reference L (Z) need not be evaluated if X is greater than Y. Similarly, in the array expression W (Z) + A where A is of size zero and W is a function, the function reference W (Z) need not be evaluated. If a statement contains a function reference in a part of an expression that need not be evaluated, all 10 entities that would have become defined in the execution of that reference become undefined at the 11 completion of evaluation of the expression containing the function reference. 12 NOTE 7.16 In the examples in Note 7.15, if L or W defines its argument, evaluation of the expressions under the specified conditions causes Z to become undefined, no matter whether or not L(Z) or W(Z) is evaluated. If a statement contains a function reference in a part of an expression that need not be evaluated, no 13 invocation of that function in that part of the expression shall execute an image control statement other 14 146 2006/07/11 WORKING DRAFT J3/06-007 than CRITICAL or END CRITICAL. 1 NOTE 7.17 This restriction is intended to avoid inadvertant deadlock caused by optimization. 7.1.8.2 Integrity of parentheses 2 Subclauses 7.1.8.2 to 7.1.8.7 state certain conditions under which a processor may evaluate an expression 3 that is different from the one specified by applying the rules given in 7.1.1 and 7.2. However, any 4 expression in parentheses shall be treated as a data entity. 5 NOTE 7.18 For example, in evaluating the expression A + (B ­ C) where A, B, and C are of numeric types, the difference of B and C shall be evaluated before the addition operation is performed; the processor shall not evaluate the mathematically equivalent expression (A + B) ­ C. 7.1.8.3 Evaluation of numeric intrinsic op erations 6 The rules given in 7.2.2 specify the interpretation of a numeric intrinsic operation. Once the interpreta- 7 tion has been established in accordance with those rules, the processor may evaluate any mathematically 8 equivalent expression, provided that the integrity of parentheses is not violated. 9 Two expressions of a numeric type are mathematically equivalent if, for all possible values of their 10 primaries, their mathematical values are equal. However, mathematically equivalent expressions of 11 numeric type may produce different computational results. 12 NOTE 7.19 Any difference between the values of the expressions (1./3.)*3. and 1. is a computational difference, not a mathematical difference. The difference between the values of the expressions 5/2 and 5./2. is a mathematical difference, not a computational difference. The mathematical definition of integer division is given in 7.2.2.1. NOTE 7.20 The following are examples of expressions with allowable alternative forms that may be used by the processor in the evaluation of those expressions. A, B, and C represent arbitrary real or complex operands; I and J represent arbitrary integer operands; and X, Y, and Z represent arbitrary operands of numeric type. Expression Allowable alternative form X+Y Y+X X*Y Y*X -X + Y Y-X X+Y+Z X + (Y + Z) X-Y+Z X - (Y - Z) X*A/Z X * (A / Z) X*Y-X*Z X * (Y - Z) A/B/C A / (B * C) A / 5.0 0.2 * A The following are examples of expressions with forbidden alternative forms that shall not be used by a processor in the evaluation of those expressions. 147 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.20 (cont.) Expression Forbidden alternative form I/2 0.5 * I X*I/J X * (I / J) I/J/A I / (J * A) (X + Y) + Z X + (Y + Z) (X * Y) - (X * Z) X * (Y - Z) X * (Y - Z) X*Y-X*Z In addition to the parentheses required to establish the desired interpretation, parentheses may be 1 included to restrict the alternative forms that may be used by the processor in the actual evaluation 2 of the expression. This is useful for controlling the magnitude and accuracy of intermediate values 3 developed during the evaluation of an expression. 4 NOTE 7.21 For example, in the expression A + (B - C) the parenthesized expression (B ­ C) shall be evaluated and then added to A. The inclusion of parentheses may change the mathematical value of an expression. For example, the two expressions A*I/J A * (I / J) may have different mathematical values if I and J are of type integer. Each operand in a numeric intrinsic operation has a type that may depend on the order of evaluation 5 used by the processor. 6 NOTE 7.22 For example, in the evaluation of the expression Z+R+I where Z, R, and I represent data ob jects of complex, real, and integer type, respectively, the type of the operand that is added to I may be either complex or real, depending on which pair of operands (Z and R, R and I, or Z and I) is added first. 7.1.8.4 Evaluation of the character intrinsic op eration 7 The rules given in 7.2.3 specify the interpretation of the character intrinsic operation. A processor is 8 only required to evaluate as much of the character intrinsic operation as is required by the context in 9 which the expression appears. 10 NOTE 7.23 For example, the statements CHARACTER (LEN = 2) C1, C2, C3, CF C1 = C2 // CF (C3) 148 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.23 (cont.) do not require the function CF to be evaluated, because only the value of C2 is needed to determine the value of C1 because C1 and C2 both have a length of 2. 7.1.8.5 Evaluation of relational intrinsic op erations 1 The rules given in 7.2.4 specify the interpretation of relational intrinsic operations. Once the interpre- 2 tation of an expression has been established in accordance with those rules, the processor may evaluate 3 any other expression that is relationally equivalent, provided that the integrity of parentheses in any 4 expression is not violated. 5 NOTE 7.24 For example, the processor may choose to evaluate the expression I>J where I and J are integer variables, as J-I<0 Two relational intrinsic operations are relationally equivalent if their logical values are equal for all 6 possible values of their primaries. 7 7.1.8.6 Evaluation of logical intrinsic op erations 8 The rules given in 7.2.5 specify the interpretation of logical intrinsic operations. Once the interpretation 9 of an expression has been established in accordance with those rules, the processor may evaluate any 10 other expression that is logically equivalent, provided that the integrity of parentheses in any expression 11 is not violated. 12 NOTE 7.25 For example, for the variables L1, L2, and L3 of type logical, the processor may choose to evaluate the expression L1 .AND. L2 .AND. L3 as L1 .AND. (L2 .AND. L3) Two expressions of type logical are logically equivalent if their values are equal for all possible values of 13 their primaries. 14 7.1.8.7 Evaluation of bits intrinsic op erations 15 The rules given in 7.2.6 specify the interpretation of bits intrinsic operations. Once the interpretation 16 of an expression has been established in accordance with those rules, the processor may evaluate any 17 other expression that is computationally equivalent, provided that the integrity of parentheses in any 18 expression is not violated. 19 149 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.26 For example, for the variables B1, B2, and B3 of type bits, the processor may choose to evaluate the expression B1 .XOR. B2 .XOR. B3 as B1 .XOR. (B2 .XOR. B3) Two expressions of type bits are computationally equivalent if their values are equal for all possible 1 values of their primaries. 2 7.1.8.8 Evaluation of a defined op eration 3 The rules given in 7.2 specify the interpretation of a defined operation. Once the interpretation of an 4 expression has been established in accordance with those rules, the processor may evaluate any other 5 expression that is equivalent, provided that the integrity of parentheses is not violated. 6 Two expressions of derived type are equivalent if their values are equal for all possible values of their 7 primaries. 8 7.2 Interpretation of op erations 9 7.2.1 General 10 The intrinsic operations are those defined in 7.1.2. These operations are divided into the following 11 categories: numeric, character, relational, logical, and bits. The interpretations defined in subclause 7.2 12 apply to both scalars and arrays; the interpretation for arrays is obtained by applying the interpretation 13 for scalars element by element. 14 The interpretation of a defined operation is provided by the function that defines the operation. The type, 15 type parameters and interpretation of an expression that consists of an intrinsic or defined operation are 16 independent of the type and type parameters of the context or any larger expression in which it appears. 17 NOTE 7.27 For example, if X is of type real, J is of type integer, and INT is the real-to-integer intrinsic conversion function, the expression INT (X + J) is an integer expression and X + J is a real expression. The operators <, <=, >, >=, ==, and /= always have the same interpretations as the operators .LT., 18 .LE., .GT., .GE., .EQ., and .NE., respectively. 19 7.2.2 Numeric intrinsic op erations 20 A numeric operation is used to express a numeric computation. Evaluation of a numeric operation 21 produces a numeric value. The permitted data types for operands of the numeric intrinsic operations 22 are specified in 7.1.2. 23 The numeric operators and their interpretation in an expression are given in Table 7.2, where x1 denotes 24 the operand to the left of the operator and x2 denotes the operand to the right of the operator. 25 150 2006/07/11 WORKING DRAFT J3/06-007 Table 7.2: Interpretation of the numeric intrinsic op erators Operator Representing Use of operator Interpretation ** Exponentiation x1 ** x2 Raise x1 to the power x2 / Division x1 / x2 Divide x1 by x2 * Multiplication x1 * x2 Multiply x1 by x2 - Subtraction x1 - x2 Subtract x2 from x1 - Negation - x2 Negate x2 + Addition x1 + x2 Add x1 and x2 + Identity + x2 Same as x2 The interpretation of a division operation depends on the types of the operands (7.2.2.1). 1 If x1 and x2 are of type integer and x2 has a negative value, the interpretation of x1 ** x2 is the same 2 as the interpretation of 1/(x1 ** ABS (x2 )), which is sub ject to the rules of integer division (7.2.2.1). 3 NOTE 7.28 For example, 2 ** (­3) has the value of 1/(2 ** 3), which is zero. 7.2.2.1 Integer division 4 One operand of type integer may be divided by another operand of type integer. Although the math- 5 ematical quotient of two integers is not necessarily an integer, Table 7.1 specifies that an expression 6 involving the division operator with two operands of type integer is interpreted as an expression of type 7 integer. The result of such an operation is the integer closest to the mathematical quotient and between 8 zero and the mathematical quotient inclusively. 9 NOTE 7.29 For example, the expression (­8) / 3 has the value (­2). 7.2.2.2 Complex exp onentiation 10 In the case of a complex value raised to a complex power, the value of the operation x1 ** x2 is the 11 principal value of xx2 . 12 1 7.2.3 Character intrinsic op eration 13 The character intrinsic operator // is used to concatenate two operands of type character with the same 14 kind type parameter. Evaluation of the character intrinsic operation produces a result of type character. 15 The interpretation of the character intrinsic operator // when used to form an expression is given in 16 Table 7.3, where x1 denotes the operand to the left of the operator and x2 denotes the operand to the 17 right of the operator. 18 Table 7.3: Interpretation of the character intrinsic op erator // Operator Representing Use of operator Interpretation // Concatenation x1 // x2 Concatenate x1 with x2 The result of the character intrinsic operation // is a character string whose value is the value of x1 19 concatenated on the right with the value of x2 and whose length is the sum of the lengths of x1 and x2 . 20 Parentheses used to specify the order of evaluation have no effect on the value of a character expression. 21 151 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.30 For example, the value of ('AB' // 'CDE') // 'F' is the string 'ABCDEF'. Also, the value of 'AB' // ('CDE' // 'F') is the string 'ABCDEF'. 7.2.4 Relational intrinsic op erations 1 A relational intrinsic operation is used to compare values of two operands using the relational intrinsic 2 operators .LT., .LE., .GT., .GE., .EQ., .NE., <, <=, >, >=, ==, and /=. The permitted types for 3 operands of the relational intrinsic operators are specified in 7.1.2. 4 NOTE 7.31 As shown in Table 7.1, a relational intrinsic operator cannot be used to compare the value of an expression of a numeric type with one of type character or logical. Also, two operands of type logical cannot be compared, a complex operand may be compared with another numeric operand only when the operator is .EQ., .NE., ==, or /=, and two character operands cannot be compared unless they have the same kind type parameter value. Evaluation of a relational intrinsic operation produces a result of type default logical. 5 The interpretation of the relational intrinsic operators is given in Table 7.4, where x1 denotes the operand 6 to the left of the operator and x2 denotes the operand to the right of the operator. 7 Table 7.4: Interpretation of the relational intrinsic op erators Operator Representing Use of operator Interpretation .LT. Less than x1 .LT. x2 x1 less than x2 < Less than x1 < x2 x1 less than x2 .LE. Less than or equal to x1 .LE. x2 x1 less than or equal to x2 <= Less than or equal to x1 <= x2 x1 less than or equal to x2 .GT. Greater than x1 .GT. x2 x1 greater than x2 > Greater than x1 > x2 x1 greater than x2 .GE. Greater than or equal to x1 .GE. x2 x1 greater than or equal to x2 >= Greater than or equal to x1 >= x2 x1 greater than or equal to x2 .EQ. Equal to x1 .EQ. x2 x1 equal to x2 == Equal to x1 == x2 x1 equal to x2 .NE. Not equal to x1 .NE. x2 x1 not equal to x2 /= Not equal to x1 /= x2 x1 not equal to x2 A numeric relational intrinsic operation is interpreted as having the logical value true if and only if the 8 values of the operands satisfy the relation specified by the operator. 9 In the numeric relational operation 10 x1 rel-op x2 11 if the types or kind type parameters of x1 and x2 differ, their values are converted to the type and kind 12 type parameter of the expression x1 + x2 before evaluation. 13 A character relational intrinsic operation is interpreted as having the logical value true if and only if the 14 values of the operands satisfy the relation specified by the operator. 15 For a character relational intrinsic operation, the operands are compared one character at a time in 16 order, beginning with the first character of each character operand. If the operands are of unequal 17 length, the shorter operand is treated as if it were extended on the right with blanks to the length of 18 152 2006/07/11 WORKING DRAFT J3/06-007 the longer operand. If both x1 and x2 are of zero length, x1 is equal to x2 ; if every character of x1 is 1 the same as the character in the corresponding position in x2 , x1 is equal to x2 . Otherwise, at the first 2 position where the character operands differ, the character operand x1 is considered to be less than x2 3 if the character value of x1 at this position precedes the value of x2 in the collating sequence (4.4.5.4); 4 x1 is greater than x2 if the character value of x1 at this position follows the value of x2 in the collating 5 sequence. 6 NOTE 7.32 The collating sequence depends partially on the processor; however, the result of the use of the operators .EQ., .NE., ==, and /= does not depend on the collating sequence. For nondefault character types, the blank padding character is processor dependent. A bits relational intrinsic operation is interpreted as having the logical value true if and only if the values 7 of the operands satisfy the relation specified by the operator. 8 For a bits relational intrinsic operation, x1 and x2 are equal if and only if each corresponding bit has 9 the same value. If x1 and x2 are not equal, and the leftmost unequal corresponding bit of x1 is 1 and 10 x2 is 0 then x1 is greater than x2 ; otherwise x1 is less than x2 . 11 7.2.5 Logical intrinsic op erations 12 A logical operation is used to express a logical computation. Evaluation of a logical operation produces 13 a result of type logical. The permitted types for operands of the logical intrinsic operations are specified 14 in 7.1.2. 15 The logical operators and their interpretation when used to form an expression are given in Table 7.5, 16 where x1 denotes the operand to the left of the operator and x2 denotes the operand to the right of the 17 operator. 18 Table 7.5: Interpretation of the logical intrinsic op erators Representing Use of operator Interpretation Operator True if x2 is false Logical negation .NOT. .NOT. x2 True if x1 and x2 are both true Logical conjunction .AND. x1 .AND. x2 Logical inclusive disjunction True if x1 and/or x2 is true .OR. x1 .OR. x2 True if both x1 and x2 are true or Logical equivalence .EQV. x1 .EQV. x2 both are false True if either x1 or x2 is true, but Logical nonequivalence .NEQV. x1 .NEQV. x2 not both True if either x1 or x2 is true, but Logical nonequivalence .XOR. x1 .XOR. x2 not both The values of the logical intrinsic operations are shown in Table 7.6. 19 Table 7.6: The values of op erations involving logical intrinsic op erators x1 x2 .NOT. x2 x1 .AND. x2 x1 .OR. x2 x1 .EQV. x2 x1 .NEQV. x2 x1 .XOR. x2 true true false true true true false false true false true false true false true true false true false false true false true true false false true false false true false false 153 J3/06-007 WORKING DRAFT 2006/07/11 7.2.6 Bits intrinsic op erations 1 Bit operations are used to express bitwise operations on sequences of bits, or to concatenate such 2 sequences. Evaluation of a bits operation produces a result of type bits. The permitted types of 3 operands of the bits intrinsic operations are specified in 7.1.2. 4 The bits operators and their interpretation when used to form an expression are given in Table 7.7, 5 where x1 denotes the operand of type bits to the left of the operator and x2 denotes the operand of type 6 bits to the right of the operator. 7 Table 7.7: Interpretation of the bits intrinsic op erators Operator Representing Use of operator Interpretation (//) Concatenation x1 // x2 Concatenation of x1 and x2 .NOT. Bitwise NOT .NOT. x2 Bitwise NOT of x2 .AND. Bitwise AND x1 .AND. x2 Bitwise AND of x1 and x2 .OR. Bitwise inclusive OR x1 .OR. x2 Bitwise OR of x1 and x2 .EQV. Bitwise equivalence x1 .EQV. x2 Bitwise equivalence of x1 and x2 .NEQV. Bitwise nonequivalence x1 .NEQV. x2 Bitwise nonequivalence of x1 and x2 .XOR. Bitwise exclusive OR x1 .XOR. x2 Bitwise exclusive OR of x1 and x2 The leftmost KIND(x1 ) bits of the result of the bits concatenation operation are the value of x1 and the 8 rightmost KIND(x2 ) bits of the result are the value of x2 . 9 For a bits intrinsic operation other than //, the result value is computed separately for each pair of bits 10 at corresponding positions in each operand. The value of each bit operation, for bits denoted b1 and b2 11 are given in Table 7.8. 12 Table 7.8: The values of bitwise op erations involving bits intrinsic op era- tors x1 x2 .NOT. x2 x1 .AND. x2 x1 .OR. x2 x1 .EQV. x2 x1 .NEQV. x2 x1 .XOR. x2 1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 7.3 Precedence of op erators 13 There is a precedence among the intrinsic and extension operations corresponding to the form of expres- 14 sions specified in 7.1.1, which determines the order in which the operands are combined unless the order 15 is changed by the use of parentheses. This precedence order is summarized in Table 7.9. 16 Table 7.9: Categories of op erations and relative precedence Category of operation Operators Precedence Extension defined-unary-op Highest Numeric ** . Numeric *, / . Numeric unary +, ­ . Numeric binary +, ­ . Character // . Relational .EQ., .NE., .LT., .LE., .GT., .GE., ==, /=, <, <=, >, >= . Logical, Bits .NOT. . 154 2006/07/11 WORKING DRAFT J3/06-007 Categories of op erations and relative precedence (cont.) Category of operation Operators Precedence Logical, Bits .AND. . Logical, Bits .OR. . Logical, Bits .EQV., .NEQV., .XOR. . Extension defined-binary-op Lowest The precedence of a defined operation is that of its operator. 1 NOTE 7.33 For example, in the expression -A ** 2 the exponentiation operator (**) has precedence over the negation operator (­); therefore, the operands of the exponentiation operator are combined to form an expression that is used as the operand of the negation operator. The interpretation of the above expression is the same as the interpretation of the expression - (A ** 2) The general form of an expression (7.1.1) also establishes a precedence among operators in the same 2 syntactic class. This precedence determines the order in which the operands are to be combined in 3 determining the interpretation of the expression unless the order is changed by the use of parentheses. 4 NOTE 7.34 In interpreting a level-2-expr containing two or more binary operators + or ­, each operand (add- operand ) is combined from left to right. Similarly, the same left-to-right interpretation for a mult- operand in add-operand , as well as for other kinds of expressions, is a consequence of the general form. However, for interpreting a mult-operand expression when two or more exponentiation operators ** combine level-1-expr operands, each level-1-expr is combined from right to left. For example, the expressions 2.1 + 3.4 + 4.9 2.1 * 3.4 * 4.9 2.1 / 3.4 / 4.9 2 ** 3 ** 4 'AB' // 'CD' // 'EF' have the same interpretations as the expressions (2.1 + 3.4) + 4.9 (2.1 * 3.4) * 4.9 (2.1 / 3.4) / 4.9 2 ** (3 ** 4) ('AB' // 'CD') // 'EF' As a consequence of the general form (7.1.1), only the first add-operand of a level-2-expr may be preceded by the identity (+) or negation (­) operator. These formation rules do not permit expressions containing two consecutive numeric operators, such as A ** ­B or A + ­B. However, expressions such as A ** (­B) and A + (­B) are permitted. The rules do allow a binary operator 155 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.34 (cont.) or an intrinsic unary operator to be followed by a defined unary operator, such as: A * .INVERSE. B - .INVERSE. (B) As another example, in the expression A .OR. B .AND. C the general form implies a higher precedence for the .AND. operator than for the .OR. opera- tor; therefore, the interpretation of the above expression is the same as the interpretation of the expression A .OR. (B .AND. C) NOTE 7.35 An expression may contain more than one category of operator. The logical expression L .OR. A + B >= C where A, B, and C are of type real, and L is of type logical, contains a numeric operator, a relational operator, and a logical operator. This expression would be interpreted the same as the expression L .OR. ((A + B) >= C) NOTE 7.36 If (1) The operator ** is extended to type logical, (2) The operator .STARSTAR. is defined to duplicate the function of ** on type real, (3) .MINUS. is defined to duplicate the unary operator ­, and (4) L1 and L2 are type logical and X and Y are type real, then in precedence: L1 ** L2 is higher than X * Y; X * Y is higher than X .STARSTAR. Y; and .MINUS. X is higher than ­X. 7.4 Assignment 1 Execution of an assignment statement causes a variable to become defined or redefined. Execution of a 2 pointer assignment statement causes a pointer to become associated with a target or causes its pointer 3 association status to become disassociated or undefined. Execution of a WHERE statement or WHERE 4 construct masks the evaluation of expressions and assignment of values in array assignment statements 5 according to the value of a logical array expression. Execution of a FORALL statement or FORALL 6 construct controls the assignment to elements of arrays by using a set of index variables and a mask 7 expression. 8 7.4.1 Assignment statement 9 A variable may be defined or redefined by execution of an assignment statement. 10 156 2006/07/11 WORKING DRAFT J3/06-007 7.4.1.1 General form 1 R734 assignment-stmt is variable = expr 2 C716 (R734) The variable shall not be a whole assumed-size array. 3 NOTE 7.37 Examples of an assignment statement are: A = 3.5 + X * Y I = INT (A) An assignment-stmt shall meet the requirements of either a defined assignment statement or an intrinsic 4 assignment statement. 5 7.4.1.2 Intrinsic assignment statement 6 An intrinsic assignment statement is an assignment statement that is not a defined assignment 7 statement (7.4.1.4). In an intrinsic assignment statement, 8 (1) if the variable is polymorphic it shall be allocatable, 9 (2) if variable is a co-indexed ob ject, it shall not be of a type that has an allocatable ultimate 10 component, 11 J3 internal note Unresolved Technical Issue 23 06-174r3 had no edit about this at all; when it came up in discussion with JKR et al they suggested making a runtime requirement that the types and shapes of the allocatable components must match; however, that would be very unsafe. Since the only safe way of programming such an assignment would be to avoid the intrinsic assignment altogether, we should not allow the intrinsic assignment in this case. Furthermore, giving different semantics to intrinsic assignment when a component is a co-indexed ob ject is a bad idea - it will confuse the users ­ better to disallow the discrepant inconsistency. The fact that this inherently unsafe idea affects cross-image variables with all the fun of race conditions and other goodies to make debugging impossible simply underlines that this is a bad idea." (3) if expr is an array then the variable shall also be an array, 12 (4) the shapes of the variable and expr shall conform unless the variable is an allocatable array 13 that has the same rank as expr and is neither a co-array nor a co-indexed ob ject, 14 (5) if the variable is an allocatable co-array or co-indexed ob ject, its dynamic type shall be the 15 same as that of expr , 16 J3 internal note Unresolved Technical Issue 24 Since this almost completely guts the polymorphic assignment feature for co-things, why not just disallow polymorphic assigment altogether for co-things? That would be MUCH SAFER, and result in the loss of almost no functionality (one can point a non-polymorphic pointer at the polymorphic co-thing if one wishes to do the required assignment. Furthermore, doing that would still allow co-arrays to be extended later on to "do the right thing" for polymorphic assignment. (6) if the variable is polymorphic it shall be type compatible with expr and have the same rank; 17 otherwise the declared types of the variable and expr shall conform as specified in Table 18 157 J3/06-007 WORKING DRAFT 2006/07/11 7.10, and 1 (7) if the variable is of derived type each kind type parameter of the variable shall have the 2 same value as the corresponding type parameter of expr , and 3 (8) if the variable is of derived type each length type parameter of the variable shall have the 4 same value as the corresponding type parameter of expr unless the variable is allocatable 5 and its corresponding type parameter is deferred. 6 7 Table 7.10: Typ e conformance for the intrinsic assignment statement Type of the variable Type of expr integer integer, real, complex, bits real integer, real, complex, bits complex integer, real, complex, bits ISO 10646, ASCII, or default character ISO 10646, ASCII, or default character other character character of the same kind type parameter as the variable logical logical, bits bits integer, real, complex, bits derived type same derived type as the variable A numeric intrinsic assignment statement is an intrinsic assignment statement for which the vari- 8 able and expr are of numeric type. A character intrinsic assignment statement is an intrinsic 9 assignment statement for which the variable and expr are of type character. A logical intrinsic as- 10 signment statement is an intrinsic assignment statement for which the variable and expr are of type 11 logical. A bits intrinsic assignment statement is an intrinsic assignment statement for which either 12 the variable or expr is of type bits. A derived-typ e intrinsic assignment statement is an intrinsic 13 assignment statement for which the variable and expr are of derived type. 14 An array intrinsic assignment statement is an intrinsic assignment statement for which the variable 15 is an array. The the variable shall not be a many-one array section (6.2.2.3.2). 16 If the variable is a pointer, it shall be associated with a definable target such that the type, type 17 parameters, and shape of the target and expr conform. 18 7.4.1.3 Interpretation of intrinsic assignments 19 Execution of an intrinsic assignment causes, in effect, the evaluation of the expression expr and all 20 expressions within variable (7.1.8), the possible conversion of expr to the type and type parameters of 21 the variable (Table 7.11), and the definition of the variable with the resulting value. The execution of 22 the assignment shall have the same effect as if the evaluation of expr and the evaluation of all expressions 23 in variable occurred before any portion of the variable is defined by the assignment. The evaluation of 24 expressions within variable shall neither affect nor be affected by the evaluation of expr . No value is 25 assigned to the variable if it is of type character and zero length, or is an array of size zero. 26 If the variable is a pointer, the value of expr is assigned to the target of the variable. 27 If the variable is an allocated allocatable variable, it is deallocated if expr is an array of different shape, 28 any of the corresponding length type parameter values of the variable and expr differ, or the dynamic 29 type of the variable and ¡expr¿ differ. If the variable is or becomes an unallocated allocatable variable, 30 then it is allocated with each deferred type parameter equal to the corresponding type parameter of expr , 31 with the shape of expr , with each lower bound equal to the corresponding element of LBOUND(expr ), 32 and with the same dynamic type as expr . 33 158 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.38 For example, given the declaration CHARACTER(:),ALLOCATABLE :: NAME then after the assignment statement NAME = 'Dr. '//FIRST_NAME//' '//SURNAME NAME will have the length LEN(FIRST NAME)+LEN(SURNAME)+5, even if it had previously been unallocated, or allocated with a different length. However, for the assignment statement NAME(:) = 'Dr. '//FIRST_NAME//' '//SURNAME NAME must already be allocated at the time of the assignment; the assigned value is truncated or blank padded to the previously allocated length of NAME. Both variable and expr may contain references to any portion of the variable. 1 NOTE 7.39 For example, in the character intrinsic assignment statement: STRING (2:5) = STRING (1:4) the assignment of the first character of STRING to the second character does not affect the evaluation of STRING (1:4). If the value of STRING prior to the assignment was 'ABCDEF', the value following the assignment is 'AABCDF'. If expr is a scalar and the variable is an array, the expr is treated as if it were an array of the same 2 shape as the variable with every element of the array equal to the scalar value of expr . 3 If the variable is an array, the assignment is performed element-by-element on corresponding array 4 elements of the variable and expr . 5 NOTE 7.40 For example, if A and B are arrays of the same shape, the array intrinsic assignment A=B assigns the corresponding elements of B to those of A; that is, the first element of B is assigned to the first element of A, the second element of B is assigned to the second element of A, etc. If C is an allocatable array of rank 1, then C = PACK(ARRAY,ARRAY>0) will cause C to contain all the positive elements of ARRAY in array element order; if C is not allocated or is allocated with the wrong size, it will be re-allocated to be of the correct size to hold the result of PACK. The processor may perform the element-by-element assignment in any order. 6 159 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.41 For example, the following program segment results in the values of the elements of array X being reversed: REAL X (10) ... X (1:10) = X (10:1:-1) For a numeric intrinsic assignment statement, the variable and expr may have different numeric types 1 or different kind type parameters, in which case the value of expr is converted to the type and kind type 2 parameter of the variable according to the rules of Table 7.11. 3 Table 7.11: Numeric conversion and the assignment statement Type of the variable Value Assigned integer INT (expr , KIND = KIND (variable )) real REAL (expr , KIND = KIND (variable )) complex CMPLX (expr , KIND = KIND (variable )) Note: The functions INT, REAL, CMPLX, and KIND are the generic functions defined in 13.7. For a logical intrinsic assignment statement, the variable and expr may have different kind type param- 4 eters, in which case the value of expr is converted to the kind type parameter of the variable. 5 For a character intrinsic assignment statement, the variable and expr may have different character length 6 parameters in which case the conversion of expr to the length of the variable is as follows. 7 (1) If the length of the variable is less than that of expr , the value of expr is truncated from 8 the right until it is the same length as the variable. 9 (2) If the length of the variable is greater than that of expr , the value of expr is extended on 10 the right with blanks until it is the same length as the variable. 11 If the variable and expr have different kind type parameters, each character c in expr is converted to 12 the kind type parameter of the variable by ACHAR(IACHAR(c ),KIND(variable )). 13 NOTE 7.42 For nondefault character types, the blank padding character is processor dependent. When assign- ing a character expression to a variable of a different kind, each character of the expression that is not representable in the kind of the variable is replaced by a processor-dependent character. For a bits intrinsic assignment statement, the variable and expr may have different types or different 14 kind type parameters, in which case the value of expr is converted to the type and kind type parameter 15 of the variable according to the rules of Table 7.12. 16 Table 7.12: Bits conversion and the assignment statement Type of the variable Value Assigned integer INT (expr , KIND = KIND (variable )) real REAL (expr , KIND = KIND (variable )) complex CMPLX (expr , KIND = KIND (variable )) logical LOGICAL (expr , KIND = KIND (variable )) bits BITS (expr , KIND = KIND (variable )) Note: The functions BITS, INT, REAL, CMPLX, and KIND are the generic functions defined in 13.7. 160 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.43 Bits assignment is not always the same as the result of the TRANSFER intrinsic, because: · bits assignment operates elementally, whereas TRANSFER does not preserve array element boundaries; · for scalars, if the source is larger TRANSFER uses those bits which occur first in memory whereas bits assignment always uses the "rightmost" bits (according to the model for bits values), independent of the endianness of the processor's memory addressing; · if the source is smaller, TRANSFER copies it to the part of the result which occurs first in memory address order and leaves the remaining bits of the result processor-dependent, whereas bits assignment copies the source to the rightmost bits and makes the remaining bits all zero. A derived-type intrinsic assignment is performed as if each component of the variable were assigned 1 from the corresponding component of expr using pointer assignment (7.4.2) for each pointer component, 2 defined assignment for each nonpointer nonallocatable component of a type that has a type-bound 3 defined assignment consistent with the component, intrinsic assignment for each co-array component, and 4 intrinsic assignment for each other nonpointer nonallocatable component. For a non-co-array allocatable 5 component the following sequence of operations is applied. 6 (1) If the component of the variable is allocated, it is deallocated. 7 (2) If the component of the value of expr is allocated, the corresponding component of the 8 variable is allocated with the same dynamic type and type parameters as the component 9 of the value of expr . If it is an array, it is allocated with the same bounds. The value of 10 the component of the value of expr is then assigned to the corresponding component of the 11 variable using defined assignment if the declared type of the component has a type-bound 12 defined assignment consistent with the component, and intrinsic assignment for the dynamic 13 type of that component otherwise. 14 The processor may perform the component-by-component assignment in any order or by any means that 15 has the same effect. 16 NOTE 7.44 For an example of a derived-type intrinsic assignment statement, if C and D are of the same derived type with a pointer component P and nonpointer components S, T, U, and V of type integer, logical, character, and another derived type, respectively, the intrinsic C=D pointer assigns D % P to C % P. It assigns D % S to C % S, D % T to C % T, and D % U to C % U using intrinsic assignment. It assigns D % V to C % V using defined assignment if ob jects of that type have a compatible type-bound defined assignment, and intrinsic assignment otherwise. NOTE 7.45 If an allocatable component of expr is unallocated, the corresponding component of the variable has an allocation status of unallocated after execution of the assignment. 7.4.1.4 Defined assignment statement 17 A defined assignment statement is an assignment statement that is defined by a subroutine and a 18 generic interface (4.5.2, 12.4.2.1.2) that specifies ASSIGNMENT (=). A defined elemental assign- 19 161 J3/06-007 WORKING DRAFT 2006/07/11 ment statement is a defined assignment statement for which the subroutine is elemental (12.8). 1 A subroutine defines the defined assignment x1 = x2 if 2 (1) the subroutine is specified with a SUBROUTINE (12.6.2.2) or ENTRY (12.6.2.5) statement 3 that specifies two dummy arguments, d1 and d2 , 4 (2) either 5 (a) a generic interface (12.4.2.1) provides the subroutine with a generic-spec of ASSIGN- 6 MENT (=), or 7 (b) there is a generic binding (4.5.2) in the declared type of x1 or x2 with a generic-spec 8 of ASSIGNMENT (=) and there is a corresponding binding to the subroutine in the 9 dynamic type of x1 or x2 , respectively, 10 (3) the types of d1 and d2 are compatible with the dynamic types of x1 and x2 , respectively, 11 (4) the type parameters, if any, of d1 and d2 match the corresponding type parameters of x1 12 and x2 , respectively, and 13 (5) either 14 (a) the ranks of x1 and x2 match those of d1 and d2 or 15 (b) the subroutine is elemental, x1 and x2 are conformable, and there is no other subrou- 16 tine that defines the operation. 17 If d1 or d2 is an array, the shapes of x1 and x2 shall match the shapes of d1 and d2 , respectively. 18 7.4.1.5 Interpretation of defined assignment statements 19 The interpretation of a defined assignment is provided by the subroutine that defines it. 20 If the defined assignment is an elemental assignment and the the variable in the assignment is an array, 21 the defined assignment is performed element-by-element, on corresponding elements of the variable and 22 expr . If expr is a scalar, it is treated as if it were an array of the same shape as the variable with every 23 element of the array equal to the scalar value of expr . 24 NOTE 7.46 The rules of defined assignment (12.4.2.1.2), procedure references (12.5), subroutine references (12.5.3), and elemental subroutine arguments (12.8.3) ensure that the defined assignment has the same effect as if the evaluation of all operations in x2 and x1 occurs before any portion of x1 is defined. If an elemental assignment is defined by a pure elemental subroutine, the element assignments may be performed simultaneously or in any order. 7.4.2 Pointer assignment 25 Pointer assignment causes a pointer to become associated with a target or causes its pointer association 26 status to become disassociated or undefined. Any previous association between the pointer and a target 27 is broken. 28 Pointer assignment for a pointer component of a structure may also take place by execution of a derived- 29 type intrinsic assignment statement (7.4.1.3). 30 A pointer may also become associated with a target by allocation of the pointer. 31 R735 pointer-assignment-stmt is data-pointer-object [ (bounds-spec -list ) ] => data-target 32 or data-pointer-object (bounds-remapping -list ) => data-target 33 or proc-pointer-object => proc-target 34 162 2006/07/11 WORKING DRAFT J3/06-007 R736 data-pointer-object is variable-name 1 or scalar-variable % data-pointer-component-name 2 C717 (R735) If data-target is not unlimited polymorphic, either data-pointer-object shall be type 3 compatible (4.3.1.3) with it and the corresponding kind type parameters shall be equal, or 4 data-target and data-pointer-object shall be bits compatible. 5 C718 (R735) If data-target is unlimited polymorphic, data-pointer-object shall be unlimited polymor- 6 phic, of a sequence derived type, or of a type with the BIND attribute. 7 C719 (R735) If bounds-spec -list is specified, the number of bounds-spec s shall equal the rank of data- 8 pointer-object . 9 C720 (R735) If bounds-remapping -list is specified, the number of bounds-remapping s shall equal the 10 rank of data-pointer-object . 11 C721 (R735) If bounds-remapping -list is not specified, the ranks of data-pointer-object and data-target 12 shall be the same. 13 C722 (R736) A variable-name shall have the POINTER attribute. 14 C723 (R736) A scalar-variable shall be a data-ref . 15 C724 (R736) A data-pointer-component-name shall be the name of a component of scalar-variable 16 that is a data pointer. 17 C725 (R736) A data-pointer-object shall not be a co-indexed ob ject. 18 R737 bounds-spec is lower-bound-expr : 19 R738 bounds-remapping is lower-bound-expr : upper-bound-expr 20 R739 data-target is variable 21 or expr 22 C726 (R739) A variable shall have either the TARGET or POINTER attribute, and shall not be an 23 array section with a vector subscript. 24 C727 (R739) A data-target shall not be a co-indexed ob ject. 25 NOTE 7.47 A data pointer and its target are always on the same image. A co-array may be of a derived type with pointer or allocatable subcomponents. For example, if PTR is a pointer component, Z[P]%PTR is a reference to the target of component PTR of Z on image P. This target is on image P and its association with Z[P]%PTR must have been established by the execution of an ALLOCATE statement or a pointer assignment on image P. C728 (R739) An expr shall be a reference to a function whose result is a data pointer. 26 R740 proc-pointer-object is proc-pointer-name 27 or proc-component-ref 28 R741 proc-component-ref is scalar-variable % procedure-component-name 29 C729 (R741) The scalar-variable shall be a data-ref . 30 C730 (R741) The procedure-component-name shall be the name of a procedure pointer component of 31 the declared type of scalar-variable . 32 R742 proc-target is expr 33 163 J3/06-007 WORKING DRAFT 2006/07/11 or procedure-name 1 or proc-component-ref 2 C731 (R742) An expr shall be a reference to a function whose result is a procedure pointer. 3 C732 (R742) A procedure-name shall be the name of an external, internal, module, or dummy proce- 4 dure, a procedure pointer, or a specific intrinsic function listed in 13.6 and not marked with a 5 bullet (·). 6 C733 (R742) The proc-target shall not be a nonintrinsic elemental procedure. 7 7.4.2.1 Data p ointer assignment 8 If data-pointer-object is not polymorphic and data-target is polymorphic with dynamic type that differs 9 from its declared type, the assignment target is the ancestor component of data-target that has the type 10 of data-pointer-object . Otherwise, the assignment target is data-target . 11 If data-target is not a pointer, data-pointer-object becomes pointer associated with the assignment target. 12 Otherwise, the pointer association status of data-pointer-object becomes that of data-target ; if data-target 13 is associated with an ob ject, data-pointer-object becomes associated with the assignment target. If data- 14 target is allocatable, it shall be allocated. 15 If data-pointer-object is polymorphic (4.3.1.3), it assumes the dynamic type of data-target . If data- 16 pointer-object is of sequence derived type or a type with the BIND attribute, the dynamic type of 17 data-target shall be that derived type. 18 If data-target is a disassociated pointer, all nondeferred type parameters of the declared type of data- 19 pointer-object that correspond to nondeferred type parameters of data-target shall have the same values 20 as the corresponding type parameters of data-target , or data-pointer-object and data-target shall be bits 21 compatible (4.3.1.3). 22 Otherwise, all nondeferred type parameters of the declared type of data-pointer-object shall have the 23 same values as the corresponding type parameters of data-target . 24 If data-pointer-object has nondeferred type parameters that correspond to deferred type parameters of 25 data-target , data-target shall not be a pointer with undefined association status. 26 If data-pointer-object has the CONTIGUOUS attribute, data-target shall be contiguous. 27 If bounds-remapping -list is specified, data-target shall be contiguous (5.3.6) or of rank one. It shall not 28 be a disassociated or undefined pointer, and the size of data-target shall not be less than the size of 29 data-pointer-object . The elements of the target of data-pointer-object , in array element order (6.2.2.2), 30 are the first SIZE(data-pointer-object ) elements of data-target . 31 If no bounds-remapping -list is specified, the extent of a dimension of data-pointer-object is the extent of 32 the corresponding dimension of data-target . If bounds-spec -list appears, it specifies the lower bounds; 33 otherwise, the lower bound of each dimension is the result of the intrinsic function LBOUND (13.7.97) 34 applied to the corresponding dimension of data-target . The upper bound of each dimension is one less 35 than the sum of the lower bound and the extent. 36 7.4.2.2 Pro cedure p ointer assignment 37 If the proc-target is not a pointer, proc-pointer-object becomes pointer associated with proc-target . Other- 38 wise, the pointer association status of proc-pointer-object becomes that of proc-target ; if proc-target is 39 associated with a procedure, proc-pointer-object becomes associated with the same procedure. 40 If proc-target is the name of an internal procedure the host instance of proc-pointer-object becomes 41 164 2006/07/11 WORKING DRAFT J3/06-007 the innermost currently executing instance of the host procedure. Otherwise if proc-target has a host 1 instance the host instance of proc-pointer-object becomes that instance. Otherwise proc-pointer-object 2 has no host instance. 3 If proc-pointer-object has an explicit interface, its characteristics shall be the same as proc-target except 4 that proc-target may be pure even if proc-pointer-object is not pure and proc-target may be an elemental 5 intrinsic procedure even if proc-pointer-object is not elemental. 6 If the characteristics of proc-pointer-object or proc-target are such that an explicit interface is required, 7 both proc-pointer-object and proc-target shall have an explicit interface. 8 If proc-pointer-object has an implicit interface and is explicitly typed or referenced as a function, proc- 9 target shall be a function. If proc-pointer-object has an implicit interface and is referenced as a subroutine, 10 proc-target shall be a subroutine. 11 If proc-target and proc-pointer-object are functions, they shall have the same type; corresponding type 12 parameters shall either both be deferred or both have the same value. 13 If procedure-name is a specific procedure name that is also a generic name, only the specific procedure 14 is associated with pointer-ob ject. 15 7.4.2.3 Examples 16 NOTE 7.48 The following are examples of pointer assignment statements. (See Note 12.14 for declarations of P and BESSEL.) NEW_NODE % LEFT => CURRENT_NODE SIMPLE_NAME => TARGET_STRUCTURE % SUBSTRUCT % COMPONENT PTR => NULL ( ) ROW => MAT2D (N, :) WINDOW => MAT2D (I-1:I+1, J-1:J+1) POINTER_OBJECT => POINTER_FUNCTION (ARG_1, ARG_2) EVERY_OTHER => VECTOR (1:N:2) WINDOW2 (0:, 0:) => MAT2D (ML:MU, NL:NU) ! P is a procedure pointer and BESSEL is a procedure with a ! compatible interface. P => BESSEL ! Likewise for a structure component. STRUCT % COMPONENT => BESSEL NOTE 7.49 It is possible to obtain different-rank views of parts of an ob ject by specifying upper bounds in pointer assignment statements. This requires that the ob ject be either rank one or contiguous. Consider the following example, in which a matrix is under consideration. The matrix is stored as a rank-one ob ject in MYDATA because its diagonal is needed for some reason ­ the diagonal cannot be gotten as a single ob ject from a rank-two representation. The matrix is represented as a rank-two view of MYDATA. real, target :: MYDATA ( NR*NC ) ! An automatic array real, pointer :: MATRIX ( :, : ) ! A rank-two view of MYDATA real, pointer :: VIEW_DIAG ( : ) MATRIX( 1:NR, 1:NC ) => MYDATA ! The MATRIX view of the data 165 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.49 (cont.) VIEW_DIAG => MYDATA( 1::NR+1 ) ! The diagonal of MATRIX Rows, columns, or blocks of the matrix can be accessed as sections of MATRIX. 7.4.3 Masked array assignment ­ WHERE 1 The masked array assignment is used to mask the evaluation of expressions and assignment of values in 2 array assignment statements, according to the value of a logical array expression. 3 7.4.3.1 General form of the masked array assignment 4 A masked array assignment is either a WHERE statement or a WHERE construct. 5 R743 where-stmt is WHERE ( mask-expr ) where-assignment-stmt 6 R744 where-construct is where-construct-stmt 7 [ where-body-construct ] ... 8 [ masked-elsewhere-stmt 9 [ where-body-construct ] ... ] ... 10 [ elsewhere-stmt 11 [ where-body-construct ] ... ] 12 end-where-stmt 13 R745 where-construct-stmt is [where-construct-name :] WHERE ( mask-expr ) 14 R746 where-body-construct is where-assignment-stmt 15 or where-stmt 16 or where-construct 17 R747 where-assignment-stmt is assignment-stmt 18 R748 mask-expr is logical-expr 19 R749 masked-elsewhere-stmt is ELSEWHERE (mask-expr ) [where-construct-name ] 20 R750 elsewhere-stmt is ELSEWHERE [where-construct-name ] 21 R751 end-where-stmt is END WHERE [where-construct-name ] 22 C734 (R747) A where-assignment-stmt that is a defined assignment shall be elemental. 23 C735 (R744) If the where-construct-stmt is identified by a where-construct-name , the corresponding 24 end-where-stmt shall specify the same where-construct-name . If the where-construct-stmt is 25 not identified by a where-construct-name , the corresponding end-where-stmt shall not specify 26 a where-construct-name . If an elsewhere-stmt or a masked-elsewhere-stmt is identified by a 27 where-construct-name , the corresponding where-construct-stmt shall specify the same where- 28 construct-name . 29 C736 (R746) A statement that is part of a where-body-construct shall not be a branch target statement. 30 If a where-construct contains a where-stmt , a masked-elsewhere-stmt , or another where-construct then 31 each mask-expr within the where-construct shall have the same shape. In each where-assignment-stmt , 32 the mask-expr and the variable being defined shall be arrays of the same shape. 33 NOTE 7.50 Examples of a masked array assignment are: WHERE (TEMP > 100.0) TEMP = TEMP - REDUCE_TEMP WHERE (PRESSURE <= 1.0) PRESSURE = PRESSURE + INC_PRESSURE TEMP = TEMP - 5.0 166 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.50 (cont.) ELSEWHERE RAINING = .TRUE. END WHERE 7.4.3.2 Interpretation of masked array assignments 1 When a WHERE statement or a where-construct-stmt is executed, a control mask is established. In 2 addition, when a WHERE construct statement is executed, a pending control mask is established. If 3 the statement does not appear as part of a where-body-construct , the mask-expr of the statement is 4 evaluated, and the control mask is established to be the value of mask-expr . The pending control mask 5 is established to have the value .NOT. mask-expr upon execution of a WHERE construct statement that 6 does not appear as part of a where-body-construct . The mask-expr is evaluated only once. 7 Each statement in a WHERE construct is executed in sequence. 8 Upon execution of a masked-elsewhere-stmt , the following actions take place in sequence. 9 (1) The control mask mc is established to have the value of the pending control mask. 10 (2) The pending control mask is established to have the value mc .AND. (.NOT. mask-expr ). 11 (3) The control mask mc is established to have the value mc .AND. mask-expr . 12 The mask-expr is evaluated at most once. 13 Upon execution of an ELSEWHERE statement, the control mask is established to have the value of the 14 pending control mask. No new pending control mask value is established. 15 Upon execution of an ENDWHERE statement, the control mask and pending control mask are es- 16 tablished to have the values they had prior to the execution of the corresponding WHERE construct 17 statement. Following the execution of a WHERE statement that appears as a where-body-construct , the 18 control mask is established to have the value it had prior to the execution of the WHERE statement. 19 NOTE 7.51 The establishment of control masks and the pending control mask is illustrated with the following example: WHERE(cond1) ! Statement 1 ... ELSEWHERE(cond2) ! Statement 2 ... ELSEWHERE ! Statement 3 ... END WHERE Following execution of statement 1, the control mask has the value cond1 and the pending control mask has the value .NOT. cond1. Following execution of statement 2, the control mask has the value (.NOT. cond1) .AND. cond2 and the pending control mask has the value (.NOT. cond1) .AND. (.NOT. cond2). Following execution of statement 3, the control mask has the value (.NOT. cond1) .AND. (.NOT. cond2). The false condition values are propagated through the execution of the masked ELSEWHERE statement. Upon execution of a WHERE construct statement that is part of a where-body-construct , the pending 20 control mask is established to have the value mc .AND. (.NOT. mask-expr ). The control mask is then 21 established to have the value mc .AND. mask-expr . The mask-expr is evaluated at most once. 22 167 J3/06-007 WORKING DRAFT 2006/07/11 Upon execution of a WHERE statement that is part of a where-body-construct , the control mask is 1 established to have the value mc .AND. mask-expr . The pending mask is not altered. 2 If a nonelemental function reference occurs in the expr or variable of a where-assignment-stmt or in a 3 mask-expr , the function is evaluated without any masked control; that is, all of its argument expressions 4 are fully evaluated and the function is fully evaluated. If the result is an array and the reference is not 5 within the argument list of a nonelemental function, elements corresponding to true values in the control 6 mask are selected for use in evaluating the expr , variable or mask-expr . 7 If an elemental operation or function reference occurs in the expr or variable of a where-assignment-stmt 8 or in a mask-expr , and is not within the argument list of a nonelemental function reference, the operation 9 is performed or the function is evaluated only for the elements corresponding to true values of the control 10 mask. 11 If an array constructor appears in a where-assignment-stmt or in a mask-expr , the array constructor is 12 evaluated without any masked control and then the where-assignment-stmt is executed or the mask-expr 13 is evaluated. 14 When a where-assignment-stmt is executed, the values of expr that correspond to true values of the 15 control mask are assigned to the corresponding elements of the variable. 16 The value of the control mask is established by the execution of a WHERE statement, a WHERE con- 17 struct statement, an ELSEWHERE statement, a masked ELSEWHERE statement, or an ENDWHERE 18 statement. Subsequent changes to the value of entities in a mask-expr have no effect on the value of the 19 control mask. The execution of a function reference in the mask expression of a WHERE statement is 20 permitted to affect entities in the assignment statement. 21 NOTE 7.52 Examples of function references in masked array assignments are: WHERE (A > 0.0) A = LOG (A) ! LOG is invoked only for positive elements. A = A / SUM (LOG (A)) ! LOG is invoked for all elements ! because SUM is transformational. END WHERE 7.4.4 FORALL 22 FORALL constructs and statements are used to control the execution of assignment and pointer assign- 23 ment statements with selection by sets of index values and an optional mask expression. 24 7.4.4.1 The FORALL Construct 25 The FORALL construct allows multiple assignments, masked array (WHERE) assignments, and nested 26 FORALL constructs and statements to be controlled by a single foral l-triplet-spec -list and scalar-mask- 27 expr . 28 R752 foral l-construct is foral l-construct-stmt 29 [foral l-body-construct ] ... 30 end-foral l-stmt 31 R753 foral l-construct-stmt is [foral l-construct-name :] FORALL foral l-header 32 R754 foral l-header is (foral l-triplet-spec -list [, scalar-mask-expr ] ) 33 R755 foral l-triplet-spec is index-name = subscript : subscript [ : stride ] 34 R619 subscript is scalar-int-expr 35 R622 stride is scalar-int-expr 36 168 2006/07/11 WORKING DRAFT J3/06-007 R756 foral l-body-construct is foral l-assignment-stmt 1 or where-stmt 2 or where-construct 3 or foral l-construct 4 or foral l-stmt 5 R757 foral l-assignment-stmt is assignment-stmt 6 or pointer-assignment-stmt 7 R758 end-foral l-stmt is END FORALL [foral l-construct-name ] 8 C737 (R758) If the foral l-construct-stmt has a foral l-construct-name , the end-foral l-stmt shall have 9 the same foral l-construct-name . If the end-foral l-stmt has a foral l-construct-name , the foral l- 10 construct-stmt shall have the same foral l-construct-name . 11 C738 (R754) The scalar-mask-expr shall be scalar and of type logical. 12 C739 (R754) Any procedure referenced in the scalar-mask-expr , including one referenced by a defined 13 operation, shall be a pure procedure (12.7). 14 C740 (R755) The index-name shall be a named scalar variable of type integer. 15 C741 (R755) A subscript or stride in a foral l-triplet-spec shall not contain a reference to any index- 16 name in the foral l-triplet-spec -list in which it appears. 17 C742 (R756) A statement in a foral l-body-construct shall not define an index-name of the foral l- 18 construct . 19 C743 (R756) Any procedure referenced in a foral l-body-construct , including one referenced by a defined 20 operation, assignment, or finalization, shall be a pure procedure. 21 C744 (R756) A foral l-body-construct shall not be a branch target. 22 C745 (R757) The variable in an assignment-stmt that is a foral l-assignment-stmt shall be a designator . 23 NOTE 7.53 An example of a FORALL construct is: REAL :: A(10, 10), B(10, 10) = 1.0 ... FORALL (I = 1:10, J = 1:10, B(I, J) /= 0.0) A(I, J) = REAL (I + J - 2) B(I, J) = A(I, J) + B(I, J) * REAL (I * J) END FORALL NOTE 7.54 An assignment statement that is a FORALL body construct may be a scalar or array assignment statement, or a defined assignment statement. The variable being defined will normally use each index name in the foral l-triplet-spec -list. For example FORALL (I = 1:N, J = 1:N) A(:, I, :, J) = 1.0 / REAL(I + J - 1) END FORALL broadcasts scalar values to rank-two subarrays of A. 169 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.55 An example of a FORALL construct containing a pointer assignment statement is: TYPE ELEMENT REAL ELEMENT_WT CHARACTER (32), POINTER :: NAME END TYPE ELEMENT TYPE(ELEMENT) CHART(200) REAL WEIGHTS (1000) CHARACTER (32), TARGET :: NAMES (1000) ... FORALL (I = 1:200, WEIGHTS (I + N - 1) > .5) CHART(I) % ELEMENT_WT = WEIGHTS (I + N - 1) CHART(I) % NAME => NAMES (I + N - 1) END FORALL The results of this FORALL construct cannot be achieved with a WHERE construct because a pointer assignment statement is not permitted in a WHERE construct. An index-name in a foral l-construct has a scope of the construct (16.4). It is a scalar variable that has 1 the type and type parameters that it would have if it were the name of a variable in the scoping unit 2 that includes the FORALL, and this type shall be integer type; it has no other attributes. 3 NOTE 7.56 The use of index-name variables in a FORALL construct does not affect variables of the same name, for example: INTEGER :: X = -1 REAL A(5, 4) J = 100 ... FORALL (X = 1:5, J = 1:4) A (X, J) = J END FORALL After execution of the FORALL, the variables X and J have the values -1 and 100 and A has the value 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 7.4.4.2 Execution of the FORALL construct 4 There are three stages in the execution of a FORALL construct: 5 (1) determination of the values for index-name variables, 6 (2) evaluation of the scalar-mask-expr , and 7 (3) execution of the FORALL body constructs. 8 170 2006/07/11 WORKING DRAFT J3/06-007 7.4.4.2.1 Determination of the values for index variables 1 The subscript and stride expressions in the foral l-triplet-spec -list are evaluated. These expressions may 2 be evaluated in any order. The set of values that a particular index-name variable assumes is determined 3 as follows. 4 (1) The lower bound m1 , the upper bound m2 , and the stride m3 are of type integer with the 5 same kind type parameter as the index-name . Their values are established by evaluating 6 the first subscript, the second subscript, and the stride expressions, respectively, including, 7 if necessary, conversion to the kind type parameter of the index-name according to the rules 8 for numeric conversion (Table 7.11). If a stride does not appear, m3 has the value 1. The 9 value m3 shall not be zero. 10 Let the value of max be (m2 - m1 + m3 )/m3 . If max 0 for some index-name , the execution (2) 11 of the construct is complete. Otherwise, the set of values for the index-name is 12 m1 + (k - 1) × m3 where k = 1, 2, ..., max. 13 The set of combinations of index-name values is the Cartesian product of the sets defined by each triplet 14 specification. An index-name becomes defined when this set is evaluated. 15 NOTE 7.57 The stride may be positive or negative; the FORALL body constructs are executed as long as max > 0. For the foral l-triplet-spec I = 10:1:-1 max has the value 10 7.4.4.2.2 Evaluation of the mask expression 16 The scalar-mask-expr , if any, is evaluated for each combination of index-name values. If the scalar- 17 mask-expr is not present, it is as if it were present with the value true. The index-name variables may 18 be primaries in the scalar-mask-expr . 19 The active combination of index-name values is defined to be the subset of all possible combinations 20 (7.4.4.2.1) for which the scalar-mask-expr has the value true. 21 NOTE 7.58 The index-name variables may appear in the mask, for example FORALL (I=1:10, J=1:10, A(I) > 0.0 .AND. B(J) < 1.0) ... 7.4.4.2.3 Execution of the FORALL b o dy constructs 22 The foral l-body-construct s are executed in the order in which they appear. Each construct is executed 23 for all active combinations of the index-name values with the following interpretation: 24 Execution of a foral l-assignment-stmt that is an assignment-stmt causes the evaluation of expr and all 25 expressions within variable for all active combinations of index-name values. These evaluations may be 26 done in any order. After all these evaluations have been performed, each expr value is assigned to the 27 corresponding variable . The assignments may occur in any order. 28 Execution of a foral l-assignment-stmt that is a pointer-assignment-stmt causes the evaluation of all 29 expressions within data-target and data-pointer-object or proc-target and proc-pointer-object , the de- 30 termination of any pointers within data-pointer-object or proc-pointer-object , and the determination of 31 171 J3/06-007 WORKING DRAFT 2006/07/11 the target for all active combinations of index-name values. These evaluations may be done in any 1 order. After all these evaluations have been performed, each data-pointer-object or proc-pointer-object 2 is associated with the corresponding target. These associations may occur in any order. 3 In a foral l-assignment-stmt , a defined assignment subroutine shall not reference any variable that be- 4 comes defined by the statement. 5 NOTE 7.59 The following FORALL construct contains two assignment statements. The assignment to array B uses the values of array A computed in the previous statement, not the values A had prior to execution of the FORALL. FORALL (I = 2:N-1, J = 2:N-1 ) A (I, J) = A(I, J-1) + A(I, J+1) + A(I-1, J) + A(I+1, J) B (I, J) = 1.0 / A(I, J) END FORALL Computations that would otherwise cause error conditions can be avoided by using an appropriate scalar-mask-expr that limits the active combinations of the index-name values. For example: FORALL (I = 1:N, Y(I) /= 0.0) X(I) = 1.0 / Y(I) END FORALL Each statement in a where-construct (7.4.3) within a foral l-construct is executed in sequence. When 6 a where-stmt , where-construct-stmt or masked-elsewhere-stmt is executed, the statement's mask-expr is 7 evaluated for all active combinations of index-name values as determined by the outer foral l-construct s, 8 masked by any control mask corresponding to outer where-construct s. Any where-assignment-stmt is 9 executed for all active combinations of index-name values, masked by the control mask in effect for the 10 where-assignment-stmt . 11 NOTE 7.60 This FORALL construct contains a WHERE statement and an assignment statement. INTEGER A(5,4), B(5,4) FORALL ( I = 1:5 ) WHERE ( A(I,:) == 0 ) A(I,:) = I B (I,:) = I / A(I,:) END FORALL When executed with the input array 0 0 0 0 1 1 1 0 A = 2 2 0 2 1 0 2 3 0 0 0 0 the results will be 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 1 A = 2 2 3 2 B = 1 1 1 1 172 2006/07/11 WORKING DRAFT J3/06-007 NOTE 7.60 (cont.) 1 4 2 3 4 1 2 1 5 5 5 5 1 1 1 1 For an example of a FORALL construct containing a WHERE construct with an ELSEWHERE statement, see C.4.5. Execution of a foral l-stmt or foral l-construct causes the evaluation of the subscript and stride expressions 1 in the foral l-triplet-spec -list for all active combinations of the index-name values of the outer FORALL 2 construct. The set of combinations of index-name values for the inner FORALL is the union of the sets 3 defined by these bounds and strides for each active combination of the outer index-name values; it also 4 includes the outer index-name values. The scalar-mask-expr is then evaluated for all combinations of the 5 index-name values of the inner construct to produce a set of active combinations for the inner construct. 6 If there is no scalar-mask-expr , it is as if it were present with the value .TRUE.. Each statement in the 7 inner FORALL is then executed for each active combination of the index-name values. 8 NOTE 7.61 This FORALL construct contains a nested FORALL construct. It assigns the transpose of the strict lower triangle of array A (the section below the main diagonal) to the strict upper triangle of A. INTEGER A (3, 3) FORALL (I = 1:N-1 ) FORALL ( J=I+1:N ) A(I,J) = A(J,I) END FORALL END FORALL If prior to execution N = 3 and 0 3 6 A = 1 4 7 2 5 8 then after execution 0 1 2 A = 1 4 5 2 5 8 7.4.4.3 The FORALL statement 9 The FORALL statement allows a single assignment statement or pointer assignment to be controlled by 10 a set of index values and an optional mask expression. 11 R759 foral l-stmt is FORALL foral l-header foral l-assignment-stmt 12 A FORALL statement is equivalent to a FORALL construct containing a single foral l-body-construct 13 that is a foral l-assignment-stmt . 14 The scope of an index-name in a foral l-stmt is the statement itself (16.4). 15 173 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 7.62 Examples of FORALL statements are: FORALL (I=1:N) A(I,I) = X(I) This statement assigns the elements of vector X to the elements of the main diagonal of matrix A. FORALL (I = 1:N, J = 1:N) X(I,J) = 1.0 / REAL (I+J-1) Array element X(I,J) is assigned the value (1.0 / REAL (I+J-1)) for values of I and J between 1 and N, inclusive. FORALL (I=1:N, J=1:N, Y(I,J) /= 0 .AND. I /= J) X(I,J) = 1.0 / Y(I,J) This statement takes the reciprocal of each nonzero off-diagonal element of array Y(1:N, 1:N) and assigns it to the corresponding element of array X. Elements of Y that are zero or on the diagonal do not participate, and no assignments are made to the corresponding elements of X. The results from the execution of the example in Note 7.61 could be obtained with a single FORALL statement: FORALL ( I = 1:N-1, J=1:N, J > I ) A(I,J) = A(J,I) For more examples of FORALL statements, see C.4.6. 7.4.4.4 Restrictions on FORALL constructs and statements 1 A many-to-one assignment is more than one assignment to the same ob ject, or association of more 2 than one target with the same pointer, whether the ob ject is referenced directly or indirectly through a 3 pointer. A many-to-one assignment shall not occur within a single statement in a FORALL construct or 4 statement. It is possible to assign or pointer assign to the same ob ject in different assignment statements 5 in a FORALL construct. 6 NOTE 7.63 The appearance of each index-name in the identification of the left-hand side of an assignment statement is helpful in eliminating many-to-one assignments, but it is not sufficient to guarantee there will be none. For example, the following is allowed FORALL (I = 1:10) A (INDEX (I)) = B(I) END FORALL if and only if INDEX(1:10) contains no repeated values. Within the scope of a FORALL construct, a nested FORALL statement or FORALL construct shall 7 not have the same index-name . The foral l-header expressions within a nested FORALL may depend on 8 the values of outer index-name variables. 9 174 2006/07/11 WORKING DRAFT J3/06-007 8 Execution control 1 8.1 Executable constructs containing blo cks 2 8.1.1 General 3 The following are executable constructs that contain blocks: 4 (1) ASSOCIATE construct; 5 (2) BLOCK construct; 6 (3) CASE construct; 7 (4) CRITICAL construct; 8 (5) DO construct; 9 (6) IF construct; 10 (7) SELECT TYPE construct. 11 12 There is also a nonblo ck form of the DO construct. A blo ck is a sequence of executable constructs that is treated as a unit. 13 R801 block is [ execution-part-construct ] ... 14 Executable constructs may be used to control which blocks of a program are executed or how many times 15 a block is executed. Blocks are always bounded by statements that are particular to the construct in 16 which they are embedded; however, in some forms of the DO construct, a sequence of executable constructs without 17 a terminating b oundary statement shall ob ey all other rules governing blo cks (8.1.2). 18 NOTE 8.1 A block need not contain any executable constructs. Execution of such a block has no effect. Any of these constructs may be named. If a construct is named, the name shall be the first lexical token 19 of the first statement of the construct and the last lexical token of the construct. In fixed source form, the 20 21 name preceding the construct shall be placed after character p osition 6. Except for a CYCLE statement, a statement b elongs to the innermost construct in which it appears 22 unless it contains a construct name, in which case it belongs to the named construct. 23 NOTE 8.2 An example of a construct containing a block is: IF (A > 0.0) THEN B = SQRT (A) ! These two statements C = LOG (A) ! form a block. END IF 175 J3/06-007 WORKING DRAFT 2006/07/11 8.1.2 Rules governing blo cks 1 8.1.2.1 Executable constructs in blo cks 2 If a block contains an executable construct, the executable construct shall be entirely within the block. 3 8.1.2.2 Control flow in blo cks 4 Transfer of control to the interior of a block from outside the block is prohibited. Transfers within a 5 block and transfers from the interior of a block to outside the block may occur. 6 Subroutine and function references (12.5.2, 12.5.3) may appear in a block. 7 8.1.2.3 Execution of a blo ck 8 Execution of a block begins with the execution of the first executable construct in the block. Execution 9 of the block is completed when the last executable construct in the sequence is executed or when a 10 branch out of the block takes place. 11 NOTE 8.3 The action that takes place at the terminal boundary depends on the particular construct and on the block within that construct. It is usually a transfer of control. 8.1.3 IF construct 12 The IF construct selects for execution at most one of its constituent blocks. The selection is based 13 on a sequence of logical expressions. The IF statement controls the execution of a single statement 14 (8.1.3.4) based on a single logical expression. 15 8.1.3.1 Form of the IF construct 16 R802 if-construct is if-then-stmt 17 block 18 [ else-if-stmt 19 block ] ... 20 [ else-stmt 21 block ] 22 end-if-stmt 23 R803 if-then-stmt is [ if-construct-name : ] IF ( scalar-logical-expr ) THEN 24 R804 else-if-stmt is ELSE IF ( scalar-logical-expr ) THEN [ if-construct-name ] 25 R805 else-stmt is ELSE [ if-construct-name ] 26 R806 end-if-stmt is END IF [ if-construct-name ] 27 C801 (R802) If the if-then-stmt of an if-construct specifies an if-construct-name , the corresponding 28 end-if-stmt shall specify the same if-construct-name . If the if-then-stmt of an if-construct does 29 not specify an if-construct-name , the corresponding end-if-stmt shall not specify an if-construct- 30 name . If an else-if-stmt or else-stmt specifies an if-construct-name , the corresponding if-then- 31 stmt shall specify the same if-construct-name . 32 8.1.3.2 Execution of an IF construct 33 At most one of the blocks in the IF construct is executed. If there is an ELSE statement in the construct, 34 exactly one of the blocks in the construct is executed. The scalar logical expressions are evaluated in 35 the order of their appearance in the construct until a true value is found or an ELSE statement or END 36 IF statement is encountered. If a true value or an ELSE statement is found, the block immediately 37 176 2006/07/11 WORKING DRAFT J3/06-007 following is executed and this completes the execution of the construct. The scalar logical expressions 1 in any remaining ELSE IF statements of the IF construct are not evaluated. If none of the evaluated 2 expressions is true and there is no ELSE statement, the execution of the construct is completed without 3 the execution of any block within the construct. 4 An ELSE IF statement or an ELSE statement shall not be a branch target statement. It is permissible 5 to branch to an END IF statement only from within its IF construct. Execution of an END IF statement 6 has no effect. 7 8.1.3.3 Examples of IF constructs 8 NOTE 8.4 IF (CVAR == 'RESET') THEN I = 0; J = 0; K = 0 END IF PROOF_DONE: IF (PROP) THEN WRITE (3, '(''QED'')') STOP ELSE PROP = NEXTPROP END IF PROOF_DONE IF (A > 0) THEN B = C/A IF (B > 0) THEN D = 1.0 END IF ELSE IF (C > 0) THEN B = A/C D = -1.0 ELSE B = ABS (MAX (A, C)) D=0 END IF 8.1.3.4 IF statement 9 The IF statement controls a single action statement (R214). 10 R807 if-stmt is IF ( scalar-logical-expr ) action-stmt 11 C802 (R807) The action-stmt in the if-stmt shall not be an if-stmt , end-program-stmt , end-function- 12 stmt , or end-subroutine-stmt . 13 Execution of an IF statement causes evaluation of the scalar logical expression. If the value of the 14 expression is true, the action statement is executed. If the value is false, the action statement is not 15 executed and execution continues. 16 The execution of a function reference in the scalar logical expression may affect entities in the action 17 statement. 18 NOTE 8.5 An example of an IF statement is: 177 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.5 (cont.) IF (A > 0.0) A = LOG (A) 8.1.4 CASE construct 1 The CASE construct selects for execution at most one of its constituent blocks. The selection is based 2 on the value of an expression. 3 8.1.4.1 Form of the CASE construct 4 R808 case-construct is select-case-stmt 5 [ case-stmt 6 block ] ... 7 end-select-stmt 8 R809 select-case-stmt is [ case-construct-name : ] SELECT CASE ( case-expr ) 9 R810 case-stmt is CASE case-selector [case-construct-name ] 10 R811 end-select-stmt is END SELECT [ case-construct-name ] 11 C803 (R808) If the select-case-stmt of a case-construct specifies a case-construct-name , the corre- 12 sponding end-select-stmt shall specify the same case-construct-name . If the select-case-stmt 13 of a case-construct does not specify a case-construct-name , the corresponding end-select-stmt 14 shall not specify a case-construct-name . If a case-stmt specifies a case-construct-name , the 15 corresponding select-case-stmt shall specify the same case-construct-name . 16 R812 case-expr is scalar-int-expr 17 or scalar-char-expr 18 or scalar-logical-expr 19 R813 case-selector is ( case-value-range -list ) 20 or DEFAULT 21 C804 (R808) No more than one of the selectors of one of the CASE statements shall be DEFAULT. 22 R814 case-value-range is case-value 23 or case-value : 24 or : case-value 25 or case-value : case-value 26 R815 case-value is scalar-int-initialization-expr 27 or scalar-char-initialization-expr 28 or scalar-logical-initialization-expr 29 C805 (R808) For a given case-construct , each case-value shall be of the same type as case-expr . For 30 character type, the kind type parameters shall be the same; character length differences are 31 allowed. 32 C806 (R808) A case-value-range using a colon shall not be used if case-expr is of type logical. 33 C807 (R808) For a given case-construct , the case-value-range s shall not overlap; that is, there shall 34 be no possible value of the case-expr that matches more than one case-value-range . 35 8.1.4.2 Execution of a CASE construct 36 The execution of the SELECT CASE statement causes the case expression to be evaluated. The resulting 37 value is called the case index. For a case value range list, a match occurs if the case index matches any 38 of the case value ranges in the list. For a case index with a value of c, a match is determined as follows. 39 178 2006/07/11 WORKING DRAFT J3/06-007 (1) If the case value range contains a single value v without a colon, a match occurs for type 1 logical if the expression c .EQV. v is true, and a match occurs for type integer or character 2 if the expression c == v is true. 3 (2) If the case value range is of the form low : high, a match occurs if the expression low <= c 4 .AND. c <= high is true. 5 (3) If the case value range is of the form low :, a match occurs if the expression low <= c is true. 6 (4) If the case value range is of the form : high, a match occurs if the expression c <= high is 7 true. 8 (5) If no other selector matches and a DEFAULT selector appears, it matches the case index. 9 (6) If no other selector matches and the DEFAULT selector does not appear, there is no match. 10 The block following the CASE statement containing the matching selector, if any, is executed. This 11 completes execution of the construct. 12 At most one of the blocks of a CASE construct is executed. 13 A CASE statement shall not be a branch target statement. It is permissible to branch to an end-select- 14 stmt only from within its CASE construct. 15 8.1.4.3 Examples of CASE constructs 16 NOTE 8.6 An integer signum function: INTEGER FUNCTION SIGNUM (N) SELECT CASE (N) CASE (:-1) SIGNUM = -1 CASE (0) SIGNUM = 0 CASE (1:) SIGNUM = 1 END SELECT END NOTE 8.7 A code fragment to check for balanced parentheses: CHARACTER (80) :: LINE ... LEVEL = 0 SCAN_LINE: DO I = 1, 80 CHECK_PARENS: SELECT CASE (LINE (I:I)) CASE ('(') LEVEL = LEVEL + 1 CASE (')') LEVEL = LEVEL - 1 IF (LEVEL < 0) THEN PRINT *, 'UNEXPECTED RIGHT PARENTHESIS' EXIT SCAN_LINE END IF CASE DEFAULT ! Ignore all other characters 179 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.7 (cont.) END SELECT CHECK_PARENS END DO SCAN_LINE IF (LEVEL > 0) THEN PRINT *, 'MISSING RIGHT PARENTHESIS' END IF NOTE 8.8 The following three fragments are equivalent: IF (SILLY == 1) THEN CALL THIS ELSE CALL THAT END IF SELECT CASE (SILLY == 1) CASE (.TRUE.) CALL THIS CASE (.FALSE.) CALL THAT END SELECT SELECT CASE (SILLY) CASE DEFAULT CALL THAT CASE (1) CALL THIS END SELECT NOTE 8.9 A code fragment showing several selections of one block: SELECT CASE (N) CASE (1, 3:5, 8) ! Selects 1, 3, 4, 5, 8 CALL SUB CASE DEFAULT CALL OTHER END SELECT 8.1.5 ASSOCIATE construct 1 The ASSOCIATE construct associates named entities with expressions or variables during the execution 2 of its block. These named construct entities (16.4) are associating entities (16.5.1.6). The names are 3 asso ciate names. 4 8.1.5.1 Form of the ASSOCIATE construct 5 R816 associate-construct is associate-stmt 6 block 7 end-associate-stmt 8 R817 associate-stmt is [ associate-construct-name : ] ASSOCIATE 9 (association -list ) 10 R818 association is associate-name => selector 11 180 2006/07/11 WORKING DRAFT J3/06-007 R819 selector is expr 1 or variable 2 C808 (R818) If selector is not a variable or is a variable that has a vector subscript, associate-name 3 shall not appear in a variable definition context (16.6.7). 4 C809 (R818) An associate-name shall not be the same as another associate-name in the same associate- 5 stmt . 6 R820 end-associate-stmt is END ASSOCIATE [ associate-construct-name ] 7 C810 (R820) If the associate-stmt of an associate-construct specifies an associate-construct-name , 8 the corresponding end-associate-stmt shall specify the same associate-construct-name . If the 9 associate-stmt of an associate-construct does not specify an associate-construct-name , the cor- 10 responding end-associate-stmt shall not specify an associate-construct-name . 11 8.1.5.2 Execution of the ASSOCIATE construct 12 Execution of an ASSOCIATE construct causes execution of its associate-stmt followed by execution 13 of its block. During execution of that block each associate name identifies an entity, which is associ- 14 ated (16.5.1.6) with the corresponding selector. The associating entity assumes the declared type and 15 type parameters of the selector. If and only if the selector is polymorphic, the associating entity is 16 polymorphic. 17 The other attributes of the associating entity are described in 8.1.5.3. 18 It is permissible to branch to an end-associate-stmt only from within its ASSOCIATE construct. 19 8.1.5.3 Attributes of asso ciate names 20 Within a SELECT TYPE or ASSOCIATE construct, each associating entity has the same rank as its 21 associated selector. The lower bound of each dimension is the result of the intrinsic function LBOUND 22 (13.7.97) applied to the corresponding dimension of selector . The upper bound of each dimension is one 23 less than the sum of the lower bound and the extent. The associating entity has the ASYNCHRONOUS 24 or VOLATILE attribute if and only if the selector is a variable and has the attribute. The associating 25 entity has the TARGET attribute if and only if the selector is a variable and has either the TARGET 26 or POINTER attribute. If the associating entity is polymorphic, it assumes the dynamic type and type 27 parameter values of the selector. If the selector has the OPTIONAL attribute, it shall be present. The 28 associating entity is contiguous if and only if the selector is contiguous. 29 If the selector (8.1.5.1) is not permitted to appear in a variable definition context (16.6.7) or is an array 30 with a vector subscript, the associate name shall not appear in a variable definition context. 31 8.1.5.4 Examples of the ASSOCIATE construct 32 NOTE 8.10 The following example illustrates an association with an expression. ASSOCIATE ( Z => EXP(-(X**2+Y**2)) * COS(THETA) ) PRINT *, A+Z, A-Z END ASSOCIATE The following example illustrates an association with a derived-type variable. ASSOCIATE ( XC => AX%B(I,J)%C ) XC%DV = XC%DV + PRODUCT(XC%EV(1:N)) 181 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.10 (cont.) END ASSOCIATE The following example illustrates association with an array section. ASSOCIATE ( ARRAY => AX%B(I,:)%C ) ARRAY(N)%EV = ARRAY(N-1)%EV END ASSOCIATE The following example illustrates multiple associations. ASSOCIATE ( W => RESULT(I,J)%W, ZX => AX%B(I,J)%D, ZY => AY%B(I,J)%D ) W = ZX*X + ZY*Y END ASSOCIATE 8.1.6 SELECT TYPE construct 1 The SELECT TYPE construct selects for execution at most one of its constituent blocks. The selection 2 is based on the dynamic type of an expression. A name is associated with the expression (16.4, 16.5.1.6), 3 in the same way as for the ASSOCIATE construct. 4 8.1.6.1 Form of the SELECT TYPE construct 5 R821 select-type-construct is select-type-stmt 6 [ type-guard-stmt 7 block ] ... 8 end-select-type-stmt 9 R822 select-type-stmt is [ select-construct-name : ] SELECT TYPE 10 ( [ associate-name => ] selector ) 11 C811 (R822) If selector is not a named variable , associate-name => shall appear. 12 C812 (R822) If selector is not a variable or is a variable that has a vector subscript, associate-name 13 shall not appear in a variable definition context (16.6.7). 14 C813 (R822) The selector in a select-type-stmt shall be polymorphic. 15 R823 type-guard-stmt is TYPE IS ( type-spec ) [ select-construct-name ] 16 or CLASS IS ( derived-type-spec ) [ select-construct-name ] 17 or CLASS DEFAULT [ select-construct-name ] 18 C814 (R823) The type-spec or derived-type-spec shall specify that each length type parameter is as- 19 sumed. 20 C815 (R823) The type-spec or derived-type-spec shall not specify a sequence derived type or a type 21 with the BIND attribute. 22 C816 (R823) If selector is not unlimited polymorphic, the type-spec or derived-type-spec shall specify 23 an extension of the declared type of selector . 24 C817 (R823) For a given select-type-construct , the same type and kind type parameter values shall 25 not be specified in more than one TYPE IS type-guard-stmt and shall not be specified in more 26 than one CLASS IS type-guard-stmt . 27 C818 (R823) For a given select-type-construct , there shall be at most one CLASS DEFAULT type- 28 182 2006/07/11 WORKING DRAFT J3/06-007 guard-stmt . 1 R824 end-select-type-stmt is END SELECT [ select-construct-name ] 2 C819 (R821) If the select-type-stmt of a select-type-construct specifies a select-construct-name , the 3 corresponding end-select-type-stmt shall specify the same select-construct-name . If the select- 4 type-stmt of a select-type-construct does not specify a select-construct-name , the corresponding 5 end-select-type-stmt shall not specify a select-construct-name . If a type-guard-stmt specifies a 6 select-construct-name , the corresponding select-type-stmt shall specify the same select-construct- 7 name . 8 The associate name of a SELECT TYPE construct is the associate-name if specified; otherwise it is the 9 name that constitutes the selector . 10 8.1.6.2 Execution of the SELECT TYPE construct 11 Execution of a SELECT TYPE construct whose selector is not a variable causes the selector expression 12 to be evaluated. 13 A SELECT TYPE construct selects at most one block to be executed. During execution of that block, 14 the associate name identifies an entity, which is associated (16.5.1.6) with the selector. 15 A TYPE IS type guard statement matches the selector if the dynamic type and kind type parameter 16 values of the selector are the same as those specified by the statement. A CLASS IS type guard 17 statement matches the selector if the dynamic type of the selector is an extension of the type specified 18 by the statement and the kind type parameter values specified by the statement are the same as the 19 corresponding type parameter values of the dynamic type of the selector. 20 The block to be executed is selected as follows. 21 (1) If a TYPE IS type guard statement matches the selector, the block following that statement 22 is executed. 23 (2) Otherwise, if exactly one CLASS IS type guard statement matches the selector, the block 24 following that statement is executed. 25 (3) Otherwise, if several CLASS IS type guard statements match the selector, one of these 26 statements must specify a type that is an extension of all the types specified in the others; 27 the block following that statement is executed. 28 (4) Otherwise, if there is a CLASS DEFAULT type guard statement, the block following that 29 statement is executed. 30 NOTE 8.11 This algorithm does not examine the type guard statements in source text order when it looks for a match; it selects the most particular type guard when there are several potential matches. Within the block following a TYPE IS type guard statement, the associating entity (16.5.5) is not 31 polymorphic (4.3.1.3), has the type named in the type guard statement, and has the type parameter 32 values of the selector. 33 Within the block following a CLASS IS type guard statement, the associating entity is polymorphic and 34 has the declared type named in the type guard statement. The type parameter values of the associating 35 entity are the corresponding type parameter values of the selector. 36 Within the block following a CLASS DEFAULT type guard statement, the associating entity is poly- 37 morphic and has the same declared type as the selector. The type parameter values of the associating 38 entity are those of the declared type of the selector. 39 183 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.12 If the declared type of the selector is T, specifying CLASS DEFAULT has the same effect as specifying CLASS IS (T). The other attributes of the associating entity are described in 8.1.5.3. 1 A type guard statement shall not be a branch target statement. It is permissible to branch to an 2 end-select-type-stmt only from within its SELECT TYPE construct. 3 8.1.6.3 Examples of the SELECT TYPE construct 4 NOTE 8.13 TYPE POINT REAL :: X, Y END TYPE POINT TYPE, EXTENDS(POINT) :: POINT_3D REAL :: Z END TYPE POINT_3D TYPE, EXTENDS(POINT) :: COLOR_POINT INTEGER :: COLOR END TYPE COLOR_POINT TYPE(POINT), TARGET :: P TYPE(POINT_3D), TARGET :: P3 TYPE(COLOR_POINT), TARGET :: C CLASS(POINT), POINTER :: P_OR_C P_OR_C => C SELECT TYPE ( A => P_OR_C ) CLASS IS ( POINT ) ! "CLASS ( POINT ) :: A" implied here PRINT *, A%X, A%Y ! This block gets executed TYPE IS ( POINT_3D ) ! "TYPE ( POINT_3D ) :: A" implied here PRINT *, A%X, A%Y, A%Z END SELECT NOTE 8.14 The following example illustrates the omission of associate-name . It uses the declarations from Note 8.13. P_OR_C => P3 SELECT TYPE ( P_OR_C ) CLASS IS ( POINT ) ! "CLASS ( POINT ) :: P_OR_C" implied here PRINT *, P_OR_C%X, P_OR_C%Y TYPE IS ( POINT_3D ) ! "TYPE ( POINT_3D ) :: P_OR_C" implied here PRINT *, P_OR_C%X, P_OR_C%Y, P_OR_C%Z ! This block gets executed END SELECT 184 2006/07/11 WORKING DRAFT J3/06-007 8.1.7 DO construct 1 8.1.7.1 General 2 The DO construct specifies the repeated execution of a sequence of executable constructs. Such a 3 repeated sequence is called a lo op. 4 The number of iterations of a loop may be determined at the beginning of execution of the DO construct, 5 or may be left indefinite ("DO forever" or DO WHILE). Except in the case of a DO CONCURRENT 6 construct, an EXIT statement (8.1.7.5.4) anywhere in the DO construct may be executed to terminate the 7 loop immediately. The current iteration of the loop may be curtailed by executing a CYCLE statement 8 (8.1.7.5.3). 9 There are three phases in the execution of a DO construct: initiation of the loop, execution of the loop 10 range, and termination of the loop. 11 The DO CONCURRENT construct is a DO construct whose DO statement contains the CONCURRENT 12 keyword. 13 8.1.7.2 Forms of the DO construct 14 The DO construct may be written in either a block form or a nonblock form. 15 R825 do-construct is block-do-construct 16 or nonblock-do-construct 17 8.1.7.2.1 Form of the blo ck DO construct 18 R826 block-do-construct is do-stmt 19 do-block 20 end-do 21 R827 do-stmt is label-do-stmt 22 or nonlabel-do-stmt 23 R828 label-do-stmt is [ do-construct-name : ] DO label [ loop-control ] 24 R829 nonlabel-do-stmt is [ do-construct-name : ] DO [ loop-control ] 25 R830 loop-control is [ , ] do-variable = scalar-int-expr , scalar-int-expr 26 [ , scalar-int-expr ] 27 or [ , ] WHILE ( scalar-logical-expr ) 28 or [ , ] CONCURRENT foral l-header 29 R831 do-variable is scalar-int-variable-name 30 C820 (R831) The do-variable shall be a variable of type integer. 31 R832 do-block is block 32 R833 end-do is end-do-stmt 33 or continue-stmt 34 R834 end-do-stmt is END DO [ do-construct-name ] 35 C821 (R826) If the do-stmt of a block-do-construct specifies a do-construct-name , the corresponding 36 end-do shall be an end-do-stmt specifying the same do-construct-name . If the do-stmt of a 37 block-do-construct does not specify a do-construct-name , the corresponding end-do shall not 38 specify a do-construct-name . 39 C822 (R826) If the do-stmt is a nonlabel-do-stmt , the corresponding end-do shall be an end-do-stmt . 40 C823 (R826) If the do-stmt is a label-do-stmt , the corresponding end-do shall be identified with the 41 same label . 42 185 J3/06-007 WORKING DRAFT 2006/07/11 8.1.7.2.2 Form of the nonblo ck DO construct 1 2 R835 nonblock-do-construct is action-term-do-construct 3 or outer-shared-do-construct 4 R836 action-term-do-construct is label-do-stmt 5 do-body 6 do-term-action-stmt 7 R837 do-body is [ execution-part-construct ] ... 8 R838 do-term-action-stmt is action-stmt 9 C824 (R838) A do-term-action-stmt shall not b e a continue-stmt , a goto-stmt , a return-stmt , a stop-stmt , an exit-stmt , 10 a cycle-stmt , an end-function-stmt , an end-subroutine-stmt , an end-program-stmt , or an arithmetic-if-stmt . 11 C825 (R835) The do-term-action-stmt shall be identified with a lab el and the corresp onding label-do-stmt shall refer 12 to the same lab el. 13 R839 outer-shared-do-construct is label-do-stmt 14 do-body 15 shared-term-do-construct 16 R840 shared-term-do-construct is outer-shared-do-construct 17 or inner-shared-do-construct 18 R841 inner-shared-do-construct is label-do-stmt 19 do-body 20 do-term-shared-stmt 21 R842 do-term-shared-stmt is action-stmt 22 C826 (R842) A do-term-shared-stmt shall not be a goto-stmt , a return-stmt , a stop-stmt , an exit-stmt , a cycle-stmt , 23 an end-function-stmt , an end-subroutine-stmt , an end-program-stmt , or an arithmetic-if-stmt . 24 C827 (R840) The do-term-shared-stmt shall be identified with a lab el and all of the label-do-stmt s of the inner-shared- 25 do-construct and outer-shared-do-construct shall refer to the same label. 26 The do-term-action-stmt , do-term-shared-stmt , or shared-term-do-construct following the do-body of a nonblo ck DO con- 27 struct is called the DO termination of that construct. 28 Within a scoping unit, all DO constructs whose DO statements refer to the same label are nonblock DO constructs, and 29 are said to share the statement identified by that lab el. 8.1.7.3 Range of the DO construct 30 The range of a block DO construct is the do-block , which shall satisfy the rules for blocks (8.1.2). In 31 particular, transfer of control to the interior of such a block from outside the block is prohibited. It 32 is permitted to branch to the end-do of a block DO construct only from within the range of that DO 33 construct. 34 35 The range of a nonblock DO construct consists of the do-body and the following DO termination. The end of such a 36 range is not b ounded by a particular statement as for the other executable constructs (e.g., END IF); nevertheless, the 37 range satisfies the rules for blo cks (8.1.2). Transfer of control into the do-body or to the DO termination from outside the 38 range is prohibited; in particular, it is p ermitted to branch to a do-term-shared-stmt only from within the range of the 39 corresp onding inner-shared-do-construct . 8.1.7.4 Active and inactive DO constructs 40 A DO construct is either active or inactive. Initially inactive, a DO construct becomes active only 41 when its DO statement is executed. 42 Once active, the DO construct becomes inactive only when it terminates (8.1.7.5.4). 43 8.1.7.5 Execution of a DO construct 44 8.1.7.5.1 Lo op initiation 45 When the DO statement is executed, the DO construct becomes active. If loop-control is 46 186 2006/07/11 WORKING DRAFT J3/06-007 [ , ] do-variable = scalar-int-expr 1 , scalar-int-expr 2 [ , scalar-int-expr 3 ] 1 the following steps are performed in sequence. 2 (1) The initial parameter m1 , the terminal parameter m2 , and the incrementation parameter 3 m3 are of type integer with the same kind type parameter as the do-variable . Their values 4 are established by evaluating scalar-int-expr 1 , scalar-int-expr 2 , and scalar-int-expr 3 , re- 5 spectively, including, if necessary, conversion to the kind type parameter of the do-variable 6 according to the rules for numeric conversion (Table 7.11). If scalar-int-expr 3 does not 7 appear, m3 has the value 1. The value of m3 shall not be zero. 8 (2) The DO variable becomes defined with the value of the initial parameter m1 . 9 The iteration count is established and is the value of the expression (m2 - m1 + m3 )/m3 , (3) 10 unless that value is negative, in which case the iteration count is 0. 11 NOTE 8.15 The iteration count is zero whenever: m1 > m2 and m3 > 0, or m1 < m2 and m3 < 0. If loop-control is omitted, no iteration count is calculated. The effect is as if a large positive iteration 12 count, impossible to decrement to zero, were established. If loop-control is [ , ] WHILE (scalar-logical- 13 expr ), the effect is as if loop-control were omitted and the following statement inserted as the first 14 statement of the do-block : 15 IF (.NOT. (scalar- logical-expr )) EXIT 16 For a DO CONCURRENT construct, the values of the index variables for the iterations of the construct 17 are determined by the rules for the index variables of the FORALL construct (7.4.4.2.1 and 7.4.4.2.2). 18 The number of distinct index value combinations in the active combination of index-name values is the 19 iteration count for the construct. 20 An index-name in a DO CONCURRENT construct has a scope of the construct (16.4). It is a scalar 21 variable that has the type and type parameters that it would have if it were the name of a variable in 22 the scoping unit that includes the DO CONCURRENT, and this type shall be integer type; it has no 23 other attributes. 24 At the completion of the execution of the DO statement, the execution cycle begins. 25 8.1.7.5.2 The execution cycle 26 The execution cycle of a DO construct that is not a DO CONCURRENT construct consists of the 27 following steps performed in sequence repeatedly until termination. 28 (1) The iteration count, if any, is tested. If it is zero, the loop terminates and the DO construct 29 becomes inactive. If loop-control is [ , ] WHILE (scalar-logical-expr ), the scalar-logical-expr 30 is evaluated; if the value of this expression is false, the loop terminates and the DO construct 31 becomes inactive. If, as a result, all of the DO constructs sharing the do-term-shared-stmt are inactive, 32 33 the execution of all of these constructs is complete. However, if some of the DO constructs sharing the 34 do-term-shared-stmt are active, execution continues with step (3) of the execution cycle of the active DO 35 construct whose DO statement was most recently executed. (2) If the iteration count is nonzero, the range of the loop is executed. 36 (3) The iteration count, if any, is decremented by one. The DO variable, if any, is incremented 37 by the value of the incrementation parameter m3 . 38 187 J3/06-007 WORKING DRAFT 2006/07/11 Except for the incrementation of the DO variable that occurs in step (3), the DO variable shall neither 1 be redefined nor become undefined while the DO construct is active. 2 The range of a DO CONCURRENT construct is executed for all of the active combinations of the 3 index-name values. Each execution of the range is an iteration. The executions may occur in any 4 order. 5 J3 internal note Unresolved Technical Issue 25 This definition of "iteration" for DO CONCURRENT almost certainly breaks the use of the term elsewhere throughout the standard. Making it not a definition of "iteration" would probably suffice to fix this. 8.1.7.5.3 CYCLE statement 6 Execution of the range of the loop may be curtailed by executing a CYCLE statement from within the 7 range of the loop. 8 R843 cycle-stmt is CYCLE [ do-construct-name ] 9 C828 (R843) If a cycle-stmt refers to a do-construct-name , it shall be within the range of that do- 10 construct ; otherwise, it shall be within the range of at least one do-construct . 11 C829 (R843) A cycle-stmt shall not appear within the range of a DO CONCURRENT construct if it 12 belongs to an outer construct. 13 A CYCLE statement belongs to a particular DO construct. If the CYCLE statement refers to a DO 14 construct name, it belongs to that DO construct; otherwise, it belongs to the innermost DO construct 15 in which it appears. 16 Execution of a CYCLE statement that belongs to a DO construct that is not a DO CONCURRENT 17 construct causes immediate progression to step (3) of the current execution cycle of the DO construct 18 to which it belongs. If this construct is a nonblock DO construct, the do-term-action-stmt or do-term-shared-stmt is 19 20 not executed. Execution of a CYCLE statement that belongs to a DO CONCURRENT construct completes execution 21 of that iteration of the construct. 22 In a block DO construct, a transfer of control to the end-do has the same effect as execution of a CYCLE 23 statement belonging to that construct. In a nonblock DO construct, transfer of control to the do-term-action-stmt 24 25 or do-term-shared-stmt causes that statement or construct itself to b e executed. Unless a further transfer of control results, 26 step (3) of the current execution cycle of the DO construct is then executed. 8.1.7.5.4 Lo op termination 27 For a DO construct that is not a DO CONCURRENT construct, the loop terminates, and the DO 28 construct becomes inactive, when any of the following occurs. 29 (1) The iteration count is determined to be zero or the scalar-logical-expr is false, when tested 30 during step (1) of the above execution cycle. 31 (2) An EXIT statement belonging to the DO construct is executed. 32 (3) An EXIT or CYCLE statement that belongs to an outer construct and is within the range 33 of the DO construct is executed. 34 (4) Control is transferred from a statement within the range of a DO construct to a statement 35 that is neither the end-do nor within the range of the same DO construct. 36 188 2006/07/11 WORKING DRAFT J3/06-007 (5) A RETURN statement within the range of the DO construct is executed. 1 (6) A STOP statement anywhere in the program is executed, or the program is terminated for 2 any other reason. 3 For a DO CONCURRENT construct, the loop terminates, and the DO construct becomes inactive when 4 all of the iterations have completed execution. 5 When a DO construct becomes inactive, the DO variable, if any, of the DO construct retains its last 6 defined value. 7 8.1.7.6 Restrictions on DO CONCURRENT constructs 8 The following restrictions apply to DO CONCURRENT constructs. 9 · A statement in the loop range shall not cause a branch out of the construct. 10 · A variable that is referenced in an iteration shall either be previously defined during that iteration, 11 or shall be defined or become undefined during any other iteration of the current execution of 12 the construct. A variable that is defined or becomes undefined by more than one iteration of the 13 current execution of the construct becomes undefined when the current execution of the construct 14 terminates. 15 · A pointer that is referenced in an iteration either shall be previously pointer associated during that 16 iteration, or shall not have its pointer association changed during any iteration. A pointer that has 17 its pointer association changed in more than one iteration has a processor dependent association 18 status when the construct terminates. 19 · An allocatable ob ject that is allocated in more than one iteration shall be subsequently deallocated 20 during the same iteration in which it was allocated. An ob ject that is allocated or deallocated in 21 only one iteration shall not be deallocated, allocated, referenced, defined, or become undefined in 22 a different iteration. 23 · An input/output statement shall not write data to a file record or position in one iteration and 24 read from the same record or position in a different iteration of the same execution of the construct. 25 · Records written by output statements in the loop range to a sequential access file appear in the 26 file in an indeterminate order. 27 · Procedures referenced in the loop range shall be PURE. References to the procedures IEEE GET FLAG, 28 IEEE SET HALTING MODE, and IEEE GET HALTING MODE from the intrinsic module IEEE EXCEPTIONS 29 shall not appear in the loop range. 30 NOTE 8.16 The restrictions on referencing variables defined in an iteration of a DO CONCURRENT construct apply to any procedure invoked within the loop. NOTE 8.17 The restrictions on the statements in the loop range of a DO CONCURRENT construct are designed to ensure there are no data dependencies between iterations of the loop. This permits code optimizations that might otherwise be difficult or impossible because they would depend on characteristics of the program not visible to the compiler. 189 J3/06-007 WORKING DRAFT 2006/07/11 8.1.7.7 Examples of DO constructs 1 NOTE 8.18 The following program fragment computes a tensor product of two arrays: DO I = 1, M DO J = 1, N C (I, J) = SUM (A (I, J, :) * B (:, I, J)) END DO END DO NOTE 8.19 The following program fragment contains a DO construct that uses the WHILE form of loop- control . The loop will continue to execute until an end-of-file or input/output error is encountered, at which point the DO statement terminates the loop. When a negative value of X is read, the program skips immediately to the next READ statement, bypassing most of the range of the loop. READ (IUN, '(1X, G14.7)', IOSTAT = IOS) X DO WHILE (IOS == 0) IF (X >= 0.) THEN CALL SUBA (X) CALL SUBB (X) ... CALL SUBZ (X) ENDIF READ (IUN, '(1X, G14.7)', IOSTAT = IOS) X END DO NOTE 8.20 The following example behaves exactly the same as the one in Note 8.19. However, the READ statement has been moved to the interior of the range, so that only one READ statement is needed. Also, a CYCLE statement has been used to avoid an extra level of IF nesting. DO ! A "DO WHILE + 1/2" loop READ (IUN, '(1X, G14.7)', IOSTAT = IOS) X IF (IOS /= 0) EXIT IF (X < 0.) CYCLE CALL SUBA (X) CALL SUBB (X) ... CALL SUBZ (X) END DO NOTE 8.21 The following example represents a case in which the user knows that the elements of the array IND form a permutation of the integers 1, ..., N. The DO CONCURRENT construct will allow the compiler to generate vector gather/scatter code, unroll the loop, or parallelize the code for this loop, significantly improving performance. INTEGER :: A(N,N),IND(N) 190 2006/07/11 WORKING DRAFT J3/06-007 NOTE 8.21 (cont.) DO CONCURRENT (I=1:N, J=1:N) A(IND(I),IND(J)) = A(IND(I),IND(J)) + 1 END DO NOTE 8.22 Additional examples of DO constructs are in C.5.3. 8.1.8 EXIT statement 1 The EXIT statement provides one way of terminating a construct. 2 R844 exit-stmt is EXIT [ construct-name ] 3 C830 If an exit-stmt refers to a construct-name , it shall be within that construct; otherwise, it shall 4 be within the range of at least one do-construct . 5 An EXIT statement belongs to a particular construct. If the EXIT statement refers to a construct name, 6 it belongs to that construct; otherwise, it belongs to the innermost DO construct in which it appears. 7 C831 An exit-stmt shall not belong to a DO CONCURRENT construct, nor shall it appear within 8 the range of a DO CONCURRENT construct if it belongs to a construct that contains that DO 9 CONCURRENT construct. 10 When an EXIT statement that belongs to a DO construct is executed, it terminates the loop (8.1.7.5.4) 11 and any active loops contained within the terminated loop. When an EXIT statement that belongs to 12 a non-DO construct is executed, it terminates any active loops contained within that construct, and 13 completes execution of that construct. 14 8.1.9 BLOCK construct 15 The BLOCK construct is a block which may contain declarations. 16 R845 block-construct is block-stmt 17 [ specification-part ] 18 block 19 end-block-stmt 20 R846 block-stmt is [ block-construct-name : ] BLOCK 21 R847 end-block-stmt is END BLOCK [ block-construct-name ] 22 C832 (R845) If the block-stmt of a block-construct specifies a block-construct-name , the corresponding 23 end-block-stmt shall specify the same block-construct-name . If the block-stmt does not specify 24 a block-construct-name , the corresponding end-block-stmt shall not specify a block-construct- 25 name . 26 Specifications in a BLOCK construct declare construct entities whose scope is that of the BLOCK 27 construct. 28 Specification expressions in the specification-part of a BLOCK construct are evaluated when the BLOCK 29 statement is executed. 30 The BLOCK construct terminates when a RETURN statement within the block is executed, or when 31 transfer of control to a statement outside the block occurs. 32 191 J3/06-007 WORKING DRAFT 2006/07/11 8.1.10 CRITICAL construct 1 A CRITICAL construct limits execution of a block to one image at a time. 2 R848 critical-construct is critical-stmt 3 block 4 end-critical-stmt 5 R849 critical-stmt is [ critical-construct-name : ] CRITICAL 6 R850 end-critical-stmt is END CRITICAL [ critical-construct-name ] 7 C833 (R848) If the critical-stmt of a critical-construct specifies a critical-construct-name , the corre- 8 sponding end-critical-stmt shall specify the same critical-construct-name . If the critical-stmt of a 9 critical-construct does not specify a critical-construct-name , the corresponding end-critical-stmt 10 shall not specify a critical-construct-name . 11 C834 (R848) The block of a critical-construct shall not contain an image control statement. 12 A CRITICAL construct completes execution if the END CRITICAL statement is executed or if control 13 is transferred to a branch target outside the block. 14 The processor shall ensure that once an image has commenced executing block , no other image shall 15 commence executing it until the image has completed executing it. If image T is the next to execute the 16 construct after image M, the segments (8.5.1) that executed before the construct on image M precede 17 the segments that execute after the construct on image T. No image control statement shall be executed 18 during the execution of a critical construct by the image executing the CRITICAL construct. 19 NOTE 8.23 If more than one image executes the block of a CRITICAL construct, its execution by one image always either precedes or succeeds its execution by another image. Typically no other statement ordering is needed. Consider the following example: CRITICAL GLOBAL_COUNTER[1] = GLOBAL_COUNTER[1] + 1 END CRITICAL The definition of GLOBAL COUNTER[1] by a particular image will always precede the reference to the same variable by the next image to execute the block. NOTE 8.24 The following example permits a large number of jobs to be shared among the images: INTEGER :: NUM_JOBS[*], JOB IF (THIS_IMAGE() == 1) READ(*,*) NUM_JOBS SYNC_ALL DO CRITICAL JOB = NUM_JOBS[1] NUM_JOBS[1] = JOB - 1 END CRITICAL IF (JOB > 0) THEN ! Work on JOB 192 2006/07/11 WORKING DRAFT J3/06-007 NOTE 8.24 (cont.) ELSE EXIT END IF END DO SYNC_ALL 8.2 Branching 1 Branching is used to alter the normal execution sequence. A branch causes a transfer of control from 2 one statement in a scoping unit to a labeled branch target statement in the same scoping unit. Branching 3 may be caused by a GOTO statement, a computed GOTO statement, an arithmetic IF statement, a 4 CALL statement that has an alt-return-spec , or an input/output statement that has an END= or ERR= 5 specifier. Although procedure references and control constructs can cause transfer of control, they are 6 not branches. A branch target statement is an action-stmt , an associate-stmt , an end-associate-stmt , 7 an if-then-stmt , an end-if-stmt , a select-case-stmt , an end-select-stmt , a select-type-stmt , an end-select- 8 type-stmt , a do-stmt , an end-do-stmt , a foral l-construct-stmt , a do-term-action-stmt , a do-term-shared-stmt , or 9 a where-construct-stmt . 10 8.2.1 GO TO statement 11 R851 goto-stmt is GO TO label 12 C835 (R851) The label shall be the statement label of a branch target statement that appears in the 13 same scoping unit as the goto-stmt . 14 Execution of a GO TO statement causes a transfer of control so that the branch target statement 15 identified by the label is executed next. 16 8.2.2 Computed GO TO statement 17 18 R852 computed-goto-stmt is GO TO ( label -list ) [ , ] scalar-int-expr 19 C836 (R852 Each label in label -list shall b e the statement lab el of a branch target statement that app ears in the same 20 scoping unit as the computed-goto-stmt . NOTE 8.25 The same statement lab el may app ear more than once in a lab el list. 21 Execution of a computed GO TO statement causes evaluation of the scalar integer expression. If this value is i such that 1 i n where n is the numb er of lab els in label -list, a transfer of control o ccurs so that the next statement executed is 22 23 the one identified by the ith label in the list of lab els. If i is less than 1 or greater than n, the execution sequence continues 24 as though a CONTINUE statement were executed. 8.2.3 Arithmetic IF statement 25 26 R853 arithmetic-if-stmt is IF ( scalar-numeric-expr ) label , label , label 27 C837 (R853) Each label shall be the lab el of a branch target statement that app ears in the same scoping unit as the 28 arithmetic-if-stmt . 29 C838 (R853) The scalar-numeric-expr shall not b e of typ e complex. 193 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.26 The same label may appear more than once in one arithmetic IF statement. 1 Execution of an arithmetic IF statement causes evaluation of the numeric expression followed by a transfer of control. The 2 branch target statement identified by the first lab el, the second lab el, or the third lab el is executed next dep ending on 3 whether the value of the numeric expression is less than zero, equal to zero, or greater than zero, resp ectively. 8.3 CONTINUE statement 4 Execution of a CONTINUE statement has no effect. 5 R854 continue-stmt is CONTINUE 6 8.4 STOP statement 7 R855 stop-stmt is STOP [ stop-code ] 8 R856 stop-code is scalar-char-initialization-expr 9 or scalar-int-initialization-expr 10 C839 (R856) The scalar-char-initialization-expr shall be of default kind. 11 C840 (R856) The scalar-int-initialization-expr shall be of default kind. 12 Normal termination of execution of the program occurs on all images if a STOP statement or end- 13 program-stmt is executed immediately after a SYNC ALL statement (8.5.2) on all images. The stop 14 code, if any, and warnings of any exceptions that are signaling shall be made available only for image 1. 15 J3 internal note Unresolved Technical Issue 26 What happens with execution of an end-program-stmt is not a proper sub ject for the STOP statement subclause. It is probably duplicative as well. This applies to later paragraphs as well as the above paragraph. J3 internal note Unresolved Technical Issue 27 The first sentence is ambiguous on several levels. Does it mean a particular SYNC ALL statement on all images? ...Or the usual "any SYNC ALL statement" syncs with any other? Does it mean that a STOP or end-program-stmt is executed on all images? ...Or can one image decide unilaterally to normally terminate the program? ...And then, is it ok for some images to execute STOP and other to execute an end-program-stmt ? From the alternative (STOP statement that does not immediately follow a SYNC ALL statement) it seems that unilateralism might be what is intended, except that then not all cases seem to be covered in the "how many images execute a STOP" situation... J3 internal note Unresolved Technical Issue 28 "made available" is not a particularly meaningful phrase. It's use seems to contradict the (non- deleted) later paragraphs of STOP. The processor shall ensure that once an image has commenced executing a STOP or an end-program-stmt 16 statement that does not immediately follow a SYNC ALL statement, no other image shall commence 17 executing such a statement. It causes normal termination (2.3.4) of execution of the program on that 18 image. The stop code, if any, and warnings of any exceptions that are signaling shall be made available 19 194 2006/07/11 WORKING DRAFT J3/06-007 only for that image. The executions of all other images are terminated. 1 J3 internal note Unresolved Technical Issue 29 What does this mean? The other image hangs forever? The other image is terminated imme- diately? How can you tell it doesn't execute a STOP (since presumably it terminates somehow anyway...). Why does this only apply to STOP not preceded by SYNC ALL? Editor's suggested rewrite of the ab ove paragraphs 2 Execution of a STOP statement causes normal termination of that image and termination of the program. 3 If there is only one image, or the STOP statement is executed immediately after a SYNC ALL statement 4 (8.5.2), the program is terminated normally (2.3.4). 5 If several images execute a STOP statement or end-program-stmt , it is processor-dependent which image's 6 stop code or signalling exception warning is made available, except that if a STOP statement is executed 7 immediately after a SYNC ALL statement on image 1, the stop code and signaling exceptions on image 8 1 are reported. 9 End of editor's suggestion 10 At the time of termination, the stop code, if any, is available in a processor-dependent manner. If 11 any exception (14) is signaling, the processor shall issue a warning indicating which exceptions are 12 signaling; this warning shall be on the unit identified by the named constant ERROR UNIT from the 13 ISO FORTRAN ENV intrinsic module (13.8.3.6). 14 J3 internal note Unresolved Technical Issue 30 Why is image 1 special? What if image 2 does all the real work? What if every other image terminates first, before image 1 does? Nearly everything about CAF is very symmetric with regards to images, having weird special abilities on termination of image 1 seems to be unnecessary and to have dubious value. J3 internal note Unresolved Technical Issue 31 If some image registers an "atexit" procedure, normal termination of execution is required to invoke it. Obviously this invocation ought to occur on the registering image, even if it is not image 1, but I'm less convinced that this is well-specified. We say that normal termination of execution includes the effect of executing the C exit function, one question is whether this is on every image or just one image? This is a relatively "soft" UTI, but I think this text needs to be looked at very carefully and thought about. J3 internal note Unresolved Technical Issue 32 Exception warnings appear to be only required in F2003 for STOP, not for end-program-stmt . Assuming that was a deliberate decision, changing this requirement for co-arrays seems outwith the scope of the feature. Not that it might not be a good idea, but it just does not seem to have anything to do with co-arrays as such. Perhaps this should be an F2003 interp? It is recommended that the stop-code is made available by formatted output to the processor-dependent 15 external unit identified by the named constant ERROR UNIT of the ISO FORTRAN ENV intrinsic 16 module (13.8.3.6). 17 195 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.27 If the stop-code is an integer, it is recommended that the value also be used as the process exit status, if the operating system supports that concept. If the integer stop-code is used as the process exit status, the operating system might be able to interpret only values within a limited range, or only a limited portion of the integer value (for example, only the least-significant 8 bits). J3 internal note Unresolved Technical Issue 33 This recommendation for the process exit status does not provide any help for STOP without a code, or for END PROGRAM. Perhaps "STOP" should be equivalent to "STOP 42" whereas "END PROGRAM" should be equivalent to "STOP 5"? Not giving an exit code recommendation for "STOP charstring" is not very good either. 8.5 Image execution control 1 8.5.1 Image control statements 2 The execution sequence on each image is as specified in 2.3.4. 3 An image control statement affects the execution ordering between images. Each of the following is 4 an image control statement: 5 · SYNC ALL statement; 6 · SYNC TEAM statement; 7 · SYNC IMAGES statement; 8 · SYNC MEMORY statement; 9 · NOTIFY statement; 10 · QUERY statement; 11 · ALLOCATE or DEALLOCATE statement involving a co-array; 12 · CRITICAL or END CRITICAL statement (8.1.10); 13 · OPEN statement with a TEAM= specifier; 14 · CLOSE statement for a file that is open with a TEAM= specifier; 15 · END, END BLOCK, or RETURN statement that involves an implicit deallocation of a co-array; 16 · CALL statement for a collective subroutine (13.1). 17 During an execution of a statement that contains more than one reference to a procedure, image control 18 statements other than CRITICAL or END CRITICAL shall be executed in at most one of the procedures 19 invoked. 20 On each image, the sequence of statements executed before the first image control statement, between 21 the execution of two image control statements, or after the last image control statement is known as 22 a segment. The segment executed immediately before the execution of an image control statement 23 includes the evaluation of all expressions within the statement. 24 By execution of image control statements or user-defined ordering (8.5.6), the program can ensure 25 that the execution of the ith segment on image P, Pi , either precedes or succeeds the execution of the 26 196 2006/07/11 WORKING DRAFT J3/06-007 j th segment on another image Q, Qj . If the program does not ensure this, segments Pi and Qj are 1 unordered; depending on the relative execution speeds of the images, some or all of the execution of 2 the segment Pi may take place at the same time as some or all of the execution of the segment Qj . 3 NOTE 8.28 The set of all segments on all images is partially ordered: the segment Pi precedes segment Qj if and only if there is a sequence of segments starting with Pi and ending with Qj such that each segment of the sequence precedes the next either because they are on the same image or because of the execution of image control statements or user-defined ordering. A scalar co-variable that is of type default integer, default logical, default real, or default bits, and has 4 the VOLATILE attribute (5.3.18) may be referenced during the execution of a segment that is unordered 5 relative to the execution of a segment in which the co-variable is defined. Otherwise, 6 · if a co-array variable is defined on an image in a segment, it shall not be referenced or defined in 7 a segment on another image unless the segments are ordered, 8 · if the allocation of an allocatable subob ject of a co-array or the association of a pointer subob ject 9 of a co-array is changed on an image in a segment, that subob ject shall not be referenced or defined 10 in a segment on another image unless the segments are ordered, and 11 · if a procedure invocation on image P is in execution in segments Pi , Pi+1 , ..., Pk and defines a 12 non-co-array dummy argument, the argument associated entity shall not be referenced or defined 13 on another image Q in a segment Qj unless Qj precedes Pi or succeeds Pk . 14 J3 internal note Unresolved Technical Issue 34 But ... re the middle item above .. you say the target of a pointer component of a co-array is always on the same image. So how can it be referenced by a remote image? Does this not mean that even non-coarrays have to be stored in remotely-accessible memory if they have the TARGET attribute? BTW, here are what some possibilities for segment notation look like: (1) The ith segment of P is Pi : e.g. in Pi , Pi+1 , ..., Pk and defines a (2) The ith segment of P is SP,i : e.g. in SP,i , SP,i+1 , ..., SP,k and defines a (3) The ith segment of P is Si,P : e.g. in Si,P , Si+1,P , ..., Sk,P and defines a (4) The ith segment of P is S(i,P): e.g. in S(i,P), S(i+1,P), ..., S(k,P) and defines a And here are some possibilities for the Notify/Query notation: (1) Count of NOTIFYs from image T to image M is NT M , Count of successful QUERYs on image M of image T is QM T , e.g. until, ... , NT M > QM T . (2) Count of NOTIFYs from image T to image M is NT ,M , Count of successful QUERYs on image M of image T is QM ,T , e.g. until, ... , NT ,M > QM ,T . (3) Count of NOTIFYs from image T to image M is n(T,M), Count of successful QUERYs on image M of image T is b(M,T), e.g. until, ... , n(T,M) > b(M,T). 197 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.29 Apart from the effects of volatile variables, the processor may optimize the execution of a segment as if it were the only image in execution. NOTE 8.30 The model upon which the interpretation of a program is based is that there is a permanent memory location for each co-array variable and that all images can access it. In practice, an image may make a copy of a non-volatile co-array variable (in cache or a register, for example) and, as an optimization, defer copying a changed value back to the permanent location while it is still being used. Since the variable is not volatile, it is safe to defer this transfer until the end of the current segment and thereafter to reload from permanent memory any co-array variable that was not defined within the segment. It would not be safe to defer these actions beyond the end of the current segment since another image might reference the variable then. If an image P writes a record during the execution of Pi to a file that is opened for direct access with a 1 TEAM= specifier, no other image Q shall read or write the record during execution of a segment that 2 is unordered with Pi . Furthermore, it shall not read the record in a segment that succeeds Pi unless 3 · after image P writes the record, it executes a FLUSH statement (9.8) for the file during the 4 execution of a segment Pk , where k >= i, and 5 · before image Q reads the record, it executes a FLUSH statement for the file during the execution 6 of a segment Qj that succeeds Pk . 7 NOTE 8.31 The incorrect sequencing of image control statements can halt execution indefinitely. For example, one image might be executing a SYNC ALL statement while another is executing an ALLOCATE statement for a co-array; or one image might be executing a blocking QUERY statement for which an image in its image set never executes the corresponding NOTIFY statement. 8.5.2 SYNC ALL statement 8 R857 sync-al l-stmt is SYNC ALL [ ( [ sync-stat -list ] ) ] 9 R858 sync-stat is STAT = stat-variable 10 or ERRMSG = errmsg-variable 11 C841 No specifier shall appear more than once in a given sync-stat -list. 12 The STAT= and ERRMSG= specifiers for image execution control statements are described in 8.5.7. 13 Execution of a SYNC ALL statement performs a synchronization of all images. Execution on an image, 14 M, of the segment following the SYNC ALL statement is delayed until each other image has executed a 15 SYNC ALL statement as many times as has image M. The segments that executed before the SYNC ALL 16 statement on an image precede the segments that execute after the SYNC ALL statement on another 17 image. 18 NOTE 8.32 If synchronization is required when the images commence statement execution, a SYNC ALL statement should be the first executable statement of the main program. This is necessary if the code relies on the initialization of a co-array variable on another image. 198 2006/07/11 WORKING DRAFT J3/06-007 NOTE 8.33 The processor might have special hardware or employ an optimized algorithm to make the SYNC ALL statement execute efficiently. Here is a simple example of its use. Image 1 reads data and broadcasts it to other images: REAL :: P[*] ... SYNC_ALL IF (THIS_IMAGE()==1) THEN READ (*,*) P DO I = 2, NUM_IMAGES() P[I] = P END DO END IF SYNC_ALL 8.5.3 SYNC TEAM statement 1 R859 sync-team-stmt is SYNC TEAM ( image-team [ , sync-stat -list ] ) 2 R860 image-team is scalar-variable 3 C842 The image-team shall be a scalar variable of type IMAGE TEAM from the intrinsic module 4 ISO FORTRAN ENV. 5 Execution of a SYNC TEAM statement performs a team synchronization, which is a synchronization 6 of the images in a team. The team is specified by the value of image-team and shall include the executing 7 image. All images of the team shall execute a SYNC TEAM statement with a value of image-team that 8 was constructed by invoking the intrinsic function FORM TEAM for the team. They do not commence 9 executing subsequent statements until all images in the team have executed a SYNC TEAM statement 10 for the team an equal number of times since FORM TEAM was invoked for the team. If images M 11 and T are any two members of the team, the segments that execute before the statement on image M 12 precede the segments that execute after the statement on image T. 13 Team synchronization is also performed by an OPEN statement with a TEAM= specifier, a CLOSE 14 statement for a file that is open with a TEAM= specifier, or the invocation of a collective subroutine. 15 199 J3/06-007 WORKING DRAFT 2006/07/11 J3 internal note Unresolved Technical Issue 35 It is not clear whether "the team" refers to the value gotten back from FORM TEAM, or the input value to FORM TEAM. Yes, I know FORM TEAM is a "collective", but that does not resolve this ambiguity. Images 1-6 do CALL form_team(team1,image_list) CALL form_team(team2,image_list) ! same list as in previous statement then images 1-3 do SYNC_TEAM(team1) whereas images 4-6 do SYNC_TEAM(team2) The question is, is this equivalent to them all doing SYNC_TEAM(team1) ??? If it is, how can SYNC_TEAM(team1) offer any advantage over SYNC_IMAGES(image_list)? SYNC_TEAM seems completely redundant. Anyway, it needs to be made clear what the answer is. NOTE 8.34 In this example the images are divided into two teams, one for an ocean calculation and one for an atmosphere calculation. USE, INTRINSIC :: ISO_FORTRAN_ENV TYPE(IMAGE_TEAM) :: TEAM INTEGER :: N2, STEP, NSTEPS LOGICAL :: OCEAN N2 = NUM_IMAGES()/2 OCEAN = (THIS_IMAGE()<=N2) IF(OCEAN) THEN CALL FORM_TEAM(TEAM, (/ (I, I=1,N2) /) ) ELSE CALL FORM_TEAM(TEAM, (/ (I, I=N2+1,NUM_IMAGES()) /) ) END IF : ! Initial calculation SYNC_ALL DO STEP = 1, NSTEPS IF (OCEAN) THEN DO : ! Ocean calculation SYNC_TEAM(TEAM) IF ( ... ) EXIT ! Ready to swap data END DO ELSE DO : ! Atmosphere calculation SYNC_TEAM(TEAM) 200 2006/07/11 WORKING DRAFT J3/06-007 NOTE 8.34 (cont.) IF ( ... ) EXIT ! Ready to swap data END DO END IF SYNC_ALL : ! Swap data END DO In the inner loops, each set of images first works entirely with its own data and each image synchronizes with the rest of its team. The number of synchronizations for the ocean team might differ from the number for the atmosphere team. The SYNC ALL statement that follows is needed to ensure that both teams have done their calculations before data are swapped. 8.5.4 SYNC IMAGES statement 1 R861 sync-images-stmt is SYNC IMAGES ( image-set [ , sync-stat -list ] ) 2 R862 image-set is int-expr 3 or * 4 C843 An image-set that is an int-expr shall be scalar or of rank one and shall not be a co-indexed 5 ob ject. 6 J3 internal note Unresolved Technical Issue 36 The restriction on image-set not being a co-indexed ob ject seems to be a restriction which has no purpose and no effect. I note that it is an expression, not a variable, so the user can just write SYNC_IMAGES((x[i]%imagelist)) instead of SYNC_IMAGES(x[i]%imagelist) This kind of thing is not going to improve the reputation of the Fortran standard and the com- mittees. If image-set is an array expression, the value of each element shall be positive and not greater than the 7 number of images, and there shall be no repeated values. 8 If image-set is a scalar expression, its value shall be positive and not greater than the number of images. 9 An image-set that is an asterisk specifies all images. 10 Execution of a SYNC IMAGES statement performs a synchronization of the image with each of the 11 other images in the image-set . Execution on an image, M, of the segment following the SYNC IMAGES 12 statement is delayed until each other image T in the image-set has executed a SYNC IMAGES statement 13 with M in its image-set as many times as image M has executed a SYNC IMAGES statement with T in 14 the image-set . The segments that executed before the SYNC IMAGES statement on image M precede 15 the segments that execute after the SYNC IMAGES statement on image T. 16 NOTE 8.35 A SYNC IMAGES statement that specifies the single image value THIS IMAGE() in its image set is allowed. This simplifies writing programs for an arbitrary number of images by allowing correct 201 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.35 (cont.) execution in the limiting case of the number of images being equal to one. NOTE 8.36 Execution of a SYNC IMAGES(*) statement is not equivalent to the execution of a SYNC ALL statement. SYNC ALL causes all images to wait for each other. SYNC IMAGES statements are not required to specify the same image set on all the images participating in the synchronization. In the following example, image 1 will wait for each of the other images to complete its use of the data. The other images wait for image 1 to set up the data, but do not wait on any of the other images. IF (THIS IMAGE() == 1) then ! Set up co-array data needed by all other images SYNC IMAGES(*) ELSE SYNC IMAGES(1) ! Use the data set up by image 1 END IF NOTE 8.37 Execution of a SYNC TEAM statement causes all the images of the team to wait for each other. There might, however, be situations where this is not efficient. In the following example, each image synchronizes with its neighbor. INTEGER :: ME, NE, STEP, NSTEPS NE = NUM_IMAGES() ME = THIS_IMAGE() ! Initial calculation SYNC_ALL DO STEP = 1, NSTEPS IF (ME > 1) SYNC_IMAGES(ME-1) ! Perform calculation IF (ME < NE) SYNC_IMAGES(ME+1) END DO SYNC_ALL The calculation starts on image 1 since all the others will be waiting on SYNC IMAGES(ME- 1). When this is done, image 2 can start and image 1 can perform its second calculation. This continues until they are all executing different steps at the same time. Eventually, image 1 will finish and then the others will finish one by one. The SYNC IMAGES syntax involves image-set rather than image-team to allow the set of images to vary from image to image. 8.5.5 NOTIFY and QUERY statements 1 R863 notify-stmt is NOTIFY ( image-set [ , sync-stat -list ] ) 2 R864 query-stmt is QUERY ( image-set [ , query-spec -list ] ) 3 R865 query-spec is READY = scalar-logical-variable 4 202 2006/07/11 WORKING DRAFT J3/06-007 or sync-stat 1 C844 (R864) No specifier shall appear more than once in a given query-spec -list. 2 Execution on image M of a NOTIFY statement with a different image T in its image-set increments by 3 1 a record of the number of times, NM T , image M executed such a NOTIFY statement. 4 A QUERY statement is blo cking if and only if it has no READY= specifier. A QUERY statement 5 is satisfied on completion of its execution if and only if it is a blocking QUERY statement or it set 6 the variable specified by its READY= specifier to true. Execution on image M of a satisfied QUERY 7 statement with a different image T included in its image set increases by 1 a record of the number of 8 times, QM T , image M executed such a QUERY statement. This increase is made after its value has 9 been compared with NT M . 10 If a READY= specifier appears, execution on image M of a QUERY statement causes the scalar-logical- 11 variable to become defined. The value is false if, for a different image T in the image set, NT M <= 12 QM T . Otherwise, the value is true. 13 If a READY= specifier does not appear, increasing QM T and completing execution of the statement 14 is delayed until, for each different T in the image set, NT M > QM T . 15 A NOTIFY statement execution on image T and a satisfied QUERY statement on image M correspond 16 if and only if 17 · the NOTIFY statement's image set includes image M, 18 · the QUERY statement's image set includes image T, and 19 · after execution of both statements has completed, NT M = QM T . 20 Segments on an image executed before the execution of a NOTIFY statement precede the segments on 21 other images that follow its corresponding QUERY statements. 22 NOTE 8.38 The NOTIFY and QUERY statements can be used to order statement executions between a producer and consumer image. INTEGER,PARAMETER :: PRODUCER = 1, CONSUMER = 2 INTEGER :: VALUE[*] LOGICAL :: READY SELECT CASE (THIS_IMAGE()) CASE (PRODUCER) VALUE[CONSUMER] = 3 NOTIFY (CONSUMER) CASE (CONSUMER) WaitLoop: DO QUERY (PRODUCER,READY=READY) IF (READY) EXIT WaitLoop ! Statements neither referencing VALUE[CONSUMER], nor causing it to ! become defined or undefined END DO WaitLoop ! references to VALUE CASE DEFAULT ! Statements neither referencing VALUE[CONSUMER], nor causing it to 203 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.38 (cont.) ! become defined or undefined END SELECT Unlike SYNC IMAGES statements, the number of notifications and corresponding queries may be unequal. A program can complete with an excess number of notifies. NOTE 8.39 NOTIFY/QUERY pairs can be used in place of SYNC ALL and SYNC IMAGES to achieve better load balancing and allow one image to proceed with calculations while another image is catching up. For example, IF (THIS_IMAGE()==1) THEN DO I=1,100 ... ! Primary processing of column I NOTIFY(2) ! Done with column I END DO SYNC_IMAGES(2) ELSE IF (THIS_IMAGE()==2) THEN DO I=1,100 QUERY(1) ! Wait until image 1 is done with column I ... ! Secondary processing of column I END DO SYNC_IMAGES(1) END IF 8.5.6 SYNC MEMORY statement 1 The SYNC MEMORY statement provides a means of dividing a segment on an image into two segments, 2 each of which can be ordered in some user-defined way with respect to segments on other images. 3 R866 sync-memory-stmt is SYNC MEMORY [ ( [ sync-stat -list ] ) ] 4 NOTE 8.40 SYNC MEMORY usually suppresses compiler optimizations that might reorder memory operations across the segment boundary defined by the SYNC MEMORY statement and ensures that all memory operations initiated in the preceding segments in its image complete before any memory operations in the subsequent segment in its image are initiated. It needs to do this unless it can establish that failure to do so could not alter processing on another image. All of the other image control statements include the effect of executing a SYNC MEMORY statement. 5 In addition, the other image control statements cause some form of cooperation with other images for 6 the purpose of ordering execution between images. 7 SYNC MEMORY in combination with user-written code that forces synchronization between images 8 can provide an effective and flexible alternative to the image control statements described in 8.5.2 to 9 8.5.5. 10 J3 internal note Unresolved Technical Issue 37 The above paragraph contributes nothing of substance, being only an advertisement for this subfeature. 204 2006/07/11 WORKING DRAFT J3/06-007 NOTE 8.41 A common example of user-written code that can be used in conjunction with SYNC MEMORY to implement specialized schemes for segment ordering is the spin-wait loop. For example: LOGICAL,VOLATILE :: LOCKED[*] = .TRUE. INTEGER :: IAM, P, Q IAM = THIS_IMAGE() IF (IAM == P) THEN ! Preceding segment SYNC_MEMORY !A ! segment Pi LOCKED[Q] = .FALSE. SYNC_MEMORY !B ELSE IF (IAM == Q) THEN ! segment Qj DO WHILE (LOCKED); END DO SYNC_MEMORY !C ! Subsequent segment END IF Here, image Q does not complete the segment Qj until image P executes segment Pi . This ensures that executions of segments before Pi on image P precede executions of segments on image Q after Qj . The first SYNC MEMORY statement (A) ensures that the compiler does not reorder the following statement (locking) with the previous statements, since the lock should be freed only after the work has been completed. The definition of LOCKED[Q] might be deferred to the end of segment Pi . The second SYNC MEMORY statement (B) ends that segment immediately after the definition, minimizing any delay in releasing the lock in segment Qj . The third SYNC MEMORY statement (C) marks the beginning of a new segment, informing the compiler that the values of co-array variables referenced in that segment might have been changed by other images in preceding segments, so need to be loaded from memory. NOTE 8.42 As a second example, the user might have access to an external procedure that performs synchro- nization between images. That library procedure will not necessarily be aware of the mechanisms used by the processor to manage remote data references and definitions, and therefore not, by itself, be able to ensure the correct memory state before and after its reference. The SYNC MEMORY statement provides the needed memory ordering that enables the safe use of the external synchro- nization routine. For example: INTEGER :: IAM REAL :: X[*] IAM = THIS_IMAGE() IF (IAM == 1) X = 1.0 SYNC_MEMORY CALL EXTERNAL SYNC() SYNC_MEMORY IF (IAM == 2) WRITE(*,*) X[1] 205 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 8.42 (cont.) where executing the subroutine EXTERNAL SYNC has an image synchronization effect similar to executing a SYNC ALL statement. 8.5.7 STAT= and ERRMSG= sp ecifiers in image execution control statements 1 If the STAT= specifier appears, successful execution of the SYNC ALL, SYNC TEAM, SYNC IMAGES, 2 SYNC MEMORY, NOTIFY, or QUERY statement causes the specified variable to become defined with 3 the value zero. If an error occurs during execution of one of these statements, the variable becomes 4 defined with a processor-dependent positive integer value. If an error condition occurs during execution 5 of a SYNC ALL, SYNC TEAM, SYNC IMAGES, SYNC MEMORY, NOTIFY, or QUERY statement 6 that does not contain the STAT= specifier, the effect is processor dependent. 7 J3 internal note Unresolved Technical Issue 38 This is substantially different from our existing uses of STAT=; there, any error condition that is not handled by STAT= causes termination of the program. Similarly for IOSTAT=. The CoFortran programmer deserves no less consideration. He should not be required to use STAT= followed by "IF (stat/=0) STOP" to ensure his program doesn't just go off the deep end with a processor-detected error. This doesn't close the door to processor extensions to return "non-fatal" errors as negative values. If the ERRMSG= specifier appears and an error condition occurs during execution of the SYNC ALL, 8 SYNC TEAM, SYNC IMAGES, SYNC MEMORY, NOTIFY, or QUERY statement, the processor shall 9 assign an explanatory message to the specified variable. If no such condition occurs, the processor shall 10 not change the value of the variable. 11 NOTE 8.43 Which errors, if any, are diagnosed is processor dependent. The processor might check that a valid set of images has been provided, with no out-of-range or repeated values. It might test for network time-outs. While the overall program would probably not be able to recover from the failure of an image, it could perhaps provide information on what failed and be able to save some of the program state to a file. 206 2006/07/11 WORKING DRAFT J3/06-007 9 Input/output statements 1 Input statements provide the means of transferring data from external media to internal storage or 2 from an internal file to internal storage. This process is called reading. Output statements provide 3 the means of transferring data from internal storage to external media or from internal storage to an 4 internal file. This process is called writing. Some input/output statements specify that editing of the 5 data is to be performed. 6 In addition to the statements that transfer data, there are auxiliary input/output statements to ma- 7 nipulate the external medium, or to describe or inquire about the properties of the connection to the 8 external medium. 9 The input/output statements are the OPEN, CLOSE, READ, WRITE, PRINT, BACKSPACE, END- 10 FILE, REWIND, FLUSH, WAIT, and INQUIRE statements. 11 The READ statement is a data transfer input statement. The WRITE statement and the PRINT 12 statement are data transfer output statements. The OPEN statement and the CLOSE state- 13 ment are file connection statements. The INQUIRE statement is a file inquiry statement. The 14 BACKSPACE, ENDFILE, and REWIND statements are file p ositioning statements. 15 A file is composed of either a sequence of file storage units (9.2.4) or a sequence of records, which 16 provide an extra level of organization to the file. A file composed of records is called a record file. A 17 file composed of file storage units is called a stream file. A processor may allow a file to be viewed 18 both as a record file and as a stream file; in this case the relationship between the file storage units when 19 viewed as a stream file and the records when viewed as a record file is processor dependent. 20 A file is either an external file (9.2) or an internal file (9.3). 21 9.1 Records 22 A record is a sequence of values or a sequence of characters. For example, a line on a terminal is usually 23 considered to be a record. However, a record does not necessarily correspond to a physical entity. There 24 are three kinds of records: 25 (1) formatted; 26 (2) unformatted; 27 (3) endfile. 28 NOTE 9.1 What is called a "record" in Fortran is commonly called a "logical record". There is no concept in Fortran of a "physical record." 9.1.1 Formatted record 29 A formatted record consists of a sequence of characters that are capable of representation in the 30 processor; however, a processor may prohibit some control characters (3.1) from appearing in a formatted 31 record. The length of a formatted record is measured in characters and depends primarily on the number 32 of characters put into the record when it is written. However, it may depend on the processor and the 33 external medium. The length may be zero. Formatted records may be read or written only by formatted 34 input/output statements. 35 207 J3/06-007 WORKING DRAFT 2006/07/11 Formatted records may be prepared by means other than Fortran. 1 9.1.2 Unformatted record 2 An unformatted record consists of a sequence of values in a processor-dependent form and may contain 3 data of any type or may contain no data. The length of an unformatted record is measured in file storage 4 units (9.2.4) and depends on the output list (9.5.2) used when it is written, as well as on the processor 5 and the external medium. The length may be zero. Unformatted records may be read or written only 6 by unformatted input/output statements. 7 9.1.3 Endfile record 8 An endfile record is written explicitly by the ENDFILE statement; the file shall be connected for 9 sequential access. An endfile record is written implicitly to a file connected for sequential access when 10 the most recent data transfer statement referring to the file is a data transfer output statement, no 11 intervening file positioning statement referring to the file has been executed, and 12 (1) a REWIND or BACKSPACE statement references the unit to which the file is connected, 13 or 14 (2) the unit is closed, either explicitly by a CLOSE statement, implicitly by a program termi- 15 nation not caused by an error condition, or implicitly by another OPEN statement for the 16 same unit. 17 An endfile record may occur only as the last record of a file. An endfile record does not have a length 18 property. 19 NOTE 9.2 An endfile record does not necessarily have any physical embodiment. The processor may use a record count or other means to register the position of the file at the time an ENDFILE statement is executed, so that it can take appropriate action when that position is reached again during a read operation. The endfile record, however it is implemented, is considered to exist for the BACKSPACE statement (9.7.1). 9.2 External files 20 An external file is any file that exists in a medium external to the program. 21 At any given time, there is a processor-dependent set of allowed access metho ds, a processor-dependent 22 set of allowed forms, a processor-dependent set of allowed actions, and a processor-dependent set of 23 allowed record lengths for a file. 24 NOTE 9.3 For example, the processor-dependent set of allowed actions for a printer would likely include the write action, but not the read action. A file may have a name; a file that has a name is called a named file. The name of a named file is 25 represented by a character string value. The set of allowable names for a file is processor dependent. 26 NOTE 9.4 Named files that are opened with the TEAM= specifier (9.4.6.7) have the same name on each image of the team. Apart from this, whether a named file on one image is the same as a file with the same name on another image is processor dependent. For code portability, if different files are 208 2006/07/11 WORKING DRAFT J3/06-007 NOTE 9.4 (cont.) needed on each image, different file names should be used. One technique is to incorporate the image number as part of the name. An external file that is connected to a unit has a p osition property (9.2.3). 1 NOTE 9.5 For more explanatory information on external files, see C.6.1. 9.2.1 File existence 2 At any given time, there is a processor-dependent set of external files that are said to exist for a program. 3 A file may be known to the processor, yet not exist for a program at a particular time. 4 NOTE 9.6 Security reasons may prevent a file from existing for a program. A newly created file may exist but contain no records. To create a file means to cause a file to exist that did not exist previously. To delete a file means to 5 terminate the existence of the file. 6 All input/output statements may refer to files that exist. An INQUIRE, OPEN, CLOSE, WRITE, 7 PRINT, REWIND, FLUSH, or ENDFILE statement also may refer to a file that does not exist. Execu- 8 tion of a WRITE, PRINT, or ENDFILE statement referring to a preconnected file that does not exist 9 creates the file. 10 9.2.2 File access 11 There are three methods of accessing the data of an external file: sequential, direct, and stream. Some 12 files may have more than one allowed access method; other files may be restricted to one access method. 13 NOTE 9.7 For example, a processor may allow only sequential access to a file on magnetic tape. Thus, the set of allowed access methods depends on the file and the processor. The method of accessing a file is determined when the file is connected to a unit (9.4.3) or when the file 14 is created if the file is preconnected (9.4.4). 15 9.2.2.1 Sequential access 16 Sequential access is a method of accessing the records of an external record file in order. 17 When connected for sequential access, an external file has the following properties. 18 (1) The order of the records is the order in which they were written if the direct access method 19 is not a member of the set of allowed access methods for the file. If the direct access method 20 is also a member of the set of allowed access methods for the file, the order of the records 21 is the same as that specified for direct access. In this case, the first record accessible by 22 sequential access is the record whose record number is 1 for direct access. The second record 23 accessible by sequential access is the record whose record number is 2 for direct access, etc. 24 A record that has not been written since the file was created shall not be read. 25 (2) The records of the file are either all formatted or all unformatted, except that the last record 26 of the file may be an endfile record. Unless the previous reference to the file was a data 27 209 J3/06-007 WORKING DRAFT 2006/07/11 transfer output statement, the last record, if any, of the file shall be an endfile record. 1 (3) The records of the file shall be read or written only by sequential access input/output 2 statements. 3 (4) Each record shall be read or written by a single image. The processor shall ensure that once 4 an image commences transferring the data of a record to the file, no other image transfers 5 data to the file until the whole record has been transferred. 6 9.2.2.2 Direct access 7 Direct access is a method of accessing the records of an external record file in arbitrary order. 8 When connected for direct access, an external file has the following properties. 9 (1) Each record of the file is uniquely identified by a positive integer called the record numb er. 10 The record number of a record is specified when the record is written. Once established, 11 the record number of a record can never be changed. The order of the records is the order 12 of their record numbers. 13 NOTE 9.8 A record cannot be deleted; however, a record may be rewritten. (2) The records of the file are either all formatted or all unformatted. If the sequential access 14 method is also a member of the set of allowed access methods for the file, its endfile record, 15 if any, is not considered to be part of the file while it is connected for direct access. If the 16 sequential access method is not a member of the set of allowed access methods for the file, 17 the file shall not contain an endfile record. 18 (3) The records of the file shall be read or written only by direct access input/output statements. 19 (4) All records of the file have the same length. 20 (5) Records need not be read or written in the order of their record numbers. Any record may 21 be written into the file while it is connected to a unit. For example, it is permissible to write 22 record 3, even though records 1 and 2 have not been written. Any record may be read from 23 the file while it is connected to a unit, provided that the record has been written since the 24 file was created, and if a READ statement for this connection is permitted. 25 (6) The records of the file shall not be read or written using list-directed formatting (10.10), 26 namelist formatting (10.11), or a nonadvancing input/output statement (9.2.3.1). 27 9.2.2.3 Stream access 28 Stream access is a method of accessing the file storage units (9.2.4) of an external stream file. 29 The properties of an external file connected for stream access depend on whether the connection is for 30 unformatted or formatted access. 31 When connected for unformatted stream access, an external file has the following properties. 32 (1) The file storage units of the file shall be read or written only by stream access input/output 33 statements. 34 (2) Each file storage unit in the file is uniquely identified by a positive integer called the position. 35 The first file storage unit in the file is at position 1. The position of each subsequent file 36 storage unit is one greater than that of its preceding file storage unit. 37 (3) If it is possible to position the file, the file storage units need not be read or written in 38 order of their position. For example, it might be permissible to write the file storage unit 39 at position 3, even though the file storage units at positions 1 and 2 have not been written. 40 Any file storage unit may be read from the file while it is connected to a unit, provided that 41 210 2006/07/11 WORKING DRAFT J3/06-007 the file storage unit has been written since the file was created, and if a READ statement 1 for this connection is permitted. 2 When connected for formatted stream access, an external file has the following properties. 3 (1) Some file storage units of the file may contain record markers; this imposes a record structure 4 on the file in addition to its stream structure. There might or might not be a record marker 5 at the end of the file. If there is no record marker at the end of the file, the final record is 6 incomplete. 7 (2) No maximum length (9.4.6.3) is applicable to these records. 8 (3) Writing an empty record with no record marker has no effect. 9 NOTE 9.9 Because the record structure is determined from the record markers that are stored in the file itself, an incomplete record at the end of the file is necessarily not empty. (4) The file storage units of the file shall be read or written only by formatted stream access 10 input/output statements. 11 (5) Each file storage unit in the file is uniquely identified by a positive integer called the position. 12 The first file storage unit in the file is at position 1. The relationship between positions of 13 successive file storage units is processor dependent; not all positive integers need correspond 14 to valid positions. 15 (6) If it is possible to position the file, the file position can be set to a position that was 16 previously identified by the POS= specifier in an INQUIRE statement. 17 NOTE 9.10 There may be some character positions in the file that do not correspond to characters written; this is because on some processors a record marker may be written to the file as a carriage-return/line- feed or other sequence. The means of determining the position in a file connected for stream access is via the POS= specifier in an INQUIRE statement (9.9.1.21). (7) A processor may prohibit some control characters (3.1) from appearing in a formatted stream 18 file. 19 9.2.3 File p osition 20 Execution of certain input/output statements affects the position of an external file. Certain circum- 21 stances can cause the position of a file to become indeterminate. 22 The initial p oint of a file is the position just before the first record or file storage unit. The terminal 23 p oint is the position just after the last record or file storage unit. If there are no records or file storage 24 units in the file, the initial point and the terminal point are the same position. 25 If a record file is positioned within a record, that record is the current record; otherwise, there is no 26 current record. 27 Let n be the number of records in the file. If 1 < i n and a file is positioned within the ith record or 28 between the (i - 1)th record and the ith record, the (i - 1)th record is the preceding record. If n 1 29 and the file is positioned at its terminal point, the preceding record is the nth and last record. If n = 0 30 or if a file is positioned at its initial point or within the first record, there is no preceding record. 31 If 1 i < n and a file is positioned within the ith record or between the ith and (i + 1)th record, the 32 (i + 1)th record is the next record. If n 1 and the file is positioned at its initial point, the first record 33 is the next record. If n = 0 or if a file is positioned at its terminal point or within the nth (last) record, 34 there is no next record. 35 211 J3/06-007 WORKING DRAFT 2006/07/11 For a file connected for stream access, the file position is either between two file storage units, at the 1 initial point of the file, at the terminal point of the file, or undefined. 2 9.2.3.1 Advancing and nonadvancing input/output 3 An advancing input/output statement always positions a record file after the last record read or 4 written, unless there is an error condition. 5 A nonadvancing input/output statement may position a record file at a character position within 6 the current record, or a subsequent record (10.8.2). Using nonadvancing input/output, it is possible to 7 read or write a record of the file by a sequence of input/output statements, each accessing a portion 8 of the record. It is also possible to read variable-length records and be notified of their lengths. If a 9 nonadvancing output statement leaves a file positioned within a current record and no further output 10 statement is executed for the file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement 11 is executed for it, the effect is as if the output statement were the corresponding advancing output 12 statement. 13 9.2.3.2 File p osition prior to data transfer 14 The positioning of the file prior to data transfer depends on the method of access: sequential, direct, or 15 stream. 16 For sequential access on input, if there is a current record, the file position is not changed. Otherwise, 17 the file is positioned at the beginning of the next record and this record becomes the current record. 18 Input shall not occur if there is no next record or if there is a current record and the last data transfer 19 statement accessing the file performed output. 20 If the file contains an endfile record, the file shall not be positioned after the endfile record prior to data 21 transfer. However, a REWIND or BACKSPACE statement may be used to reposition the file. 22 For sequential access on output, if there is a current record, the file position is not changed and the 23 current record becomes the last record of the file. Otherwise, a new record is created as the next record 24 of the file; this new record becomes the last and current record of the file and the file is positioned at 25 the beginning of this record. 26 For direct access, the file is positioned at the beginning of the record specified by the REC= specifier. 27 This record becomes the current record. 28 For stream access, the file is positioned immediately before the file storage unit specified by the POS= 29 specifier; if there is no POS= specifier, the file position is not changed. 30 File positioning for child data transfer statements is described in 9.5.3.7. 31 9.2.3.3 File p osition after data transfer 32 If an error condition (9.10) occurred, the position of the file is indeterminate. If no error condition 33 occurred, but an end-of-file condition (9.10) occurred as a result of reading an endfile record, the file is 34 positioned after the endfile record. 35 For unformatted stream access, if no error condition occurred, the file position is not changed. For 36 unformatted stream output, if the file position exceeds the previous terminal point of the file, the 37 terminal point is set to the file position. 38 NOTE 9.11 An unformatted stream output statement with a POS= specifier and an empty output list can have the effect of extending the terminal point of a file without actually writing any data. 212 2006/07/11 WORKING DRAFT J3/06-007 For a formatted stream output statement, if no error condition occurred, the terminal point of the file 1 is set to the highest-numbered position to which data was transferred by the statement. 2 NOTE 9.12 The highest-numbered position might not be the current one if the output involved T or TL edit descriptors (10.8.1.1). For formatted stream input, if an end-of-file condition occurred, the file position is not changed. 3 For nonadvancing input, if no error condition or end-of-file condition occurred, but an end-of-record 4 condition (9.10) occurred, the file is positioned after the record just read. If no error condition, end-of- 5 file condition, or end-of-record condition occurred in a nonadvancing input statement, the file position 6 is not changed. If no error condition occurred in a nonadvancing output statement, the file position is 7 not changed. 8 In all other cases, the file is positioned after the record just read or written and that record becomes the 9 preceding record. 10 9.2.4 File storage units 11 A file storage unit is the basic unit of storage in a stream file or an unformatted record file. It is the 12 unit of file position for stream access, the unit of record length for unformatted files, and the unit of file 13 size for all external files. 14 Every value in a stream file or an unformatted record file shall occupy an integer number of file storage 15 units; if the stream or record file is unformatted, this number shall be the same for all scalar values of 16 the same type and type parameters. The number of file storage units required for an item of a given type 17 and type parameters may be determined using the IOLENGTH= specifier of the INQUIRE statement 18 (9.9.3). 19 For a file connected for unformatted stream access, the processor shall not have alignment restrictions 20 that prevent a value of any type from being stored at any positive integer file position. 21 The number of bits in a file storage unit is given by the constant FILE STORAGE SIZE (13.8.3.7) 22 defined in the intrinsic module ISO FORTRAN ENV. It is recommended that the file storage unit be 23 an 8-bit octet where this choice is practical. 24 NOTE 9.13 The requirement that every data value occupy an integer number of file storage units implies that data items inherently smaller than a file storage unit will require padding. This suggests that the file storage unit be small to avoid wasted space. Ideally, the file storage unit would be chosen such that padding is never required. A file storage unit of one bit would always meet this goal, but would likely be impractical because of the alignment requirements. The prohibition on alignment restrictions prohibits the processor from requiring data alignments larger than the file storage unit. The 8-bit octet is recommended as a good compromise that is small enough to accommodate the requirements of many applications, yet not so small that the data alignment requirements are likely to cause significant performance problems. 213 J3/06-007 WORKING DRAFT 2006/07/11 9.3 Internal files 1 Internal files provide a means of transferring and converting data from internal storage to internal 2 storage. 3 An internal file is a record file with the following properties. 4 (1) The file is a variable of default, ASCII, or ISO 10646 character type that is not an array 5 section with a vector subscript. 6 (2) A record of an internal file is a scalar character variable. 7 (3) If the file is a scalar character variable, it consists of a single record whose length is the same 8 as the length of the scalar character variable. If the file is a character array, it is treated 9 as a sequence of character array elements. Each array element, if any, is a record of the 10 file. The ordering of the records of the file is the same as the ordering of the array elements 11 in the array (6.2.2.2) or the array section (6.2.2.3). Every record of the file has the same 12 length, which is the length of an array element in the array. 13 (4) A record of the internal file becomes defined by writing the record. If the number of 14 characters written in a record is less than the length of the record, the remaining portion 15 of the record is filled with blanks. The number of characters to be written shall not exceed 16 the length of the record. 17 (5) A record may be read only if the record is defined. 18 (6) A record of an internal file may become defined (or undefined) by means other than an 19 output statement. For example, the character variable may become defined by a character 20 assignment statement. 21 (7) An internal file is always positioned at the beginning of the first record prior to data transfer, 22 except for child data transfer statements (9.5.3.7). This record becomes the current record. 23 (8) The initial value of a connection mode (9.4.1) is the value that would be implied by an 24 initial OPEN statement without the corresponding keyword. 25 (9) Reading and writing records shall be accomplished only by sequential access formatted 26 input/output statements. 27 (10) An internal file shall not be specified as the unit in a file connection statement or a file 28 positioning statement. 29 9.4 File connection 30 A unit, specified by an io-unit , provides a means for referring to a file. 31 R901 io-unit is file-unit-number 32 or * 33 or internal-file-variable 34 R902 file-unit-number is scalar-int-expr 35 R903 internal-file-variable is char-variable 36 C901 (R903) The char-variable shall not be an array section with a vector subscript. 37 C902 (R903) The char-variable shall be of type default character, ASCII character, or ISO 10646 38 character. 39 A unit is either an external unit or an internal unit. An external unit is used to refer to an external 40 file and is specified by an asterisk or a file-unit-number . The value of file-unit-number shall be non- 41 negative, equal to one of the named constants INPUT UNIT, OUTPUT UNIT, or ERROR UNIT of 42 the ISO FORTRAN ENV module (13.8.3), or a NEWUNIT value (9.4.6). An internal unit is used to 43 refer to an internal file and is specified by an internal-file-variable or a file-unit-number whose value is 44 214 2006/07/11 WORKING DRAFT J3/06-007 equal to the unit argument of an active derived-type input/output procedure (9.5.3.7). The value of a 1 file-unit-number shall identify a valid unit. 2 The external unit identified by a particular value of a scalar-int-expr is the same external unit in all 3 program units of the program, and on all images. 4 NOTE 9.14 In the example: SUBROUTINE A READ (6) X ... SUBROUTINE B N=6 REWIND N the value 6 used in both program units identifies the same external unit. An asterisk identifies particular processor-dependent external units that are preconnected for format- 5 ted sequential access (9.5.3.2). These units are also identified by unit numbers defined by the named 6 constants INPUT UNIT and OUTPUT UNIT of the ISO FORTRAN ENV module (13.8.3). 7 This standard identifies a processor-dependent external unit for the purpose of error reporting. This 8 unit shall be preconnected for sequential formatted output. The processor may define this to be the 9 same as the output unit identified by an asterisk. This unit is also identified by a unit number defined 10 by the named constant ERROR UNIT of the ISO FORTRAN ENV intrinsic module. 11 9.4.1 Connection mo des 12 A connection for formatted input/output has several changeable modes: the blank interpretation mode 13 (10.8.6), delimiter mode (10.10.2, 10.11.2.1), sign mode (10.8.4), decimal edit mode (10.8.8), I/O round- 14 ing mode (10.7.2.3.7), pad mode (9.5.3.4.2), and scale factor (10.8.5). A connection for unformatted 15 input/output has no changeable modes. 16 Values for the modes of a connection are established when the connection is initiated. If the connection 17 is initiated by an OPEN statement, the values are as specified, either explicitly or implicitly, by the 18 OPEN statement. If the connection is initiated other than by an OPEN statement (that is, if the file is 19 an internal file or preconnected file) the values established are those that would be implied by an initial 20 OPEN statement without the corresponding keywords. 21 The scale factor cannot be explicitly specified in an OPEN statement; it is implicitly 0. 22 The modes of a connection to an external file may be changed by a subsequent OPEN statement that 23 modifies the connection. 24 The modes of a connection may be temporarily changed by a corresponding keyword specifier in a 25 data transfer statement or by an edit descriptor. Keyword specifiers take effect at the beginning of 26 execution of the data transfer statement. Edit descriptors take effect when they are encountered in 27 format processing. When a data transfer statement terminates, the values for the modes are reset to the 28 values in effect immediately before the data transfer statement was executed. 29 9.4.2 Unit existence 30 At any given time, there is a processor-dependent set of external units that are said to exist for a 31 program. 32 215 J3/06-007 WORKING DRAFT 2006/07/11 All input/output statements may refer to units that exist. The CLOSE, INQUIRE, and WAIT state- 1 ments also may refer to units that do not exist. 2 9.4.3 Connection of a file to a unit 3 An external unit has a property of being connected or not connected. If connected, it refers to an 4 external file, and the connection is for a team of images. An external unit may become connected by 5 preconnection or by the execution of an OPEN statement. The property of connection is symmetric; the 6 unit is connected to a file if and only if the file is connected to the unit. 7 J3 internal note Unresolved Technical Issue 39 The second sentence now contradicts the first sentence. Sorry guys, but the unit ***is global*** and only has one state, that of being connected or not. This subclause is about connection, not about whether it is formatted or unformatted, or whether there is some restriction about what image is permitted to reference it. Not doing the edit to the second sentence would be sufficient to resolve this issue here, but later edits (under the TEAM= description) also need changing. Every input/output statement except an OPEN, CLOSE, INQUIRE, or WAIT statement shall refer to 8 a unit that is connected to a file and thereby make use of or affect that file. 9 A file may be connected and not exist (9.2.1). 10 NOTE 9.15 An example is a preconnected external file that has not yet been written. A unit shall not be connected to more than one file at the same time, and a file shall not be connected to 11 more than one unit at the same time. However, means are provided to change the status of an external 12 unit and to connect a unit to a different file. 13 This standard defines means of portable interoperation with C. C streams are described in 7.19.2 of the C 14 International Standard. Whether a unit may be connected to a file that is also connected to a C stream 15 is processor dependent. If the processor allows a unit to be connected to a file that is also connected to 16 a C stream, the results of performing input/output operations on such a file are processor dependent. 17 It is processor dependent whether the files connected to the units INPUT UNIT, OUTPUT UNIT, 18 and ERROR UNIT correspond to the predefined C text streams standard input, standard output, and 19 standard error. If a procedure defined by means of Fortran and a procedure defined by means other than 20 Fortran perform input/output operations on the same external file, the results are processor dependent. 21 A procedure defined by means of Fortran and a procedure defined by means other than Fortran can 22 perform input/output operations on different external files without interference. 23 After an external unit has been disconnected by the execution of a CLOSE statement, it may be con- 24 nected again within the same program to the same file or to a different file. After an external file has 25 been disconnected by the execution of a CLOSE statement, it may be connected again within the same 26 program to the same unit or to a different unit. 27 NOTE 9.16 The only means of referencing a file that has been disconnected is by the appearance of its name in an OPEN or INQUIRE statement. There might be no means of reconnecting an unnamed file once it is disconnected. An internal unit is always connected to the internal file designated by the variable that identifies the 28 216 2006/07/11 WORKING DRAFT J3/06-007 unit. 1 NOTE 9.17 For more explanatory information on file connection properties, see C.6.5. 9.4.4 Preconnection 2 Preconnection means that the unit is connected to a file at the beginning of execution of the program 3 and therefore it may be specified in input/output statements without the prior execution of an OPEN 4 statement. 5 9.4.5 OPEN statement 6 An OPEN statement initiates or modifies the connection between an external file and a specified unit. 7 The OPEN statement may be used to connect an existing file to a unit, create a file that is preconnected, 8 create a file and connect it to a unit, or change certain modes of a connection between a file and a unit. 9 An external unit may be connected by an OPEN statement in any program unit of a program and, once 10 connected, a reference to it may appear in any program unit of the program. 11 If a unit is connected to a file that exists, execution of an OPEN statement for that unit is permitted. 12 If the FILE= specifier is not included in such an OPEN statement, the file to be connected to the unit 13 is the same as the file to which the unit is already connected. 14 If the file to be connected to the unit does not exist but is the same as the file to which the unit is 15 preconnected, the modes specified by an OPEN statement become a part of the connection. 16 If the file to be connected to the unit is not the same as the file to which the unit is connected, the effect 17 is as if a CLOSE statement without a STATUS= specifier had been executed for the unit immediately 18 prior to the execution of an OPEN statement. 19 If the file to be connected to the unit is the same as the file to which the unit is connected, only the 20 specifiers for changeable modes (9.4.1) may have values different from those currently in effect. If the 21 POSITION= specifier appears in such an OPEN statement, the value specified shall not disagree with 22 the current position of the file. If the STATUS= specifier is included in such an OPEN statement, it shall 23 be specified with the value OLD. Execution of such an OPEN statement causes any new values of the 24 specifiers for changeable modes to be in effect, but does not cause any change in any of the unspecified 25 specifiers and the position of the file is unaffected. The ERR=, IOSTAT=, and IOMSG= specifiers from 26 any previously executed OPEN statement have no effect on any currently executed OPEN statement. 27 A STATUS= specifier with a value of OLD is always allowed when the file to be connected to the unit is 28 the same as the file to which the unit is connected. In this case, if the status of the file was SCRATCH 29 before execution of the OPEN statement, the file will still be deleted when the unit is closed, and the 30 file is still considered to have a status of SCRATCH. 31 If a file is already connected to a unit, execution of an OPEN statement on that file and a different unit 32 is not permitted. 33 R904 open-stmt is OPEN ( connect-spec -list ) 34 R905 connect-spec is [ UNIT = ] file-unit-number 35 or ACCESS = scalar-default-char-expr 36 or ACTION = scalar-default-char-expr 37 or ASYNCHRONOUS = scalar-default-char-expr 38 or BLANK = scalar-default-char-expr 39 or DECIMAL = scalar-default-char-expr 40 217 J3/06-007 WORKING DRAFT 2006/07/11 or DELIM = scalar-default-char-expr 1 or ENCODING = scalar-default-char-expr 2 or ERR = label 3 or FILE = file-name-expr 4 or FORM = scalar-default-char-expr 5 or IOMSG = iomsg-variable 6 or IOSTAT = scalar-int-variable 7 or NEWUNIT = scalar-int-variable 8 or PAD = scalar-default-char-expr 9 or POSITION = scalar-default-char-expr 10 or RECL = scalar-int-expr 11 or ROUND = scalar-default-char-expr 12 or SIGN = scalar-default-char-expr 13 or STATUS = scalar-default-char-expr 14 or TEAM = image-team 15 R906 file-name-expr is scalar-default-char-expr 16 R907 iomsg-variable is scalar-default-char-variable 17 C903 No specifier shall appear more than once in a given connect-spec -list. 18 C904 (R904) If the NEWUNIT= specifier does not appear, a file-unit-number shall be specified; if 19 the optional characters UNIT= are omitted, the file-unit-number shall be the first item in the 20 connect-spec -list. 21 C905 (R904) The label used in the ERR= specifier shall be the statement label of a branch target 22 statement that appears in the same scoping unit as the OPEN statement. 23 C906 (R904) If a NEWUNIT= specifier appears, a file-unit-number shall not appear. 24 If the STATUS= specifier has the value NEW or REPLACE, the FILE= specifier shall appear. If the 25 STATUS= specifier has the value SCRATCH, the FILE= specifier shall not appear. If the STATUS= 26 specifier has the value OLD, the FILE= specifier shall appear unless the unit is connected and the file 27 connected to the unit exists. 28 If the NEWUNIT= specifier appears in an OPEN statement, either the FILE= specifier shall appear, 29 or the STATUS= specifier shall appear with a value of SCRATCH. The unit identified by a NEWUNIT 30 value shall not be preconnected. 31 A specifier that requires a scalar-default-char-expr may have a limited list of character values. These 32 values are listed for each such specifier. Any trailing blanks are ignored. The value specified is without 33 regard to case. Some specifiers have a default value if the specifier is omitted. 34 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 9.10. 35 NOTE 9.18 An example of an OPEN statement is: OPEN (10, FILE = 'employee.names', ACTION = 'READ', PAD = 'YES') NOTE 9.19 For more explanatory information on the OPEN statement, see C.6.4. 218 2006/07/11 WORKING DRAFT J3/06-007 9.4.5.1 ACCESS= sp ecifier in the OPEN statement 1 The scalar-default-char-expr shall evaluate to SEQUENTIAL, DIRECT, or STREAM. The ACCESS= 2 specifier specifies the access method for the connection of the file as being sequential, direct, or stream. 3 If this specifier is omitted, the default value is SEQUENTIAL. For an existing file, the specified access 4 method shall be included in the set of allowed access methods for the file. For a new file, the processor 5 creates the file with a set of allowed access methods that includes the specified method. 6 9.4.5.2 ACTION= sp ecifier in the OPEN statement 7 The scalar-default-char-expr shall evaluate to READ, WRITE, or READWRITE. READ specifies that 8 the WRITE, PRINT, and ENDFILE statements shall not refer to this connection. WRITE specifies 9 that READ statements shall not refer to this connection. READWRITE permits any input/output 10 statements to refer to this connection. If this specifier is omitted, the default value is processor dependent. 11 If READWRITE is included in the set of allowable actions for a file, both READ and WRITE also shall 12 be included in the set of allowed actions for that file. For an existing file, the specified action shall be 13 included in the set of allowed actions for the file. For a new file, the processor creates the file with a set 14 of allowed actions that includes the specified action. 15 9.4.5.3 ASYNCHRONOUS= sp ecifier in the OPEN statement 16 The scalar-default-char-expr shall evaluate to YES or NO. If YES is specified, asynchronous input/output 17 on the unit is allowed. If NO is specified, asynchronous input/output on the unit is not allowed. If this 18 specifier is omitted, the default value is NO. 19 9.4.5.4 BLANK= sp ecifier in the OPEN statement 20 The scalar-default-char-expr shall evaluate to NULL or ZERO. The BLANK= specifier is permitted only 21 for a connection for formatted input/output. It specifies the current value of the blank interpretation 22 mode (10.8.6, 9.5.1.5) for input for this connection. This mode has no effect on output. It is a changeable 23 mode (9.4.1). If this specifier is omitted in an OPEN statement that initiates a connection, the default 24 value is NULL. 25 9.4.5.5 DECIMAL= sp ecifier in the OPEN statement 26 The scalar-default-char-expr shall evaluate to COMMA or POINT. The DECIMAL= specifier is per- 27 mitted only for a connection for formatted input/output. It specifies the current value of the decimal 28 edit mode (10.8.8, 9.5.1.6) for this connection. This is a changeable mode (9.4.1). If this specifier is 29 omitted in an OPEN statement that initiates a connection, the default value is POINT. 30 9.4.5.6 DELIM= sp ecifier in the OPEN statement 31 The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE. The DELIM= spec- 32 ifier is permitted only for a connection for formatted input/output. It specifies the current value of the 33 delimiter mode (9.5.1.7) for list-directed (10.10.2) and namelist (10.11.2.1) output for the connection. 34 This mode has no effect on input. It is a changeable mode (9.4.1). If this specifier is omitted in an 35 OPEN statement that initiates a connection, the default value is NONE. 36 9.4.5.7 ENCODING= sp ecifier in the OPEN statement 37 The scalar-default-char-expr shall evaluate to UTF-8 or DEFAULT. The ENCODING= specifier is 38 permitted only for a connection for formatted input/output. The value UTF-8 specifies that the encoding 39 form of the file is UTF-8 as specified by ISO/IEC 10646-1:2000. Such a file is called a Unico de file, 40 and all characters therein are of ISO 10646 character type. The value UTF-8 shall not be specified if 41 the processor does not support the ISO 10646 character type. The value DEFAULT specifies that the 42 219 J3/06-007 WORKING DRAFT 2006/07/11 encoding form of the file is processor-dependent. If this specifier is omitted in an OPEN statement that 1 initiates a connection, the default value is DEFAULT. 2 9.4.5.8 FILE= sp ecifier in the OPEN statement 3 The value of the FILE= specifier is the name of the file to be connected to the specified unit. Any trailing 4 blanks are ignored. The file-name-expr shall be a name that is allowed by the processor. If this specifier 5 is omitted and the unit is not connected to a file, the STATUS= specifier shall be specified with a value 6 of SCRATCH; in this case, the connection is made to a processor-dependent file. The interpretation of 7 case is processor dependent. 8 9.4.5.9 FORM= sp ecifier in the OPEN statement 9 The scalar-default-char-expr shall evaluate to FORMATTED or UNFORMATTED. The FORM= spec- 10 ifier determines whether the file is being connected for formatted or unformatted input/output. If this 11 specifier is omitted, the default value is UNFORMATTED if the file is being connected for direct access 12 or stream access, and the default value is FORMATTED if the file is being connected for sequential 13 access. For an existing file, the specified form shall be included in the set of allowed forms for the file. 14 For a new file, the processor creates the file with a set of allowed forms that includes the specified form. 15 9.4.6 NEWUNIT= sp ecifier in the OPEN statement 16 The variable is defined with a processor determined NEWUNIT value if no error occurs during the 17 execution of the OPEN statement. If an error occurs, the processor shall not change the value of the 18 variable. 19 A NEWUNIT value is a negative number, and shall not be equal to -1, any of the named constants 20 ERROR UNIT, INPUT UNIT, or OUTPUT UNIT from the ISO FORTRAN ENV intrinsic module 21 (13.8.3), any value used by the processor for the unit argument to a user-defined derived-type in- 22 put/output procedure, nor any previous NEWUNIT value that identifies a file that is currently con- 23 nected. 24 9.4.6.1 PAD= sp ecifier in the OPEN statement 25 The scalar-default-char-expr shall evaluate to YES or NO. The PAD= specifier is permitted only for a 26 connection for formatted input/output. It specifies the current value of the pad mode (9.5.3.4.2, 9.5.1.9) 27 for input for this connection. This mode has no effect on output. It is a changeable mode (9.4.1). If this 28 specifier is omitted in an OPEN statement that initiates a connection, the default value is YES. 29 NOTE 9.20 For nondefault character types, the blank padding character is processor dependent. 9.4.6.2 POSITION= sp ecifier in the OPEN statement 30 The scalar-default-char-expr shall evaluate to ASIS, REWIND, or APPEND. The connection shall be 31 for sequential or stream access. A new file is positioned at its initial point. REWIND positions an 32 existing file at its initial point. APPEND positions an existing file such that the endfile record is the 33 next record, if it has one. If an existing file does not have an endfile record, APPEND positions the 34 file at its terminal point. ASIS leaves the position unchanged if the file exists and already is connected. 35 ASIS leaves the position unspecified if the file exists but is not connected. If this specifier is omitted, 36 the default value is ASIS. 37 220 2006/07/11 WORKING DRAFT J3/06-007 9.4.6.3 RECL= sp ecifier in the OPEN statement 1 The value of the RECL= specifier shall be positive. It specifies the length of each record in a file being 2 connected for direct access, or specifies the maximum length of a record in a file being connected for 3 sequential access. This specifier shall not appear when a file is being connected for stream access. This 4 specifier shall appear when a file is being connected for direct access. If this specifier is omitted when 5 a file is being connected for sequential access, the default value is processor dependent. If the file is 6 being connected for formatted input/output, the length is the number of characters for all records that 7 contain only characters of type default character. When a record contains any nondefault characters, 8 the appropriate value for the RECL= specifier is processor dependent. If the file is being connected for 9 unformatted input/output, the length is measured in file storage units. For an existing file, the value of 10 the RECL= specifier shall be included in the set of allowed record lengths for the file. For a new file, 11 the processor creates the file with a set of allowed record lengths that includes the specified value. 12 9.4.6.4 ROUND= sp ecifier in the OPEN statement 13 The scalar-default-char-expr shall evaluate to one of UP, DOWN, ZERO, NEAREST, COMPATIBLE, 14 or PROCESSOR DEFINED. The ROUND= specifier is permitted only for a connection for formatted 15 input/output. It specifies the current value of the I/O rounding mode (10.7.2.3.7, 9.5.1.12) for this 16 connection. This is a changeable mode (9.4.1). If this specifier is omitted in an OPEN statement that 17 initiates a connection, the I/O rounding mode is processor dependent; it shall be one of the above modes. 18 NOTE 9.21 A processor is free to select any I/O rounding mode for the default mode. The mode might correspond to UP, DOWN, ZERO, NEAREST, or COMPATIBLE; or it might be a completely different I/O rounding mode. 9.4.6.5 SIGN= sp ecifier in the OPEN statement 19 The scalar-default-char-expr shall evaluate to one of PLUS, SUPPRESS, or PROCESSOR DEFINED. 20 The SIGN= specifier is permitted only for a connection for formatted input/output. It specifies the 21 current value of the sign mode (10.8.4, 9.5.1.13) for this connection. This is a changeable mode (9.4.1). 22 If this specifier is omitted in an OPEN statement that initiates a connection, the default value is PRO- 23 CESSOR DEFINED. 24 9.4.6.6 STATUS= sp ecifier in the OPEN statement 25 The scalar-default-char-expr shall evaluate to OLD, NEW, SCRATCH, REPLACE, or UNKNOWN. If 26 OLD is specified, the file shall exist. If NEW is specified, the file shall not exist. 27 Successful execution of an OPEN statement with NEW specified creates the file and changes the status 28 to OLD. If REPLACE is specified and the file does not already exist, the file is created and the status is 29 changed to OLD. If REPLACE is specified and the file does exist, the file is deleted, a new file is created 30 with the same name, and the status is changed to OLD. If SCRATCH is specified, the file is created 31 and connected to the specified unit for use by the program but is deleted at the execution of a CLOSE 32 statement referring to the same unit or at the normal termination of the program. 33 NOTE 9.22 SCRATCH shall not be specified with a named file. If UNKNOWN is specified, the status is processor dependent. If this specifier is omitted, the default 34 value is UNKNOWN. 35 221 J3/06-007 WORKING DRAFT 2006/07/11 9.4.6.7 TEAM= sp ecifier in the OPEN statement 1 The image-team specifies the connect team for the unit, which is the set of images that are permitted 2 to reference the unit. The team shall include the executing image. If there is no TEAM= specifier, the 3 connect team consists of only the executing image." 4 J3 internal note Unresolved Technical Issue 40 There is no INQUIRE(TEAM=) which is rather a glaring omission, since that particular charac- teristic of a unit is even more important than things like the BLANK= mode, since it determines whether an image is permitted to use the unit. After that is fixed, one might consider allowing INQUIRE to reference a unit even from an image that is not part of the team, at least to find out whether it is connected and what the team is... It was suggested (with edits) that OPENED= should return true only for images in the connect- team. That is completely unacceptable. We cannot seriously think about breaking existing carefully-written libraries and programs that use INQUIRE to discover unused units to use for i/o. That mandates us to have OPENED= return true for any unit that is open, no matter what the TEAM= status. All images in the connect team, and no others, shall invoke the same OPEN statement with identical 5 values for the connect-spec s. There is an implicit team synchronization. 6 The OPEN statement connects the file on the invoking images only. If the OPEN statement does not 7 have a FILE= specifier and the unit is not connected to a file, the processor shall connect the same file 8 to the unit on all images in the connect team. 9 J3 internal note Unresolved Technical Issue 41 A few problems: (1) The bit about connection and "invoking images" appears to be completely unneces- sary, since we already say elsewhere what the effect of TEAM= is (and the effect of leaving TEAM= off ). (2) This shares the same problem as the earlier edit where the concept of connection state is contradictory. (3) The bit about "shall connect the same file" appears to be completely unnecessary given the bit about the same name identifying the same file in the TEAM= case, plus the TEAM= requirement that all the connect-spec s be the same on all the team. If the connect team contains more than one image, the OPEN statement shall 10 · specify direct access or 11 · specify sequential access and have an ACTION= specifier that evaluates to WRITE. 12 NOTE 9.23 Writing to a sequential file from more than one image without using synchronization is permitted, but is only useful for situations in which the ordering of records is unimportant. An example is for diagnostic output that is labeled with the image index. Preconnected units and the units identified by the values INPUT UNIT, OUTPUT UNIT, and ER- 13 ROR UNIT in the intrinsic module ISO FORTRAN ENV have a connect team consisting of all the 14 222 2006/07/11 WORKING DRAFT J3/06-007 images. If an image with index greater than one executes an input/output statement on one of these 1 units, it shall be a WRITE or PRINT statement. 2 J3 internal note Unresolved Technical Issue 42 Prohibiting INQUIRE seems ... excessive and unwarranted to say the least. Subgroup agree, but there is still a question-mark over other i/o statements. (BACKSPACE, ENDFILE, WAIT, FLUSH, CLOSE, OPEN, REWIND). J3 internal note Unresolved Technical Issue 43 Since READ is prohibited except on image one, in what way does INPUT UNIT have a connect team (since no-one can do anything)? Surely it would be simpler if its connect term were image 1 only? As implied by the following note... NOTE 9.24 The input unit identified by * is therefore only available on the image with index one. 9.4.7 CLOSE statement 3 The CLOSE statement is used to terminate the connection of a specified unit to an external file. 4 Execution of a CLOSE statement for a unit may occur in any program unit of a program and need not 5 occur in the same program unit as the execution of an OPEN statement referring to that unit. 6 Execution of a CLOSE statement performs a wait operation for any pending asynchronous data transfer 7 operations for the specified unit. 8 Execution of a CLOSE statement specifying a unit that does not exist or has no file connected to it is 9 permitted and affects no file. 10 After a unit has been disconnected by execution of a CLOSE statement, it may be connected again 11 within the same program, either to the same file or to a different file. After a named file has been 12 disconnected by execution of a CLOSE statement, it may be connected again within the same program, 13 either to the same unit or to a different unit, provided that the file still exists. 14 At normal termination of execution of a program, all units that are connected are closed. Each unit 15 is closed with status KEEP unless the file status prior to termination of execution was SCRATCH, in 16 which case the unit is closed with status DELETE. 17 NOTE 9.25 The effect is as though a CLOSE statement without a STATUS= specifier were executed on each connected unit. R908 close-stmt is CLOSE ( close-spec -list ) 18 R909 close-spec is [ UNIT = ] file-unit-number 19 or IOSTAT = scalar-int-variable 20 or IOMSG = iomsg-variable 21 or ERR = label 22 or STATUS = scalar-default-char-expr 23 C907 (R909) No specifier shall appear more than once in a given close-spec -list. 24 C908 (R909) A file-unit-number shall be specified; if the optional characters UNIT= are omitted, the 25 223 J3/06-007 WORKING DRAFT 2006/07/11 file-unit-number shall be the first item in the close-spec -list. 1 C909 (R909) The label used in the ERR= specifier shall be the statement label of a branch target 2 statement that appears in the same scoping unit as the CLOSE statement. 3 The scalar-default-char-expr has a limited list of character values. Any trailing blanks are ignored. The 4 value specified is without regard to case. 5 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 9.10. 6 NOTE 9.26 An example of a CLOSE statement is: CLOSE (10, STATUS = 'KEEP') NOTE 9.27 For more explanatory information on the CLOSE statement, see C.6.6. 9.4.7.1 STATUS= sp ecifier in the CLOSE statement 7 The scalar-default-char-expr shall evaluate to KEEP or DELETE. The STATUS= specifier determines 8 the disposition of the file that is connected to the specified unit. KEEP shall not be specified for a file 9 whose status prior to execution of a CLOSE statement is SCRATCH. If KEEP is specified for a file that 10 exists, the file continues to exist after the execution of a CLOSE statement. If KEEP is specified for a 11 file that does not exist, the file will not exist after the execution of a CLOSE statement. If DELETE is 12 specified, the file will not exist after the execution of a CLOSE statement. If this specifier is omitted, the 13 default value is KEEP, unless the file status prior to execution of the CLOSE statement is SCRATCH, 14 in which case the default value is DELETE. 15 9.5 Data transfer statements 16 The READ statement is the data transfer input statement. The WRITE statement and the 17 PRINT statement are the data transfer output statements. 18 R910 read-stmt is READ ( io-control-spec -list ) [ input-item -list ] 19 or READ format [ , input-item -list ] 20 R911 write-stmt is WRITE ( io-control-spec -list ) [ output-item -list ] 21 R912 print-stmt is PRINT format [ , output-item -list ] 22 NOTE 9.28 Examples of data transfer statements are: READ (6, *) SIZE READ 10, A, B WRITE (6, 10) A, S, J PRINT 10, A, S, J 10 FORMAT (2E16.3, I5) 9.5.1 Control information list 23 A control information list is an io-control-spec -list. It governs data transfer. 24 224 2006/07/11 WORKING DRAFT J3/06-007 R913 io-control-spec is [ UNIT = ] io-unit 1 or [ FMT = ] format 2 or [ NML = ] namelist-group-name 3 or ADVANCE = scalar-default-char-expr 4 or ASYNCHRONOUS = scalar-char-initialization-expr 5 or BLANK = scalar-default-char-expr 6 or DECIMAL = scalar-default-char-expr 7 or DELIM = scalar-default-char-expr 8 or END = label 9 or EOR = label 10 or ERR = label 11 or ID = scalar-int-variable 12 or IOMSG = iomsg-variable 13 or IOSTAT = scalar-int-variable 14 or PAD = scalar-default-char-expr 15 or POS = scalar-int-expr 16 or REC = scalar-int-expr 17 or ROUND = scalar-default-char-expr 18 or SIGN = scalar-default-char-expr 19 or SIZE = scalar-int-variable 20 C910 (R913) No specifier shall appear more than once in a given io-control-spec -list. 21 C911 (R913) An io-unit shall be specified; if the optional characters UNIT= are omitted, the io-unit 22 shall be the first item in the io-control-spec -list. 23 C912 (R913) A DELIM= or SIGN= specifier shall not appear in a read-stmt . 24 C913 (R913) A BLANK=, PAD=, END=, EOR=, or SIZE= specifier shall not appear in a write-stmt . 25 C914 (R913) The label in the ERR=, EOR=, or END= specifier shall be the statement label of a 26 branch target statement that appears in the same scoping unit as the data transfer statement. 27 C915 (R913) A namelist-group-name shall be the name of a namelist group. 28 C916 (R913) A namelist-group-name shall not appear if an input-item -list or an output-item -list 29 appears in the data transfer statement. 30 C917 (R913) An io-control-spec -list shall not contain both a format and a namelist-group-name . 31 C918 (R913) If format appears without a preceding FMT=, it shall be the second item in the io- 32 control-spec -list and the first item shall be io-unit . 33 C919 (R913) If namelist-group-name appears without a preceding NML=, it shall be the second item 34 in the io-control-spec -list and the first item shall be io-unit . 35 C920 (R913) If io-unit is not a file-unit-number , the io-control-spec -list shall not contain a REC= 36 specifier or a POS= specifier. 37 C921 (R913) If the REC= specifier appears, an END= specifier shall not appear, a namelist-group- 38 name shall not appear, and the format , if any, shall not be an asterisk. 39 C922 (R913) An ADVANCE= specifier may appear only in a formatted sequential or stream in- 40 put/output statement with explicit format specification (10.2) whose control information list 41 225 J3/06-007 WORKING DRAFT 2006/07/11 does not contain an internal-file-variable as the io-unit . 1 C923 (R913) If an EOR= specifier appears, an ADVANCE= specifier also shall appear. 2 C924 (R913) If a SIZE= specifier appears, an ADVANCE= specifier also shall appear. 3 C925 (R913) The scalar-char-initialization-expr in an ASYNCHRONOUS= specifier shall be of type 4 default character and shall have the value YES or NO. 5 C926 (R913) An ASYNCHRONOUS= specifier with a value YES shall not appear unless io-unit is a 6 file-unit-number . 7 C927 (R913) If an ID= specifier appears, an ASYNCHRONOUS= specifier with the value YES shall 8 also appear. 9 C928 (R913) If a POS= specifier appears, the io-control-spec -list shall not contain a REC= specifier. 10 C929 (R913) If a DECIMAL=, BLANK=, PAD=, SIGN=, or ROUND= specifier appears, a format 11 or namelist-group-name shall also appear. 12 C930 (R913) If a DELIM= specifier appears, either format shall be an asterisk or namelist-group-name 13 shall appear. 14 A SIZE= specifier may appear only in an input statement that contains an ADVANCE= specifier with 15 the value NO. 16 An EOR= specifier may appear only in an input statement that contains an ADVANCE= specifier with 17 the value NO. 18 If the data transfer statement contains a format or namelist-group-name , the statement is a formatted 19 input/output statement; otherwise, it is an unformatted input/output statement. 20 The ADVANCE=, ASYNCHRONOUS=, DECIMAL=, BLANK=, DELIM=, PAD=, SIGN=, and 21 ROUND= specifiers have a limited list of character values. Any trailing blanks are ignored. The 22 values specified are without regard to case. 23 The IOSTAT=, ERR=, EOR=, END=, and IOMSG= specifiers are described in 9.10. 24 NOTE 9.29 An example of a READ statement is: READ (IOSTAT = IOS, UNIT = 6, FMT = '(10F8.2)') A, B 9.5.1.1 FMT= sp ecifier in a data transfer statement 25 The FMT= specifier supplies a format specification or specifies list-directed formatting for a formatted 26 input/output statement. 27 R914 format is default-char-expr 28 or label 29 or * 30 C931 (R914) The label shall be the label of a FORMAT statement that appears in the same scoping 31 unit as the statement containing the FMT= specifier. 32 The default-char-expr shall evaluate to a valid format specification (10.2.1 and 10.2.2). 33 226 2006/07/11 WORKING DRAFT J3/06-007 NOTE 9.30 A default-char-expr includes a character constant. If default-char-expr is an array, it is treated as if all of the elements of the array were specified in array 1 element order and were concatenated. 2 If format is *, the statement is a list-directed input/output statement. 3 NOTE 9.31 An example in which the format is a character expression is: READ (6, FMT = "(" // CHAR_FMT // ")" ) X, Y, Z where CHAR FMT is a default character variable. 9.5.1.2 NML= sp ecifier in a data transfer statement 4 The NML= specifier supplies the namelist-group-name (5.6). This name identifies a particular collection 5 of data ob jects on which transfer is to be performed. 6 If a namelist-group-name appears, the statement is a namelist input/output statement. 7 9.5.1.3 ADVANCE= sp ecifier in a data transfer statement 8 The scalar-default-char-expr shall evaluate to YES or NO. The ADVANCE= specifier determines wheth- 9 er advancing input/output occurs for a nonchild input/output statement. If YES is specified, advancing 10 input/output occurs. If NO is specified, nonadvancing input/output occurs (9.2.3.1). If this specifier is 11 omitted from a nonchild input/output statement that allows the specifier, the default value is YES. A for- 12 matted child input/output statement is a nonadvancing input/output statement, and any ADVANCE= 13 specifier is ignored. 14 9.5.1.4 ASYNCHRONOUS= sp ecifier in a data transfer statement 15 The ASYNCHRONOUS= specifier determines whether this input/output statement is synchronous or 16 asynchronous. If YES is specified, the statement and the input/output operation are said to be asyn- 17 chronous. If NO is specified or if the specifier is omitted, the statement and the input/output operation 18 are said to be synchronous. 19 Asynchronous input/output is permitted only for external files opened with an ASYNCHRONOUS= 20 specifier with the value YES in the OPEN statement. 21 NOTE 9.32 Both synchronous and asynchronous input/output are allowed for files opened with an ASYN- CHRONOUS= specifier of YES. For other files, only synchronous input/output is allowed; this includes files opened with an ASYNCHRONOUS= specifier of NO, files opened without an ASYN- CHRONOUS= specifier, preconnected files accessed without an OPEN statement, and internal files. The ASYNCHRONOUS= specifier value in a data transfer statement is an initialization expression because it effects compiler optimizations and, therefore, needs to be known at compile time. The processor may perform an asynchronous data transfer operation asynchronously, but it is not re- 22 quired to do so. For each external file, records and file storage units read or written by asynchronous 23 data transfer statements are read, written, and processed in the same order as they would have been if 24 227 J3/06-007 WORKING DRAFT 2006/07/11 the data transfer statements were synchronous. 1 If a variable is used in an asynchronous data transfer statement as 2 (1) an item in an input/output list, 3 (2) a group ob ject in a namelist, or 4 (3) a SIZE= specifier 5 the base ob ject of the data-ref is implicitly given the ASYNCHRONOUS attribute in the scoping unit 6 of the data transfer statement. This attribute may be confirmed by explicit declaration. 7 When an asynchronous input/output statement is executed, the set of storage units specified by the 8 item list or NML= specifier, plus the storage units specified by the SIZE= specifier, is defined to be the 9 pending input/output storage sequence for the data transfer operation. 10 NOTE 9.33 A pending input/output storage sequence is not necessarily a contiguous set of storage units. A pending input/output storage sequence affector is a variable of which any part is associated with a 11 storage unit in a pending input/output storage sequence. 12 9.5.1.5 BLANK= sp ecifier in a data transfer statement 13 The scalar-default-char-expr shall evaluate to NULL or ZERO. The BLANK= specifier temporarily 14 changes (9.4.1) the blank interpretation mode (10.8.6, 9.4.5.4) for the connection. If the specifier is 15 omitted, the mode is not changed. 16 9.5.1.6 DECIMAL= sp ecifier in a data transfer statement 17 The scalar-default-char-expr shall evaluate to COMMA or POINT. The DECIMAL= specifier temporar- 18 ily changes (9.4.1) the decimal edit mode (10.8.8, 9.4.5.5) for the connection. If the specifier is omitted, 19 the mode is not changed. 20 9.5.1.7 DELIM= sp ecifier in a data transfer statement 21 The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE. The DELIM= spec- 22 ifier temporarily changes (9.4.1) the delimiter mode (10.10.2, 10.11.2.1, 9.4.5.6) for the connection. If 23 the specifier is omitted, the mode is not changed. 24 9.5.1.8 ID= sp ecifier in a data transfer statement 25 Successful execution of an asynchronous data transfer statement containing an ID= specifier causes the 26 variable specified in the ID= specifier to become defined with a processor-dependent value. This value 27 is referred to as the identifier of the data transfer operation. It can be used in a subsequent WAIT or 28 INQUIRE statement to identify the particular data transfer operation. 29 If an error occurs during the execution of a data transfer statement containing an ID= specifier, the 30 variable specified in the ID= specifier becomes undefined. 31 A child data transfer statement shall not specify the ID= specifier. 32 9.5.1.9 PAD= sp ecifier in a data transfer statement 33 The scalar-default-char-expr shall evaluate to YES or NO. The PAD= specifier temporarily changes 34 (9.4.1) the pad mode (9.5.3.4.2, 9.4.6.1) for the connection. If the specifier is omitted, the mode is not 35 changed. 36 228 2006/07/11 WORKING DRAFT J3/06-007 9.5.1.10 POS= sp ecifier in a data transfer statement 1 The POS= specifier specifies the file position in file storage units. This specifier may appear in a data 2 transfer statement only if the statement specifies a unit connected for stream access. A child data 3 transfer statement shall not specify this specifier. 4 A processor may prohibit the use of POS= with particular files that do not have the properties necessary 5 to support random positioning. A processor may also prohibit positioning a particular file to any 6 position prior to its current file position if the file does not have the properties necessary to support such 7 positioning. 8 NOTE 9.34 A file that represents connection to a device or data stream might not be positionable. If the file is connected for formatted stream access, the file position specified by POS= shall be equal to 9 either 1 (the beginning of the file) or a value previously returned by a POS= specifier in an INQUIRE 10 statement for the file. 11 9.5.1.11 REC= sp ecifier in a data transfer statement 12 The REC= specifier specifies the number of the record that is to be read or written. This specifier 13 may appear only in an input/output statement that specifies a unit connected for direct access; it 14 shall not appear in a child data transfer statement. If the control information list contains a REC= 15 specifier, the statement is a direct access input/output statement. A child data transfer statement 16 is a direct access data transfer statement if the parent is a direct access data transfer statement. Any 17 other data transfer statement is a sequential access input/output statement or a stream access 18 input/output statement, depending on whether the file connection is for sequential access or stream 19 access. 20 9.5.1.12 ROUND= sp ecifier in a data transfer statement 21 The scalar-default-char-expr shall evaluate to one of the values specified in 9.4.6.4. The ROUND= 22 specifier temporarily changes (9.4.1) the I/O rounding mode (10.7.2.3.7, 9.4.6.4) for the connection. If 23 the specifier is omitted, the mode is not changed. 24 9.5.1.13 SIGN= sp ecifier in a data transfer statement 25 The scalar-default-char-expr shall evaluate to PLUS, SUPPRESS, or PROCESSOR DEFINED. The 26 SIGN= specifier temporarily changes (9.4.1) the sign mode (10.8.4, 9.4.6.5) for the connection. If the 27 specifier is omitted, the mode is not changed. 28 9.5.1.14 SIZE= sp ecifier in a data transfer statement 29 When a synchronous nonadvancing input statement terminates, the variable specified in the SIZE= 30 specifier becomes defined with the count of the characters transferred by data edit descriptors during 31 execution of the current input statement. Blanks inserted as padding (9.5.3.4.2) are not counted. 32 For asynchronous nonadvancing input, the storage units specified in the SIZE= specifier become defined 33 with the count of the characters transferred when the corresponding wait operation is executed. 34 9.5.2 Data transfer input/output list 35 An input/output list specifies the entities whose values are transferred by a data transfer input/output 36 statement. 37 229 J3/06-007 WORKING DRAFT 2006/07/11 R915 input-item is variable 1 or io-implied-do 2 R916 output-item is expr 3 or io-implied-do 4 R917 io-implied-do is ( io-implied-do-object -list , io-implied-do-control ) 5 R918 io-implied-do-object is input-item 6 or output-item 7 R919 io-implied-do-control is do-variable = scalar-int-expr , 8 scalar-int-expr [ , scalar-int-expr ] 9 C932 (R915) A variable that is an input-item shall not be a whole assumed-size array. 10 C933 (R915) A variable that is an input-item shall not be a procedure pointer. 11 C934 (R919) The do-variable shall be a named scalar variable of type integer. 12 C935 (R918) In an input-item -list, an io-implied-do-object shall be an input-item . In an output-item - 13 list, an io-implied-do-object shall be an output-item . 14 C936 (R916) An expression that is an output-item shall not have a value that is a procedure pointer. 15 An input-item shall not appear as, nor be associated with, the do-variable of any io-implied-do that 16 contains the input-item . 17 NOTE 9.35 A constant, an expression involving operators or function references, or an expression enclosed in parentheses may appear as an output list item but shall not appear as an input list item. If an input item is a pointer, it shall be associated with a definable target and data are transferred from 18 the file to the associated target. If an output item is a pointer, it shall be associated with a target and 19 data are transferred from the target to the file. 20 NOTE 9.36 Data transfers always involve the movement of values between a file and internal storage. A pointer as such cannot be read or written. Therefore, a pointer shall not appear as an item in an input/output list unless it is associated with a target that can receive a value (input) or can deliver a value (output). If an input item or an output item is allocatable, it shall be allocated. 21 A list item shall not be polymorphic unless it is processed by a user-defined derived-type input/output 22 procedure (9.5.3.7). 23 The do-variable of an io-implied-do that is in another io-implied-do shall not appear as, nor be associated 24 with, the do-variable of the containing io-implied-do . 25 The following rules describing whether to expand an input/output list item are re-applied to each 26 expanded list item until none of the rules apply. 27 If an array appears as an input/output list item, it is treated as if the elements, if any, were specified in 28 array element order (6.2.2.2). However, no element of that array may affect the value of any expression 29 in the input-item , nor may any element appear more than once in an input-item . 30 230 2006/07/11 WORKING DRAFT J3/06-007 NOTE 9.37 For example: INTEGER A (100), J (100) ... READ *, A (A) ! Not allowed READ *, A (LBOUND (A, 1) : UBOUND (A, 1)) ! Allowed READ *, A (J) ! Allowed if no two elements ! of J have the same value A(1) = 1; A(10) = 10 READ *, A (A (1) : A (10)) ! Not allowed If a list item of derived type in an unformatted input/output statement is not processed by a user-defined 1 derived-type input/output procedure (9.5.3.7), and if any subob ject of that list item would be processed 2 by a user-defined derived-type input/output procedure, the list item is treated as if all of the components 3 of the ob ject were specified in the list in component order (4.5.4.6); those components shall be accessible 4 in the scoping unit containing the input/output statement and shall not be pointers or allocatable. 5 An effective input/output list item of derived type in an unformatted input/output statement is treated 6 as a single value in a processor-dependent form unless the list item or a subob ject thereof is processed 7 by a user-defined derived-type input/output procedure (9.5.3.7). 8 NOTE 9.38 The appearance of a derived-type ob ject as an input/output list item in an unformatted in- put/output statement is not equivalent to the list of its components. Unformatted input/output involving derived-type list items forms the single exception to the rule that the appearance of an aggregate list item (such as an array) is equivalent to the appearance of its expanded list of component parts. This exception permits the processor greater latitude in improving efficiency or in matching the processor-dependent sequence of values for a derived-type ob ject to similar sequences for aggregate ob jects used by means other than Fortran. However, formatted input/output of all list items and unformatted input/output of list items other than those of derived types adhere to the above rule. If a list item of derived type in a formatted input/output statement is not processed by a user-defined 9 derived-type input/output procedure, that list item is treated as if all of the components of the list item 10 were specified in the list in component order; those components shall be accessible in the scoping unit 11 containing the input/output statement and shall not be pointers or allocatable. 12 If a derived-type list item is not treated as a list of its individual components, that list item's ultimate 13 components shall not have the POINTER or ALLOCATABLE attribute unless that list item is processed 14 by a user-defined derived-type input/output procedure. 15 The scalar ob jects resulting when a data transfer statement's list items are expanded according to the 16 rules in this subclause for handling array and derived-type list items are called effective items. Zero- 17 sized arrays and io-implied-do s with an iteration count of zero do not contribute to the effective list 18 items. A scalar character item of zero length is an effective list item. 19 NOTE 9.39 In a formatted input/output statement, edit descriptors are associated with effective list items, which are always scalar. The rules in 9.5.2 determine the set of effective list items corresponding to each actual list item in the statement. These rules may have to be applied repetitively until all of the effective list items are scalar items. 231 J3/06-007 WORKING DRAFT 2006/07/11 For an io-implied-do , the loop initialization and execution is the same as for a DO construct (8.1.7.5). 1 An input/output list shall not contain an item of nondefault character type if the input/output statement 2 specifies an internal file of default character type. An input/output list shall not contain an item of 3 nondefault character type other than ISO 10646 or ASCII character type if the input/output statement 4 specifies an internal file of ISO 10646 character type. An input/output list shall not contain a character 5 item of any character type other than ASCII character type if the input/output statement specifies an 6 internal file of ASCII character type. 7 NOTE 9.40 An example of an output list with an implied DO is: WRITE (LP, FMT = '(10F8.2)') (LOG (A (I)), I = 1, N + 9, K), G 9.5.3 Execution of a data transfer input/output statement 8 Execution of a WRITE or PRINT statement for a file that does not exist creates the file unless an error 9 condition occurs. 10 The effect of executing a synchronous data transfer input/output statement shall be as if the following 11 operations were performed in the order specified. 12 (1) Determine the direction of data transfer. 13 (2) Identify the unit. 14 (3) Perform a wait operation for all pending input/output operations for the unit. If an error, 15 end-of-file, or end-of-record condition occurs during any of the wait operations, steps 4 16 through 8 are skipped for the current data transfer statement. 17 (4) Establish the format if one is specified. 18 (5) If the statement is not a child data transfer statement (9.5.3.7), 19 (a) position the file prior to data transfer (9.2.3.2), and 20 (b) for formatted data transfer, set the left tab limit (10.8.1.1). 21 (6) Transfer data between the file and the entities specified by the input/output list (if any) or 22 namelist. 23 (7) Determine whether an error, end-of-file, or end-of-record condition has occurred. 24 (8) Position the file after data transfer (9.2.3.3) unless the statement is a child data transfer 25 statement (9.5.3.7). 26 (9) Cause any variable specified in a SIZE= specifier to become defined. 27 (10) If an error, end-of-file, or end-of-record condition occurred, processing continues as specified 28 in 9.10; otherwise any variable specified in an IOSTAT= specifier is assigned the value zero. 29 The effect of executing an asynchronous data transfer input/output statement shall be as if the following 30 operations were performed in the order specified. 31 (1) Determine the direction of data transfer. 32 (2) Identify the unit. 33 (3) Establish the format if one is specified. 34 (4) Position the file prior to data transfer (9.2.3.2) and, for formatted data transfer, set the left 35 tab limit (10.8.1.1). 36 (5) Establish the set of storage units identified by the input/output list. For a READ statement, 37 this might require some or all of the data in the file to be read if an input variable is used 38 as a scalar-int-expr in an io-implied-do-control in the input/output list, as a subscript , 39 substring-range , stride , or is otherwise referenced. 40 232 2006/07/11 WORKING DRAFT J3/06-007 (6) Initiate an asynchronous data transfer between the file and the entities specified by the 1 input/output list (if any) or namelist. The asynchronous data transfer may complete (and 2 an error, end-of-file, or end-of-record condition may occur) during the execution of this data 3 transfer statement or during a later wait operation. 4 (7) Determine whether an error, end-of-file, or end-of-record condition has occurred. The con- 5 ditions may occur during the execution of this data transfer statement or during the corre- 6 sponding wait operation, but not both. 7 Also, any of these conditions that would have occurred during the corresponding wait oper- 8 ation for a previously pending data transfer operation that does not have an ID= specifier 9 may occur during the execution of this data transfer statement. 10 (8) Position the file as if the data transfer had finished (9.2.3.3). 11 (9) Cause any variable specified in a SIZE= specifier to become undefined. 12 (10) If an error, end-of-file, or end-of-record condition occurred, processing continues as specified 13 in 9.10; otherwise any variable specified in an IOSTAT= specifier is assigned the value zero. 14 For an asynchronous data transfer statement, the data transfers may occur during execution of the 15 statement, during execution of the corresponding wait operation, or anywhere between. The data transfer 16 operation is considered to be pending until a corresponding wait operation is performed. 17 For asynchronous output, a pending input/output storage sequence affector (9.5.1.4) shall not be rede- 18 fined, become undefined, or have its pointer association status changed. 19 For asynchronous input, a pending input/output storage sequence affector shall not be referenced, be- 20 come defined, become undefined, become associated with a dummy argument that has the VALUE 21 attribute, or have its pointer association status changed. 22 Error, end-of-file, and end-of-record conditions in an asynchronous data transfer operation may occur 23 during execution of either the data transfer statement or the corresponding wait operation. If an ID= 24 specifier does not appear in the initiating data transfer statement, the conditions may occur during the 25 execution of any subsequent data transfer or wait operation for the same unit. When a condition occurs 26 for a previously executed asynchronous data transfer statement, a wait operation is performed for all 27 pending data transfer operations on that unit. When a condition occurs during a subsequent statement, 28 any actions specified by IOSTAT=, IOMSG=, ERR=, END=, and EOR= specifiers for that statement 29 are taken. 30 NOTE 9.41 Because end-of-file and error conditions for asynchronous data transfer statements without an ID= specifier may be reported by the processor during the execution of a subsequent data transfer statement, it may be impossible for the user to determine which input/output statement caused the condition. Reliably detecting which READ statement caused an end-of-file condition requires that all asynchronous READ statements for the unit include an ID= specifier. 9.5.3.1 Direction of data transfer 31 Execution of a READ statement causes values to be transferred from a file to the entities specified by 32 the input list, if any, or specified within the file itself for namelist input. Execution of a WRITE or 33 PRINT statement causes values to be transferred to a file from the entities specified by the output list 34 and format specification, if any, or by the namelist-group-name for namelist output. 35 9.5.3.2 Identifying a unit 36 A data transfer input/output statement that contains an input/output control list includes a UNIT= 37 specifier that identifies an external or internal unit. A READ statement that does not contain an 38 input/output control list specifies a particular processor-dependent unit, which is the same as the unit 39 233 J3/06-007 WORKING DRAFT 2006/07/11 identified by * in a READ statement that contains an input/output control list. The PRINT statement 1 specifies some other processor-dependent unit, which is the same as the unit identified by * in a WRITE 2 statement. Thus, each data transfer input/output statement identifies an external or internal unit. 3 The unit identified by a data transfer input/output statement shall be connected to a file when execution 4 of the statement begins. 5 NOTE 9.42 The file may be preconnected. 9.5.3.3 Establishing a format 6 If the input/output control list contains * as a format, list-directed formatting is established. If namelist- 7 group-name appears, namelist formatting is established. If no format or namelist-group-name is spec- 8 ified, unformatted data transfer is established. Otherwise, the format specification identified by the 9 FMT= specifier is established. 10 On output, if an internal file has been specified, a format specification that is in the file or is associated 11 with the file shall not be specified. 12 9.5.3.4 Data transfer 13 Data are transferred between the file and the entities specified by the input/output list or namelist. 14 The list items are processed in the order of the input/output list for all data transfer input/output 15 statements except namelist formatted data transfer statements. The list items for a namelist input 16 statement are processed in the order of the entities specified within the input records. The list items 17 for a namelist output statement are processed in the order in which the variables are specified in the 18 namelist-group-object -list. Effective items are derived from the input/output list items as described in 19 9.5.2. 20 All values needed to determine which entities are specified by an input/output list item are determined 21 at the beginning of the processing of that item. 22 All values are transmitted to or from the entities specified by a list item prior to the processing of any 23 succeeding list item for all data transfer input/output statements. 24 NOTE 9.43 In the example, READ (N) N, X (N) the old value of N identifies the unit, but the new value of N is the subscript of X. All values following the name = part of the namelist entity (10.11) within the input records are transmit- 25 ted to the matching entity specified in the namelist-group-object -list prior to processing any succeeding 26 entity within the input record for namelist input statements. If an entity is specified more than once 27 within the input record during a namelist formatted data transfer input statement, the last occurrence 28 of the entity specifies the value or values to be used for that entity. 29 An input list item, or an entity associated with it, shall not contain any portion of an established format 30 specification. 31 If the input/output item is a pointer, data are transferred between the file and the associated target. 32 If an internal file has been specified, an input/output list item shall not be in the file or associated with 33 234 2006/07/11 WORKING DRAFT J3/06-007 the file. 1 NOTE 9.44 The file is a data ob ject. A DO variable becomes defined and its iteration count established at the beginning of processing of the 2 items that constitute the range of an io-implied-do . 3 On output, every entity whose value is to be transferred shall be defined. 4 9.5.3.4.1 Unformatted data transfer 5 During unformatted data transfer, data are transferred without editing between the file and the entities 6 specified by the input/output list. If the file is connected for sequential or direct access, exactly one 7 record is read or written. 8 Ob jects of intrinsic or derived types may be transferred by means of an unformatted data transfer 9 statement. 10 A value in the file is stored in a contiguous sequence of file storage units, beginning with the file storage 11 unit immediately following the current file position. 12 After each value is transferred, the current file position is moved to a point immediately after the last 13 file storage unit of the value. 14 On input from a file connected for sequential or direct access, the number of file storage units required 15 by the input list shall be less than or equal to the number of file storage units in the record. 16 On input, if the file storage units transferred do not contain a value with the same type and type 17 parameters as the input list entity, then the resulting value of the entity is processor-dependent except 18 in the following cases. 19 (1) A complex list entity may correspond to two real values of the same kind stored in the file, 20 or vice-versa. 21 (2) A default character list entity of length n may correspond to n default characters stored in 22 the file, regardless of the length parameters of the entities that were written to these storage 23 units of the file. If the file is connected for stream input, the characters may have been 24 written by formatted stream output. 25 On output to a file connected for unformatted direct access, the output list shall not specify more values 26 than can fit into the record. If the file is connected for direct access and the values specified by the 27 output list do not fill the record, the remainder of the record is undefined. 28 If the file is connected for unformatted sequential access, the record is created with a length sufficient 29 to hold the values from the output list. This length shall be one of the set of allowed record lengths for 30 the file and shall not exceed the value specified in the RECL= specifier, if any, of the OPEN statement 31 that established the connection. 32 If the file is not connected for unformatted input/output, unformatted data transfer is prohibited. 33 The unit specified shall be an external unit. 34 9.5.3.4.2 Formatted data transfer 35 During formatted data transfer, data are transferred with editing between the file and the entities 36 specified by the input/output list or by the namelist-group-name . Format control is initiated and editing 37 is performed as described in Clause 10. 38 235 J3/06-007 WORKING DRAFT 2006/07/11 The current record and possibly additional records are read or written. 1 Values may be transferred by means of a formatted data transfer statement to or from ob jects of intrinsic 2 or derived types. In the latter case, the transfer is in the form of values of intrinsic types to or from the 3 components of intrinsic types that ultimately comprise these structured ob jects unless the derived-type 4 list item is processed by a user-defined derived-type input/output procedure (9.5.3.7). 5 If the file is not connected for formatted input/output, formatted data transfer is prohibited. 6 During advancing input when the pad mode has the value NO, the input list and format specification 7 shall not require more characters from the record than the record contains. 8 During advancing input when the pad mode has the value YES, blank characters are supplied by the 9 processor if the input list and format specification require more characters from the record than the 10 record contains. 11 During nonadvancing input when the pad mode has the value NO, an end-of-record condition (9.10) 12 occurs if the input list and format specification require more characters from the record than the record 13 contains, and the record is complete (9.2.2.3). If the record is incomplete, an end-of-file condition occurs 14 instead of an end-of-record condition. 15 During nonadvancing input when the pad mode has the value YES, blank characters are supplied by the 16 processor if an input item and its corresponding data edit descriptor require more characters from the 17 record than the record contains. If the record is incomplete, an end-of-file condition occurs; otherwise 18 an end-of-record condition occurs. 19 If the file is connected for direct access, the record number is increased by one as each succeeding record 20 is read or written. 21 On output, if the file is connected for direct access or is an internal file and the characters specified by 22 the output list and format do not fill a record, blank characters are added to fill the record. 23 On output, the output list and format specification shall not specify more characters for a record than 24 have been specified by a RECL= specifier in the OPEN statement or the record length of an internal 25 file. 26 9.5.3.5 List-directed formatting 27 If list-directed formatting has been established, editing is performed as described in 10.10. 28 9.5.3.6 Namelist formatting 29 If namelist formatting has been established, editing is performed as described in 10.11. 30 Every allocatable namelist-group-object in the namelist group shall be allocated and every namelist- 31 group-object that is a pointer shall be associated with a target. If a namelist-group-object is polymorphic 32 or has an ultimate component that is allocatable or a pointer, that ob ject shall be processed by a user- 33 defined derived-type input/output procedure (9.5.3.7). 34 9.5.3.7 User-defined derived-typ e input/output 35 User-defined derived-type input/output procedures allow a program to override the default handling of 36 derived-type ob jects and values in data transfer input/output statements described in 9.5.2. 37 A user-defined derived-type input/output procedure is a procedure accessible by a dtio-generic-spec 38 (12.4.2.1). A particular user-defined derived-type input/output procedure is selected as described in 39 9.5.3.7.3. 40 236 2006/07/11 WORKING DRAFT J3/06-007 9.5.3.7.1 Executing user-defined derived-typ e input/output data transfers 1 If a derived-type input/output procedure is selected as specified in 9.5.3.7.3, the processor shall call the se- 2 lected user-defined derived-type input/output procedure for any appropriate data transfer input/output 3 statements executed in that scoping unit. The user-defined derived-type input/output procedure controls 4 the actual data transfer operations for the derived-type list item. 5 A data transfer statement that includes a derived-type list item and that causes a user-defined derived- 6 type input/output procedure to be invoked is called a parent data transfer statement. A data 7 transfer statement that is executed while a parent data transfer statement is being processed and that 8 specifies the unit passed into a user-defined derived-type input/output procedure is called a child data 9 transfer statement. 10 NOTE 9.45 A user-defined derived-type input/output procedure will usually contain child data transfer state- ments that read values from or write values to the current record or at the current file position. The effect of executing the user-defined derived-type input/output procedure is similar to that of substituting the list items from any child data transfer statements into the parent data transfer statement's list items, along with similar substitutions in the format specification. NOTE 9.46 A particular execution of a READ, WRITE or PRINT statement can be both a parent and a child data transfer statement. A user-defined derived-type input/output procedure can indirectly call itself or another user-defined derived-type input/output procedure by executing a child data transfer statement containing a list item of derived type, where a matching interface is accessible for that derived type. If a user-defined derived-type input/output procedure calls itself indirectly in this manner, it shall be declared RECURSIVE. A child data transfer statement is processed differently from a nonchild data transfer statement in the 11 following ways. 12 · Executing a child data transfer statement does not position the file prior to data transfer. 13 · An unformatted child data transfer statement does not position the file after data transfer is 14 complete. 15 · Any ADVANCE= specifier in a child input/output statement is ignored. 16 9.5.3.7.2 User-defined derived-typ e input/output pro cedures 17 For a particular derived type and a particular set of kind type parameter values, there are four possible 18 sets of characteristics for user-defined derived-type input/output procedures; one each for formatted 19 input, formatted output, unformatted input, and unformatted output. The user need not supply all four 20 procedures. The procedures are specified to be used for derived-type input/output by interface blocks 21 (12.4.2.1) or by generic bindings (4.5.5), with a dtio-generic-spec (R1208). 22 In the four interfaces, which specify the characteristics of user-defined procedures for derived-type in- 23 put/output, the following syntax term is used: 24 R920 dtv-type-spec is TYPE( derived-type-spec ) 25 or CLASS( derived-type-spec ) 26 C937 (R920) If derived-type-spec specifies an extensible type, the CLASS keyword shall be used; 27 237 J3/06-007 WORKING DRAFT 2006/07/11 otherwise, the TYPE keyword shall be used. 1 C938 (R920) All length type parameters of derived-type-spec shall be assumed. 2 If the dtio-generic-spec is READ (FORMATTED), the characteristics shall be the same as those specified 3 by the following interface: 4 SUBROUTINE my_read_routine_formatted & 5 (dtv, & 6 unit, & 7 iotype, v_list, & 8 iostat, iomsg) 9 ! the derived-type value/variable 10 dtv-type-spec , INTENT(INOUT) :: dtv 11 INTEGER, INTENT(IN) :: unit ! unit number 12 ! the edit descriptor string 13 CHARACTER (LEN=*), INTENT(IN) :: iotype 14 INTEGER, INTENT(IN) :: v_list(:) 15 INTEGER, INTENT(OUT) :: iostat 16 CHARACTER (LEN=*), INTENT(INOUT) :: iomsg 17 END 18 If the dtio-generic-spec is READ (UNFORMATTED), the characteristics shall be the same as those 19 specified by the following interface: 20 SUBROUTINE my_read_routine_unformatted & 21 (dtv, & 22 unit, & 23 iostat, iomsg) 24 ! the derived-type value/variable 25 dtv-type-spec , INTENT(INOUT) :: dtv 26 INTEGER, INTENT(IN) :: unit 27 INTEGER, INTENT(OUT) :: iostat 28 CHARACTER (LEN=*), INTENT(INOUT) :: iomsg 29 END 30 If the dtio-generic-spec is WRITE (FORMATTED), the characteristics shall be the same as those spec- 31 ified by the following interface: 32 SUBROUTINE my_write_routine_formatted & 33 (dtv, & 34 unit, & 35 iotype, v_list, & 36 iostat, iomsg) 37 ! the derived-type value/variable 38 dtv-type-spec , INTENT(IN) :: dtv 39 INTEGER, INTENT(IN) :: unit 40 ! the edit descriptor string 41 CHARACTER (LEN=*), INTENT(IN) :: iotype 42 INTEGER, INTENT(IN) :: v_list(:) 43 INTEGER, INTENT(OUT) :: iostat 44 CHARACTER (LEN=*), INTENT(INOUT) :: iomsg 45 END 46 238 2006/07/11 WORKING DRAFT J3/06-007 If the dtio-generic-spec is WRITE (UNFORMATTED), the characteristics shall be the same as those 1 specified by the following interface: 2 SUBROUTINE my_write_routine_unformatted & 3 (dtv, & 4 unit, & 5 iostat, iomsg) 6 ! the derived-type value/variable 7 dtv-type-spec , INTENT(IN) :: dtv 8 INTEGER, INTENT(IN) :: unit 9 INTEGER, INTENT(OUT) :: iostat 10 CHARACTER (LEN=*), INTENT(INOUT) :: iomsg 11 END 12 The actual specific procedure names (the my ... routine ... procedure names above) are not signifi- 13 cant. In the discussion here and elsewhere, the dummy arguments in these interfaces are referred by the 14 names given above; the names are, however, arbitrary. 15 When a user-defined derived-type input/output procedure is invoked, the processor shall pass a unit 16 argument that has a value as follows. 17 · If the parent data transfer statement uses a file-unit-number , the value of the unit argument shall 18 be that of the file-unit-number . 19 · If the parent data transfer statement is a WRITE statement with an asterisk unit or a PRINT 20 statement, the unit argument shall have the same value as the OUTPUT UNIT named constant 21 of the ISO FORTRAN ENV intrinsic module (13.8.3). 22 · If the parent data transfer statement is a READ statement with an asterisk unit or a READ 23 statement without an io-control-spec -list, the unit argument shall have the same value as the 24 INPUT UNIT named constant of the ISO FORTRAN ENV intrinsic module (13.8.3). 25 · Otherwise the parent data transfer statement must access an internal file, in which case the unit 26 argument shall have a processor-dependent negative value. 27 NOTE 9.47 The unit argument passed to a user-defined derived-type input/output procedure will be negative when the parent input/output statement specified an internal unit, or specified an external unit that is a NEWUNIT value. When an internal unit is used with the INQUIRE statement, an error condition will occur, and any variable specified in an IOSTAT= specifier will be assigned the value IOSTAT INQUIRE INTERNAL UNIT from the ISO FORTRAN ENV intrinsic module (13.8.3). For formatted data transfer, the processor shall pass an iotype argument that has the value 28 · "LISTDIRECTED" if the parent data transfer statement specified list directed formatting, 29 · "NAMELIST" if the parent data transfer statement specified namelist formatting, or 30 · "DT" concatenated with the char-literal-constant , if any, of the edit descriptor, if the parent data 31 transfer statement contained a format specification and the list item's corresponding edit descriptor 32 was a DT edit descriptor. 33 239 J3/06-007 WORKING DRAFT 2006/07/11 If the parent data transfer statement is a READ statement, the dtv dummy argument is argument 1 associated with the effective list item that caused the user-defined derived-type input procedure to be 2 invoked, as if the effective list item were an actual argument in this procedure reference (2.5.6). 3 If the parent data transfer statement is a WRITE or PRINT statement, the processor shall provide the 4 value of the effective list item in the dtv dummy argument. 5 If the v -list of the edit descriptor appears in the parent data transfer statement, the processor shall 6 provide the values from it in the v list dummy argument, with the same number of elements in the 7 same order as v -list. If there is no v -list in the edit descriptor or if the data transfer statement specifies 8 list-directed or namelist formatting, the processor shall provide v list as a zero-sized array. 9 NOTE 9.48 The user's procedure may choose to interpret an element of the v list argument as a field width, but this is not required. If it does, it would be appropriate to fill an output field with "*"s if the width is too small. The iostat argument is used to report whether an error, end-of-record, or end-of-file condition (9.10) 10 occurs. If an error condition occurs, the user-defined derived-type input/output procedure shall assign 11 a positive value to the iostat argument. Otherwise, if an end-of-file condition occurs, the user-defined 12 derived-type input procedure shall assign the value of the named constant IOSTAT END (13.8.3.10) 13 to the iostat argument. Otherwise, if an end-of-record condition occurs, the user-defined derived- 14 type input procedure shall assign the value of the named constant IOSTAT EOR (13.8.3.11) to iostat. 15 Otherwise, the user-defined derived-type input/output procedure shall assign the value zero to the 16 iostat argument. 17 If the user-defined derived-type input/output procedure returns a nonzero value for the iostat argument, 18 the procedure shall also return an explanatory message in the iomsg argument. Otherwise, the procedure 19 shall not change the value of the iomsg argument. 20 NOTE 9.49 The values of the iostat and iomsg arguments set in a user-defined derived-type input/output procedure need not be passed to all of the parent data transfer statements. If the iostat argument of the user-defined derived-type input/output procedure has a nonzero value 21 when that procedure returns, and the processor therefore terminates execution of the program as de- 22 scribed in 9.10, the processor shall make the value of the iomsg argument available in a processor- 23 dependent manner. 24 When a parent READ statement is active, an input/output statement shall not read from any external 25 unit other than the one specified by the dummy argument unit and shall not perform output to any 26 external unit. 27 When a parent WRITE or PRINT statement is active, an input/output statement shall not perform 28 output to any external unit other than the one specified by the dummy argument unit and shall not 29 read from any external unit. 30 When a parent data transfer statement is active, a data transfer statement that specifies an internal file 31 is permitted. 32 OPEN, CLOSE, BACKSPACE, ENDFILE, and REWIND statements shall not be executed while a 33 parent data transfer statement is active. 34 A user-defined derived-type input/output procedure may use a FORMAT with a DT edit descriptor for 35 handling a component of the derived type that is itself of a derived type. A child data transfer statement 36 240 2006/07/11 WORKING DRAFT J3/06-007 that is a list directed or namelist input/output statement may contain a list item of derived type. 1 Because a child data transfer statement does not position the file prior to data transfer, the child data 2 transfer statement starts transferring data from where the file was positioned by the parent data transfer 3 statement's most recently processed effective list item or record positioning edit descriptor. This is not 4 necessarily at the beginning of a record. 5 A record positioning edit descriptor, such as TL and TR, used on unit by a child data transfer statement 6 shall not cause the record position to be positioned before the record position at the time the user-defined 7 derived-type input/output procedure was invoked. 8 NOTE 9.50 A robust user-defined derived-type input/output procedure may wish to use INQUIRE to deter- mine the settings of BLANK=, PAD=, ROUND=, DECIMAL=, and DELIM= for an external unit. The INQUIRE provides values as specified in 9.9. Neither a parent nor child data transfer statement shall be asynchronous. 9 A user-defined derived-type input/output procedure, and any procedures invoked therefrom, shall not 10 define, nor cause to become undefined, any storage location referenced by any input/output list item, 11 the corresponding format, or any specifier in any active parent data transfer statement, except through 12 the dtv argument. 13 NOTE 9.51 A child data transfer statement shall not specify the ID=, POS=, or REC= specifiers in an input/output control list. NOTE 9.52 A simple example of derived type formatted output follows. The derived type variable chairman has two components. The type and an associated write formatted procedure are defined in a module so as to be accessible from wherever they might be needed. It would also be possible to check that iotype indeed has the value 'DT' and to set iostat and iomsg accordingly. MODULE p TYPE :: person CHARACTER (LEN=20) :: name INTEGER :: age CONTAINS GENERIC :: WRITE(FORMATTED) => pwf END TYPE person CONTAINS SUBROUTINE pwf (dtv,unit,iotype,vlist,iostat,iomsg) ! argument definitions CLASS(person), INTENT(IN) :: dtv INTEGER, INTENT(IN) :: unit CHARACTER (LEN=*), INTENT(IN) :: iotype INTEGER, INTENT(IN) :: vlist(:) INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg ! local variable 241 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 9.52 (cont.) CHARACTER (LEN=9) :: pfmt ! vlist(1) and (2) are to be used as the field widths of the two ! components of the derived type variable. First set up the format to ! be used for output. WRITE(pfmt,'(A,I2,A,I2,A)' ) '(A', vlist(1), ',I', vlist(2), ')' ! now the basic output statement WRITE(unit, FMT=pfmt, IOSTAT=iostat) dtv%name, dtv%age END SUBROUTINE pwf END MODULE p PROGRAM USE p INTEGER id, members TYPE (person) :: chairman ... WRITE(6, FMT="(I2, DT (15,6), I5)" ) id, chairman, members ! this writes a record with four fields, with lengths 2, 15, 6, 5 ! respectively END PROGRAM NOTE 9.53 In the following example, the variables of the derived type node form a linked list, with a single value at each node. The subroutine pwf is used to write the values in the list, one per line. MODULE p TYPE node INTEGER :: value = 0 TYPE (NODE), POINTER :: next_node => NULL ( ) CONTAINS GENERIC :: WRITE(FORMATTED) => pwf END TYPE node CONTAINS RECURSIVE SUBROUTINE pwf (dtv,unit,iotype,vlist,iostat,iomsg) ! Write the chain of values, each on a separate line in I9 format. CLASS(node), INTENT(IN) :: dtv INTEGER, INTENT(IN) :: unit CHARACTER (LEN=*), INTENT(IN) :: iotype INTEGER, INTENT(IN) :: vlist(:) INTEGER, INTENT(OUT) :: iostat CHARACTER (LEN=*), INTENT(INOUT) :: iomsg WRITE(unit,'(i9 /)', IOSTAT = iostat) dtv%value IF(iostat/=0) RETURN 242 2006/07/11 WORKING DRAFT J3/06-007 NOTE 9.53 (cont.) IF(ASSOCIATED(dtv%next_node)) WRITE(unit,'(dt)', IOSTAT=iostat) dtv%next_node END SUBROUTINE pwf END MODULE p 9.5.3.7.3 Resolving derived-typ e input/output pro cedure references 1 A suitable generic interface for user-defined derived-type input/output of an effective item is one that 2 has a dtio-generic-spec that is appropriate to the direction (read or write) and form (formatted or 3 unformatted) of the data transfer as specified in 9.5.3.7, and has a specific interface whose dtv argument 4 is compatible with the effective item according to the rules for argument association in 12.5.1.4. 5 When an effective item (9.5.2) that is of derived-type is encountered during a data transfer, user-defined 6 derived-type input/output occurs if both of the following conditions are true. 7 (1) The circumstances of the input/output are such that user-defined derived-type input/output 8 is permitted; that is, either 9 (a) the transfer was initiated by a list-directed, namelist, or unformatted input/output 10 statement, or 11 (b) a format specification is supplied for the input/output statement, and the edit de- 12 scriptor corresponding to the effective item is a DT edit descriptor. 13 (2) A suitable user-defined derived-type input/output procedure is available; that is, either 14 (a) the declared type of the effective item has a suitable generic type-bound procedure, 15 or 16 (b) a suitable generic interface is accessible. 17 If (2a) is true, the procedure referenced is determined as for explicit type-bound procedure references 18 (12.5); that is, the binding with the appropriate specific interface is located in the declared type of the 19 effective item, and the corresponding binding in the dynamic type of the effective item is selected. 20 If (2a) is false and (2b) is true, the reference is to the procedure identified by the appropriate specific 21 interface in the interface block. This reference shall not be to a dummy procedure that is not present, 22 or to a disassociated procedure pointer. 23 9.5.4 Termination of data transfer statements 24 Termination of an input/output data transfer statement occurs when 25 (1) format processing encounters a data edit descriptor and there are no remaining elements in 26 the input-item -list or output-item -list, 27 (2) unformatted or list-directed data transfer exhausts the input-item -list or output-item -list, 28 (3) namelist output exhausts the namelist-group-object -list, 29 (4) an error condition occurs, 30 (5) an end-of-file condition occurs, 31 (6) a slash (/) is encountered as a value separator (10.10, 10.11) in the record being read during 32 list-directed or namelist input, or 33 (7) an end-of-record condition occurs during execution of a nonadvancing input statement 34 (9.10). 35 243 J3/06-007 WORKING DRAFT 2006/07/11 9.6 Waiting on pending data transfer 1 Execution of an asynchronous data transfer statement in which neither an error, end-of-record, nor end- 2 of-file condition occurs initiates a pending data transfer operation. There may be multiple pending data 3 transfer operations for the same or multiple units simultaneously. A pending data transfer operation 4 remains pending until a corresponding wait operation is performed. A wait operation may be performed 5 by a WAIT, INQUIRE, CLOSE, or file positioning statement. 6 9.6.1 WAIT statement 7 A WAIT statement performs a wait operation for specified pending asynchronous data transfer opera- 8 tions. 9 NOTE 9.54 The CLOSE, INQUIRE, and file positioning statements may also perform wait operations. R921 wait-stmt is WAIT (wait-spec -list ) 10 R922 wait-spec is [ UNIT = ] file-unit-number 11 or END = label 12 or EOR = label 13 or ERR = label 14 or ID = scalar-int-expr 15 or IOMSG = iomsg-variable 16 or IOSTAT = scalar-int-variable 17 C939 (R922) No specifier shall appear more than once in a given wait-spec -list. 18 C940 (R922) A file-unit-number shall be specified; if the optional characters UNIT= are omitted, the 19 file-unit-number shall be the first item in the wait-spec -list. 20 C941 (R922) The label in the ERR=, EOR=, or END= specifier shall be the statement label of a 21 branch target statement that appears in the same scoping unit as the WAIT statement. 22 The IOSTAT=, ERR=, EOR=, END=, and IOMSG= specifiers are described in 9.10. 23 The value of the expression specified in the ID= specifier shall be the identifier of a pending data transfer 24 operation for the specified unit. If the ID= specifier appears, a wait operation for the specified data 25 transfer operation is performed. If the ID= specifier is omitted, wait operations for all pending data 26 transfers for the specified unit are performed. 27 Execution of a WAIT statement specifying a unit that does not exist, has no file connected to it, or was 28 not opened for asynchronous input/output is permitted, provided that the WAIT statement has no ID= 29 specifier; such a WAIT statement does not cause an error or end-of-file condition to occur. 30 NOTE 9.55 An EOR= specifier has no effect if the pending data transfer operation is not a nonadvancing read. And END= specifier has no effect if the pending data transfer operation is not a READ. 9.6.2 Wait op eration 31 A wait operation completes the processing of a pending data transfer operation. Each wait operation 32 completes only a single data transfer operation, although a single statement may perform multiple wait 33 operations. 34 If the actual data transfer is not yet complete, the wait operation first waits for its completion. If the 35 244 2006/07/11 WORKING DRAFT J3/06-007 data transfer operation is an input operation that completed without error, the storage units of the 1 input/output storage sequence then become defined with the values as described in 9.5.1.14 and 9.5.3.4. 2 If any error, end-of-file, or end-of-record conditions occur, the applicable actions specified by the IO- 3 STAT=, IOMSG=, ERR=, END=, and EOR= specifiers of the statement that performs the wait oper- 4 ation are taken. 5 If an error or end-of-file condition occurs during a wait operation for a unit, the processor performs a 6 wait operation for all pending data transfer operations for that unit. 7 NOTE 9.56 Error, end-of-file, and end-of-record conditions may be raised either during the data transfer state- ment that initiates asynchronous input/output, a subsequent asynchronous data transfer statement for the same unit, or during the wait operation. If such conditions are raised during a data transfer statement, they trigger actions according to the IOSTAT=, ERR=, END=, and EOR= specifiers of that statement; if they are raised during the wait operation, the actions are in accordance with the specifiers of the statement that performs the wait operation. After completion of the wait operation, the data transfer operation and its input/output storage sequence 8 are no longer considered to be pending. 9 9.7 File positioning statements 10 R923 backspace-stmt is BACKSPACE file-unit-number 11 or BACKSPACE ( position-spec -list ) 12 R924 endfile-stmt is ENDFILE file-unit-number 13 or ENDFILE ( position-spec -list ) 14 R925 rewind-stmt is REWIND file-unit-number 15 or REWIND ( position-spec -list ) 16 A file that is connected for direct access shall not be referred to by a BACKSPACE, ENDFILE, or 17 REWIND statement. A file that is connected for unformatted stream access shall not be referred to by a 18 BACKSPACE statement. A file that is connected with an ACTION= specifier having the value READ 19 shall not be referred to by an ENDFILE statement. 20 R926 position-spec is [ UNIT = ] file-unit-number 21 or IOMSG = iomsg-variable 22 or IOSTAT = scalar-int-variable 23 or ERR = label 24 C942 (R926) No specifier shall appear more than once in a given position-spec -list. 25 C943 (R926) A file-unit-number shall be specified; if the optional characters UNIT= are omitted, the 26 file-unit-number shall be the first item in the position-spec -list. 27 C944 (R926) The label in the ERR= specifier shall be the statement label of a branch target statement 28 that appears in the same scoping unit as the file positioning statement. 29 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 9.10. 30 Execution of a file positioning statement performs a wait operation for all pending asynchronous data 31 transfer operations for the specified unit. 32 245 J3/06-007 WORKING DRAFT 2006/07/11 9.7.1 BACKSPACE statement 1 Execution of a BACKSPACE statement causes the file connected to the specified unit to be positioned 2 before the current record if there is a current record, or before the preceding record if there is no current 3 record. If the file is at its initial point, the position of the file is not changed. 4 NOTE 9.57 If the preceding record is an endfile record, the file is positioned before the endfile record. If a BACKSPACE statement causes the implicit writing of an endfile record, the file is positioned before 5 the record that precedes the endfile record. 6 Backspacing a file that is connected but does not exist is prohibited. 7 Backspacing over records written using list-directed or namelist formatting is prohibited. 8 A BACKSPACE statement shall not reference a unit whose connect team has more than one image. 9 NOTE 9.58 An example of a BACKSPACE statement is: BACKSPACE (10, IOSTAT = N) 9.7.2 ENDFILE statement 10 Execution of an ENDFILE statement for a file connected for sequential access writes an endfile record 11 as the next record of the file. The file is then positioned after the endfile record, which becomes the last 12 record of the file. If the file also may be connected for direct access, only those records before the endfile 13 record are considered to have been written. Thus, only those records may be read during subsequent 14 direct access connections to the file. 15 After execution of an ENDFILE statement for a file connected for sequential access, a BACKSPACE 16 or REWIND statement shall be used to reposition the file prior to execution of any data transfer 17 input/output statement or ENDFILE statement. 18 Execution of an ENDFILE statement for a file connected for stream access causes the terminal point of 19 the file to become equal to the current file position. Only file storage units before the current position are 20 considered to have been written; thus only those file storage units may be subsequently read. Subsequent 21 stream output statements may be used to write further data to the file. 22 Execution of an ENDFILE statement for a file that is connected but does not exist creates the file; if 23 the file is connected for sequential access, it is created prior to writing the endfile record. 24 An ENDFILE statement shall not reference a unit whose connect team has more than one image. 25 NOTE 9.59 An example of an ENDFILE statement is: ENDFILE K 9.7.3 REWIND statement 26 Execution of a REWIND statement causes the specified file to be positioned at its initial point. 27 246 2006/07/11 WORKING DRAFT J3/06-007 NOTE 9.60 If the file is already positioned at its initial point, execution of this statement has no effect on the position of the file. Execution of a REWIND statement for a file that is connected but does not exist is permitted and has 1 no effect on any file. 2 A REWIND statement shall not reference a unit whose connect team has more than one image. 3 NOTE 9.61 An example of a REWIND statement is: REWIND 10 9.8 FLUSH statement 4 The form of the FLUSH statement is: 5 R927 flush-stmt is FLUSH file-unit-number 6 or FLUSH ( flush-spec -list ) 7 R928 flush-spec is [UNIT =] file-unit-number 8 or IOSTAT = scalar-int-variable 9 or IOMSG = iomsg-variable 10 or ERR = label 11 C945 (R928) No specifier shall appear more than once in a given flush-spec -list. 12 C946 (R928) A file-unit-number shall be specified; if the optional characters UNIT= are omitted from 13 the unit specifier, the file-unit-number shall be the first item in the flush-spec -list. 14 C947 (R928) The label in the ERR= specifier shall be the statement label of a branch target statement 15 that appears in the same scoping unit as the FLUSH statement. 16 The IOSTAT=, IOMSG= and ERR= specifiers are described in 9.10. The IOSTAT= variable shall 17 be set to a processor-dependent positive value if an error occurs, to zero if the processor-dependent 18 flush operation was successful, or to a processor-dependent negative value if the flush operation is not 19 supported for the unit specified. 20 Execution of a FLUSH statement causes data written to an external unit to be made available to other 21 images of the unit's connect team which execute a FLUSH statement in a subsequent segment for that 22 unit. It also causes data written to an external file to be available to other processes, or causes data 23 placed in an external file by means other than Fortran to be available to a READ statement. The action 24 is processor dependent. 25 Execution of a FLUSH statement for a file that is connected but does not exist is permitted and has no 26 effect on any file. A FLUSH statement has no effect on file position. 27 NOTE 9.62 Because this standard does not specify the mechanism of file storage, the exact meaning of the flush operation is not precisely defined. The intention is that the flush operation should make all data written to a file available to other processes or devices, or make data recently added to a file by other processes or devices available to the program via a subsequent read operation. This is commonly called "flushing I/O buffers". 247 J3/06-007 WORKING DRAFT 2006/07/11 NOTE 9.63 An example of a FLUSH statement is: FLUSH( 10, IOSTAT=N) 9.9 File inquiry 1 The INQUIRE statement may be used to inquire about properties of a particular named file or of the 2 connection to a particular unit. There are three forms of the INQUIRE statement: inquire by file, 3 which uses the FILE= specifier, inquire by unit, which uses the UNIT= specifier, and inquire by 4 output list, which uses only the IOLENGTH= specifier. All specifier value assignments are performed 5 according to the rules for assignment statements. 6 An INQUIRE statement may be executed before, while, or after a file is connected to a unit. All values 7 assigned by an INQUIRE statement are those that are current at the time the statement is executed. 8 R929 inquire-stmt is INQUIRE ( inquire-spec -list ) 9 or INQUIRE ( IOLENGTH = scalar-int-variable ) 10 output-item -list 11 NOTE 9.64 Examples of INQUIRE statements are: INQUIRE (IOLENGTH = IOL) A (1:N) INQUIRE (UNIT = JOAN, OPENED = LOG_01, NAMED = LOG_02, & FORM = CHAR_VAR, IOSTAT = IOS) 9.9.1 Inquiry sp ecifiers 12 Unless constrained, the following inquiry specifiers may be used in either of the inquire by file or inquire 13 by unit forms of the INQUIRE statement: 14 R930 inquire-spec is [ UNIT = ] file-unit-number 15 or FILE = file-name-expr 16 or ACCESS = scalar-default-char-variable 17 or ACTION = scalar-default-char-variable 18 or ASYNCHRONOUS = scalar-default-char-variable 19 or BLANK = scalar-default-char-variable 20 or DECIMAL = scalar-default-char-variable 21 or DELIM = scalar-default-char-variable 22 or DIRECT = scalar-default-char-variable 23 or ENCODING = scalar-default-char-variable 24 or ERR = label 25 or EXIST = scalar-default-logical-variable 26 or FORM = scalar-default-char-variable 27 or FORMATTED = scalar-default-char-variable 28 or ID = scalar-int-expr 29 or IOMSG = iomsg-variable 30 or IOSTAT = scalar-int-variable 31 or NAME = scalar-default-char-variable 32 or NAMED = scalar-default-logical-variable 33 or NEXTREC = scalar-int-variable 34 248 2006/07/11 WORKING DRAFT J3/06-007 or NUMBER = scalar-int-variable 1 or OPENED = scalar-default-logical-variable 2 or PAD = scalar-default-char-variable 3 or PENDING = scalar-default-logical-variable 4 or POS = scalar-int-variable 5 or POSITION = scalar-default-char-variable 6 or READ = scalar-default-char-variable 7 or READWRITE = scalar-default-char-variable 8 or RECL = scalar-int-variable 9 or ROUND = scalar-default-char-variable 10 or SEQUENTIAL = scalar-default-char-variable 11 or SIGN = scalar-default-char-variable 12 or SIZE = scalar-int-variable 13 or STREAM = scalar-default-char-variable 14 or UNFORMATTED = scalar-default-char-variable 15 or WRITE = scalar-default-char-variable 16 C948 (R930) No specifier shall appear more than once in a given inquire-spec -list. 17 C949 (R930) An inquire-spec -list shall contain one FILE= specifier or one UNIT= specifier, but not 18 both. 19 C950 (R930) In the inquire by unit form of the INQUIRE statement, if the optional characters UNIT= 20 are omitted, the file-unit-number shall be the first item in the inquire-spec -list. 21 C951 (R930) If an ID= specifier appears, a PENDING= specifier shall also appear. 22 C952 (R928) The label in the ERR= specifier shall be the statement label of a branch target statement 23 that appears in the same scoping unit as the INQUIRE statement. 24 If file-unit-number identifies an internal unit (9.5.3.7.2), an error condition occurs. 25 When a returned value of a specifier other than the NAME= specifier is of type character, the value 26 returned is in upper case. 27 If an error condition occurs during execution of an INQUIRE statement, all of the inquiry specifier 28 variables become undefined, except for variables in the IOSTAT= and IOMSG= specifiers (if any). 29 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 9.10. 30 9.9.1.1 FILE= sp ecifier in the INQUIRE statement 31 The value of the file-name-expr in the FILE= specifier specifies the name of the file being inquired about. 32 The named file need not exist or be connected to a unit. The value of the file-name-expr shall be of a 33 form acceptable to the processor as a file name. Any trailing blanks are ignored. The interpretation of 34 case is processor dependent. 35 9.9.1.2 ACCESS= sp ecifier in the INQUIRE statement 36 The scalar-default-char-variable in the ACCESS= specifier is assigned the value SEQUENTIAL if the 37 file is connected for sequential access, DIRECT if the file is connected for direct access, or STREAM if 38 the file is connected for stream access. If there is no connection, it is assigned the value UNDEFINED. 39 9.9.1.3 ACTION= sp ecifier in the INQUIRE statement 40 The scalar-default-char-variable in the ACTION= specifier is assigned the value READ if the file is 41 connected for input only, WRITE if the file is connected for output only, and READWRITE if it 42 249 J3/06-007 WORKING DRAFT 2006/07/11 is connected for both input and output. If there is no connection, the scalar-default-char-variable is 1 assigned the value UNDEFINED. 2 9.9.1.4 ASYNCHRONOUS= sp ecifier in the INQUIRE statement 3 The scalar-default-char-variable in the ASYNCHRONOUS= specifier is assigned the value YES if the 4 file is connected and asynchronous input/output on the unit is allowed; it is assigned the value NO if the 5 file is connected and asynchronous input/output on the unit is not allowed. If there is no connection, 6 the scalar-default-char-variable is assigned the value UNDEFINED. 7 9.9.1.5 BLANK= sp ecifier in the INQUIRE statement 8 The scalar-default-char-variable in the BLANK= specifier is assigned the value ZERO or NULL, corre- 9 sponding to the blank interpretation mode in effect for a connection for formatted input/output. If there 10 is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable 11 is assigned the value UNDEFINED. 12 9.9.1.6 DECIMAL= sp ecifier in the INQUIRE statement 13 The scalar-default-char-variable in the DECIMAL= specifier is assigned the value COMMA or POINT, 14 corresponding to the decimal edit mode in effect for a connection for formatted input/output. If there 15 is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable 16 is assigned the value UNDEFINED. 17 9.9.1.7 DELIM= sp ecifier in the INQUIRE statement 18 The scalar-default-char-variable in the DELIM= specifier is assigned the value APOSTROPHE, QUOTE, 19 or NONE, corresponding to the delimiter mode in effect for a connection for formatted input/output. 20 If there is no connection or if the connection is not for formatted input/output, the scalar-default-char- 21 variable is assigned the value UNDEFINED. 22 9.9.1.8 DIRECT= sp ecifier in the INQUIRE statement 23 The scalar-default-char-variable in the DIRECT= specifier is assigned the value YES if DIRECT is 24 included in the set of allowed access methods for the file, NO if DIRECT is not included in the set of 25 allowed access methods for the file, and UNKNOWN if the processor is unable to determine whether or 26 not DIRECT is included in the set of allowed access methods for the file. 27 9.9.1.9 ENCODING= sp ecifier in the INQUIRE statement 28 The scalar-default-char-variable in the ENCODING= specifier is assigned the value UTF-8 if the file 29 is connected for formatted input/output with an encoding form of UTF-8, and is assigned the value 30 UNDEFINED if the file is connected for unformatted input/output. If there is no connection, it is 31 assigned the value UTF-8 if the processor is able to determine that the encoding form of the file is 32 UTF-8. If the processor is unable to determine the encoding form of the file, the variable is assigned the 33 value UNKNOWN. 34 NOTE 9.65 The value assigned may be something other than UTF-8, UNDEFINED, or UNKNOWN if the processor supports other specific encoding forms (e.g. UTF-16BE). 9.9.1.10 EXIST= sp ecifier in the INQUIRE statement 35 Execution of an INQUIRE by file statement causes the scalar-default-logical-variable in the EXIST= 36 specifier to be assigned the value true if there exists a file with the specified name; otherwise, false is 37 250 2006/07/11 WORKING DRAFT J3/06-007 assigned. Execution of an INQUIRE by unit statement causes true to be assigned if the specified unit 1 exists; otherwise, false is assigned. 2 9.9.1.11 FORM= sp ecifier in the INQUIRE statement 3 The scalar-default-char-variable in the FORM= specifier is assigned the value FORMATTED if the 4 file is connected for formatted input/output, and is assigned the value UNFORMATTED if the file is 5 connected for unformatted input/output. If there is no connection, it is assigned the value UNDEFINED. 6 9.9.1.12 FORMATTED= sp ecifier in the INQUIRE statement 7 The scalar-default-char-variable in the FORMATTED= specifier is assigned the value YES if FORMAT- 8 TED is included in the set of allowed forms for the file, NO if FORMATTED is not included in the set 9 of allowed forms for the file, and UNKNOWN if the processor is unable to determine whether or not 10 FORMATTED is included in the set of allowed forms for the file. 11 9.9.1.13 ID= sp ecifier in the INQUIRE statement 12 The value of the expression specified in the ID= specifier shall be the identifier of a pending data transfer 13 operation for the specified unit. This specifier interacts with the PENDING= specifier (9.9.1.20). 14 9.9.1.14 NAME= sp ecifier in the INQUIRE statement 15 The scalar-default-char-variable in the NAME= specifier is assigned the value of the name of the file if 16 the file has a name; otherwise, it becomes undefined. 17 NOTE 9.66 If this specifier appears in an INQUIRE by file statement, its value is not necessarily the same as the name given in the FILE= specifier. However, the value returned shall be suitable for use as the value of the file-name-expr in the FILE= specifier in an OPEN statement. The processor may return a file name qualified by a user identification, device, directory, or other relevant information. The case of the characters assigned to scalar-default-char-variable is processor dependent. 18 9.9.1.15 NAMED= sp ecifier in the INQUIRE statement 19 The scalar-default-logical-variable in the NAMED= specifier is assigned the value true if the file has a 20 name; otherwise, it is assigned the value false. 21 9.9.1.16 NEXTREC= sp ecifier in the INQUIRE statement 22 The scalar-int-variable in the NEXTREC= specifier is assigned the value n + 1, where n is the record 23 number of the last record read from or written to the file connected for direct access. If the file is con- 24 nected but no records have been read or written since the connection, the scalar-int-variable is assigned 25 the value 1. If the file is not connected for direct access or if the position of the file is indeterminate 26 because of a previous error condition, the scalar-int-variable becomes undefined. If there are pending 27 data transfer operations for the specified unit, the value assigned is computed as if all the pending data 28 transfers had already completed. 29 J3 internal note Unresolved Technical Issue 44 NEXTREC= does not have a well-defined meaning in the context of a unit opened with the TEAM= specifier. 251 J3/06-007 WORKING DRAFT 2006/07/11 9.9.1.17 NUMBER= sp ecifier in the INQUIRE statement 1 The scalar-int-variable in the NUMBER= specifier is assigned the value of the external unit number of 2 the unit that is connected to the file. If there is no unit connected to the file, the value -1 is assigned. 3 9.9.1.18 OPENED= sp ecifier in the INQUIRE statement 4 Execution of an INQUIRE by file statement causes the scalar-default-logical-variable in the OPENED= 5 specifier to be assigned the value true if the file specified is connected to a unit; otherwise, false is 6 assigned. Execution of an INQUIRE by unit statement causes the scalar-default-logical-variable to be 7 assigned the value true if the specified unit is connected to a file; otherwise, false is assigned. 8 9.9.1.19 PAD= sp ecifier in the INQUIRE statement 9 The scalar-default-char-variable in the PAD= specifier is assigned the value YES or NO, corresponding 10 to the pad mode in effect for a connection for formatted input/output. If there is no connection or if 11 the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value 12 UNDEFINED. 13 9.9.1.20 PENDING= sp ecifier in the INQUIRE statement 14 The PENDING= specifier is used to determine whether or not previously pending asynchronous data 15 transfers are complete. A data transfer operation is previously pending if it is pending at the beginning 16 of execution of the INQUIRE statement. 17 If an ID= specifier appears and the specified data transfer operation is complete, then the variable 18 specified in the PENDING= specifier is assigned the value false and the INQUIRE statement performs 19 the wait operation for the specified data transfer. 20 If the ID= specifier is omitted and all previously pending data transfer operations for the specified unit 21 are complete, then the variable specified in the PENDING= specifier is assigned the value false and the 22 INQUIRE statement performs wait operations for all previously pending data transfers for the specified 23 unit. 24 In all other cases, the variable specified in the PENDING= specifier is assigned the value true and no 25 wait operations are performed; in this case the previously pending data transfers remain pending after 26 the execution of the INQUIRE statement. 27 NOTE 9.67 The processor has considerable flexibility in defining when it considers a transfer to be complete. Any of the following approaches could be used: (1) The INQUIRE statement could consider an asynchronous data transfer to be incom- plete until after the corresponding wait operation. In this case PENDING= would always return true unless there were no previously pending data transfers for the unit. (2) The INQUIRE statement could wait for all specified data transfers to complete and then always return false for PENDING=. (3) The INQUIRE statement could actually test the state of the specified data transfer operations. 9.9.1.21 POS= sp ecifier in the INQUIRE statement 28 The scalar-int-variable in the POS= specifier is assigned the number of the file storage unit immediately 29 following the current position of a file connected for stream access. If the file is positioned at its terminal 30 position, the variable is assigned a value one greater than the number of the highest-numbered file storage 31 252 2006/07/11 WORKING DRAFT J3/06-007 unit in the file. If the file is not connected for stream access or if the position of the file is indeterminate 1 because of previous error conditions, the variable becomes undefined. 2 9.9.1.22 POSITION= sp ecifier in the INQUIRE statement 3 The scalar-default-char-variable in the POSITION= specifier is assigned the value REWIND if the file 4 is connected by an OPEN statement for positioning at its initial point, APPEND if the file is connected 5 for positioning before its endfile record or at its terminal point, and ASIS if the file is connected without 6 changing its position. If there is no connection or if the file is connected for direct access, the scalar- 7 default-char-variable is assigned the value UNDEFINED. If the file has been repositioned since the 8 connection, the scalar-default-char-variable is assigned a processor-dependent value, which shall not be 9 REWIND unless the file is positioned at its initial point and shall not be APPEND unless the file is 10 positioned so that its endfile record is the next record or at its terminal point if it has no endfile record. 11 9.9.1.23 READ= sp ecifier in the INQUIRE statement 12 The scalar-default-char-variable in the READ= specifier is assigned the value YES if READ is included 13 in the set of allowed actions for the file, NO if READ is not included in the set of allowed actions for 14 the file, and UNKNOWN if the processor is unable to determine whether or not READ is included in 15 the set of allowed actions for the file. 16 9.9.1.24 READWRITE= sp ecifier in the INQUIRE statement 17 The scalar-default-char-variable in the READWRITE= specifier is assigned the value YES if READ- 18 WRITE is included in the set of allowed actions for the file, NO if READWRITE is not included in the 19 set of allowed actions for the file, and UNKNOWN if the processor is unable to determine whether or 20 not READWRITE is included in the set of allowed actions for the file. 21 9.9.1.25 RECL= sp ecifier in the INQUIRE statement 22 The scalar-int-variable in the RECL= specifier is assigned the value of the record length of a file con- 23 nected for direct access, or the value of the maximum record length for a file connected for sequential 24 access. If the file is connected for formatted input/output, the length is the number of characters for all 25 records that contain only characters of type default character. If the file is connected for unformatted 26 input/output, the length is measured in file storage units. If there is no connection, or if the connection 27 is for stream access, the scalar-int-variable becomes undefined. 28 9.9.1.26 ROUND= sp ecifier in the INQUIRE statement 29 The scalar-default-char-variable in the ROUND= specifier is assigned the value UP, DOWN, ZERO, 30 NEAREST, COMPATIBLE, or PROCESSOR DEFINED, corresponding to the I/O rounding mode in 31 effect for a connection for formatted input/output. If there is no connection or if the connection is not 32 for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED. The 33 processor shall return the value PROCESSOR DEFINED only if the I/O rounding mode currently in 34 effect behaves differently than the UP, DOWN, ZERO, NEAREST, and COMPATIBLE modes. 35 9.9.1.27 SEQUENTIAL= sp ecifier in the INQUIRE statement 36 The scalar-default-char-variable in the SEQUENTIAL= specifier is assigned the value YES if SEQUEN- 37 TIAL is included in the set of allowed access methods for the file, NO if SEQUENTIAL is not included 38 in the set of allowed access methods for the file, and UNKNOWN if the processor is unable to determine 39 whether or not SEQUENTIAL is included in the set of allowed access methods for the file. 40 253 J3/06-007 WORKING DRAFT 2006/07/11 9.9.1.28 SIGN= sp ecifier in the INQUIRE statement 1 The scalar-default-char-variable in the SIGN= specifier is assigned the value PLUS, SUPPRESS, or 2 PROCESSOR DEFINED, corresponding to the sign mode in effect for a connection for formatted in- 3 put/output. If there is no connection, or if the connection is not for formatted input/output, the 4 scalar-default-char-variable is assigned the value UNDEFINED. 5 9.9.1.29 SIZE= sp ecifier in the INQUIRE statement 6 The scalar-int-variable in the SIZE= specifier is assigned the size of the file in file storage units. If the 7 file size cannot be determined, the variable is assigned the value -1. 8 For a file that may be connected for stream access, the file size is the number of the highest-numbered 9 file storage unit in the file. 10 For a file that may be connected for sequential or direct access, the file size may be different from the 11 number of storage units implied by the data in the records; the exact relationship is processor-dependent. 12 9.9.1.30 STREAM= sp ecifier in the INQUIRE statement 13 The scalar-default-char-variable in the STREAM= specifier is assigned the value YES if STREAM is 14 included in the set of allowed access methods for the file, NO if STREAM is not included in the set of 15 allowed access methods for the file, and UNKNOWN if the processor is unable to determine whether or 16 not STREAM is included in the set of allowed access methods for the file. 17 9.9.1.31 UNFORMATTED= sp ecifier in the INQUIRE statement 18 The scalar-default-char-variable in the UNFORMATTED= specifier is assigned the value YES if UN- 19 FORMATTED is included in the set of allowed forms for the file, NO if UNFORMATTED is not included 20 in the set of allowed forms for the file, and UNKNOWN if the processor is unable to determine whether 21 or not UNFORMATTED is included in the set of allowed forms for the file. 22 9.9.1.32 WRITE= sp ecifier in the INQUIRE statement 23 The scalar-default-char-variable in the WRITE= specifier is assigned the value YES if WRITE is included 24 in the set of allowed actions for the file, NO if WRITE is not included in the set of allowed actions for 25 the file, and UNKNOWN if the processor is unable to determine whether or not WRITE is included in 26 the set of allowed actions for the file. 27 9.9.2 Restrictions on inquiry sp ecifiers 28 The inquire-spec -list in an INQUIRE by file statement shall contain exactly one FILE= specifier and 29 shall not contain a UNIT= specifier. The inquire-spec -list in an INQUIRE by unit statement shall 30 contain exactly one UNIT= specifier and shall not contain a FILE= specifier. The unit specified need 31 not exist or be connected to a file. If it is connected to a file, the inquiry is being made about the 32 connection and about the file connected. 33 9.9.3 Inquire by output list 34 The inquire by output list form of the INQUIRE statement has only an IOLENGTH= specifier and an 35 output list. 36 The scalar-int-variable in the IOLENGTH= specifier is assigned the processor-dependent number of file 37 storage units that would be required to store the data of the output list in an unformatted file. The 38 value shall be suitable as a RECL= specifier in an OPEN statement that connects a file for unformatted 39 direct access when there are input/output statements with the same input/output list. 40 254 2006/07/11 WORKING DRAFT J3/06-007 The output list in an INQUIRE statement shall not contain any derived-type list items that require 1 a user-defined derived-type input/output procedure as described in subclause 9.5.2. If a derived-type 2 list item appears in the output list, the value returned for the IOLENGTH= specifier assumes that no 3 user-defined derived-type input/output procedure will be invoked. 4 9.10 Error, end-of-record, and end-of-file conditions 5 The set of input/output error conditions is processor dependent. 6 An end-of-record condition occurs when a nonadvancing input statement attempts to transfer data 7 from a position beyond the end of the current record, unless the file is a stream file and the current 8 record is at the end of the file (an end-of-file condition occurs instead). 9 An end-of-file condition occurs when 10 (1) an endfile record is encountered during the reading of a file connected for sequential access, 11 (2) an attempt is made to read a record beyond the end of an internal file, or 12 (3) an attempt is made to read beyond the end of a stream file. 13 An end-of-file condition may occur at the beginning of execution of an input statement. An end-of-file 14 condition also may occur during execution of a formatted input statement when more than one record 15 is required by the interaction of the input list and the format. An end-of-file condition also may occur 16 during execution of a stream input statement. 17 9.10.1 Error conditions and the ERR= sp ecifier 18 If an error condition occurs during execution of an input/output statement, the position of the file 19 becomes indeterminate. 20 If an error condition occurs during execution of an input/output statement that contains neither an 21 ERR= nor IOSTAT= specifier, execution of the program is terminated. If an error condition occurs 22 during execution of an input/output statement that contains either an ERR= specifier or an IOSTAT= 23 specifier then 24 (1) processing of the input/output list, if any, terminates, 25 (2) if the statement is a data transfer statement or the error occurs during a wait operation, all 26 do-variable s in the statement that initiated the transfer become undefined, 27 (3) if an IOSTAT= specifier appears, the scalar-int-variable in the IOSTAT= specifier becomes 28 defined as specified in 9.10.4, 29 (4) if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 9.10.5, 30 (5) if the statement is a READ statement and it contains a SIZE= specifier, the scalar-int- 31 variable in the SIZE= specifier becomes defined as specified in 9.5.1.14, 32 (6) if the statement is a READ statement or the error condition occurs in a wait operation for 33 a transfer initiated by a READ statement, all input items or namelist group ob jects in the 34 statement that initiated the transfer become undefined, and 35 (7) if an ERR= specifier appears, execution continues with the statement labeled by the label 36 in the ERR= specifier. 37 9.10.2 End-of-file condition and the END= sp ecifier 38 If an end-of-file condition occurs during execution of an input/output statement that contains neither 39 an END= specifier nor an IOSTAT= specifier, execution of the program is terminated. If an end-of-file 40 condition occurs during execution of an input/output statement that contains either an END= specifier 41 or an IOSTAT= specifier, and an error condition does not occur then 42 255 J3/06-007 WORKING DRAFT 2006/07/11 (1) processing of the input list, if any, terminates, 1 (2) if the statement is a data transfer statement or the error occurs during a wait operation, all 2 do-variable s in the statement that initiated the transfer become undefined, 3 (3) if the statement is a READ statement or the end-of-file condition occurs in a wait operation 4 for a transfer initiated by a READ statement, all input list items or namelist group ob jects 5 in the statement that initiated the transfer become undefined, 6 (4) if the file specified in the input statement is an external record file, it is positioned after the 7 endfile record, 8 (5) if an IOSTAT= specifier appears, the scalar-int-variable in the IOSTAT= specifier becomes 9 defined as specified in 9.10.4, 10 (6) if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 9.10.5, 11 and 12 (7) if an END= specifier appears, execution continues with the statement labeled by the label 13 in the END= specifier. 14 9.10.3 End-of-record condition and the EOR= sp ecifier 15 If an end-of-record condition occurs during execution of an input/output statement that contains neither 16 an EOR= specifier nor an IOSTAT= specifier, execution of the program is terminated. If an end-of- 17 record condition occurs during execution of an input/output statement that contains either an EOR= 18 specifier or an IOSTAT= specifier, and an error condition does not occur then 19 (1) If the pad mode has the value 20 (a) YES, the record is padded with blanks to satisfy the input list item (9.5.3.4.2) and 21 corresponding data edit descriptor that requires more characters than the record con- 22 tains, 23 (b) NO, the input list item becomes undefined, 24 (2) processing of the input list, if any, terminates, 25 (3) if the statement is a data transfer statement or the error occurs during a wait operation, all 26 do-variable s in the statement that initiated the transfer become undefined, 27 (4) the file specified in the input statement is positioned after the current record, 28 (5) if an IOSTAT= specifier appears, the scalar-int-variable in the IOSTAT= specifier becomes 29 defined as specified in 9.10.4, 30 (6) if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 9.10.5, 31 (7) if a SIZE= specifier appears, the scalar-int-variable in the SIZE= specifier becomes defined 32 as specified in (9.5.1.14), and 33 (8) if an EOR= specifier appears, execution continues with the statement labeled by the label 34 in the EOR= specifier. 35 9.10.4 IOSTAT= specifier 36 Execution of an input/output statement containing the IOSTAT= specifier causes the scalar-int-variable 37 in the IOSTAT= specifier to become defined with 38 (1) a zero value if neither an error condition, an end-of-file condition, nor an end-of-record 39 condition occurs, 40 (2) the processor-dependent positive integer value of the constant IOSTAT INQUIRE INTERNAL - 41 UNIT from the ISO FORTRAN ENV intrinsic module (13.8.3) if a unit number in an IN- 42 QUIRE statement identifies an internal file, 43 (3) a processor-dependent positive integer value different from IOSTAT INQUIRE INTERNAL - 44 UNIT if any other error condition occurs, 45 256 2006/07/11 WORKING DRAFT J3/06-007 (4) the processor-dependent negative integer value of the constant IOSTAT END (13.8.3.10) if 1 an end-of-file condition occurs and no error condition occurs, or 2 (5) the processor-dependent negative integer value of the constant IOSTAT EOR (13.8.3.11) if 3 an end-of-record condition occurs and no error condition or end-of-file condition occurs. 4 NOTE 9.68 An end-of-file condition may occur only for sequential or stream input and an end-of-record con- dition may occur only for nonadvancing input. Consider the example: READ (FMT = "(E8.3)", UNIT = 3, IOSTAT = IOSS) X IF (IOSS < 0) THEN ! Perform end-of-file processing on the file connected to unit 3. CALL END_PROCESSING ELSE IF (IOSS > 0) THEN ! Perform error processing CALL ERROR_PROCESSING END IF 9.10.5 IOMSG= sp ecifier 5 If an error, end-of-file, or end-of-record condition occurs during execution of an input/output statement, 6 the processor shall assign an explanatory message to iomsg-variable . If no such condition occurs, the 7 processor shall not change the value of iomsg-variable . 8 9.11 Restrictions on input/output statements 9 If a unit, or a file connected to a unit, does not have all of the properties required for the execution of 10 certain input/output statements, those statements shall not refer to the unit. 11 An input/output statement that is executed while another input/output statement is being executed is 12 called a recursive input/output statement. 13 A recursive input/output statement shall not identify an external unit that is identified by another 14 input/output statement being executed except that a child data transfer statement may identify its 15 parent data transfer statement external unit. 16 An input/output statement shall not cause the value of any established format specification to be 17 modified. 18 A recursive input/output statement shall not modify the value of any internal unit except that a recursive 19 WRITE statement may modify the internal unit identified by that recursive WRITE statement. 20 The value of a specifier in an input/output statement shall not depend on any input-item , io-implied- 21 do do-variable , or on the definition or evaluation of any other specifier in the io-control-spec -list or 22 inquire-spec -list in that statement. 23 The value of any subscript or substring bound of a variable that appears in a specifier in an input/output 24 statement shall not depend on any input-item , io-implied-do do-variable , or on the definition or evalua- 25 tion of any other specifier in the io-control-spec -list or inquire-spec -list in that statement. 26 In a data transfer statement, the variable specified in an IOSTAT=, IOMSG=, or SIZE= specifier, if 27 any, shall not be associated with any entity in the data transfer input/output list (9.5.2) or namelist- 28 group-object -list, nor with a do-variable of an io-implied-do in the data transfer input/output list. 29 257 J3/06-007 WORKING DRAFT 2006/07/11 In a data transfer statement, if a variable specified in an IOSTAT=, IOMSG=, or SIZE= specifier is an 1 array element reference, its subscript values shall not be affected by the data transfer, the io-implied-do 2 processing, or the definition or evaluation of any other specifier in the io-control-spec -list. 3 A variable that may become defined or undefined as a result of its use in a specifier in an INQUIRE 4 statement, or any associated entity, shall not appear in another specifier in the same INQUIRE statement. 5 A STOP statement shall not be executed during execution of an input/output statement. 6 NOTE 9.69 Restrictions on the evaluation of expressions (7.1.8) prohibit certain side effects. 258 2006/07/11 WORKING DRAFT J3/06-007 10 Input/output editing 1 10.1 Format sp ecifications 2 A format used in conjunction with an input/output statement provides information that directs the 3 editing between the internal representation of data and the characters of a sequence of formatted records. 4 A FMT= specifier (9.5.1.1) in an input/output statement may refer to a FORMAT statement or to a 5 character expression that contains a format specification. A format specification provides explicit editing 6 information. The FMT= specifier alternatively may be an asterisk (*), which indicates list-directed 7 formatting (10.10). Namelist formatting (10.11) may be indicated by specifying a namelist-group-name 8 instead of a format . 9 10.2 Explicit format specification methods 10 10.2.1 FORMAT statement 11 R1001 format-stmt is FORMAT format-specification 12 R1002 format-specification is ( [ format-item -list ] ) 13 or ( [ format-item -list, ] unlimited-format-item ) 14 C1001 (R1001) The format-stmt shall be labeled. 15 C1002 (R1002) The comma used to separate format-item s in a format-item -list may be omitted 16 (1) between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit 17 descriptor (10.8.5), possibly preceded by a repeat specifier, 18 (2) before a slash edit descriptor when the optional repeat specification is not present (10.8.2), 19 (3) after a slash edit descriptor, or 20 (4) before or after a colon edit descriptor (10.8.3) 21 Blank characters may precede the initial left parenthesis of the format specification. Additional blank 22 characters may appear at any point within the format specification, with no effect on the interpretation 23 of the format specification, except within a character string edit descriptor (10.9). 24 NOTE 10.1 Examples of FORMAT statements are: 5 FORMAT (1PE12.4, I10) 9 FORMAT (I12, /, ' Dates: ', 2 (2I3, I5)) 10.2.2 Character format specification 25 A character expression used as a format in a formatted input/output statement shall evaluate to a 26 character string whose leading part is a valid format specification. 27 NOTE 10.2 The format specification begins with a left parenthesis and ends with a right parenthesis. 259 J3/06-007 WORKING DRAFT 2006/07/11 All character positions up to and including the final right parenthesis of the format specification shall be 1 defined at the time the input/output statement is executed, and shall not become redefined or undefined 2 during the execution of the statement. Character positions, if any, following the right parenthesis that 3 ends the format specification need not be defined and may contain any character data with no effect on 4 the interpretation of the format specification. 5 If the format is a character array, it is treated as if all of the elements of the array were specified in array 6 element order and were concatenated. However, if a format is a character array element, the format 7 specification shall be entirely within that array element. 8 NOTE 10.3 If a character constant is used as a format in an input/output statement, care shall be taken that the value of the character constant is a valid format specification. In particular, if a format specification delimited by apostrophes contains a character constant edit descriptor delimited with apostrophes, two apostrophes shall be written to delimit the edit descriptor and four apostrophes shall be written for each apostrophe that occurs within the edit descriptor. For example, the text: 2 ISN'T 3 may be written by various combinations of output statements and format specifications: WRITE (6, 100) 2, 3 100 FORMAT (1X, I1, 1X, 'ISN''T', 1X, I1) WRITE (6, '(1X, I1, 1X, ''ISN''''T'', 1X, I1)') 2, 3 WRITE (6, '(A)') ' 2 ISN''T 3' Doubling of internal apostrophes usually can be avoided by using quotation marks to delimit the format specification and doubling of internal quotation marks usually can be avoided by using apostrophes as delimiters. 10.3 Form of a format item list 9 10.3.1 Syntax 10 R1003 format-item is [ r ] data-edit-desc 11 or control-edit-desc 12 or char-string-edit-desc 13 or [ r ] ( format-item -list ) 14 R1004 unlimited-format-item is * ( format-item -list ) 15 R1005 r is int-literal-constant 16 C1003 (R1005) r shall be positive. 17 C1004 (R1005) r shall not have a kind parameter specified for it. 18 The integer literal constant r is called a rep eat sp ecification. 19 10.3.2 Edit descriptors 20 An edit descriptor is a data edit descriptor, a control edit descriptor, or a character string 21 edit descriptor. 22 R1006 data-edit-desc is I w [ . m ] 23 or B w [ . m ] 24 260 2006/07/11 WORKING DRAFT J3/06-007 or Ow [. m] 1 or Zw [. m] 2 or Fw . d 3 or Ew . d [Ee] 4 or EN w . d [ E e ] 5 or ES w . d [ E e ] 6 or Gw [. d [Ee]] 7 or Lw 8 or A[w ] 9 or Dw . d 10 or DT [ char-literal-constant ] [ ( v -list ) ] 11 R1007 w is int-literal-constant 12 R1008 m is int-literal-constant 13 R1009 d is int-literal-constant 14 R1010 e is int-literal-constant 15 R1011 v is signed-int-literal-constant 16 C1005 (R1010) e shall be positive. 17 C1006 (R1007) w shall be zero or positive for the I, B, O, Z, F, and G edit descriptors. w shall be 18 positive for all other edit descriptors. 19 C1007 (R1006) For the G edit descriptor, d shall be specified if and only if w is not zero. 20 C1008 (R1006) w , m , d , e , and v shall not have kind parameters specified for them. 21 C1009 (R1006) The char-literal-constant in the DT edit descriptor shall not have a kind parameter 22 specified for it. 23 I, B, O, Z, F, E, EN, ES, G, L, A, D, and DT indicate the manner of editing. 24 R1012 control-edit-desc is position-edit-desc 25 or [r ]/ 26 or : 27 or sign-edit-desc 28 or kP 29 or blank-interp-edit-desc 30 or round-edit-desc 31 or decimal-edit-desc 32 R1013 k is signed-int-literal-constant 33 C1010 (R1013) k shall not have a kind parameter specified for it. 34 In k P, k is called the scale factor. 35 R1014 position-edit-desc is Tn 36 or TL n 37 or TR n 38 or nX 39 R1015 n is int-literal-constant 40 C1011 (R1015) n shall be positive. 41 C1012 (R1015) n shall not have a kind parameter specified for it. 42 R1016 sign-edit-desc is SS 43 or SP 44 261 J3/06-007 WORKING DRAFT 2006/07/11 or S 1 R1017 blank-interp-edit-desc is BN 2 or BZ 3 R1018 round-edit-desc is RU 4 or RD 5 or RZ 6 or RN 7 or RC 8 or RP 9 R1019 decimal-edit-desc is DC 10 or DP 11 T, TL, TR, X, slash, colon, SS, SP, S, P, BN, BZ, RU, RD, RZ, RN, RC, RP, DC, and DP indicate the 12 manner of editing. 13 R1020 char-string-edit-desc is char-literal-constant 14 C1013 (R1020) The char-literal-constant shall not have a kind parameter specified for it. 15 Each rep-char in a character string edit descriptor shall be one of the characters capable of representation 16 by the processor. 17 The character string edit descriptors provide constant data to be output, and are not valid for input. 18 The edit descriptors are without regard to case except for the characters in the character constants. 19 10.3.3 Fields 20 A field is a part of a record that is read on input or written on output when format control encounters 21 a data edit descriptor or a character string edit descriptor. The field width is the size in characters of 22 the field. 23 10.4 Interaction b etween input/output list and format 24 The start of formatted data transfer using a format specification initiates format control (9.5.3.4.2). 25 Each action of format control depends on information jointly provided by the next edit descriptor in the 26 format specification and the next effective item in the input/output list, if one exists. 27 If an input/output list specifies at least one effective list item, at least one data edit descriptor shall 28 exist in the format specification. 29 NOTE 10.4 An empty format specification of the form ( ) may be used only if the input/output list has no effective list items (9.5.3.4). Zero length character items are effective list items, but zero sized arrays and implied DO lists with an iteration count of zero are not. A format specification is interpreted from left to right. The exceptions are format items preceded by a 30 repeat specification r , and format reversion (described below). 31 A format item preceded by a repeat specification is processed as a list of r items, each identical to the 32 format item but without the repeat specification and separated by commas. 33 262 2006/07/11 WORKING DRAFT J3/06-007 NOTE 10.5 An omitted repeat specification is treated in the same way as a repeat specification whose value is one. To each data edit descriptor interpreted in a format specification, there corresponds one effective item 1 specified by the input/output list (9.5.2), except that an input/output list item of type complex requires 2 the interpretation of two F, E, EN, ES, D, or G edit descriptors. For each control edit descriptor or 3 character edit descriptor, there is no corresponding item specified by the input/output list, and format 4 control communicates information directly with the record. 5 Whenever format control encounters a data edit descriptor in a format specification, it determines 6 whether there is a corresponding effective item specified by the input/output list. If there is such an 7 item, it transmits appropriately edited information between the item and the record, and then format 8 control proceeds. If there is no such item, format control terminates. 9 If format control encounters a colon edit descriptor in a format specification and another effective in- 10 put/output list item is not specified, format control terminates. 11 If format control encounters the rightmost parenthesis of a complete format specification and another 12 effective input/output list item is not specified, format control terminates. However, if another effective 13 input/output list item is specified, format control then reverts to the beginning of the format item 14 terminated by the last preceding right parenthesis that is not part of a DT edit descriptor. If there 15 is no such preceding right parenthesis, format control reverts to the first left parenthesis of the format 16 specification. If any reversion occurs, the reused portion of the format specification shall contain at 17 least one data edit descriptor. If format control reverts to a parenthesis that is preceded by a repeat 18 specification, the repeat specification is reused. Reversion of format control, of itself, has no effect on 19 the changeable modes (9.4.1). If format control reverts to a parenthesis that is not the beginning of an 20 unlimited-format-item , the file is positioned in a manner identical to the way it is positioned when a 21 slash edit descriptor is processed (10.8.2). 22 NOTE 10.6 Example: The format specification: 10 FORMAT (1X, 2(F10.3, I5)) with an output list of WRITE (10,10) 10.1, 3, 4.7, 1, 12.4, 5, 5.2, 6 produces the same output as the format specification: 10 FORMAT (1X, F10.3, I5, F10.3, I5/F10.3, I5, F10.3, I5) NOTE 10.7 The effect of an unlimited-format-item is as if its enclosed list were preceded by a very large repeat count. There is no file positioning implied by unlimited-format-item reversion. This may be used to write what is commonly called a comma separated value record. For example, WRITE( 10, '( "IARRAY =", *( I0, :, ","))') IARRAY produces a single record with a header and a comma separated list of integer values. 263 J3/06-007 WORKING DRAFT 2006/07/11 10.5 Positioning by format control 1 After each data edit descriptor or character string edit descriptor is processed, the file is positioned after 2 the last character read or written in the current record. 3 After each T, TL, TR, or X edit descriptor is processed, the file is positioned as described in 10.8.1. 4 After each slash edit descriptor is processed, the file is positioned as described in 10.8.2. 5 During formatted stream output, processing of an A edit descriptor may cause file positioning to occur 6 (10.7.4). 7 If format control reverts as described in 10.4, the file is positioned in a manner identical to the way it is 8 positioned when a slash edit descriptor is processed (10.8.2). 9 During a read operation, any unprocessed characters of the current record are skipped whenever the 10 next record is read. 11 10.6 Decimal symbol 12 The decimal symb ol is the character that separates the whole and fractional parts in the decimal 13 representation of a real number in an internal or external file. When the decimal edit mode is POINT, 14 the decimal symbol is a decimal point. When the decimal edit mode is COMMA, the decimal symbol is 15 a comma. 16 10.7 Data edit descriptors 17 10.7.1 General 18 Data edit descriptors cause the conversion of data to or from its internal representation; during formatted 19 stream output, the A data edit descriptor may also cause file positioning. On input, the specified variable 20 becomes defined unless an error condition, an end-of-file condition, or an end-of-record condition occurs. 21 On output, the specified expression is evaluated. 22 During input from a Unicode file, 23 (1) characters in the record that correspond to an ASCII character variable shall have a position 24 in the ISO 10646 character type collating sequence of 127 or less, and 25 (2) characters in the record that correspond to a default character variable shall be representable 26 in the default character type. 27 During input from a non-Unicode file, 28 (1) characters in the record that correspond to a character variable shall have the kind of the 29 character variable, and 30 (2) characters in the record that correspond to a numeric logical, or bits variable shall be of 31 default character type. 32 During output to a Unicode file, all characters transmitted to the record are of ISO 10646 character 33 type. If a character input/output list item or character string edit descriptor contains a character that 34 is not representable in the ISO 10646 character type, the result is processor-dependent. 35 During output to a non-Unicode file, characters transmitted to the record as a result of processing a 36 character string edit descriptor or as a result of evaluating a numeric, logical, bits, or default character 37 data entity, are of type default character. 38 264 2006/07/11 WORKING DRAFT J3/06-007 10.7.2 Numeric and bits editing 1 10.7.2.1 General rules 2 The I, B, O, Z, F, E, EN, ES, D, and G edit descriptors may be used to specify the input/output of 3 integer, real, complex, and bits data. The following general rules apply. 4 (1) On input, leading blanks are not significant. When the input field is not an IEEE excep- 5 tional specification (10.7.2.3.2), the interpretation of blanks, other than leading blanks, is 6 determined by the blank interpretation mode (10.8.6). Plus signs may be omitted. A field 7 containing only blanks is considered to be zero. 8 (2) On input, with F, E, EN, ES, D, and G editing, a decimal symbol appearing in the input 9 field overrides the portion of an edit descriptor that specifies the decimal symbol location. 10 The input field may have more digits than the processor uses to approximate the value of 11 the datum. 12 (3) On output with I, F, E, EN, ES, D, and G editing, the representation of a positive or zero 13 internal value in the field may be prefixed with a plus sign, as controlled by the S, SP, and 14 SS edit descriptors or the processor. The representation of a negative internal value in the 15 field shall be prefixed with a minus sign. 16 (4) On output, the representation is right justified in the field. If the number of characters 17 produced by the editing is smaller than the field width, leading blanks are inserted in the 18 field. 19 (5) On output, if the number of characters produced exceeds the field width or if an exponent 20 exceeds its specified length using the Ew.d Ee, ENw.d Ee, ESw.d Ee, or Gw.d Ee edit 21 descriptor, the processor shall fill the entire field of width w with asterisks. However, 22 the processor shall not produce asterisks if the field width is not exceeded when optional 23 characters are omitted. 24 NOTE 10.8 When an SP edit descriptor is in effect, a plus sign is not optional. (6) On output, with I, B, O, Z, F, and G editing, the specified value of the field width w may 25 be zero. In such cases, the processor selects the smallest positive actual field width that 26 does not result in a field filled with asterisks. The specified value of w shall not be zero on 27 input. 28 10.7.2.2 Integer editing 29 The Iw and Iw.m, edit descriptors indicate that the field to be edited occupies w positions, except when 30 w is zero. When w is zero, the processor selects the field width. On input, w shall not be zero. The 31 specified input/output list item shall be of type integer or bits. The G, B, O, and Z edit descriptor also 32 may be used to edit integer data (10.7.5.2.1, 10.7.2.4). 33 If the input list item is of type bits, the input field is edited as if the input list item were of type integer 34 and bits compatible with the actual list item, followed by the effect of an intrinsic assignment of the 35 resulting integer value to the actual list item. 36 265 J3/06-007 WORKING DRAFT 2006/07/11 J3 internal note (cont.) J3 internal note Unresolved Technical Issue 45 This is misplaced and/or misguided. The type and kind of the input item do not affect input editing (read through the existing subclause - nowhere does this even mention the type or more pertinantly kind of the input item). Nor does input editing define the list item, that is "data transfer" (04-007: 9.5.3.4 and in particular 9.5.3.4.2). Worse, one of the bits paper's own edits makes a change to how input editing is done (!) depending on the type of the list item, but the "as if " rule above means that is ineffective. J3 internal note Unresolved Technical Issue 46 This proposal appears to be requiring unsigned integers by the back door. However, since we don't actually have unsigned integers it does not work. Consider, for example, an 8-bit bits variable, reading the value "130". According to the above, this is equivalent to reading it into a one-byte integer - but that is not valid, 130 not being in the set of values. So it may fail. J3 internal note Unresolved Technical Issue 47 This feature is unusable by the normal user. If he has a bits variable of KIND==7, what is the effect? It is all very well saying "as if" there was an integer variable of the right kind, but that kind is not guaranteed to exist and might well not exist. On input, m has no effect. 1 In the input field for the I edit descriptor, the character string shall be a signed-digit-string (R409) if 2 the list item is of type integer and a digit-string (R410) if it is of type bits, except for the interpretation 3 of blanks. 4 The output field for the Iw edit descriptor consists of zero or more leading blanks followed by a minus 5 sign if the internal value is negative, or an optional plus sign otherwise, followed by the magnitude of 6 the internal value as a digit-string without leading zeros. 7 NOTE 10.9 A digit-string always consists of at least one digit. The output field for the Iw.m edit descriptor is the same as for the Iw edit descriptor, except that the 8 digit-string consists of at least m digits. If necessary, sufficient leading zeros are included to achieve the 9 minimum of m digits. The value of m shall not exceed the value of w , except when w is zero. If m is 10 zero and the internal value is zero, the output field consists of only blank characters, regardless of the 11 sign control in effect. When m and w are both zero, and the internal value is zero, one blank character 12 is produced. 13 10.7.2.3 Real and complex editing 14 10.7.2.3.1 General 15 The F, E, EN, ES, and D edit descriptors specify the editing of real and complex data. An input/output 16 list item corresponding to an F, E, EN, ES, or D edit descriptor shall be real or complex. The G, B, O, 17 and Z edit descriptors also may be used to edit real and complex data (10.7.5.2.2). 18 A lower-case letter is equivalent to the corresponding upper-case letter in an IEEE exceptional specifi- 19 266 2006/07/11 WORKING DRAFT J3/06-007 cation or the exponent in a numeric input field. 1 10.7.2.3.2 F editing 2 The Fw.d edit descriptor indicates that the field occupies w positions, the fractional part of which 3 consists of d digits. When w is zero, the processor selects the field width. On input, w shall not be zero. 4 The input field is either an IEEE exceptional specification or consists of an optional sign, followed by a 5 string of one or more digits optionally containing a decimal symbol, including any blanks interpreted as 6 zeros. The d has no effect on input if the input field contains a decimal symbol. If the decimal symbol 7 is omitted, the rightmost d digits of the string, with leading zeros assumed if necessary, are interpreted 8 as the fractional part of the value represented. The string of digits may contain more digits than a 9 processor uses to approximate the value. The basic form may be followed by an exponent of one of the 10 following forms: 11 (1) a sign followed by a digit-string ; 12 (2) the letter E followed by zero or more blanks, followed by a signed-digit-string ; 13 (3) the letter D followed by zero or more blanks, followed by a signed-digit-string . 14 An exponent containing a D is processed identically to an exponent containing an E. 15 NOTE 10.10 If the input field does not contain an exponent, the effect is as if the basic form were followed by an exponent with a value of -k , where k is the established scale factor (10.8.5). An input field that is an IEEE exceptional specification consists of optional blanks, followed by either 16 (1) an optional sign, followed by the string 'INF' or the string 'INFINITY', or 17 (2) an optional sign, followed by the string 'NAN', optionally followed by zero or more alphanu- 18 meric characters enclosed in parentheses, 19 optionally followed by blanks. 20 The value specified by form (1) is an IEEE infinity; this form shall not be used if the processor does 21 not support IEEE infinities for the input variable. The value specified by form (2) is an IEEE NaN; 22 this form shall not be used if the processor does not support IEEE NaNs for the input variable. The 23 NaN value is a quiet NaN if the only nonblank characters in the field are 'NAN' or 'NAN()'; otherwise, 24 the NaN value is processor-dependent. The interpretation of a sign in a NaN input field is processor 25 dependent. 26 For an internal value that is an IEEE infinity, the output field consists of blanks, if necessary, followed 27 by a minus sign for negative infinity or an optional plus sign otherwise, followed by the letters 'Inf ' or 28 'Infinity', right justified within the field. If w is less than 3, the field is filled with asterisks; otherwise, 29 if w is less than 8, 'Inf ' is produced. 30 For an internal value that is an IEEE NaN, the output field consists of blanks, if necessary, followed by 31 the letters 'NaN' and optionally followed by one to w - 5 alphanumeric processor-dependent characters 32 enclosed in parentheses, right justified within the field. If w is less than 3, the field is filled with asterisks. 33 NOTE 10.11 The processor-dependent characters following 'NaN' may convey additional information about that particular NaN. For an internal value that is neither an IEEE infinity nor a NaN, the output field consists of blanks, if 34 necessary, followed by a minus sign if the internal value is negative, or an optional plus sign otherwise, 35 267 J3/06-007 WORKING DRAFT 2006/07/11 followed by a string of digits that contains a decimal symbol and represents the magnitude of the internal 1 value, as modified by the established scale factor and rounded to d fractional digits. Leading zeros are 2 not permitted except for an optional zero immediately to the left of the decimal symbol if the magnitude 3 of the value in the output field is less than one. The optional zero shall appear if there would otherwise 4 be no digits in the output field. 5 10.7.2.3.3 E and D editing 6 The Ew.d, Dw.d, and Ew.d Ee edit descriptors indicate that the external field occupies w positions, the 7 fractional part of which consists of d digits, unless a scale factor greater than one is in effect, and the 8 exponent part consists of e digits. The e has no effect on input. 9 The form and interpretation of the input field is the same as for Fw.d editing (10.7.2.3.2). 10 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for 11 Fw.d. 12 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field for a scale 13 factor of zero is: 14 [ ± ] [0].x1 x2 . . . xd exp 15 where: 16 ± signifies a plus sign or a minus sign. 17 . signifies a decimal symbol (10.6). 18 x1 x2 . . . xd are the d most significant digits of the internal value after rounding. 19 exp is a decimal exponent having one of the following forms: 20 Edit Absolute Value Form of Descriptor of Exponent Exponent |exp| 99 E±z1 z2 or ±0z1 z2 Ew.d 99 < |exp| 999 ±z1 z2 z3 |exp| 10e - 1 E±z1 z2 . . . ze Ew.d Ee |exp| 99 D±z1 z2 or E±z1 z2 Dw.d or ±0z1 z2 99 < |exp| 999 ±z1 z2 z3 where each z is a digit. 21 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero. The edit 22 descriptor forms Ew.d and Dw.d shall not be used if |exp| > 999. 23 The scale factor k controls the decimal normalization (10.3.2, 10.8.5). If -d < k 0, the output field 24 contains exactly |k | leading zeros and d - |k | significant digits after the decimal symbol. If 0 < k < d + 2, 25 the output field contains exactly k significant digits to the left of the decimal symbol and d - k + 1 26 significant digits to the right of the decimal symbol. Other values of k are not permitted. 27 10.7.2.3.4 EN editing 28 The EN edit descriptor produces an output field in the form of a real number in engineering notation 29 such that the decimal exponent is divisible by three and the absolute value of the significand (R414) is 30 greater than or equal to 1 and less than 1000, except when the output value is zero. The scale factor 31 has no effect on output. 32 The forms of the edit descriptor are ENw.d and ENw.d Ee indicating that the external field occupies w 33 268 2006/07/11 WORKING DRAFT J3/06-007 positions, the fractional part of which consists of d digits and the exponent part consists of e digits. 1 The form and interpretation of the input field is the same as for Fw.d editing (10.7.2.3.2). 2 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for 3 Fw.d. 4 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is: 5 [ ± ] yyy . x1 x2 . . . xd exp 6 where: 7 ± signifies a plus sign or a minus sign. 8 yyy are the 1 to 3 decimal digits representative of the most significant digits of the internal 9 value after rounding (yyy is an integer such that 1 y y y < 1000 or, if the output value is 10 zero, y y y = 0). 11 . signifies a decimal symbol (10.6). 12 x1 x2 . . . xd are the d next most significant digits of the internal value after rounding. 13 exp is a decimal exponent, divisible by three, of one of the following forms: 14 Edit Absolute Value Form of Descriptor of Exponent Exponent |exp| 99 E±z1 z2 or ±0z1 z2 ENw.d 99 < |exp| 999 ±z1 z2 z3 |exp| 10e - 1 E±z1 z2 . . . ze ENw.d Ee where each z is a digit. 15 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero. The edit 16 descriptor form ENw.d shall not be used if |exp| > 999. 17 NOTE 10.12 Examples: Internal Value Output field Using SS, EN12.3 6.421 6.421E+00 -.5 -500.000E-03 .00217 2.170E-03 4721.3 4.721E+03 10.7.2.3.5 ES editing 18 The ES edit descriptor produces an output field in the form of a real number in scientific notation such 19 that the absolute value of the significand (R414) is greater than or equal to 1 and less than 10, except 20 when the output value is zero. The scale factor has no effect on output. 21 The forms of the edit descriptor are ESw.d and ESw.d Ee indicating that the external field occupies w 22 positions, the fractional part of which consists of d digits and the exponent part consists of e digits. 23 The form and interpretation of the input field is the same as for Fw.d editing (10.7.2.3.2). 24 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for 25 Fw.d. 26 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is: 27 269 J3/06-007 WORKING DRAFT 2006/07/11 [ ± ] y . x1 x2 . . . xd exp 1 where: 2 ± signifies a plus sign or a minus sign. 3 y is a decimal digit representative of the most significant digit of the internal value after 4 rounding. 5 . signifies a decimal symbol (10.6). 6 x1 x2 . . . xd are the d next most significant digits of the internal value after rounding. 7 exp is a decimal exponent having one of the following forms: 8 Edit Absolute Value Form of Descriptor of Exponent Exponent |exp| 99 E±z1 z2 or ±0z1 z2 ESw.d 99 < |exp| 999 ±z1 z2 z3 |exp| 10e - 1 E±z1 z2 . . . ze ESw.d Ee where each z is a digit. 9 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero. The edit 10 descriptor form ESw.d shall not be used if |exp | > 999. 11 NOTE 10.13 Examples: Internal Value Output field Using SS, ES12.3 6.421 6.421E+00 -.5 -5.000E-01 .00217 2.170E-03 4721.3 4.721E+03 10.7.2.3.6 Complex editing 12 A complex datum consists of a pair of separate real data. The editing of a scalar datum of complex type 13 is specified by two edit descriptors each of which specifies the editing of real data. The first of the edit 14 descriptors specifies the real part; the second specifies the imaginary part. The two edit descriptors may 15 be different. Control and character string edit descriptors may be processed between the edit descriptor 16 for the real part and the edit descriptor for the imaginary part. 17 10.7.2.3.7 Rounding mo de 18 The rounding mode can be specified by an OPEN statement (9.4.1), a data transfer input/output 19 statement (9.5.1.12), or an edit descriptor (10.8.7). 20 In what follows, the term "decimal value" means the exact decimal number as given by the character 21 string, while the term "internal value" means the number actually stored (typically in binary form) in 22 the processor. For example, in dealing with the decimal constant 0.1, the decimal value is the exact 23 mathematical quantity 1/10, which has no exact representation on most processors. Formatted output 24 of real data involves conversion from an internal value to a decimal value; formatted input involves 25 conversion from a decimal value to an internal value. 26 When the I/O rounding mode is UP, the value resulting from conversion shall be the smallest repre- 27 sentable value that is greater than or equal to the original value. When the I/O rounding mode is 28 DOWN, the value resulting from conversion shall be the largest representable value that is less than or 29 270 2006/07/11 WORKING DRAFT J3/06-007 equal to the original value. When the I/O rounding mode is ZERO, the value resulting from conversion 1 shall be the value closest to the original value and no greater in magnitude than the original value. When 2 the I/O rounding mode is NEAREST, the value resulting from conversion shall be the closer of the two 3 nearest representable values if one is closer than the other. If the two nearest representable values are 4 equidistant from the original value, it is processor dependent which one of them is chosen. When the 5 I/O rounding mode is COMPATIBLE, the value resulting from conversion shall be the closer of the 6 two nearest representable values or the value away from zero if halfway between them. When the I/O 7 rounding mode is PROCESSOR DEFINED, rounding during conversion shall be a processor dependent 8 default mode, which may correspond to one of the other modes. 9 On processors that support IEEE rounding on conversions, NEAREST shall correspond to round to 10 nearest, as specified in the IEEE International Standard. 11 NOTE 10.14 On processors that support IEEE rounding on conversions, the I/O rounding modes COMPATI- BLE and NEAREST will produce the same results except when the datum is halfway between the two representable values. In that case, NEAREST will pick the even value, but COMPATIBLE will pick the value away from zero. The I/O rounding modes UP, DOWN, and ZERO have the same effect as those specified in the IEEE International Standard for round toward +, round toward -, and round toward 0, respectively. 10.7.2.4 Bits editing 12 The Bw , Bw .m , Ow , Ow .m , Zw , and Zw.m edit descriptors indicate that the field to be edited occupies 13 w positions, except when w is zero. When w is zero, the processor selects the field width. On input, 14 w shall not be zero. The input/output list item shall be of type bits, integer, real, complex, or logical. 15 The G edit descriptor (10.7.5.3) or the I edit descriptor (10.7.2.2) also can be used to edit bits data. 16 If the input list item is not of type bits, the input field is edited as if the input list item were of type 17 bits and bits compatible with the actual list item. 18 On input, m has no effect. 19 In the input field for the B, O, and Z edit descriptors the character string shall consist of binary, octal, 20 or hexadecimal digits (as in R426, R427, R428) in the respective input field. The lower-case hexadecimal 21 digits a through f in a hexadecimal input field are equivalent to the corresponding upper-case hexadecimal 22 digits. 23 If the output list item is not of type bits, it is first converted to a list item of type bits that is bits 24 compatible with it. 25 If the output list item, x, is not of type bits, it is interpreted as if it were of type bits with the value 26 BITS(x ). 27 The output field for the Bw , Ow , and Zw descriptors consists of zero or more leading blanks followed by 28 the internal value in a form identical to the digits of a binary, octal, or hexadecimal constant, respectively, 29 with the same value and without leading zeros. 30 NOTE 10.15 A binary, octal, or hexadecimal constant always consists of at least one digit or hexadecimal digit. R1021 hex-digit-string is hex-digit [ hex-digit ] ... 31 The output field for the Bw.m, Ow.m, and Zw.m edit descriptor is the same as for the Bw , Ow , and Zw 32 edit descriptor, except that the digit-string or hex-digit-string consists of at least m digits. If necessary, 33 271 J3/06-007 WORKING DRAFT 2006/07/11 sufficient leading zeros are included to achieve the minimum of m digits. The value of m shall not exceed 1 the value of w , except when w is zero. If m is zero and the internal value consists of all zero bits, the 2 output field consists of only blank characters. When m and w are both zero, and the internal value 3 consists of all zero bits, one blank character is produced. 4 10.7.3 Logical editing 5 The Lw edit descriptor indicates that the field occupies w positions. The specified input/output list 6 item shall be of type logical. The G edit descriptor also may be used to edit logical data (10.7.5.4). 7 The input field consists of optional blanks, optionally followed by a period, followed by a T for true or 8 F for false. The T or F may be followed by additional characters in the field, which are ignored. 9 A lower-case letter is equivalent to the corresponding upper-case letter in a logical input field. 10 NOTE 10.16 The logical constants .TRUE. and .FALSE. are acceptable input forms. The output field consists of w - 1 blanks followed by a T or F, depending on whether the internal value 11 is true or false, respectively. 12 10.7.4 Character editing 13 The A[w ] edit descriptor is used with an input/output list item of type character. The G edit descriptor 14 also may be used to edit character data (10.7.5.5). The kind type parameter of all characters transferred 15 and converted under control of one A or G edit descriptor is implied by the kind of the corresponding 16 list item. 17 If a field width w is specified with the A edit descriptor, the field consists of w characters. If a field 18 width w is not specified with the A edit descriptor, the number of characters in the field is the length of 19 the corresponding list item, regardless of the value of the kind type parameter. 20 Let len be the length of the input/output list item. If the specified field width w for an A edit descriptor 21 corresponding to an input item is greater than or equal to len, the rightmost len characters will be taken 22 from the input field. If the specified field width w is less than len, the w characters will appear left 23 justified with len -w trailing blanks in the internal value. 24 If the specified field width w for an A edit descriptor corresponding to an output item is greater than 25 len, the output field will consist of w - len blanks followed by the len characters from the internal value. 26 If the specified field width w is less than or equal to len, the output field will consist of the leftmost w 27 characters from the internal value. 28 NOTE 10.17 For nondefault character types, the blank padding character is processor dependent. If the file is connected for stream access, the output may be split across more than one record if it 29 contains newline characters. A newline character is a nonblank character returned by the intrinsic 30 function NEW LINE. Beginning with the first character of the output field, each character that is not 31 a newline is written to the current record in successive positions; each newline character causes file 32 positioning at that point as if by slash editing (the current record is terminated at that point, a new 33 empty record is created following the current record, this new record becomes the last and current record 34 of the file, and the file is positioned at the beginning of this new record). 35 272 2006/07/11 WORKING DRAFT J3/06-007 NOTE 10.18 If the intrinsic function NEW LINE returns a blank character for a particular character kind, then the processor does not support using a character of that kind to cause record termination in a formatted stream file. 10.7.5 Generalized editing 1 10.7.5.1 Overview 2 The Gw , Gw.d and Gw.d Ee edit descriptors are used with an input/output list item of any intrinsic 3 type. When w is nonzero, these edit descriptors indicate that the external field occupies w positions, 4 the fractional part of which consists of a maximum of d digits and the exponent part consists of e digits. 5 When these edit descriptors are used to specify the input/output of integer, logical, bits, or character 6 data, d and e have no effect. When w is zero the processor selects the field width. On input, w shall 7 not be zero." 8 10.7.5.2 Generalized numeric editing 9 When used to specify the input/output of integer, real, and complex data, the Gw , Gw.d and Gw.d Ee 10 edit descriptors follow the general rules for numeric editing (10.7.2). 11 NOTE 10.19 The Gw.d Ee edit descriptor follows any additional rules for the Ew.d Ee edit descriptor. 10.7.5.2.1 Generalized integer editing 12 When used to specify the input/output of integer data, the Gw.d and Gw.d Ee edit descriptors follow 13 the rules for the Iw edit descriptor (10.7.2.2), except that w shall not be zero. When used to specify the 14 output of integer data, the G0 edit descriptor follows the rules for the I0 edit descriptor. 15 10.7.5.2.2 Generalized real and complex editing 16 The form and interpretation of the input field is the same as for Fw.d editing (10.7.2.3.2). 17 When used to specify the output of real or complex data, the G0 edit descriptor follows the rules for 18 the ESw.d Ee edit descriptor. Reasonable processor-dependent values of w , d , and e are used with each 19 output value. 20 For an internal value that is an IEEE infinity or NaN, the form of the output field for the Gw.d and 21 Gw.d Ee edit descriptors is the same as for Fw.d. 22 Otherwise, the method of representation in the output field depends on the magnitude of the internal 23 value being edited. Let N be the magnitude of the internal value and r be the rounding mode value 24 defined in the table below. If 0 < N < 0.1 - r × 10-d-1 or N 10d - r, or N is identically 0 and 25 d is 0, Gw.d output editing is the same as k PEw.d output editing and Gw.d Ee output editing is 26 the same as k PEw.d Ee output editing, where k is the scale factor (10.8.5) currently in effect. If 27 0.1 - r × 10-d-1 N < 10d - r or N is identically 0 and d is not zero, the scale factor has no effect, 28 and the value of N determines the editing as follows: 29 Magnitude of Internal Value Equivalent Conversion F(w - n).(d - 1), n('b') N =0 0.1 - r × 10-d-1 N < 1 - r × 10-d F(w - n).d, n('b') 1 - r × 10-d N < 10 - r × 10-d+1 F(w - n).(d - 1), n('b') 10 - r × 10-d+1 N < 100 - r × 10-d+2 F(w - n).(d - 2), n('b') 273 J3/06-007 WORKING DRAFT 2006/07/11 Magnitude of Internal Value Equivalent Conversion · · · · · · 10d-2 - r × 10-2 N < 10d-1 - r × 10-1 F(w - n).1, n('b') 10d-1 - r × 10-1 N < 10d - r F(w - n).0, n('b') where b is a blank, n is 4 for Gw.d and e + 2 for Gw.d Ee, and r is defined for each rounding mode as 1 follows: 2 I/O Rounding Mode r COMPATIBLE 0.5 0.5 if the higher value is even NEAREST -0.5 if the lower value is even UP 1 DOWN 0 1 if internal value is negative ZERO 0 if internal value is positive The value of w - n shall be positive 3 NOTE 10.20 The scale factor has no effect on output unless the magnitude of the datum to be edited is outside the range that permits effective use of F editing. 10.7.5.3 Generalized bits editing 4 When used to specify the input/output of bits data, the Gw.d and Gw.d Ee edit descriptors follow the 5 rules for the Zw edit descriptor (10.7.2.4), except that w shall not be zero. When used to specify the 6 output of bits data, the G0 edit descriptor follows the rules for the Z0 edit descriptor. 7 10.7.5.4 Generalized logical editing 8 When used to specify the input/output of logical data, the Gw.d and Gw.d Ee edit descriptors follow 9 the rules for the Lw edit descriptor (10.7.3). When used to specify the output of logical data, the G0 10 edit descriptor follows the rules for the L1 edit descriptor. 11 10.7.5.5 Generalized character editing 12 When used to specify the input/output of character data, the Gw.d and Gw.d Ee edit descriptors follow 13 the rules for the Aw edit descriptor (10.7.4). When used to specify the output of character data, the G0 14 edit descriptor follows the rules for the A edit descriptor with no field width. 15 10.7.6 User-defined derived-type editing 16 The DT edit descriptor allows a user-provided procedure to be used instead of the processor's default 17 input/output formatting for processing a list item of derived type. 18 The DT edit descriptor may include a character literal constant. The character value "DT" concatenated 19 with the character literal constant is passed to the user-defined derived-type input/output procedure as 20 the iotype argument (9.5.3.7). The v values of the edit descriptor are passed to the user-defined 21 derived-type input/output procedure as the v list array argument. 22 274 2006/07/11 WORKING DRAFT J3/06-007 NOTE 10.21 For the edit descriptor DT'Link List'(10, 4, 2), iotype is "DTLink List" and v list is (/10, 4, 2/). If a derived-type variable or value corresponds to a DT edit descriptor, there shall be an accessible 1 interface to a corresponding derived-type input/output procedure for that derived type (9.5.3.7). A DT 2 edit descriptor shall not correspond with a list item that is not of a derived type. 3 10.8 Control edit descriptors 4 A control edit descriptor does not cause the transfer of data or the conversion of data to or from internal 5 representation, but may affect the conversions performed by subsequent data edit descriptors. 6 10.8.1 Position editing 7 The T, TL, TR, and X edit descriptors specify the position at which the next character will be transmitted 8 to or from the record. If any character skipped by a T, TL, TR, or X edit descriptor is of type nondefault 9 character, and the unit is an internal file of type default character or an external non-Unicode file, the 10 result of that position editing is processor dependent. 11 The position specified by a T edit descriptor may be in either direction from the current position. On 12 input, this allows portions of a record to be processed more than once, possibly with different editing. 13 The position specified by an X edit descriptor is forward from the current position. On input, a position 14 beyond the last character of the record may be specified if no characters are transmitted from such 15 positions. 16 NOTE 10.22 An n X edit descriptor has the same effect as a TRn edit descriptor. On output, a T, TL, TR, or X edit descriptor does not by itself cause characters to be transmitted and 17 therefore does not by itself affect the length of the record. If characters are transmitted to positions at 18 or after the position specified by a T, TL, TR, or X edit descriptor, positions skipped and not previously 19 filled are filled with blanks. The result is as if the entire record were initially filled with blanks. 20 On output, a character in the record may be replaced. However, a T, TL, TR, or X edit descriptor never 21 directly causes a character already placed in the record to be replaced. Such edit descriptors may result 22 in positioning such that subsequent editing causes a replacement. 23 10.8.1.1 T, TL, and TR editing 24 The left tab limit affects file positioning by the T and TL edit descriptors. Immediately prior to 25 nonchild data transfer, the left tab limit becomes defined as the character position of the current record 26 or the current position of the stream file. If, during data transfer, the file is positioned to another record, 27 the left tab limit becomes defined as character position one of that record. 28 The Tn edit descriptor indicates that the transmission of the next character to or from a record is to 29 occur at the n th character position of the record, relative to the left tab limit. 30 The TLn edit descriptor indicates that the transmission of the next character to or from the record is 31 to occur at the character position n characters backward from the current position. However, if n is 32 greater than the difference between the current position and the left tab limit, the TLn edit descriptor 33 indicates that the transmission of the next character to or from the record is to occur at the left tab 34 limit. 35 275 J3/06-007 WORKING DRAFT 2006/07/11 The TRn edit descriptor indicates that the transmission of the next character to or from the record is 1 to occur at the character position n characters forward from the current position. 2 NOTE 10.23 The n in a Tn, TLn, or TRn edit descriptor shall be specified and shall be greater than zero. 10.8.1.2 X editing 3 The n X edit descriptor indicates that the transmission of the next character to or from a record is to 4 occur at the position n characters forward from the current position. 5 NOTE 10.24 The n in an n X edit descriptor shall be specified and shall be greater than zero. 10.8.2 Slash editing 6 The slash edit descriptor indicates the end of data transfer to or from the current record. 7 On input from a file connected for sequential or stream access, the remaining portion of the current 8 record is skipped and the file is positioned at the beginning of the next record. This record becomes 9 the current record. On output to a file connected for sequential or stream access, a new empty record 10 is created following the current record; this new record then becomes the last and current record of the 11 file and the file is positioned at the beginning of this new record. 12 For a file connected for direct access, the record number is increased by one and the file is positioned 13 at the beginning of the record that has that record number, if there is such a record, and this record 14 becomes the current record. 15 NOTE 10.25 A record that contains no characters may be written on output. If the file is an internal file or a file connected for direct access, the record is filled with blank characters. An entire record may be skipped on input. The repeat specification is optional in the slash edit descriptor. If it is not specified, the default value is 16 one. 17 10.8.3 Colon editing 18 The colon edit descriptor terminates format control if there are no more effective items in the in- 19 put/output list (9.5.2). The colon edit descriptor has no effect if there are more effective items in the 20 input/output list. 21 10.8.4 SS, SP, and S editing 22 The SS, SP, and S edit descriptors temporarily change (9.4.1) the sign mode (9.4.6.5, 9.5.1.13) for the 23 connection. The edit descriptors SS, SP, and S set the sign mode corresponding to the SIGN= specifier 24 values SUPPRESS, PLUS, and PROCESSOR DEFINED, respectively. 25 The sign mode controls optional plus characters in numeric output fields. When the sign mode is PLUS, 26 the processor shall produce a plus sign in any position that normally contains an optional plus sign. 27 When the sign mode is SUPPRESS, the processor shall not produce a plus sign in such positions. When 28 the sign mode is PROCESSOR DEFINED, the processor has the option of producing a plus sign or not 29 in such positions, sub ject to 10.7.2(5). 30 276 2006/07/11 WORKING DRAFT J3/06-007 The SS, SP, and S edit descriptors affect only I, F, E, EN, ES, D, and G editing during the execution of 1 an output statement. The SS, SP, and S edit descriptors have no effect during the execution of an input 2 statement. 3 10.8.5 P editing 4 The k P edit descriptor temporarily changes (9.4.1) the scale factor for the connection to k . The scale 5 factor affects the editing of F, E, EN, ES, D, and G edit descriptors for numeric quantities. 6 The scale factor k affects the appropriate editing in the following manner. 7 (1) On input, with F, E, EN, ES, D, and G editing (provided that no exponent exists in the 8 field) and F output editing, the scale factor effect is that the externally represented number 9 equals the internally represented number multiplied by 10k . 10 (2) On input, with F, E, EN, ES, D, and G editing, the scale factor has no effect if there is an 11 exponent in the field. 12 (3) On output, with E and D editing, the significand (R414) part of the quantity to be produced 13 is multiplied by 10k and the exponent is reduced by k . 14 (4) On output, with G editing, the effect of the scale factor is suspended unless the magnitude 15 of the datum to be edited is outside the range that permits the use of F editing. If the use 16 of E editing is required, the scale factor has the same effect as with E output editing. 17 (5) On output, with EN and ES editing, the scale factor has no effect. 18 If UP, DOWN, ZERO, or NEAREST I/O rounding mode is in effect, 19 (1) on input, the scale factor is applied to the external decimal value and then this is converted 20 using the current I/O rounding mode, and 21 (2) on output, the internal value is converted using the current I/O rounding mode and then 22 the scale factor is applied to the converted decimal value. 23 10.8.6 BN and BZ editing 24 The BN and BZ edit descriptors temporarily change (9.4.1) the blank interpretation mode (9.4.5.4, 25 9.5.1.5) for the connection. The edit descriptors BN and BZ set the blank interpretation mode corre- 26 sponding to the BLANK= specifier values NULL and ZERO, respectively. 27 The blank interpretation mode controls the interpretation of nonleading blanks in numeric and bits 28 input fields. Such blank characters are interpreted as zeros when the blank interpretation mode has the 29 value ZERO; they are ignored when the blank interpretation mode has the value NULL. The effect of 30 ignoring blanks is to treat the input field as if blanks had been removed, the remaining portion of the 31 field right justified, and the blanks replaced as leading blanks. However, a field containing only blanks 32 has the value zero. 33 The blank interpretation mode affects only numeric editing, bits editing, generalized numeric editing, 34 and generalized bits editing on input. It has no effect on output. 35 10.8.7 RU, RD, RZ, RN, RC, and RP editing 36 The round edit descriptors temporarily change (9.4.1) the connection's I/O rounding mode (9.4.6.4, 37 9.5.1.12, 10.7.2.3.7). The round edit descriptors RU, RD, RZ, RN, RC, and RP set the I/O rounding 38 mode corresponding to the ROUND= specifier values UP, DOWN, ZERO, NEAREST, COMPATIBLE, 39 and PROCESSOR DEFINED, respectively. The I/O rounding mode affects the conversion of real and 40 complex values in formatted input/output. It affects only D, E, EN, ES, F, and G editing. 41 277 J3/06-007 WORKING DRAFT 2006/07/11 10.8.8 DC and DP editing 1 The decimal edit descriptors temporarily change (9.4.1) the decimal edit mode (9.4.5.5, 9.5.1.6) for the 2 connection. The edit descriptors DC and DP set the decimal edit mode corresponding to the DECIMAL= 3 specifier values COMMA and POINT, respectively. 4 The decimal edit mode controls the representation of the decimal symbol (10.6) during conversion of 5 real and complex values in formatted input/output. The decimal edit mode affects only D, E, EN, ES, 6 F, and G editing. If the mode is COMMA during list-directed input/output, the character used as a 7 value separator is a semicolon in place of a comma. 8 10.9 Character string edit descriptors 9 A character string edit descriptor shall not be used on input. 10 The character string edit descriptor causes characters to be written from the enclosed characters of the 11 edit descriptor itself, including blanks. For a character string edit descriptor, the width of the field is 12 the number of characters between the delimiting characters. Within the field, two consecutive delimiting 13 characters are counted as a single character. 14 NOTE 10.26 A delimiter for a character string edit descriptor is either an apostrophe or quote. 10.10 List-directed formatting 15 List-directed input/output allows data editing according to the type of the list item instead of by a 16 format specification. It also allows data to be free-field, that is, separated by commas (or semicolons) 17 or blanks. 18 The characters in one or more list-directed records constitute a sequence of values and value separators. 19 The end of a record has the same effect as a blank character, unless it is within a character constant. Any 20 sequence of two or more consecutive blanks is treated as a single blank, unless it is within a character 21 constant. 22 Each value is either a null value, c, r *c, or r *, where c is a literal constant, optionally signed if integer 23 or real, or an undelimited character constant and r is an unsigned, nonzero, integer literal constant. 24 Neither c nor r shall have kind type parameters specified. The constant c is interpreted as though 25 it had the same kind type parameter as the corresponding list item. The r *c form is equivalent to r 26 successive appearances of the constant c, and the r * form is equivalent to r successive appearances of 27 the null value. Neither of these forms may contain embedded blanks, except where permitted within the 28 constant c. 29 A value separator is 30 (1) a comma optionally preceded by one or more contiguous blanks and optionally followed by 31 one or more contiguous blanks, unless the decimal edit mode is COMMA, in which case a 32 semicolon is used in place of the comma, 33 (2) a slash optionally preceded by one or more contiguous blanks and optionally followed by 34 one or more contiguous blanks, or 35 (3) one or more contiguous blanks between two nonblank values or following the last nonblank 36 value, where a nonblank value is a constant, an r *c form, or an r * form. 37 278 2006/07/11 WORKING DRAFT J3/06-007 NOTE 10.27 Although a slash encountered in an input record is referred to as a separator, it actually causes termination of list-directed and namelist input statements; it does not actually separate two values. NOTE 10.28 If no list items are specified in a list-directed input/output statement, one input record is skipped or one empty output record is written. 10.10.1 List-directed input 1 Input forms acceptable to edit descriptors for a given type are acceptable for list-directed formatting, 2 except as noted below. The form of the input value shall be acceptable for the type of the next effective 3 item in the list. Blanks are never used as zeros, and embedded blanks are not permitted in constants, 4 except within character constants and complex constants as specified below. 5 For the r *c form of an input value, the constant c is interpreted as an undelimited character constant 6 if the first list item corresponding to this value is of type default, ASCII, or ISO 10646 character, there 7 is a nonblank character immediately after r *, and that character is not an apostrophe or a quotation 8 mark; otherwise, c is interpreted as a literal constant. 9 NOTE 10.29 The end of a record has the effect of a blank, except when it appears within a character constant. When the next effective item is of type integer, the value in the input record is interpreted as if an Iw 10 edit descriptor with a suitable value of w were used. 11 When the next effective item is of type bits, the value in the input record is interpreted as if a Zw edit 12 descriptor with a suitable value of w were used. 13 When the next effective item is of type real, the input form is that of a numeric input field. A numeric 14 input field is a field suitable for F editing (10.7.2.3.2) that is assumed to have no fractional digits unless 15 a decimal symbol appears within the field. 16 When the next effective item is of type complex, the input form consists of a left parenthesis followed 17 by an ordered pair of numeric input fields separated by a separator, and followed by a right parenthesis. 18 The first numeric input field is the real part of the complex constant and the second is the imaginary 19 part. Each of the numeric input fields may be preceded or followed by any number of blanks and ends of 20 records. The separator is a comma if the decimal edit mode is POINT; it is a semicolon if the decimal 21 edit mode is COMMA. The end of a record may occur between the real part and the separator or between 22 the separator and the imaginary part. 23 When the next effective item is of type logical, the input form shall not include value separators among 24 the optional characters permitted for L editing. 25 When the next effective item is of type character, the input form consists of a possibly delimited sequence 26 of zero or more rep-char s whose kind type parameter is implied by the kind of the effective list item. 27 Character sequences may be continued from the end of one record to the beginning of the next record, 28 but the end of record shall not occur between a doubled apostrophe in an apostrophe-delimited character 29 sequence, nor between a doubled quote in a quote-delimited character sequence. The end of the record 30 does not cause a blank or any other character to become part of the character sequence. The character 31 sequence may be continued on as many records as needed. The characters blank, comma, semicolon, 32 and slash may appear in default, ASCII, or ISO 10646 character sequences. 33 279 J3/06-007 WORKING DRAFT 2006/07/11 If the next effective item is of type default, ASCII, or ISO 10646 character and 1 (1) the character sequence does not contain value separators, 2 (2) the character sequence does not cross a record boundary, 3 (3) the first nonblank character is not a quotation mark or an apostrophe, 4 (4) the leading characters are not digit s followed by an asterisk, and 5 (5) the character sequence contains at least one character, 6 the delimiting apostrophes or quotation marks are not required. If the delimiters are omitted, the 7 character sequence is terminated by the first blank, comma (if the decimal edit mode is POINT), 8 semicolon (if the decimal edit mode is COMMA), slash, or end of record; in this case apostrophes and 9 quotation marks within the datum are not to be doubled. 10 Let len be the length of the next effective item, and let w be the length of the character sequence. If 11 len is less than or equal to w, the leftmost len characters of the sequence are transmitted to the next 12 effective item. If len is greater than w, the sequence is transmitted to the leftmost w characters of the 13 next effective item and the remaining len -w characters of the next effective item are filled with blanks. 14 The effect is as though the sequence were assigned to the next effective item in a character assignment 15 statement (7.4.1.3). 16 10.10.1.1 Null values 17 A null value is specified by 18 (1) the r * form, 19 (2) no characters between consecutive value separators, or 20 (3) no characters before the first value separator in the first record read by each execution of a 21 list-directed input statement. 22 NOTE 10.30 The end of a record following any other value separator, with or without separating blanks, does not specify a null value in list-directed input. A null value has no effect on the definition status of the next effective item. A null value shall not be 23 used for either the real or imaginary part of a complex constant, but a single null value may represent 24 an entire complex constant. 25 A slash encountered as a value separator during execution of a list-directed input statement causes 26 termination of execution of that input statement after the assignment of the previous value. Any 27 characters remaining in the current record are ignored. If there are additional items in the input list, 28 the effect is as if null values had been supplied for them. Any do-variable in the input list is defined as 29 though enough null values had been supplied for any remaining input list items. 30 NOTE 10.31 All blanks in a list-directed input record are considered to be part of some value separator except for (1) blanks embedded in a character sequence, (2) embedded blanks surrounding the real or imaginary part of a complex constant, and (3) leading blanks in the first record read by each execution of a list-directed input state- ment, unless immediately followed by a slash or comma. 280 2006/07/11 WORKING DRAFT J3/06-007 NOTE 10.32 List-directed input example: INTEGER I; REAL X (8); CHARACTER (11) P; COMPLEX Z; LOGICAL G ... READ *, I, X, P, Z, G ... The input data records are: 12345,12345,,2*1.5,4* ISN'T_BOB'S,(123,0),.TEXAS$ The results are: Variable Value I 12345 X (1) 12345.0 X (2) unchanged X (3) 1.5 X (4) 1.5 X (5) ­ X (8) unchanged ISN'T BOB'S P Z (123.0,0.0) G true 10.10.2 List-directed output 1 The form of the values produced is the same as that required for input, except as noted otherwise. With 2 the exception of adjacent undelimited character sequences, the values are separated by one or more 3 blanks or by a comma, or a semicolon if the decimal edit mode is comma, optionally preceded by one or 4 more blanks and optionally followed by one or more blanks. 5 The processor may begin new records as necessary, but the end of record shall not occur within a 6 constant except for complex constants and character sequences. The processor shall not insert blanks 7 within character sequences or within constants, except for complex constants. 8 Logical output values are T for the value true and F for the value false. 9 Integer output constants are produced with the effect of an Iw edit descriptor. 10 k+3 Bits output constants are produced with the effect of a Zw edit descriptor with w equal to where 11 4 k is the kind type parameter value of the list item. 12 281 J3/06-007 WORKING DRAFT 2006/07/11 J3 internal note (cont.) J3 internal note Unresolved Technical Issue 48 The above formula was based on the idea that leading zeros of bit values are significant. However, this cannot be true, since they are suppressed using the normal edit descriptors and in particular for B0 O0 and Z0. Therefore I recommend changing the above to Z0. Actually, there is another question, which is why is it that bits values are apparently "naturally" written with Z notation? I would have expected B notation. Furthermore, the above formula is ambiguous. Does it mean k+3 , k+3 , or [ k+3 ]? Should we 4 4 4 stick to something like this formula, I think it should be k . 4 BTW, when this gets changed, the corresponding change should be made for namelist output. Real constants are produced with the effect of either an F edit descriptor or an E edit descriptor, 1 depending on the magnitude x of the value and a range 10d1 x < 10d2 , where d1 and d2 are processor- 2 dependent integers. If the magnitude x is within this range or is zero, the constant is produced using 3 0PFw.d ; otherwise, 1PEw.d Ee is used. 4 For numeric output, reasonable processor-dependent values of w , d , and e are used for each of the 5 numeric constants output. 6 Complex constants are enclosed in parentheses with a separator between the real and imaginary parts, 7 each produced as defined above for real constants. The separator is a comma if the decimal edit mode is 8 POINT; it is a semicolon if the decimal edit mode is COMMA. The end of a record may occur between 9 the separator and the imaginary part only if the entire constant is as long as, or longer than, an entire 10 record. The only embedded blanks permitted within a complex constant are between the separator and 11 the end of a record and one blank at the beginning of the next record. 12 Character sequences produced when the delimiter mode has a value of NONE 13 (1) are not delimited by apostrophes or quotation marks, 14 (2) are not separated from each other by value separators, 15 (3) have each internal apostrophe or quotation mark represented externally by one apostrophe 16 or quotation mark, and 17 (4) have a blank character inserted by the processor at the beginning of any record that begins 18 with the continuation of a character sequence from the preceding record. 19 Character sequences produced when the delimiter mode has a value of QUOTE are delimited by quotes, 20 are preceded and followed by a value separator, and have each internal quote represented on the external 21 medium by two contiguous quotes. 22 Character sequences produced when the delimiter mode has a value of APOSTROPHE are delimited 23 by apostrophes, are preceded and followed by a value separator, and have each internal apostrophe 24 represented on the external medium by two contiguous apostrophes. 25 If two or more successive values in an output record have identical values, the processor has the option 26 of producing a repeated constant of the form r *c instead of the sequence of identical values. 27 Slashes, as value separators, and null values are not produced as output by list-directed formatting. 28 Except for continuation of delimited character sequences, each output record begins with a blank char- 29 acter. 30 282 2006/07/11 WORKING DRAFT J3/06-007 NOTE 10.33 The length of the output records is not specified exactly and may be processor dependent. 10.11 Namelist formatting 1 Namelist input/output allows data editing with NAME=value subsequences. This facilitates documen- 2 tation of input and output files and more flexibility on input. 3 The characters in one or more namelist records constitute a sequence of name-value subsequences, 4 each of which consists of an ob ject designator followed by an equals and followed by one or more values 5 and value separators. The equals may optionally be preceded or followed by one or more contiguous 6 blanks. The end of a record has the same effect as a blank character, unless it is within a character 7 constant. Any sequence of two or more consecutive blanks is treated as a single blank, unless it is within 8 a character constant. 9 The name may be any name in the namelist-group-object -list (5.6). 10 Each value is either a null value (10.11.1.4), c, r *c, or r *, where c is a literal constant, optionally signed 11 if integer or real, and r is an unsigned, nonzero, integer literal constant. A kind type parameter shall 12 not be specified for c or r. The constant c is interpreted as though it had the same kind type parameter 13 as the corresponding list item. The r *c form is equivalent to r successive appearances of the constant c, 14 and the r * form is equivalent to r successive null values. Neither of these forms may contain embedded 15 blanks, except where permitted within the constant c. 16 A value separator for namelist formatting is the same as for list-directed formatting (10.10). 17 10.11.1 Namelist input 18 Input for a namelist input statement consists of 19 (1) optional blanks and namelist comments, 20 (2) the character & followed immediately by the namelist-group-name as specified in the NAMELIST 21 statement, 22 (3) one or more blanks, 23 (4) a sequence of zero or more name-value subsequences separated by value separators, and 24 (5) a slash to terminate the namelist input. 25 NOTE 10.34 A slash encountered in a namelist input record causes the input statement to terminate. A slash cannot be used to separate two values in a namelist input statement. In each name-value subsequence, the name shall be the name of a namelist group ob ject list item with 26 an optional qualification and the name with the optional qualification shall not be a zero-sized array, a 27 zero-sized array section, or a zero-length character string. The optional qualification, if any, shall not 28 contain a vector subscript. 29 A group name or ob ject name is without regard to case. 30 10.11.1.1 Namelist group object names 31 Within the input data, each name shall correspond to a particular namelist group ob ject name. Sub- 32 scripts, strides, and substring range expressions used to qualify group ob ject names shall be optionally 33 signed integer literal constants with no kind type parameters specified. If a namelist group ob ject is 34 283 J3/06-007 WORKING DRAFT 2006/07/11 an array, the input record corresponding to it may contain either the array name or the designator of 1 a subob ject of that array, using the syntax of ob ject designators (R603). If the namelist group ob ject 2 name is the name of a variable of derived type, the name in the input record may be either the name of 3 the variable or the designator of one of its components, indicated by qualifying the variable name with 4 the appropriate component name. Successive qualifications may be applied as appropriate to the shape 5 and type of the variable represented. 6 The order of names in the input records need not match the order of the namelist group ob ject items. 7 The input records need not contain all the names of the namelist group ob ject items. The definition 8 status of any names from the namelist-group-object -list that do not occur in the input record remains 9 unchanged. In the input record, each ob ject name or subob ject designator may be preceded and followed 10 by one or more optional blanks but shall not contain embedded blanks. 11 10.11.1.2 Namelist input values 12 The datum c (10.11) is any input value acceptable to format specifications for a given type, except for 13 a restriction on the form of input values corresponding to list items of types logical, integer, bits, and 14 character as specified in 10.11.1.3. The form of a real or complex value is dependent on the decimal edit 15 mode in effect (10.8.8). The form of an input value shall be acceptable for the type of the namelist group 16 ob ject list item. The number and forms of the input values that may follow the equals in a name-value 17 subsequence depend on the shape and type of the ob ject represented by the name in the input record. 18 When the name in the input record is that of a scalar variable of an intrinsic type, the equals shall 19 not be followed by more than one value. Blanks are never used as zeros, and embedded blanks are not 20 permitted in constants except within character constants and complex constants as specified in 10.11.1.3. 21 The name-value subsequences are evaluated serially, in left-to-right order. A namelist group ob ject 22 designator may appear in more than one name-value sequence. 23 When the name in the input record represents an array variable or a variable of derived type, the effect 24 is as if the variable represented were expanded into a sequence of scalar list items, in the same way 25 that formatted input/output list items are expanded (9.5.2). Each input value following the equals shall 26 then be acceptable to format specifications for the type of the list item in the corresponding position in 27 the expanded sequence, except as noted in 10.11.1.3. The number of values following the equals shall 28 not exceed the number of list items in the expanded sequence, but may be less; in the latter case, the 29 effect is as if sufficient null values had been appended to match any remaining list items in the expanded 30 sequence. 31 NOTE 10.35 For example, if the name in the input record is the name of an integer array of size 100, at most 100 values, each of which is either a digit string or a null value, may follow the equals; these values would then be assigned to the elements of the array in array element order. A slash encountered as a value separator during the execution of a namelist input statement causes 32 termination of execution of that input statement after assignment of the previous value. If there are 33 additional items in the namelist group ob ject being transferred, the effect is as if null values had been 34 supplied for them. 35 A namelist comment may appear after any value separator except a slash. A namelist comment is also 36 permitted to start in the first nonblank position of an input record except within a character literal 37 constant. 38 Successive namelist records are read by namelist input until a slash is encountered; the remainder of the 39 record is ignored and need not follow the rules for namelist input values. 40 284 2006/07/11 WORKING DRAFT J3/06-007 10.11.1.3 Namelist group object list items 1 When the next effective namelist group ob ject list item is of type real, the input form of the input value 2 is that of a numeric input field. A numeric input field is a field suitable for F editing (10.7.2.3.2) that is 3 assumed to have no fractional digits unless a decimal symbol appears within the field. 4 When the next effective item is of type complex, the input form of the input value consists of a left 5 parenthesis followed by an ordered pair of numeric input fields separated by a comma (if the decimal 6 edit mode is POINT) or a semicolon (if the decimal edit mode is COMMA), and followed by a right 7 parenthesis. The first numeric input field is the real part of the complex constant and the second part 8 is the imaginary part. Each of the numeric input fields may be preceded or followed by any number of 9 blanks and ends of records. The end of a record may occur between the real part and the comma or 10 semicolon, or between the comma or semicolon and the imaginary part. 11 When the next effective item is of type logical, the input form of the input value shall not include equals 12 or value separators among the optional characters permitted for L editing (10.7.3). 13 When the next effective item is of type integer, the value in the input record is interpreted as if an Iw 14 edit descriptor with a suitable value of w were used. 15 When the next effective list item is of type bits, the value in the input record is interpreted as if a Zw 16 edit descriptor with a suitable value of w were used. 17 When the next effective item is of type character, the input form consists of a delimited sequence of zero 18 or more rep-char s whose kind type parameter is implied by the kind of the corresponding list item. Such 19 a sequence may be continued from the end of one record to the beginning of the next record, but the 20 end of record shall not occur between a doubled apostrophe in an apostrophe-delimited sequence, nor 21 between a doubled quote in a quote-delimited sequence. The end of the record does not cause a blank or 22 any other character to become part of the sequence. The sequence may be continued on as many records 23 as needed. The characters blank, comma, semicolon, and slash may appear in such character sequences. 24 NOTE 10.36 A character sequence corresponding to a namelist input item of character type shall be delimited either with apostrophes or with quotes. The delimiter is required to avoid ambiguity between undelimited character sequences and ob ject names. The value of the DELIM= specifier, if any, in the OPEN statement for an external file is ignored during namelist input (9.4.5.6). Let len be the length of the next effective item, and let w be the length of the character sequence. If 25 len is less than or equal to w, the leftmost len characters of the sequence are transmitted to the next 26 effective item. If len is greater than w, the constant is transmitted to the leftmost w characters of the 27 next effective item and the remaining len -w characters of the next effective item are filled with blanks. 28 The effect is as though the sequence were assigned to the next effective item in a character assignment 29 statement (7.4.1.3). 30 10.11.1.4 Null values 31 A null value is specified by 32 (1) the r * form, 33 (2) blanks between two consecutive value separators following an equals, 34 (3) zero or more blanks preceding the first value separator and following an equals, or 35 (4) two consecutive nonblank value separators. 36 A null value has no effect on the definition status of the corresponding input list item. If the namelist 37 group ob ject list item is defined, it retains its previous value; if it is undefined, it remains undefined. A 38 285 J3/06-007 WORKING DRAFT 2006/07/11 null value shall not be used as either the real or imaginary part of a complex constant, but a single null 1 value may represent an entire complex constant. 2 NOTE 10.37 The end of a record following a value separator, with or without intervening blanks, does not specify a null value in namelist input. 10.11.1.5 Blanks 3 All blanks in a namelist input record are considered to be part of some value separator except for 4 (1) blanks embedded in a character constant, 5 (2) embedded blanks surrounding the real or imaginary part of a complex constant, 6 (3) leading blanks following the equals unless followed immediately by a slash or comma, or a 7 semicolon if the decimal edit mode is comma, and 8 (4) blanks between a name and the following equals. 9 10.11.1.6 Namelist Comments 10 Except within a character literal constant, a "!" character after a value separator or in the first nonblank 11 position of a namelist input record initiates a comment. The comment extends to the end of the current 12 input record and may contain any graphic character in the processor-dependent character set. The 13 comment is ignored. A slash within the namelist comment does not terminate execution of the namelist 14 input statement. Namelist comments are not allowed in stream input because comments depend on 15 record structure. 16 NOTE 10.38 Namelist input example: INTEGER I; REAL X (8); CHARACTER (11) P; COMPLEX Z; LOGICAL G NAMELIST / TODAY / G, I, P, Z, X READ (*, NML = TODAY) The input data records are: &TODAY I = 12345, X(1) = 12345, X(3:4) = 2*1.5, I=6, ! This is a comment. P = ''ISN'T_BOB'S'', Z = (123,0)/ The results stored are: Variable Value I 6 X (1) 12345.0 X (2) unchanged X (3) 1.5 X (4) 1.5 X (5) ­ X (8) unchanged ISN'T BOB'S P Z (123.0,0.0) G unchanged 286 2006/07/11 WORKING DRAFT J3/06-007 10.11.2 Namelist output 1 The form of the output produced is the same as that required for input, except for the forms of real, 2 character, and logical values. The name in the output is in upper case. With the exception of adjacent 3 undelimited character values, the values are separated by one or more blanks or by a comma, or a 4 semicolon if the decimal edit mode is COMMA, optionally preceded by one or more blanks and optionally 5 followed by one or more blanks. 6 Namelist output shall not include namelist comments. 7 The processor may begin new records as necessary. However, except for complex constants and character 8 values, the end of a record shall not occur within a constant, character value, or name, and blanks shall 9 not appear within a constant, character value, or name. 10 NOTE 10.39 The length of the output records is not specified exactly and may be processor dependent. 10.11.2.1 Namelist output editing 11 Logical output values are T for the value true and F for the value false. 12 Integer output constants are produced with the effect of an Iw edit descriptor. 13 k+3 Bits output constants are produced with the effect of a Zw edit descriptor with w equal to where 14 4 k is the kind type parameter value of the list item. 15 Real constants are produced with the effect of either an F edit descriptor or an E edit descriptor, 16 depending on the magnitude x of the value and a range 10d1 x < 10d2 , where d1 and d2 are processor- 17 dependent integers. If the magnitude x is within this range or is zero, the constant is produced using 18 0PFw.d ; otherwise, 1PEw.d Ee is used. 19 For numeric output, reasonable processor-dependent integer values of w, d, and e are used for each of 20 the numeric constants output. 21 Complex constants are enclosed in parentheses with a separator between the real and imaginary parts, 22 each produced as defined above for real constants. The separator is a comma if the decimal edit mode is 23 POINT; it is a semicolon if the decimal edit mode is COMMA. The end of a record may occur between 24 the separator and the imaginary part only if the entire constant is as long as, or longer than, an entire 25 record. The only embedded blanks permitted within a complex constant are between the separator and 26 the end of a record and one blank at the beginning of the next record. 27 Character sequences produced when the delimiter mode has a value of NONE 28 (1) are not delimited by apostrophes or quotation marks, 29 (2) are not separated from each other by value separators, 30 (3) have each internal apostrophe or quotation mark represented externally by one apostrophe 31 or quotation mark, and 32 (4) have a blank character inserted by the processor at the beginning of any record that begins 33 with the continuation of a character sequence from the preceding record. 34 NOTE 10.40 Namelist output records produced with a DELIM= specifier with a value of NONE and which contain a character sequence might not be acceptable as namelist input records. Character sequences produced when the delimiter mode has a value of QUOTE are delimited by quotes, 35 287 J3/06-007 WORKING DRAFT 2006/07/11 are preceded and followed by a value separator, and have each internal quote represented on the external 1 medium by two contiguous quotes. 2 Character sequences produced when the delimiter mode has a value of APOSTROPHE are delimited 3 by apostrophes, are preceded and followed by a value separator, and have each internal apostrophe 4 represented on the external medium by two contiguous apostrophes. 5 10.11.2.2 Namelist output records 6 If two or more successive values in an array in an output record produced have identical values, the 7 processor has the option of producing a repeated constant of the form r *c instead of the sequence of 8 identical values. 9 The name of each namelist group ob ject list item is placed in the output record followed by an equals 10 and a list of values of the namelist group ob ject list item. 11 An ampersand character followed immediately by a namelist-group-name will be produced by namelist 12 formatting at the start of the first output record to indicate which particular group of data ob jects is 13 being output. A slash is produced by namelist formatting to indicate the end of the namelist formatting. 14 A null value is not produced by namelist formatting. 15 Except for new records created by explicit formatting within a user-defined derived-type output pro- 16 cedure or by continuation of delimited character sequences, each output record begins with a blank 17 character. 18 288 2006/07/11 WORKING DRAFT J3/06-007 11 Program units 1 The terms and basic concepts of program units were introduced in 2.2. A program unit is a main 2 program, an external subprogram, a module, a submodule, or a block data program unit. 3 This clause describes main programs, modules, submodules, and block data program units. Clause 12 4 describes external subprograms. 5 11.1 Main program 6 A Fortran main program is a program unit that does not contain a SUBROUTINE, FUNCTION, 7 MODULE, or BLOCK DATA statement as its first statement. 8 R1101 main-program is [ program-stmt ] 9 [ specification-part ] 10 [ execution-part ] 11 [ internal-subprogram-part ] 12 end-program-stmt 13 R1102 program-stmt is PROGRAM program-name 14 R1103 end-program-stmt is END [ PROGRAM [ program-name ] ] 15 C1101 (R1101) In a main-program , the execution-part shall not contain a RETURN statement or an 16 ENTRY statement. 17 C1102 (R1101) The program-name may be included in the end-program-stmt only if the optional 18 program-stmt is used and, if included, shall be identical to the program-name specified in the 19 program-stmt . 20 C1103 (R1101) An automatic ob ject shall not appear in the specification-part (R204) of a main program. 21 NOTE 11.1 The program name is global to the program (16.2). For explanatory information about uses for the program name, see subclause C.8.1. NOTE 11.2 An example of a main program is: PROGRAM ANALYZE REAL A, B, C (10,10) ! Specification part CALL FIND ! Execution part CONTAINS SUBROUTINE FIND ! Internal subprogram ... END SUBROUTINE FIND END PROGRAM ANALYZE The main program may be defined by means other than Fortran; in that case, the program shall not 22 contain a main-program program unit. 23 A reference to a Fortran main-program shall not appear in any program unit in the program, including 24 289 J3/06-007 WORKING DRAFT 2006/07/11 itself. 1 11.2 Mo dules 2 A mo dule contains specifications and definitions that are to be accessible to other program units. A 3 module that is provided as an inherent part of the processor is an intrinsic mo dule. A nonintrinsic 4 mo dule is defined by a module program unit or a means other than Fortran. 5 Procedures and types defined in an intrinsic module are not themselves intrinsic. 6 R1104 module is module-stmt 7 [ specification-part ] 8 [ module-subprogram-part ] 9 end-module-stmt 10 R1105 module-stmt is MODULE module-name 11 R1106 end-module-stmt is END [ MODULE [ module-name ] ] 12 R1107 module-subprogram-part is contains-stmt 13 [ module-subprogram ] ... 14 R1108 module-subprogram is function-subprogram 15 or subroutine-subprogram 16 or separate-module-subprogram 17 C1104 (R1104) If the module-name is specified in the end-module-stmt , it shall be identical to the 18 module-name specified in the module-stmt . 19 C1105 (R1104) A module specification-part shall not contain a stmt-function-stmt , an entry-stmt , or a 20 format-stmt . 21 C1106 (R1104) An automatic ob ject shall not appear in the specification-part of a module.