1 Overview 1 1.1 Scope 1 1.2 Processor 1 1.3 Inclusions 1 1.4 Exclusions 1 1.5 Conformance 2 1.5.1 Fortran 95 compatibility 3 1.5.2 Fortran 90 compatibility 3 1.5.3 FORTRAN 77 compatibility 3 1.6 Notation used in this standard 4 1.6.1 Informative notes 4 1.6.2 Syntax rules 4 1.6.3 Assumed syntax rules 5 1.6.4 Syntax conventions and characteristics 5 1.6.5 Text conventions 6 1.7 Deleted and obsolescent features 6 1.7.1 Nature of deleted features 6 1.7.2 Nature of obsolescent features 6 1.8 Normative references 7 2 Fortran terms and concepts 9 2.1 High level syntax 9 2.2 Program unit concepts 11 2.2.1 Program 12 2.2.2 Main program 12 2.2.3 Procedure 12 2.2.4 Module 13 2.3 Execution concepts 13 2.3.1 Executable/nonexecutable statements 13 2.3.2 Statement order 13 2.3.3 The END statement 14 2.3.4 Execution sequence 15 2.4 Data concepts 15 2.4.1 Data type 15 2.4.2 Data value 16 2.4.3 Data entity 16 2.4.4 Scalar 17 2.4.5 Array 17 2.4.6 Pointer 18 2.4.7 Storage 18 2.5 Fundamental terms 18 2.5.1 Name and designator 18 2.5.2 Keyword 18 2.5.3 Declaration 19 2.5.4 Definition 19 2.5.5 Reference 19 2.5.6 Association 19 2.5.7 Intrinsic 19 2.5.8 Operator 20 2.5.9 Sequence 20 2.5.10 Companion processors 20 3 Characters, lexical tokens, and source form 21 3.1 Processor character set 21 3.1.1 Letters 21 3.1.2 Digits 21 3.1.3 Underscore 22 3.1.4 Special characters 22 3.1.5 Other characters 22 3.2 Low-level syntax 22 3.2.1 Names 23 3.2.2 Constants 23 3.2.3 Operators 23 3.2.4 Statement labels 24 3.2.5 Delimiters 24 3.3 Source form 25 3.3.1 Free source form 25 3.3.2 Fixed source form 27 3.4 Including source text 28 4 Data types 29 4.1 The concept of data type 29 4.1.1 Set of values 29 4.1.2 Constants 29 4.1.3 Operations 30 4.2 Type parameters 30 4.3 Relationship of types and values to objects 31 4.4 Intrinsic data types 31 4.4.1 Integer type 31 4.4.2 Real type 33 4.4.3 Complex type 34 4.4.4 Character type 35 4.4.5 Logical type 37 4.5 Derived types 38 4.5.1 Derived-type definition 39 4.5.2 Determination of derived types 52 4.5.3 Extensible types 53 4.5.4 Component order 55 4.5.5 Type parameter order 56 4.5.6 Derived-type values 56 4.5.7 Derived-type specifier 56 4.5.8 Construction of derived-type values 56 4.5.9 Derived-type operations and assignment 58 4.5.10 The finalization process 59 4.5.11 When finalization occurs 59 4.5.12 Objects that are not finalized 60 4.6 Type aliases 60 4.7 Enumerations and enumerators 61 4.8 Construction of array values 63 5 Data object declarations and specifications 65 5.1 Type declaration statements 65 5.1.1 Type specifiers 69 5.1.2 Attributes 71 5.2 Attribute specification statements 81 5.2.1 INTENT statement 81 5.2.2 OPTIONAL statement 81 5.2.3 Accessibility statements 82 5.2.4 SAVE statement 82 5.2.5 DIMENSION statement 83 5.2.6 ALLOCATABLE statement 83 5.2.7 POINTER statement 83 5.2.8 TARGET statement 83 5.2.9 PARAMETER statement 84 5.2.10 ASYNCHRONOUS statement 84 5.2.11 VOLATILE statement 84 5.2.12 VALUE statement 84 5.2.13 BIND statement 84 5.2.14 DATA statement 85 5.3 IMPLICIT statement 87 5.4 NAMELIST statement 89 5.5 Storage association of data objects 90 5.5.1 EQUIVALENCE statement 90 5.5.2 COMMON statement 92 6 Use of data objects 97 6.1 Scalars 97 6.1.1 Substrings 98 6.1.2 Structure components 98 6.1.3 Type parameter inquiry 100 6.2 Arrays 100 6.2.1 Whole arrays 100 6.2.2 Array elements and array sections 100 6.3 Dynamic association 104 6.3.1 ALLOCATE statement 104 6.3.2 NULLIFY statement 108 6.3.3 DEALLOCATE statement 108 7 Expressions and assignment 113 7.1 Expressions 113 7.1.1 Form of an expression 113 7.1.2 Intrinsic operations 117 7.1.3 Defined operations 118 7.1.4 Data type, type parameters, and shape of an expression 118 7.1.5 Conformability rules for elemental operations 121 7.1.6 Specification expression 121 7.1.7 Initialization expression 122 7.1.8 Evaluation of operations 124 7.2 Interpretation of intrinsic operations 129 7.2.1 Numeric intrinsic operations 129 7.2.2 Character intrinsic operation 130 7.2.3 Relational intrinsic operations 130 7.2.4 Logical intrinsic operations 132 7.3 Interpretation of defined operations 132 7.3.1 Unary defined operation 132 7.3.2 Binary defined operation 133 7.4 Precedence of operators 133 7.5 Assignment 135 7.5.1 Assignment statement 135 7.5.2 Pointer assignment 139 7.5.3 Masked array assignment - WHERE 140 7.5.4 FORALL 143 8 Execution control 149 8.1 Executable constructs containing blocks 149 8.1.1 Rules governing blocks 149 8.1.2 IF construct 150 8.1.3 CASE construct 151 8.1.4 SELECT TYPE and ASSOCIATE constructs 154 8.1.5 DO construct 158 8.2 Branching 162 8.2.1 Statement labels 163 8.2.2 GO TO statement 163 8.2.3 Computed GO TO statement 163 8.2.4 Arithmetic IF statement 163 8.3 CONTINUE statement 163 8.4 STOP statement 163 9 Input/output statements 165 9.1 Records 165 9.1.1 Formatted record 165 9.1.2 Unformatted record 166 9.1.3 Endfile record 166 9.2 External files 166 9.2.1 File existence 166 9.2.2 File access 167 9.2.3 File position 169 9.2.4 File storage units 171 9.3 Internal files 171 9.4 File connection 172 9.4.1 Unit existence 173 9.4.2 Connection of a file to a unit 173 9.4.3 Preconnection 174 9.4.4 The OPEN statement 174 9.4.5 The CLOSE statement 178 9.5 Data transfer statements 179 9.5.1 Control information list 180 9.5.2 Data transfer input/output list 184 9.5.3 Error, end-of-record, and end-of-file conditions 186 9.5.4 Execution of a data transfer input/output statement 187 9.5.5 Termination of data transfer statements 196 9.6 Waiting on pending data transfer 196 9.6.1 WAIT statement 196 9.6.2 Wait operation 197 9.7 File positioning statements 197 9.7.1 BACKSPACE statement 198 9.7.2 ENDFILE statement 198 9.7.3 REWIND statement 199 9.8 File inquiry 199 9.8.1 Inquiry specifiers 199 9.8.2 Restrictions on inquiry specifiers 205 9.8.3 Inquire by output list 205 9.9 Error processing 205 9.9.1 IOSTAT= specifier 205 9.9.2 IOMSG= specifier 206 9.9.3 ERR= specifier 206 9.9.4 END= specifier 206 9.9.5 EOR= specifier 207 9.10 Restriction on input/output statements 207 10 Input/output editing 209 10.1 Explicit format specification methods 209 10.1.1 FORMAT statement 209 10.1.2 Character format specification 209 10.2 Form of a format item list 210 10.2.1 Edit descriptors 210 10.2.2 Fields 212 10.3 Interaction between input/output list and format 212 10.4 Positioning by format control 213 10.5 Decimal symbol 213 10.6 Data edit descriptors 213 10.6.1 Numeric editing 214 10.6.2 Logical editing 218 10.6.3 Character editing 218 10.6.4 Generalized editing 219 10.6.5 User-defined derived-type editing 220 10.7 Control edit descriptors 221 10.7.1 Position editing 221 10.7.2 Slash editing 222 10.7.3 Colon editing 222 10.7.4 S, SP, and SS editing 222 10.7.5 P editing 223 10.7.6 BN and BZ editing 223 10.7.7 RU, RD, RZ, RN, RC, and RP editing 224 10.7.8 DC and DP editing 225 10.8 Character string edit descriptors 225 10.9 List-directed formatting 225 10.9.1 List-directed input 226 10.9.2 List-directed output 228 10.10 Namelist formatting 229 10.10.1 Namelist input 230 10.10.2 Namelist output 233 11 Program units 235 11.1 Main program 235 11.1.1 Main program executable part 236 11.1.2 Main program internal subprograms 236 11.2 External subprograms 236 11.3 Modules 236 11.3.1 Module reference 237 11.3.2 The USE statement and use association 237 11.4 Block data program units 240 12 Procedures 243 12.1 Procedure classifications 243 12.1.1 Procedure classification by reference 243 12.1.2 Procedure classification by means of definition 243 12.2 Characteristics of procedures 244 12.2.1 Characteristics of dummy arguments 244 12.2.2 Characteristics of function results 244 12.3 Procedure interface 244 12.3.1 Implicit and explicit interfaces 245 12.3.2 Specification of the procedure interface 246 12.4 Procedure reference 254 12.4.1 Actual arguments, dummy arguments, and argument association 256 12.4.2 Function reference 264 12.4.3 Subroutine reference 264 12.5 Procedure definition 264 12.5.1 Intrinsic procedure definition 264 12.5.2 Procedures defined by subprograms 265 12.5.3 Definition and invocation of procedures by means other than Fortran 272 12.5.4 Statement function 274 12.6 Pure procedures 274 12.7 Elemental procedures 276 12.7.1 Elemental procedure declaration and interface 276 12.7.2 Elemental function actual arguments and results 277 12.7.3 Elemental subroutine actual arguments 277 13 Intrinsic procedures and modules 279 13.1 Intrinsic functions 279 13.2 Elemental intrinsic procedures 279 13.3 Arguments to intrinsic procedures 279 13.4 Argument presence inquiry function 280 13.5 Numeric, mathematical, character, kind, logical, and bit procedures 280 13.5.1 Numeric functions 280 13.5.2 Mathematical functions 280 13.5.3 Character functions 280 13.5.4 Character inquiry function 280 13.5.5 Kind functions 280 13.5.6 Logical function 281 13.5.7 Bit manipulation and inquiry procedures 281 13.6 Transfer function 281 13.7 Numeric manipulation and inquiry functions 281 13.7.1 Models for integer and real data 282 13.7.2 Numeric inquiry functions 282 13.7.3 Floating point manipulation functions 282 13.8 Array intrinsic functions 283 13.8.1 The shape of array arguments 283 13.8.2 Mask arguments 283 13.8.3 Vector and matrix multiplication functions 283 13.8.4 Array reduction functions 283 13.8.5 Array inquiry functions 283 13.8.6 Array construction functions 284 13.8.7 Array reshape function 284 13.8.8 Array manipulation functions 284 13.8.9 Array location functions 284 13.9 Allocation status inquiry functions 284 13.10 Pointer association status functions 284 13.11 Type inquiry functions 284 13.12 System environment inquiry functions 284 13.13 Intrinsic subroutines 284 13.13.1 Date and time subroutines 285 13.13.2 Pseudorandom numbers 285 13.13.3 Bit copy subroutine 285 13.13.4 System environment subroutines 285 13.14 Generic intrinsic functions 285 13.14.1 Argument presence inquiry function 286 13.14.2 Numeric functions 286 13.14.3 Mathematical functions 286 13.14.4 Character functions 286 13.14.5 Character inquiry function 287 13.14.6 Kind functions 287 13.14.7 Logical function 287 13.14.8 Numeric inquiry functions 287 13.14.9 Bit inquiry function 287 13.14.10 Bit manipulation functions 287 13.14.11 Transfer function 288 13.14.12 Floating-point manipulation functions 288 13.14.13 Vector and matrix multiply functions 288 13.14.14 Array reduction functions 288 13.14.15 Array inquiry functions 288 13.14.16 Array construction functions 288 13.14.17 Array reshape function 289 13.14.18 Array manipulation functions 289 13.14.19 Array location functions 289 13.14.20 Allocation status inquiry functions 289 13.14.21 Pointer association status functions 289 13.14.22 Type inquiry functions 289 13.14.23 System environment inquiry functions 289 13.15 Intrinsic subroutines 289 13.16 Specific names for intrinsic functions 290 13.17 Specifications of the intrinsic procedures 291 13.18 The ISO_FORTRAN_ENV intrinsic module 342 13.18.1 Standard input/output units 342 13.18.2 Input/output status 342 14 Scope, association, and definition 345 14.1 Scope of names 345 14.1.1 Global entities 345 14.1.2 Local entities 345 14.1.3 Statement and construct entities 352 14.2 Scope of labels 353 14.3 Scope of external input/output units 353 14.4 Scope of operators 353 14.5 Scope of the assignment symbol 353 14.6 Association 353 14.6.1 Name association 353 14.6.2 Pointer association 356 14.6.3 Storage association 358 14.6.4 Inheritance association 360 14.7 Definition and undefinition of variables 360 14.7.1 Definition of objects and subobjects 360 14.7.2 Variables that are always defined 361 14.7.3 Variables that are initially defined 361 14.7.4 Variables that are initially undefined 361 14.7.5 Events that cause variables to become defined 361 14.7.6 Events that cause variables to become undefined 363 14.7.7 Variable definition context 364 15 Exceptions and IEEE arithmetic 367 15.1 Derived data types defined in the modules 368 15.2 The exceptions 368 15.3 The rounding modes 370 15.4 Halting 370 15.5 The floating point status 370 15.6 Exceptional values 371 15.7 IEEE arithmetic 371 15.8 Tables of the procedures 372 15.8.1 Inquiry functions 372 15.8.2 Elemental functions 372 15.8.3 Kind function 373 15.8.4 Elemental subroutines 373 15.8.5 Nonelemental subroutines 373 15.9 Specifications of the procedures 374 15.10 Examples 387 16 Interoperability with C 391 16.1 The ISO_C_BINDING intrinsic module 391 16.2 Interoperation between Fortran and C entities 392 16.2.1 Fortran scalar intrinsic entities and C entities 392 16.2.2 Interoperation with C pointer types 395 16.2.3 Interoperability inquiry functions 395 16.2.4 Interoperation with C struct types 397 16.2.5 Interoperation with C array types 397 16.2.6 Interoperation with C functions 398 16.2.7 Interoperation with C global variables 400 A. Glossary of technical terms 403 B. Decremental features 415 B.1 Deleted features 415 B.1.1 Real and double precision DO variables 415 B.1.2 Branching to an END IF statement from outside its IF block 416 B.1.3 PAUSE statement 416 B.1.4 ASSIGN, assigned GO TO, and assigned FORMAT 416 B.1.5 H edit descriptor 417 B.2 Obsolescent features 418 B.2.1 Alternate return 418 B.2.2 Computed GO TO statement 419 B.2.3 Statement functions 419 B.2.4 DATA statements among executables 419 B.2.5 Assumed character length functions 419 B.2.6 Fixed form source 419 B.2.7 CHARACTER* form of CHARACTER declaration 419 C. Extended notes 421 C.1 Section 4 notes 421 C.1.1 Intrinsic and derived data types (4.4, 4.5) 421 C.1.2 Selection of the approximation methods (4.4.2) 422 C.1.3 Extensible types (4.5.3) 423 C.1.4 Pointers (4.5.1) 424 C.1.5 Structure constructors and generic names 424 C.1.6 Final subroutines (4.5.1.10, 4.5.10, 4.5.11, 4.5.12) 426 C.2 Section 5 notes 427 C.2.1 The POINTER attribute (5.1.2.7) 427 C.2.2 The TARGET attribute (5.1.2.8) 428 C.2.3 The VOLATILE attribute (5.1.2.13) 428 C.3 Section 6 notes 429 C.3.1 Structure components (6.1.2) 429 C.3.2 Allocation with dynamic type (6.3.1) 430 C.3.3 Pointer allocation and association 430 C.4 Section 7 notes 431 C.4.1 Character assignment 431 C.4.2 Evaluation of function references 431 C.4.3 Pointers in expressions 432 C.4.4 Pointers on the left side of an assignment 432 C.4.5 An example of a FORALL construct containing a WHERE construct 433 C.4.6 Examples of FORALL statements 433 C.5 Section 8 notes 434 C.5.1 Loop control 434 C.5.2 The CASE construct 434 C.5.3 Additional examples of DO constructs 434 C.5.4 Examples of invalid DO constructs 436 C.6 Section 9 notes 436 C.6.1 External files (9.2) 436 C.6.2 Nonadvancing input/output (9.2.3.1) 437 C.6.3 Asynchronous input/output 438 C.6.4 OPEN statement (9.4.4) 440 C.6.5 Connection properties (9.4.2) 441 C.6.6 CLOSE statement (9.4.5) 442 C.6.7 INQUIRE statement (9.8) 443 C.7 Section 10 notes 443 C.7.1 Number of records (10.3, 10.4, 10.7.2) 443 C.7.2 List-directed input (10.9.1) 444 C.8 Section 11 notes 445 C.8.1 Main program and block data program unit (11.1, 11.4) 445 C.8.2 Dependent compilation (11.3) 445 C.8.3 Examples of the use of modules 447 C.9 Section 12 notes 452 C.9.1 Portability problems with external procedures (12.3.2.2) 452 C.9.2 Procedures defined by means other than Fortran (12.5.3) 452 C.9.3 Procedure interfaces (12.3) 453 C.9.4 Argument association and evaluation (12.4.1.2) 453 C.9.5 Pointers and targets as arguments (12.4.1.2) 454 C.9.6 Polymorphic Argument Association (12.4.1.3) 455 C.10 Section 14 notes 456 C.10.1 Examples of host association (14.6.1.3) 456 C.11 Array feature notes 457 C.11.1 Summary of features 457 C.11.2 Examples 458 C.11.3 FORmula TRANslation and array processing 462 C.11.4 Sum of squared residuals 463 C.11.5 Vector norms: infinity-norm and one-norm 463 C.11.6 Matrix norms: infinity-norm and one-norm 463 C.11.7 Logical queries 463 C.11.8 Parallel computations 464 C.11.9 Example of element-by-element computation 464 C.11.10 Bit manipulation and inquiry procedures 465 C.12 Section 16 notes 465 C.12.1 Examples of Interoperation between Fortran and C Functions 465 C.12.2 Example of C calling Fortran 466 D. Index 469 Contents