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 6 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 23 3.1 Processor character set 23 3.1.1 Letters 23 3.1.2 Digits 23 3.1.3 Underscore 24 3.1.4 Special characters 24 3.1.5 Other characters 24 3.2 Low-level syntax 24 3.2.1 Names 25 3.2.2 Constants 25 3.2.3 Operators 25 3.2.4 Statement labels 26 3.2.5 Delimiters 26 3.3 Source form 27 3.3.1 Free source form 27 3.3.2 Fixed source form 29 3.4 Including source text 30 4 Data types 31 4.1 The concept of data type 31 4.1.1 Set of values 31 4.1.2 Constants 31 4.1.3 Operations 32 4.2 Type parameters 32 4.3 Relationship of types and values to objects 33 4.4 Intrinsic data types 34 4.4.1 Integer type 34 4.4.2 Real type 35 4.4.3 Complex type 37 4.4.4 Character type 38 4.4.5 Logical type 40 4.5 Derived types 41 4.5.1 Derived-type definition 41 4.5.2 Determination of derived types 51 4.5.3 Extensible types 53 4.5.4 Derived-type values 55 4.5.5 Derived-type specifier 55 4.5.6 Construction of derived-type values 55 4.5.7 Derived-type operations and assignment 57 4.6 Type aliases 57 4.7 Enumerations and enumerators 58 4.8 Construction of array values 60 5 Data object declarations and specifications 63 5.1 Type declaration statements 63 5.1.1 Type specifiers 67 5.1.2 Attributes 70 5.2 Attribute specification statements 79 5.2.1 INTENT statement 79 5.2.2 OPTIONAL statement 79 5.2.3 Accessibility statements 79 5.2.4 SAVE statement 80 5.2.5 DIMENSION statement 81 5.2.6 ALLOCATABLE statement 81 5.2.7 POINTER statement 81 5.2.8 TARGET statement 81 5.2.9 PARAMETER statement 82 5.2.10 ASYNCHRONOUS statement 82 5.2.11 VOLATILE statement 82 5.2.12 VALUE statement 82 5.2.13 BIND statement 82 5.2.14 DATA statement 83 5.3 IMPLICIT statement 85 5.4 NAMELIST statement 87 5.5 Storage association of data objects 88 5.5.1 EQUIVALENCE statement 88 5.5.2 COMMON statement 90 6 Use of data objects 95 6.1 Scalars 95 6.1.1 Substrings 96 6.1.2 Structure components 96 6.1.3 Type parameter inquiry 98 6.2 Arrays 98 6.2.1 Whole arrays 98 6.2.2 Array elements and array sections 98 6.3 Dynamic association 102 6.3.1 ALLOCATE statement 102 6.3.2 NULLIFY statement 106 6.3.3 DEALLOCATE statement 106 7 Expressions and assignment 109 7.1 Expressions 109 7.1.1 Form of an expression 109 7.1.2 Intrinsic operations 113 7.1.3 Defined operations 114 7.1.4 Data type, type parameters, and shape of an expression 114 7.1.5 Conformability rules for elemental operations 116 7.1.6 Specification expression 117 7.1.7 Initialization expression 118 7.1.8 Evaluation of operations 120 7.2 Interpretation of intrinsic operations 126 7.2.1 Numeric intrinsic operations 126 7.2.2 Character intrinsic operation 127 7.2.3 Relational intrinsic operations 127 7.2.4 Logical intrinsic operations 129 7.3 Interpretation of defined operations 129 7.3.1 Unary defined operation 129 7.3.2 Binary defined operation 130 7.4 Precedence of operators 130 7.5 Assignment 132 7.5.1 Assignment statement 132 7.5.2 Pointer assignment 136 7.5.3 Masked array assignment - WHERE 137 7.5.4 FORALL 140 8 Execution control 147 8.1 Executable constructs containing blocks 147 8.1.1 Rules governing blocks 147 8.1.2 IF construct 148 8.1.3 CASE construct 149 8.1.4 SELECT TYPE and ASSOCIATE constructs 152 8.1.5 DO construct 156 8.2 Branching 160 8.2.1 Statement labels 161 8.2.2 GO TO statement 161 8.2.3 Computed GO TO statement 161 8.2.4 Arithmetic IF statement 161 8.3 CONTINUE statement 161 8.4 STOP statement 161 9 Input/output statements 163 9.1 Records 163 9.1.1 Formatted record 163 9.1.2 Unformatted record 164 9.1.3 Endfile record 164 9.2 External files 164 9.2.1 File existence 164 9.2.2 File access 165 9.2.3 File position 167 9.2.4 File storage units 169 9.3 Internal files 169 9.4 File connection 170 9.4.1 Unit existence 171 9.4.2 Connection of a file to a unit 171 9.4.3 Preconnection 172 9.4.4 The OPEN statement 172 9.4.5 The CLOSE statement 176 9.5 Data transfer statements 178 9.5.1 Control information list 178 9.5.2 Data transfer input/output list 182 9.5.3 Error, end-of-record, and end-of-file conditions 184 9.5.4 Execution of a data transfer input/output statement 185 9.5.5 Printing of formatted records 194 9.5.6 Termination of data transfer statements 194 9.6 Waiting on pending data transfer 195 9.6.1 WAIT statement 195 9.6.2 Wait operation 196 9.7 File positioning statements 196 9.7.1 BACKSPACE statement 197 9.7.2 ENDFILE statement 197 9.7.3 REWIND statement 197 9.8 File inquiry 198 9.8.1 Inquiry specifiers 198 9.8.2 Restrictions on inquiry specifiers 204 9.8.3 Inquire by output list 204 9.9 Error processing 204 9.9.1 IOSTAT= specifier 204 9.9.2 IOMSG= specifier 205 9.9.3 ERR= specifier 205 9.9.4 END= specifier 205 9.9.5 EOR= specifier 205 9.10 Restriction on input/output statements 206 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 223 10.7.5 P editing 223 10.7.6 BN and BZ editing 224 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 226 10.9.1 List-directed input 226 10.9.2 List-directed output 228 10.10 Namelist formatting 230 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 arguments 236 11.1.2 Main program specifications 237 11.1.3 Main program executable part 238 11.1.4 Main program internal subprograms 238 11.2 External subprograms 238 11.3 Modules 238 11.3.1 Module reference 239 11.3.2 The USE statement and use association 239 11.4 Block data program units 241 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 245 12.4 Procedure reference 254 12.4.1 Actual arguments, dummy arguments, and argument association 255 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 281 13.7.2 Numeric inquiry functions 282 13.7.3 Floating point manipulation functions 282 13.8 Array intrinsic functions 282 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 283 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 Intrinsic subroutines 284 13.12.1 Date and time subroutines 284 13.12.2 Pseudorandom numbers 285 13.12.3 Bit copy subroutine 285 13.12.4 Environment variable subroutine 285 13.13 Generic intrinsic functions 285 13.13.1 Argument presence inquiry function 285 13.13.2 Numeric functions 285 13.13.3 Mathematical functions 286 13.13.4 Character functions 286 13.13.5 Character inquiry function 286 13.13.6 Kind functions 287 13.13.7 Logical function 287 13.13.8 Numeric inquiry functions 287 13.13.9 Bit inquiry function 287 13.13.10 Bit manipulation functions 287 13.13.11 Transfer function 287 13.13.12 Floating-point manipulation functions 287 13.13.13 Vector and matrix multiply functions 288 13.13.14 Array reduction functions 288 13.13.15 Array inquiry functions 288 13.13.16 Array construction functions 288 13.13.17 Array reshape function 288 13.13.18 Array manipulation functions 288 13.13.19 Array location functions 288 13.13.20 Allocation status inquiry functions 289 13.13.21 Pointer association status functions 289 13.13.22 Type inquiry functions 289 13.14 Intrinsic subroutines 289 13.15 Specific names for intrinsic functions 289 13.16 Specifications of the intrinsic procedures 291 13.17 The ISO_FORTRAN_ENV intrinsic module 339 13.17.1 Standard input/output units 339 13.17.2 Input/output status values 340 14 Scope, association, and definition 341 14.1 Scope of names 341 14.1.1 Global entities 341 14.1.2 Local entities 341 14.1.3 Statement and construct entities 347 14.2 Scope of labels 348 14.3 Scope of external input/output units 348 14.4 Scope of operators 348 14.5 Scope of the assignment symbol 348 14.6 Association 348 14.6.1 Name association 348 14.6.2 Pointer association 351 14.6.3 Storage association 352 14.7 Definition and undefinition of variables 355 14.7.1 Definition of objects and subobjects 355 14.7.2 Variables that are always defined 356 14.7.3 Variables that are initially defined 356 14.7.4 Variables that are initially undefined 356 14.7.5 Events that cause variables to become defined 356 14.7.6 Events that cause variables to become undefined 357 14.7.7 Variable definition context 359 15 Exceptions and IEEE arithmetic 361 15.1 Derived data types defined in the modules 362 15.2 The exceptions 362 15.3 The rounding modes 364 15.4 Halting 365 15.5 The floating point status 365 15.6 Exceptional values 365 15.7 IEEE arithmetic 366 15.8 Tables of the procedures 366 15.8.1 Inquiry functions 366 15.8.2 Elemental functions 367 15.8.3 Kind function 368 15.8.4 Elemental subroutines 368 15.8.5 Nonelemental subroutines 368 15.9 Specifications of the procedures 368 15.10 Examples 381 16 Interoperability with C 385 16.1 The ISO_C_BINDING intrinsic module 385 16.2 Interoperation between Fortran and C entities 387 16.2.1 Fortran scalar intrinsic entities and C entities 387 16.2.2 Interoperation with C pointer types 389 16.2.3 The C address operator 389 16.2.4 Interoperation with C struct types 390 16.2.5 Interoperation with C array types 391 16.2.6 Interoperation with C functions 392 16.2.7 Interoperation with C global variables 394 A. Glossary of technical terms 397 B. Decremental features 409 B.1 Deleted features 409 B.1.1 Real and double precision DO variables 409 B.1.2 Branching to an END IF statement from outside its IF block 410 B.1.3 PAUSE statement 410 B.1.4 ASSIGN, assigned GO TO, and assigned FORMAT 410 B.1.5 H edit descriptor 411 B.2 Obsolescent features 412 B.2.1 Alternate return 412 B.2.2 Computed GO TO statement 413 B.2.3 Statement functions 413 B.2.4 DATA statements among executables 413 B.2.5 Assumed character length functions 413 B.2.6 Fixed form source 413 B.2.7 CHARACTER* form of CHARACTER declaration 413 C. Extended notes 415 C.1 Section 4 notes 415 C.1.1 Intrinsic and derived data types (4.4, 4.5) 415 C.1.2 Selection of the approximation methods (4.4.2) 416 C.1.3 Extensible types (4.5.3) 417 C.1.4 Pointers (4.5.1) 418 C.2 Section 5 notes 419 C.2.1 The POINTER attribute (5.1.2.7) 419 C.2.2 The TARGET attribute (5.1.2.8) 419 C.2.3 The VOLATILE attribute (5.1.2.13) 420 C.3 Section 6 notes 421 C.3.1 Structure components (6.1.2) 421 C.3.2 Pointer allocation and association 422 C.4 Section 7 notes 423 C.4.1 Character assignment 423 C.4.2 Evaluation of function references 423 C.4.3 Pointers in expressions 423 C.4.4 Pointers on the left side of an assignment 423 C.4.5 An example of a FORALL construct containing a WHERE construct 424 C.4.6 Examples of FORALL statements 425 C.5 Section 8 notes 425 C.5.1 Loop control 425 C.5.2 The CASE construct 425 C.5.3 Additional examples of DO constructs 425 C.5.4 Examples of invalid DO constructs 427 C.6 Section 9 notes 428 C.6.1 External files (9.2) 428 C.6.2 Nonadvancing input/output (9.2.3.1) 429 C.6.3 Asynchronous input/output 430 C.6.4 OPEN statement (9.4.4) 431 C.6.5 Connection properties (9.4.2) 432 C.6.6 CLOSE statement (9.4.5) 433 C.6.7 INQUIRE statement (9.8) 434 C.7 Section 10 notes 434 C.7.1 Number of records (10.3, 10.4, 10.7.2) 434 C.7.2 List-directed input (10.9.1) 435 C.8 Section 11 notes 436 C.8.1 Main program and block data program unit (11.1, 11.4) 436 C.8.2 Dependent compilation (11.3) 436 C.8.3 Examples of the use of modules 438 C.9 Section 12 notes 443 C.9.1 Portability problems with external procedures (12.3.2.2) 443 C.9.2 Procedures defined by means other than Fortran (12.5.3) 443 C.9.3 Procedure interfaces (12.3) 444 C.9.4 Argument association and evaluation (12.4.1.2) 444 C.9.5 Pointers and targets as arguments (12.4.1.2) 445 C.9.6 Polymorphic Argument Association (12.4.1.3) 446 C.10 Section 14 notes 447 C.10.1 Examples of host association (14.6.1.3) 447 C.11 Array feature notes 448 C.11.1 Summary of features 448 C.11.2 Examples 449 C.11.3 FORmula TRANslation and array processing 453 C.11.4 Sum of squared residuals 454 C.11.5 Vector norms: infinity-norm and one-norm 454 C.11.6 Matrix norms: infinity-norm and one-norm 454 C.11.7 Logical queries 454 C.11.8 Parallel computations 455 C.11.9 Example of element-by-element computation 455 C.11.10 Bit manipulation and inquiry procedures 456 D. Index 457 Contents