ISO/IEC JTC 1/SC 22/WG 5/N2146
DRAFT |
INTERNATIONAL ISO/IEC
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PDF disclaimerThis PDF file may contain embedded typefaces. In accordance with Adobe’s licensing policy, this file may be | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
printed or viewed but shall not be edited unless the typefaces which are embedded are licensed to and installed on the computer performing the editing. In downloading this file, parties accept therein the responsibility of not infringing Adobe’s licensing policy. The ISO Central Secretariat accepts no liability in this area. Adobe is a trademark of Adobe Systems Incorporated. Details of the software products used to create this PDF file can be found in the General Info relative to the file; the PDF-creation parameters were optimized for printing. Every care has been taken to ensure that the file is suitable for use by ISO member bodies. In the unlikely event that a problem relating to it is found, please inform the Central Secretariat at the address given below. This ISO document is a Draft International Standard and is copyright-protected by ISO. Except as permitted under the applicable laws of the user’s country, neither this ISO draft nor any extract from it may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, photocopying, recording or otherwise, without prior written permission being secured. Requests for permission to reproduce should be addressed to either ISO at the address below or ISO’s member body in the country of the requester.
ISO copyright officeReproduction may be subject to royalty payments or a licensing agreement. Violators may be prosecuted. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)Contents | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xviii
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
5.3.7 Termination of execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7.5 | Derived types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
7.5.1 Derived type concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8 | Attribute declarations and specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8.1 Attributes of procedures and data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
8.6.11 PARAMETER statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
11 Execution control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
11.1 Executable constructs containing blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
12.5.6 OPEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13.9 Character string edit descriptors . . . . . . . . . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
13.11.1 Purpose of namelist formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
14 Program units . . . . . . . . . . . . . . . . . . . . . . . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
14.1 Main program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29315 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
15.1 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29916 Intrinsic procedures and modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
16.1 Classes of intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
16.2.1 General rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
18.10.1 Definition and reference of interoperable procedures . . . . . . . . . . . . . . . . . . . . . 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19 Scope, association, and definition . . . . . . . . . . . . . . . . . . . . . . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
19.1 Scopes, identifiers, and entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509Annex A (informative) Processor dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A.1 Unspecified items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
B.3.12 Specific names for intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C.13 Clause 19 notes : Examples of host association (19.5.1.4) . . . . . . . . . . . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
17.3 IEEE_EXCEPTIONS module procedure summary . . . . . . . . . . . . . . . . . . . . . . . 451
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)Foreword | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commis-
sion) form the specialized system for worldwide standardization. National bodies that are members of ISO or2 International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2. 3 The main task of the joint technical committee is to prepare International Standards. Draft International Stand-
ards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an4 Attention is drawn to the possibility that some of the elements of this document may be the subject of patent
rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights.5 ISO/IEC 1539-1 was prepared by Joint Technical Committee ISO/IEC JTC 1, Information technology, Subcom-
mittee SC 22, Programming languages, their environments and system software interfaces.6 This fourth edition cancels and replaces the third edition (ISO/IEC 1539-1:2010), which has been technic-
ally revised. It also incorporates the Technical Corrigenda ISO/IEC 1539-1:2010/Cor. 1:2012, ISO/IEC 1539-7 ISO/IEC 1539 consists of the following parts, under the general title Information technology — Programming
languages — Fortran:8 — Part 1: Base language 9 — Part 2: Varying length character strings
⃝c ISO/IEC 2017 – All rights reserved xvii1 This document comprises the specification of the base Fortran language, informally known as Fortran 2018.
With the limitations noted in 4.3.3, the syntax and semantics of Fortran 2008 are contained entirely within2 Fortran 2018 contains several extensions to Fortran 2008; these are listed below.
• Data declaration:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)requirement, except for RANDOM_SEED. Specific names for intrinsic functions are now deemed obsoles- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cent. All standard procedures in the intrinsic module ISO_C_BINDING, other than C_F_POINTER, are now pure. The arguments to the intrinsic function SIGN can be of different kind. Nonpolymorphic pointer arguments to the intrinsic functions EXTENDS_TYPE_OF and SAME_TYPE_AS need not have defined pointer association status. The effects of invoking the intrinsic procedures COMMAND_ARGUMENT_- COUNT, GET_COMMAND, and GET_COMMAND_ARGUMENT, on images other than image one, are no longer processor dependent. Access to error messages from the intrinsic subroutines GET_COMMAND, GET_COMMAND_ARGUMENT, and GET_ENVIRONMENT_VARIABLE is provided by an optional ERRMSG argument. The result of NORM2 for a zero-sized array argument has been clarified. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
• Program units and procedures: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The IMPORT statement can appear in a contained subprogram or BLOCK construct, and can restrict• Features previously described by ISO/IEC TS 29113:2012: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A dummy data object can assume its rank from its effective argument. A dummy data object can assume• Changes to the intrinsic modules IEEE_ARITHMETIC, IEEE_EXCEPTIONS, and IEEE_FEATURES | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for conformance with ISO/IEC/IEEE 60559:2011:• Features previously described by ISO/IEC TS 18508:2015: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The CRITICAL statement has optional ERRMSG= and STAT= specifiers. The intrinsic subroutines⃝ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)3 This document is organized in 19 clauses, dealing with 8 conceptual areas. These 8 areas, and the clauses in | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
which they are treated, are:4 It also contains the following nonnormative material: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Processor dependencies Annex A | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)Information technology — Programming languages — | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fortran — Part 1: Base language 1 Scope | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 This document specifies the form and establishes the interpretation of programs expressed in the base Fortran | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
language. The purpose of this document is to promote portability, reliability, maintainability, and efficient2 This document specifies | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
• the forms that a program written in the Fortran language may take,3 Except where stated otherwise, requirements and prohibitions specified by this document apply to programs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rather than processors.4 This document does not specify | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
• the mechanism by which programs are transformed for use on computing systems, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)3.9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
assumed-type declared with a TYPE(*) type specifier (7.3.2) 3.10 attribute property of an entity that determines its uses (8.1) 3.11 automatic data object nondummy data object with a type parameter or array bound that depends on the value of a specification-expr that is not a constant expression (8.3) 3.12 base object ⟨data-ref ⟩ object designated by the leftmost part-name (9.4.2) 3.13 binding type-bound procedure or final subroutine (7.5.5) 3.14 binding name name given to a specific or generic type-bound procedure in the type definition (7.5.5) 3.15 binding label default character value specifying the name by which a global entity with the BIND attribute is known to the companion processor (18.10.2, 18.9.2) 3.16 block sequence of executable constructs formed by the syntactic class block and which is treated as a unit by the executable constructs described in 11.1 3.17 bound array bound limit of a dimension of an array (8.5.8) 3.18 branch target statement action-stmt, associate-stmt, end-associate-stmt, if-then-stmt, end-if-stmt, select-case-stmt, end-select-stmt, select- rank-stmt, end-select-rank-stmt, select-type-stmt, end-select-type-stmt, do-stmt, end-do-stmt, block-stmt, end- block-stmt, critical-stmt, end-critical-stmt, forall-construct-stmt , where-construct-stmt, end-function-stmt, end-mp- subprogram-stmt, end-program-stmt, or end-subroutine-stmt, whose statement label appears as a label in a GO TO statement, computed GO TO statement, alt-return-spec, END= specifier, EOR= specifier, or ERR= specifier (11.2.1) 3.19 C address value identifying the location of a data object or procedure either defined by the companion processor or which might be accessible to the companion processor
NOTE 3.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.20 C descriptor C structure of type CFI_cdesc_t defined in the source file ISO_Fortran_binding.h (18.4, 18.5) 3.21 character context within a character literal constant (7.4.4) or within a character string edit descriptor (13.3.2) 3.22 characteristics ⟨dummy argument⟩ being a dummy data object, dummy procedure, or an asterisk (alternate return indicator) 3.23 characteristics ⟨dummy data object⟩ properties listed in 15.3.2.2 3.24 characteristics ⟨dummy procedure or dummy procedure pointer⟩ properties listed in 15.3.2.3 3.25 characteristics ⟨function result⟩ properties listed in 15.3.3 3.26 characteristics ⟨procedure⟩ properties listed in 15.3.1 3.27 coarray data entity that has nonzero corank (5.4.7) 3.27.1 established coarray coarray that is accessible using an image-selector (5.4.8) 3.28 cobound bound (limit) of a codimension (8.5.6) 3.29 codimension dimension of the pattern formed by a set of corresponding coarrays (8.5.6) 3.30 coindexed object data object whose designator includes an image-selector (R924, 9.6) 3.31 collating sequence one-to-one mapping from a character set into the nonnegative integers (7.4.4.4) 3.32 common block block of physical storage specified by a COMMON statement (8.10.2) 3.32.1 blank common unnamed common block
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.39 construct entity entity whose identifier has the scope of a construct (19.1, 19.4) 3.40 constant expression expression satisfying the requirements specified in 10.1.12, thus ensuring that its value is constant 3.41 contiguous ⟨array⟩ having array elements in order that are not separated by other data objects, as specified in 8.5.7 3.42 contiguous ⟨multi-part data object⟩ that the parts in order are not separated by other data objects 3.43 corank number of codimensions of a coarray (zero for objects that are not coarrays) (8.5.6) 3.44 cosubscript (R925) scalar integer expression in an image-selector (R924) 3.45 data entity data object, result of the evaluation of an expression, or the result of the execution of a function reference 3.46 data object object constant (7.1.4), variable (9), or subobject of a constant (5.4.3.2.3) 3.47 decimal symbol character that separates the whole and fractional parts in the decimal representation of a real number in a file (13.6) 3.48 declaration specification of attributes for various program entities
NOTE 3.23.49 default initialization mechanism for automatically initializing pointer components to have a defined pointer association status, and nonpointer components to have a particular value (7.5.4.6) 3.50 default-initialized ⟨subcomponent⟩ subject to a default initialization specified in the type definition for that component (7.5.4.6) 3.51 definable capable of definition and permitted to become defined
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)3.52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
defined ⟨data object⟩ has a valid value 3.53 defined ⟨pointer⟩ has a pointer association status of associated or disassociated (19.5.2.2) 3.54 defined assignment assignment defined by a procedure (10.2.1.4, 15.4.3.4.3) 3.55 defined input/output input/output defined by a procedure and accessed via a defined-io-generic-spec (R1509, 12.6.4.8) 3.56 defined operation operation defined by a procedure (10.1.6.1, 15.4.3.4.2) 3.57 definition ⟨data object⟩ process by which the data object becomes defined (19.6.5) 3.58 definition ⟨derived type (7.5.2), enumeration (7.6), or procedure (15.6)⟩ specification of the type, enumeration, or procedure 3.59 descendant ⟨module or submodule⟩ submodule that extends that module or submodule or that extends another descendant thereof (14.2.3) 3.60 designator name followed by zero or more component selectors, complex part selectors, array section selectors, array element selectors, image selectors, and substring selectors (9.1) 3.60.1 complex part designator designator that designates the real or imaginary part of a complex data object, independently of the other part (9.4.4) 3.60.2 object designator data object designator designator for a data object
NOTE 3.33.60.3 procedure designator designator for a procedure
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.61 disassociated ⟨pointer association⟩ pointer association status of not being associated with any target and not being undefined (19.5.2.2) 3.62 disassociated ⟨pointer⟩ has a pointer association status of disassociated 3.63 dummy argument entity whose identifier appears in a dummy argument list (R1536) in a FUNCTION, SUBROUTINE, ENTRY, or statement function statement, or whose name can be used as an argument keyword in a reference to an intrinsic procedure or a procedure in an intrinsic module 3.63.1 dummy data object dummy argument that is a data object 3.63.2 dummy function dummy procedure that is a function 3.64 effective argument entity that is argument-associated with a dummy argument (15.5.2.3) 3.65 effective item scalar object resulting from the application of the rules in 12.6.3 to an input/output list 3.66 elemental independent scalar application of an action or operation to elements of an array or corresponding elements of a set of conformable arrays and scalars, or possessing the capability of elemental operation
NOTE 3.4Combination of scalar and array operands or arguments combine the scalar operand(s) with each element
3.66.1 elemental assignment assignment that operates elementally 3.66.2 elemental operation operation that operates elementally 3.66.3 elemental operator operator in an elemental operation 3.66.4 elemental procedure elemental intrinsic procedure or procedure defined by an elemental subprogram (15.8)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)3.66.5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elemental reference reference to an elemental procedure with at least one array actual argument 3.66.6 elemental subprogram subprogram with the ELEMENTAL prefix (15.8.1) 3.67 END statement
end-block-data-stmt, end-function-stmt, end-module-stmt, end-mp-subprogram-stmt, end-program-stmt,end-submodule-stmt, or end-subroutine-stmt 3.68 explicit initialization initialization of a data object by a specification statement (8.4, 8.6.7) 3.69 extent number of elements in a single dimension of an array 3.70 external file file that exists in a medium external to the program (12.3) 3.71 external unit external input/output unit entity that can be connected to an external file (12.5.3, 12.5.4) 3.72 file storage unit unit of storage in a stream file or an unformatted record file (12.3.5) 3.73 final subroutine subroutine whose name appears in a FINAL statement (7.5.6) in a type definition, and which can be automatically invoked by the processor when an object of that type is finalized (7.5.6.2) 3.74 finalizable ⟨type⟩ has a final subroutine or a nonpointer nonallocatable component of finalizable type 3.75 finalizable ⟨nonpointer data entity⟩ of finalizable type 3.76 finalization process of calling final subroutines when one of the events listed in 7.5.6.3 occurs 3.77 function procedure that is invoked by an expression 3.78 function result entity that returns the value of a function (15.6.2.2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.79 generic identifier lexical token sequence that identifies a generic set of procedures, intrinsic operations, and/or intrinsic assignments (15.4.3.4) 3.80 host instance ⟨internal procedure, or dummy procedure or procedure pointer associated with an internal procedure⟩ instance of the host procedure that supplies the host environment of the internal procedure (15.6.2.4) 3.81 host scoping unit host scoping unit immediately surrounding another scoping unit, or the scoping unit extended by a submodule 3.82 IEEE infinity ISO/IEC/IEEE 60559:2011 conformant infinite floating-point value 3.83 IEEE NaN ISO/IEC/IEEE 60559:2011 conformant floating-point datum that does not represent a number 3.84 image instance of a Fortran program (5.3.4) 3.84.1 active image image that has not failed or stopped (5.3.6) 3.84.2 failed image image that has not initiated termination but which has ceased to participate in program execution (5.3.6) 3.84.3 stopped image image that has initiated normal termination (5.3.6) 3.85 image index integer value identifying an image within a team 3.86 image control statement statement that affects the execution ordering between images (11.6) 3.87 inclusive scope nonblock scoping unit plus every block scoping unit whose host is that scoping unit or that is nested within such a block scoping unit
NOTE 3.5That is, inclusive scope is the scope as if BLOCK constructs were not scoping units.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.93 intrinsic type, procedure, module, assignment, operator, or input/output operation defined in this document and accessible without further definition or specification, or a procedure or module provided by a processor but not defined in this document 3.93.1 standard intrinsic ⟨procedure or module⟩ defined in this document (16) 3.93.2 nonstandard intrinsic ⟨procedure or module⟩ provided by a processor but not defined in this document 3.94 internal file character variable that is connected to an internal unit (12.4) 3.95 internal unit input/output unit that is connected to an internal file (12.5.4) 3.96 ISO 10646 character character whose representation method corresponds to UCS-4 in ISO/IEC 10646 3.97 keyword statement keyword, argument keyword, type parameter keyword, or component keyword 3.97.1 argument keyword word that identifies the corresponding dummy argument in an actual argument list (15.5.2.1) 3.97.2 component keyword word that identifies a component in a structure constructor (7.5.10) 3.97.3 statement keyword word that is part of the syntax of a statement (5.5.2) 3.97.4 type parameter keyword word that identifies a type parameter in a type parameter list 3.98 lexical token keyword, name, literal constant other than a complex literal constant, operator, label, delimiter, comma, =, =>, :, ::, ;, or % (6.2) 3.99 line sequence of zero or more characters 3.100 main program program unit that is not a subprogram, module, submodule, or block data program unit (14.1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.111 preconnected ⟨file or unit⟩ connected at the beginning of execution of the program (12.5.5) 3.112 procedure entity encapsulating an arbitrary sequence of actions that can be invoked directly during program execution 3.112.1 dummy procedure procedure that is a dummy argument (15.2.2.3) 3.112.2 external procedure procedure defined by an external subprogram (R503) or by means other than Fortran (15.6.3) 3.112.3 internal procedure procedure defined by an internal subprogram (R512) 3.112.4 module procedure procedure defined by a module subprogram, or a procedure provided by an intrinsic module (R1408) 3.112.5 pure procedure procedure declared or defined to be pure (15.7) 3.112.6 type-bound procedure procedure that is bound to a derived type and referenced via an object of that type (7.5.5) 3.113 processor combination of a computing system and mechanism by which programs are transformed for use on that computing system 3.114 processor dependent not completely specified in this document, having methods and semantics determined by the processor 3.115 program set of Fortran program units and entities defined by means other than Fortran that includes exactly one main program 3.116 program unit main program, external subprogram, module, submodule, or block data program unit (5.2.1) 3.117 rank number of array dimensions of a data entity (zero for a scalar entity) 3.118 record sequence of values or characters in a file (12.2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.126.1 character sequence type sequence type with no allocatable or pointer components, and whose components are all default character or of another character sequence type 3.126.2 numeric sequence type sequence type with no allocatable or pointer components, and whose components are all default complex, default integer, default logical, default real, double precision real, or of another numeric sequence type 3.127 shape array dimensionality of a data entity, represented as a rank-one array whose size is the rank of the data entity and whose elements are the extents of the data entity
NOTE 3.63.128 simply contiguous ⟨array designator or variable⟩ satisfying the conditions specified in 9.5.4
NOTE 3.73.129 size ⟨array⟩ total number of elements in the array 3.130 specification expression expression satisfying the requirements specified in 10.1.11, thus being suitable for use in specifications 3.131 specific name name that is not a generic name 3.132 standard-conforming program program that uses only those forms and relationships described in, and has an interpretation according to, this document 3.133 statement sequence of one or more complete or partial lines satisfying a syntax rule that ends in -stmt (6.3) 3.133.1 executable statement end-function-stmt, end-mp-subprogram-stmt, end-program-stmt, end-subroutine-stmt, or statement that is a mem- ber of the syntactic class executable-construct, excluding those in the block-specification-part of a BLOCK con- struct 3.133.2 nonexecutable statement statement that is not an executable statement
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)3.134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statement entity entity whose identifier has the scope of a statement or part of a statement (19.1, 19.4) 3.135 statement label label unsigned positive number of up to five digits that refers to an individual statement (6.2.5) 3.136 storage sequence contiguous sequence of storage units (19.5.3.2) 3.137 storage unit character storage unit, numeric storage unit, file storage unit, or unspecified storage unit (19.5.3.2) 3.137.1 character storage unit unit of storage that holds a default character value (19.5.3.2) 3.137.2 numeric storage unit unit of storage that holds a default real, default integer, or default logical value (19.5.3.2) 3.137.3 unspecified storage unit unit of storage that holds a value that is not default character, default real, double precision real, default logical, or default complex (19.5.3.2) 3.138 stream file file composed of a sequence of file storage units (12.1) 3.139 structure scalar data object of derived type (7.5) 3.139.1 structure component component of a structure 3.139.2 structure constructor syntax (structure-constructor, 7.5.10) that specifies a structure value or creates such a value 3.140 submodule program unit that extends a module or another submodule (14.2.3) 3.141 subobject portion of data object that can be referenced, and if it is a variable defined, independently of any other portion (9.4.2) 3.142 subprogram function-subprogram (R1529) or subroutine-subprogram (R1534)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.142.1 external subprogram subprogram that is not contained in a main program, module, submodule, or another subprogram 3.142.2 internal subprogram subprogram that is contained in a main program or another subprogram 3.142.3 module subprogram subprogram that is contained in a module or submodule but is not an internal subprogram 3.143 subroutine procedure invoked by a CALL statement, by defined assignment, or by some operations on derived-type entities 3.143.1 atomic subroutine intrinsic subroutine that performs an action on its ATOM argument atomically (16.5) 3.143.2 collective subroutine intrinsic subroutine that performs a calculation on a team of images without requiring synchronization 3.144 target entity that is pointer associated with a pointer (19.5.2.2), entity on the right-hand-side of a pointer assignment statement (R1033), or entity with the TARGET attribute (8.5.17) 3.145 team ordered set of images created by execution of a FORM TEAM statement, or the initial ordered set of all images 3.145.1 current team team specified by the most recently executed CHANGE TEAM statement of a CHANGE TEAM construct that has not completed execution (11.1.5), or initial team if no CHANGE TEAM construct is being executed 3.145.2 initial team team existing at the beginning of program execution, consisting of all images 3.145.3 parent team ⟨team except for initial team⟩ current team at time of execution of the FORM TEAM statement that created the team (11.6.9) 3.145.4 team number −1 which identifies the initial team, or positive integer that identifies a team within its parent team 3.146 transformational function intrinsic function, or function in an intrinsic module, that is neither elemental nor an inquiry function
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
3.147.12.1 assumed type parameter length type parameter that assumes the type parameter value from another entity
NOTE 3.83.147.12.2 deferred type parameter length type parameter whose value can change during execution of a program and whose type-param-value is a colon 3.147.12.3 kind type parameter type parameter whose value is required to be defaulted or given by a constant expression 3.147.12.4 length type parameter type parameter whose value is permitted to be assumed, deferred, or given by a specification expression 3.147.12.5 type parameter inquiry syntax (type-param-inquiry) that is used to inquire the value of a type parameter of a data object (9.4.5) 3.147.12.6 type parameter order ordering of the type parameters of a type (7.5.3.2) used for derived-type specifiers (derived-type-spec, 7.5.9) 3.148 ultimate argument nondummy entity with which a dummy argument is associated via a chain of argument associations (15.5.2.3) 3.149 undefined ⟨data object⟩ does not have a valid value 3.150 undefined ⟨pointer⟩ does not have a pointer association status of associated or disassociated (19.5.2.2) 3.151 unit input/output unit means, specified by an io-unit, for referring to a file (12.5.1) 3.152 unlimited polymorphic able to have any dynamic type during program execution (7.3.2.3) 3.153 unsaved not having the SAVE attribute (8.5.16)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)3.154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
variable data entity that can be defined and redefined during execution of a program 3.154.1 event variable scalar variable of type EVENT_TYPE (16.10.2.10) from the intrinsic module ISO_FORTRAN_ENV 3.154.2 local variable variable in a scoping unit that is not a dummy argument or part thereof, is not a global entity or part thereof, and is not an entity or part of an entity that is accessible outside that scoping unit 3.154.3 lock variable scalar variable of type LOCK_TYPE (16.10.2.19) from the intrinsic module ISO_FORTRAN_ENV 3.154.4 team variable scalar variable of type TEAM_TYPE (16.10.2.32) from the intrinsic module ISO_FORTRAN_ENV 3.155 vector subscript section-subscript that is an array (9.5.3.3.2) 3.156 whole array array component or array name without further qualification (9.5.2)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)or bind-stmt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
or codimension-stmt or contiguous-stmt or dimension-stmt or external-stmt or intent-stmt or intrinsic-stmt or namelist-stmt or optional-stmt or pointer-stmt or protected-stmt or save-stmt or target-stmt or volatile-stmt or value-stmt or common-stmt or equivalence-stmt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
R514 executable-construct | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is action-stmt | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
or associate-construct | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)1 Program units are the fundamental components of a Fortran program. A program unit is a main program, an | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
external subprogram, a module, a submodule, or a block data program unit.2 A subprogram is a function subprogram or a subroutine subprogram. A module contains definitions that can be | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
made accessible to other program units. A submodule is an extension of a module; it may contain the definitions3 Each type of program unit is described in Clause 14 or 15. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 A program unit consists of a set of nonoverlapping scoping units.
NOTE 5.2The module or submodule containing a module subprogram is the host scoping unit of the module subpro-
any number (including zero) of external procedures, and any number (including zero) of other entities defined by1 A procedure is either a function or a subroutine. Invocation of a function in an expression causes a value to be
computed which is then used in evaluating the expression.2 A procedure that is not pure might change the program state by changing the value of accessible data objects or
procedure pointers.3 Procedures are described further in Clause 15.
38 ⃝c ISO/IEC 2017 – All rights reserved1 A module contains (or accesses from other modules) definitions that can be made accessible to other program units.
These definitions include data object declarations, type definitions, procedure definitions, and interface blocks.1 A submodule extends a module or another submodule. 2 It may provide definitions (15.6) for procedures whose interfaces are declared (15.4.3.2) in an ancestor module
or submodule. It may also contain declarations and definitions of other entities, which are accessible in its1 Each Fortran statement is classified as either an executable statement or a nonexecutable statement. 2 An executable statement is an instruction to perform or control an action. Thus, the executable statements of a
program unit determine the behavior of the program unit.3 Nonexecutable statements are used to configure the program environment in which actions take place.
5.3.2 Statement order | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statements statements Derived-type definitions,
FORMAT | interface blocks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and PARAMETER type declaration statements, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statements procedure declarations, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
specification statements,and statement function statements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
statements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
constructs | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CONTAINS statement | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 The syntax rules of subclause 5.1 specify the statement order within program units and subprograms. These | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rules are illustrated in Table 5.1 and Table 5.2. Table 5.1 shows the ordering rules for statements and applies1 Each program unit, module subprogram, and internal subprogram shall have exactly one END statement. The | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
end-program-stmt, end-function-stmt, end-subroutine-stmt, and end-mp-subprogram-stmt statements are execut-2 The end-module-stmt, end-submodule-stmt, and end-block-data-stmt statements are nonexecutable. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5.3.4 Program execution1 Execution of a program consists of the asynchronous execution of a fixed number (which may be one) of its images. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Each image has its own execution state, floating-point status (17.7), and set of data objects, input/output units,2 A team is an ordered set of images that is either the initial team, consisting of all images, or a subset of a parent | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
team formed by execution of a FORM TEAM statement. The initial team has no parent; every other team has a3 During execution, each image has a current team, which is only changed by execution of CHANGE TEAM | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and END TEAM statements. Image indices, and thus coindexing of variable names with an image-selector, are1 Following the creation of a fixed number of images, execution begins on each image. Image execution is a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sequence, in time, of actions. Actions take place during execution of the statement that performs them (except2 If the program contains a Fortran main program, each image begins execution with the first executable construct | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
of the main program. The execution of a main program or subprogram involves execution of the executable1 There are three image execution states: active, stopped, and failed. An image that has initiated normal termin- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ation of execution is a stopped image. An image that has ceased participating in program execution but has not2 A failed image remains failed for the remainder of the execution of the program. The conditions that cause an | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
image to fail are processor dependent.3 Defining a coindexed object on a failed image has no effect other than defining the stat-variable, if one appears, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with the value STAT_FAILED_IMAGE (16.10.2.26). The value of a reference to a coindexed object on a failed4 When an image fails during the execution of a segment, a data object on a nonfailed image becomes undefined | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if it is not a lock variable or event variable and it might be defined or become undefined by execution of a1 Termination of execution of a program is either normal termination or error termination. Normal termination | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
occurs only when all images initiate normal termination and occurs in three steps: initiation, synchronization,2 Normal termination of execution of an image is initiated when a STOP statement or end-program-stmt is executed. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Normal termination of execution of an image also may be initiated during execution of a procedure defined by a3 Error termination of execution of an image is initiated if an ERROR STOP statement is executed or as specified | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
elsewhere in this document. When error termination on an image has been initiated, the processor should initiate4 If the processor supports the concept of a process exit status, it is recommended that error termination initiated | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
other than by an ERROR STOP statement supplies a processor-dependent nonzero value as the process exit1 A type is a named categorization of data that, together with its type parameters, determines the set of values, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
syntax for denoting these values, and the set of operations that interpret and manipulate the values. This central2 A type is either an intrinsic type or a derived type. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5.4.1.1 Intrinsic type1 The intrinsic types are integer, real, complex, character, and logical. The properties of intrinsic types are described | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
in 7.4.2 All intrinsic types have a kind type parameter called KIND, which determines the representation method for the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
specified type. The intrinsic type character also has a length type parameter called LEN, which determines the1 Derived types may be parameterized. A scalar object of derived type is a structure; assignment of structures | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is defined intrinsically (10.2.1.3), but there are no intrinsic operations for structures. For each derived type, a2 Derived types are described further in 7.5. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5.4.2 Data value1 Each intrinsic type has associated with it a set of values that a datum of that type may take, depending on the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
values of the type parameters. The values for each intrinsic type are described in 7.4. The values that objects of1 A data entity has a type and type parameters; it might have a data value (an exception is an undefined variable). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Every data entity has a rank and is thus either a scalar or an array.2 A data entity that is the result of the execution of a function reference is called the function result. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5.4.3.2 Data object1 A data object is either a constant, variable, or a subobject of a constant. The type and type parameters of a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
named data object may be specified explicitly (8.2) or implicitly (8.7).2 Subobjects are portions of data objects that may be referenced and defined (variables only) independently of the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
other portions.3 These include portions of arrays (array elements and array sections), portions of character strings (substrings), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
portions of complex objects (real and imaginary parts), and portions of structures (components). Subobjects4 The following objects are referenced by a name: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
• a named scalar (a scalar object);5 The following subobjects are referenced by an object designator: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
• an array element (a scalar subobject); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 A variable can have a value or be undefined; during execution of a program it can be defined, redefined, or become | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
undefined.2 A local variable of a module, submodule, main program, subprogram, or BLOCK construct is accessible only in | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
that scoping unit or construct and in any contained scoping units and constructs.1 A constant is either a named constant or a literal constant. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 Named constants are defined using the PARAMETER attribute (8.5.13, 8.6.11). The syntax of literal constants
is described in 7.4.1 A subobject of a constant is a portion of a constant. 2 In an object designator for a subobject of a constant, the portion referenced may depend on the value of a variable.
NOTE 5.9
1 An expression (10.1) produces a data entity when evaluated. An expression represents either a data object
reference or a computation; it is formed from operands, operators, and parentheses. The type, type parameters,1 A function reference produces a data entity when the function is executed during expression evaluation. The
type, type parameters, and rank of a function result are determined by the interface of the function (15.3.3). The1 When an object is given a valid value during program execution, it becomes defined. This is often accomplished
by execution of an assignment or input statement. When a variable does not have a predictable value, it is2 Similarly, when a pointer is associated with a target or nullified, its pointer association status becomes defined.
When the association status of a pointer is not predictable, its pointer association status is undefined.3 Clause 19 describes the ways in which variables become defined and undefined and the association status of
pointers becomes defined and undefined.1 A data object is referenced when its value is required during execution. A procedure is referenced when it is
executed.2 The appearance of a data object designator or procedure designator as an actual argument does not constitute
a reference to that data object or procedure unless such a reference is necessary to complete the specification of1 An array may have up to fifteen dimensions minus its corank, and any extent in any dimension. The size of an
array is the total number of elements, which is equal to the product of the extents. An array may have zero2 Any intrinsic operation defined for scalar objects may be applied to conformable objects. Such operations are
performed elementally to produce a resultant array conformable with the array operands. If an elemental operation3 A rank-one array may be constructed from scalars and other arrays and may be reshaped into any allowable array
shape (7.8).4 Arrays may be of any type and are described further in 9.5.
5.4.7 Coarray1 A coarray is a data entity that has nonzero corank; it can be directly referenced or defined by other images. It
may be a scalar or an array.2 For each coarray on an image, there is a corresponding coarray with the same type, type parameters, and bounds
on every other image of a team in which it is established (5.4.8).3 The set of corresponding coarrays on all images in a team is arranged in a rectangular pattern. The dimensions of
this pattern are the codimensions; the number of codimensions is the corank. The bounds for each codimension4 A coarray on any image can be accessed directly by using cosubscripts. On its own image, a coarray can also be
accessed without use of cosubscripts.5 A subobject of a coarray is a coarray if it does not have any cosubscripts, vector subscripts, allocatable component
selection, or pointer component selection.6 For a coindexed object, its cosubscript list determines the image index (9.6) in the same way that a subscript list
determines the subscript order value for an array element (9.5.3.2).7 Intrinsic procedures are provided for mapping between an image index and a list of cosubscripts.
NOTE 5.11The mechanism for an image to reference and define a coarray on another image might vary according
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)
NOTE 5.12Except in contexts where coindexed objects are disallowed, accessing a coarray on its own image by using
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 A nonallocatable coarray with the SAVE attribute is established in the initial team. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 An allocated allocatable coarray is established in the team in which it was allocated. An unallocated allocatable
coarray is not established.3 A coarray that is an associating entity in a coarray-association of a CHANGE TEAM statement is established
in the team of its CHANGE TEAM construct.4 A nonallocatable coarray that is an associating entity in an ASSOCIATE, SELECT RANK, or SELECT TYPE
construct is established in the team in which the ASSOCIATE, SELECT RANK, or SELECT TYPE statement5 A nonallocatable coarray that is a dummy argument or host associated with a dummy argument is established
in the team in which the procedure was invoked. A coarray dummy argument is not established in any ancestor1 A pointer has an association status which is either associated, disassociated, or undefined (19.5.2.2). 2 A pointer that is not associated shall not be referenced or defined. 3 If a data pointer is an array, the rank is declared, but the bounds are determined when it is associated with a
target.1 The allocation status of an allocatable variable is either allocated or unallocated. An allocatable variable becomes
allocated as described in 9.7.1.3. It becomes unallocated as described in 9.7.3.2.2 An unallocated allocatable variable shall not be referenced or defined. 3 If an allocatable variable is an array, the rank is declared, but the bounds are determined when it is allocated. If
an allocatable variable is a coarray, the corank is declared, but the cobounds are determined when it is allocated.1 Many of the facilities of this document make no assumptions about the physical storage characteristics of data
objects. However, program units that include storage association dependent features shall observe the storage1 A name is used to identify a program constituent, such as a program unit, named variable, named constant,
dummy argument, or derived type.2 A designator is used to identify a program constituent or a part thereof.
5.5.2 Statement keyword1 A statement keyword is not a reserved word; that is, a name with the same spelling is allowed. In the syntax
rules, such keywords appear literally. In descriptive text, this meaning is denoted by the term “keyword” without1 Other keywords denote names that identify items in a list. In this case, items are identified by a preceding
keyword= rather than their position within the list.2 An argument keyword is the name of a dummy argument in the interface for the procedure being referenced, and
may appear in an actual argument list. A type parameter keyword is the name of a type parameter in the type1 Name association (19.5.1) permits an entity to be identified by different names in the same scoping unit or by
the same name or different names in different scoping units.2 Pointer association (19.5.2) between a pointer and a target allows the target to be denoted by the pointer. 3 Storage association (19.5.3) causes different entities to use the same storage. 4 Inheritance association (19.5.4) occurs between components of the parent component and components inherited
by type extension.1 All intrinsic types, procedures, assignments, and operators may be used in any scoping unit without further
definition or specification. Intrinsic modules (16.10, 17, 18.2) may be accessed by use association.1 This document specifies a number of intrinsic operators (e.g., the arithmetic operators +, –, *, /, and ** with
numeric operands and the logical operators .AND., .OR., etc. with logical operands). Additional operators may1 A processor has one or more companion processors. A companion processor may be a mechanism that references
and defines such entities by a means other than Fortran (15.6.3), it may be the Fortran processor itself, or it may2 If a procedure is defined by means of a companion processor that is not the Fortran processor itself, this document
refers to the C function that defines the procedure, although the procedure need not be defined by means of theISO/IEC DIS 1539-1:2017 (E)
NOTE 5.14
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)6 Lexical tokens and source form | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 The processor character set is processor dependent. Each character in a processor character set is either a control | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
character or a graphic character. The set of graphic characters is further divided into letters (6.1.2), digits (6.1.3),2 The letters, digits, underscore, and special characters make up the Fortran character set. Together, the set of | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
letters, digits, and underscore define the syntax class alphanumeric-character.3 Except for the currency symbol, the graphics used for the characters shall be as given in 6.1.2, 6.1.3, 6.1.4, and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6.1.5. However, the style of any graphic is not specified.1 The twenty-six letters are: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)1 A statement label provides a means of referring to an individual statement. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
R611 label is digit [ digit [ digit [ digit [ digit ] ] ] ]2 If a statement is labeled, the statement shall contain a nonblank character. The same statement label shall not | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
be given to more than one statement in its scope. Leading zeros are not significant in distinguishing between3 Any statement that is not part of another statement, and that is not preceded by a semicolon in fixed form, may begin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with a statement label, but the labels are used only in the following ways.1 A lexical token that is a delimiter is a (, ), /, [, ], (/, or /). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
52 ⃝c ISO/IEC 2017 – All rights reserved1 A Fortran program unit is a sequence of one or more lines, organized as Fortran statements, comments, and | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
INCLUDE lines. A line is a sequence of zero or more characters. Lines following a program unit END statement2 A comment may contain any character that may occur in any character context. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 There are two source forms. Subclause 6.3.2 applies only to free form source. Subclause 6.3.3 applies only to fixed source
form. Free form and fixed form shall not be mixed in the same program unit. The means for specifying the source form of a program1 In free source form there are no restrictions on where a statement (or portion of a statement) may appear within
a line. A line may contain zero characters. If a line consists entirely of characters of default kind (7.4.4), it may1 In free source form blank characters shall not appear within lexical tokens other than in a character context or in
a format specification. Blanks may be inserted freely between tokens to improve readability; for example, blanks2 A blank shall be used to separate names, constants, or labels from adjacent keywords, names, constants, or labels.
NOTE 6.5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
READ 10
30 DO K=1,3
3 One or more blanks shall be used to separate adjacent keywords except in the following cases, where blanks are
optional:Table 6.2: Adjacent keywords where separating blanks are optional
⃝c ISO/IEC 2017 – All rights reserved 53
ISO/IEC DIS 1539-1:2017 (E)
6.3.2.3 Free form commentary
1 The character “!” initiates a comment except where it appears within a character context. The comment extends
to the end of the line. If the first nonblank character on a line is an “!”, the line is a comment line. Lines1 The character “&” is used to indicate that the statement is continued on the next line that is not a commentcontaining only blanks or containing no characters are also comment lines. Comments may appear anywhere in
a program unit and may precede the first statement of a program unit or follow the last statement of a program
unit. Comments have no effect on the interpretation of the program unit.
NOTE 6.6
This document does not restrict the number of consecutive comment lines.
6.3.2.4 Free form statement continuation
line. Comment lines cannot be continued; an “&” in a comment has no effect. Comments may occur within a2 If a noncharacter context is to be continued, an “&” shall be the last nonblank character on the line, or the lastcontinued statement. When used for continuation, the “&” is not part of the statement. No line shall contain
a single “&” as the only nonblank character or as the only nonblank character before an “!” that initiates a
comment.
nonblank character before an “!”. There shall be a later line that is not a comment; the statement is continued3 If a lexical token is split across the end of a line, the first nonblank character on the first following noncommenton the next such line. If the first nonblank character on that line is an “&”, the statement continues at the next
character position following that “&”; otherwise, it continues with the first character position of that line.
line shall be an “&” immediately followed by the successive characters of the split token.4 If a character context is to be continued, an “&” shall be the last nonblank character on the line. There shall be
a later line that is not a comment; an “&” shall be the first nonblank character on the next such line and the1 If a statement is not continued, a comment or the end of the line terminates the statement.statement continues with the next character following that “&”.
6.3.2.5 Free form statement termination
2 A statement may alternatively be terminated by a “;” character that appears other than in a character context
or in a comment. The “;” is not part of the statement. After a “;” terminator, another statement may appear1 A label may precede any statement not forming part of another statement.on the same line, or begin on that line and be continued. A sequence consisting only of zero or more blanks and
one or more “;” terminators, in any order, is equivalent to a single “;” terminator.
6.3.2.6 Free form statements
NOTE 6.72 A statement shall not have more than 255 continuation lines.No Fortran statement begins with a digit.
6.3.3 Fixed source form1 In fixed source form, there are restrictions on where a statement may appear within a line. If a source line contains only characters6.3.3.1 General
of default kind, it shall contain exactly 72 characters; otherwise, its maximum number of characters is processor dependent.2 Except in a character context, blanks are insignificant and may be used freely throughout the program.
54 ⃝1 The character “!” initiates a comment except where it appears within a character context or in character position 6. The commentc ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
6.3.3.2 Fixed form commentary
extends to the end of the line. If the first nonblank character on a line is an “!” in any character position other than character1 Except within commentary, character position 6 is used to indicate continuation. If character position 6 contains a blank or zero, theposition 6, the line is a comment line. Lines beginning with a “C” or “*” in character position 1 and lines containing only blanks are
also comment lines. Comments may appear anywhere in a program unit and may precede the first statement of the program unit or
follow the last statement of a program unit. Comments have no effect on the interpretation of the program unit.
NOTE 6.8
This document does not restrict the number of consecutive comment lines.
6.3.3.3 Fixed form statement continuation
line is the initial line of a new statement, which begins in character position 7. If character position 6 contains any character other2 Comment lines cannot be continued. Comment lines may occur within a continued statement.than blank or zero, character positions 7–72 of the line constitute a continuation of the preceding noncomment line.
NOTE 6.9
An “!” or “;” in character position 6 is interpreted as a continuation indicator unless it appears within commentary indicated
by a “C” or “*” in character position 1 or by an “!” in character positions 1–5.
6.3.3.4 Fixed form statement termination1 If a statement is not continued, a comment or the end of the line terminates the statement.
2 A statement may alternatively be terminated by a “;” character that appears other than in a character context, in a comment, or in
character position 6. The “;” is not part of the statement. After a “;” terminator, another statement may begin on the same line, or1 A label, if it appears, shall occur in character positions 1 through 5 of the first line of a statement; otherwise, positions 1 throughbegin on that line and be continued. A “;” shall not appear as the first nonblank character on an initial line. A sequence consisting
only of zero or more blanks and one or more “;” terminators, in any order, is equivalent to a single “;” terminator.
6.3.3.5 Fixed form statements
5 shall be blank. Blanks may appear anywhere within a label. A statement following a “;” on the same line shall not be labeled.
Character positions 1 through 5 of any continuation lines shall be blank. A statement shall not have more than 255 continuation
lines. The program unit END statement shall not be continued. A statement whose initial line appears to be a program unit END
statement shall not be continued.
6.4 Including source text 1 Additional text may be incorporated into the source text of a program unit during processing. This is accomplished
with the INCLUDE line, which has the form2 The char-literal-constant shall not have a kind type parameter value that is a named-constant.INCLUDE char-literal-constant
3 An INCLUDE line is not a Fortran statement.
4 An INCLUDE line shall appear on a single source line where a statement may appear; it shall be the only
nonblank text on this line other than an optional trailing comment. Thus, a statement label is not allowed.5 The effect of the INCLUDE line is as if the referenced source text physically replaced the INCLUDE line prior
to program processing. Included text may contain any source text, including additional INCLUDE lines; such6 When an INCLUDE line is resolved, the first included statement line shall not be a continuation line and the lastnested INCLUDE lines are similarly replaced with the specified source text. The maximum depth of nesting of
any nested INCLUDE lines is processor dependent. Inclusion of the source text referenced by an INCLUDE line
shall not, at any level of nesting, result in inclusion of the same source text.
⃝c ISO/IEC 2017 – All rights reserved 55
ISO/IEC DIS 1539-1:2017 (E)
included statement line shall not be continued.7 The interpretation of char-literal-constant is processor dependent. An example of a possible valid interpretation
is that char-literal-constant is the name of a file that contains the source text to be included.1 Fortran provides an abstract means whereby data can be categorized without relying on a particular physicalNOTE 6.10
In some circumstances, for example where source code is maintained in an INCLUDE file for use in programs whose source
form might be either fixed or free, observing the following rules allows the code to be used with either source form.
• Confine statement labels to character positions 1 to 5 and statements to character positions 7 to 72.
• Treat blanks as being significant.
• Use only the exclamation mark (!) to indicate a comment, but do not start the comment in character position 6.
• For continued statements, place an ampersand (&) in both character position 73 of a continued line and character
position 6 of a continuation line.
56 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
7 Types
7.1 Characteristics of types
7.1.1 The concept of type
representation. This abstract means is the concept of type.2 A type has a name, a set of valid values, a means to denote such values (constants), and a set of operations to
manipulate the values.1 A type is either an intrinsic type or a derived type.7.1.2 Type classification
2 This document defines five intrinsic types: integer, real, complex, character, and logical.
3 A derived type is one that is defined by a derived-type definition (7.5.2) or by an intrinsic module. It shall be
used only where it is accessible (7.5.2.2). An intrinsic type is always accessible.1 For each type, there is a set of valid values. The set of valid values for logical is completely determined by this7.1.3 Set of values
document. The sets of valid values for integer, character, and real are processor dependent. The set of valid1 The syntax for denoting a value indicates the type, type parameters, and the particular value.values for complex consists of the set of all the combinations of the values of the real and imaginary parts. The
set of valid values for a derived type is as defined in 7.5.8.
7.1.4 Constants
2 The syntax for literal constants of each intrinsic type is specified in 7.4.
3 A structure constructor (7.5.10) that is a constant expression (10.1.12) denotes a scalar constant value of derived
type. An array constructor (7.8) that is a constant expression denotes a constant array value of intrinsic or4 A constant value can be named (8.5.13, 8.6.11).derived type.
7.1.5 Operations1 For each of the intrinsic types, a set of operations and corresponding operators is defined intrinsically. These are
described in Clause 10. The intrinsic set can be augmented with operations and operators defined by functions2 For derived types, there are no intrinsic operations. Operations on derived types can be defined by the programwith the OPERATOR interface (15.4.3.2). Operator definitions are described in Clauses 10 and 15.
(7.5.11).1 A type might be parameterized. In this case, the set of values, the syntax for denoting the values, and the set of⃝c ISO/IEC 2017 – All rights reserved 57
ISO/IEC DIS 1539-1:2017 (E)
7.2 Type parameters
operations on the values of the type depend on the values of the parameters.2 A type parameter is either a kind type parameter or a length type parameter. All type parameters are of type
integer. A kind type parameter participates in generic resolution (15.5.5.2), but a length type parameter does3 Each intrinsic type has a kind type parameter named KIND. The intrinsic character type has a length typenot.
parameter named LEN. A derived type can have type parameters.4 A type parameter value may be specified by a type specification (7.4, 7.5.9).
R701 type-param-value is scalar-int-expr5 A colon as a type-param-value specifies a deferred type parameter.or *
or :
C701 (R701) The type-param-value for a kind type parameter shall be a constant expression.
C702 (R701) A colon shall not be used as a type-param-value except in the declaration of an entity that has
the POINTER or ALLOCATABLE attribute.
6 The values of the deferred type parameters of an object are determined by successful execution of an ALLOCATE
statement (9.7.1), execution of an intrinsic assignment statement (10.2.1.3), execution of a pointer assignment7 An asterisk as a type-param-value specifies that a length type parameter is an assumed type parameter. It is usedstatement (10.2.2), or by argument association (15.5.2).
NOTE 7.1
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.
for a dummy argument to assume the type parameter value from the effective argument, for an associate name1 The name of a type serves as a type specifier and may be used to declare objects of that type. A declarationin a SELECT TYPE construct to assume the type parameter value from the corresponding selector, and for a
named constant of type character to assume the character length from the constant-expr.
NOTE 7.2
The value of a kind type parameter is always 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.
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 can 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.
7.3 Types, type specifiers, and values
7.3.1 Relationship of types and values to objects
specifies the type of a named object. A data object may be declared explicitly or implicitly. A data object has2 Scalar data of any intrinsic or derived type may be shaped in a rectangular pattern to compose an array of the58 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
attributes in addition to its type. Clause 8 describes the way in which a data object is declared and how its type
and other attributes are specified.
same type and type parameters. An array object has a type and type parameters just as a scalar object does.3 A variable is a data object. The type and type parameters of a variable determine which values that variable
may take. Assignment (10.2) provides one means of changing the value of a variable of any type.4 The type of a variable determines the operations that may be used to manipulate the variable.
7.3.2 Type specifiers and type compatibility1 A type specifier specifies a type and type parameter values. It is either a type-spec or a declaration-type-spec.7.3.2.1 Type specifier syntax
R702 type-spec is intrinsic-type-spec2 An intrinsic-type-spec specifies the named intrinsic type and its type parameter values. A derived-type-specor derived-type-spec
C703 (R702) The derived-type-spec shall not specify an abstract type (7.5.7).
R703 declaration-type-spec is intrinsic-type-spec
or TYPE ( intrinsic-type-spec )
or TYPE ( derived-type-spec )
or CLASS ( derived-type-spec )
or CLASS ( * )
or TYPE ( * )
C704 (R703) In a declaration-type-spec, every type-param-value that is not a colon or an asterisk shall be a
specification-expr.
C705 (R703) In a declaration-type-spec that uses the CLASS keyword, derived-type-spec shall specify an ex-
tensible type (7.5.7).
C706 (R703) TYPE(derived-type-spec) shall not specify an abstract type (7.5.7).
C707 (R702) In TYPE(intrinsic-type-spec) the intrinsic-type-spec shall not end with a comma.
C708 An entity declared with the CLASS keyword shall be a dummy argument or have the ALLOCATABLE
or POINTER attribute.
specifies the named derived type and its type parameter values.1 A TYPE type specifier is used to declare entities that are assumed-type, or of an intrinsic or derived type.NOTE 7.3
A type-spec is used in an array constructor, a SELECT TYPE construct, or an ALLOCATE statement. An
integer-type-spec is used in a DO CONCURRENT or FORALL statement. Elsewhere, a declaration-type-spec
is used.
7.3.2.2 TYPE type specifier
2 A derived-type-spec in a TYPE type specifier in a type declaration statement shall specify a previously defined
derived type. If the data entity is a function result, the derived type may be specified in the FUNCTION3 An entity that is declared using the TYPE(*) type specifier is assumed-type and is an unlimited polymorphicstatement provided the derived type is defined within the body of the function or is accessible there by use or
host association. If the derived type is specified in the FUNCTION statement and is defined within the body
of the function, it is as if the function result were declared with that derived type immediately following the
derived-type-def of the specified derived type.
⃝c ISO/IEC 2017 – All rights reserved 59
ISO/IEC DIS 1539-1:2017 (E)
entity. It is not declared to have a type, and is not considered to have the same declared type as any other entity,1 The CLASS type specifier is used to declare polymorphic entities. A polymorphic entity is a data entity that isincluding another unlimited polymorphic entity. Its dynamic type and type parameters are assumed from its
effective argument.
C709 An assumed-type entity shall be a dummy data object that does not have the ALLOCATABLE, CODI-
MENSION, INTENT (OUT), POINTER, or VALUE attribute and is not an explicit-shape array.
C710 An assumed-type variable name shall not appear in a designator or expression except as an actual
argument corresponding to a dummy argument that is assumed-type, or as the first argument to the
intrinsic function IS_CONTIGUOUS, LBOUND, PRESENT, RANK, SHAPE, SIZE, or UBOUND, or
the function C_LOC from the intrinsic module ISO_C_BINDING.
C711 An assumed-type actual argument that corresponds to an assumed-rank dummy argument shall be
assumed-shape or assumed-rank.
7.3.2.3 CLASS type specifier
able to be of differing dynamic types during program execution.2 A derived-type-spec in a CLASS type specifier in a type declaration statement shall specify a previously defined
derived type. If the data entity is a function result, the derived type may be specified in the FUNCTION3 The declared type of a polymorphic entity is the specified type if the CLASS type specifier contains a type name.statement provided the derived type is defined within the body of the function or is accessible there by use or
host association. If the derived type is specified in the FUNCTION statement and is defined within the body
of the function, it is as if the function result were declared with that derived type immediately following its
derived-type-def .
4 An entity declared with the CLASS(*) specifier is an unlimited polymorphic entity. It is not declared to have
a type, and is not considered to have the same declared type as any other entity, including another unlimited5 A nonpolymorphic entity is type compatible only with entities of the same declared type. A polymorphic entitypolymorphic entity.
that is not an unlimited polymorphic entity is type compatible with entities of the same declared type or any ofits extensions. Even though an unlimited polymorphic entity is not considered to have a declared type, it is type
compatible with all entities. An entity is type compatible with a type if it is type compatible with entities of that
type.
NOTE 7.4
Given
...
TYPE,EXTENDS(TROOT) :: TEXTENDED
...
CLASS(TROOT) A
CLASS(TEXTENDED) B
...
A is type compatible with B but B is not type compatible with A.
6 A polymorphic allocatable object may be allocated to be of any type with which it is type compatible. A
polymorphic pointer or dummy argument may, during program execution, be associated with objects with which7 The dynamic type of an allocated allocatable polymorphic object is the type with which it was allocated. Theit is type compatible.
60 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
dynamic type of an associated polymorphic pointer is the dynamic type of its target. The dynamic type of a1 Each intrinsic type is classified as a numeric type or a nonnumeric type. The numeric types are integer, real, andnonallocatable nonpointer polymorphic dummy argument is the dynamic type of its effective argument. The
dynamic type of an unallocated allocatable object or a disassociated pointer is the same as its declared type. The
dynamic type of an entity identified by an associate name (11.1.3) is the dynamic type of the selector with which
it is associated. The dynamic type of an object that is not polymorphic is its declared type.
7.4 Intrinsic types
7.4.1 Classification and specification
complex. The nonnumeric intrinsic types are character and logical.2 Each intrinsic type has a kind type parameter named KIND; this type parameter is of type integer with default
kind.1 Intrinsic numeric operations are defined as specified in 10.1.5.2.1 for the numeric intrinsic types. RelationalR704 intrinsic-type-spec is integer-type-spec
or REAL [ kind-selector ]
or DOUBLE PRECISION
or COMPLEX [ kind-selector ]
or CHARACTER [ char-selector ]
or LOGICAL [ kind-selector ]
R705 integer-type-spec is INTEGER [ kind-selector ]
R706 kind-selector is ( [ KIND = ] scalar-int-constant-expr )
C712 (R706) The value of scalar-int-constant-expr shall be nonnegative and shall specify a representation
method that exists on the processor.
7.4.2 Intrinsic operations on intrinsic types
intrinsic operations are defined as specified in 10.1.5.5 for numeric and character intrinsic types. The intrinsic1 The set of values for the integer type is a subset of the mathematical integers. The processor shall provide one orconcatenation operation is defined as specified in 10.1.5.3 for the character type. Logical intrinsic operations are
defined as specified in 10.1.5.4 for the logical type.
7.4.3 Numeric intrinsic types
7.4.3.1 Integer type
more representation methods that define sets of values for data of type integer. Each such method is characterized2 The processor shall provide at least one representation method with a decimal exponent range greater than orby a value for the kind type parameter KIND. The kind type parameter of a representation method is returned
by the intrinsic function KIND (16.9.108). The decimal exponent range of a representation method is returned
by the intrinsic function RANGE (16.9.158). The intrinsic function SELECTED_INT_KIND (16.9.169) returns
a kind value based on a specified decimal exponent range requirement. The integer type includes a zero value,
which is considered to be neither negative nor positive. The value of a signed integer zero is the same as the
value of an unsigned integer zero.
equal to 18.3 The type specifier for the integer type uses the keyword INTEGER.
⃝c ISO/IEC 2017 – All rights reserved 614 The keyword INTEGER with no kind-selector specifies type integer with default kind; the kind type parameter
ISO/IEC DIS 1539-1:2017 (E)
value is equal to KIND (0). The decimal exponent range of default integer shall be at least 5.5 Any integer value may be represented as a signed-int-literal-constant.
R707 signed-int-literal-constant is [ sign ] int-literal-constant6 The optional kind type parameter following digit-string specifies the kind type parameter of the integer constant;R708 int-literal-constant is digit-string [ _ kind-param ]
R709 kind-param is digit-string
or scalar-int-constant-name
R710 signed-digit-string is [ sign ] digit-string
R711 digit-string is digit [ digit ] ...
R712 sign is +
or –
C713 (R709) A scalar-int-constant-name shall be a named constant of type integer.
C714 (R709) The value of kind-param shall be nonnegative.
C715 (R708) The value of kind-param shall specify a representation method that exists on the processor.
if it does not appear, the constant is default integer.7 An integer constant is interpreted as a decimal value.
NOTE 7.5Examples of signed integer literal constants are:
473
+56
-101
21_2
21_SHORT
1976354279568241_8
where SHORT is a scalar integer named constant. A program that uses a digit-string as a kind-param is
unlikely to be portable.
7.4.3.2 Real type 1 The real type has values that approximate the mathematical real numbers. The processor shall provide two
or more approximation methods that define sets of values for data of type real. Each such method has a2 The decimal precision, decimal exponent range, and radix of an approximation method are returned by therepresentation method and is characterized by a value for the kind type parameter KIND. The kind type parameter
of an approximation method is returned by the intrinsic function KIND (16.9.108).
intrinsic functions PRECISION (16.9.151), RANGE (16.9.158), and RADIX (16.9.154). The intrinsic function3 The real type includes a zero value. Processors that distinguish between positive and negative zeros shall treatSELECTED_REAL_KIND (16.9.170) returns a kind value based on specified precision, range, and radix re-
quirements.
NOTE 7.6
See C.2.1 for remarks concerning selection of approximation methods.
62 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
them as mathematically equivalent4 The type specifier for the real type uses the keyword REAL. The keyword DOUBLE PRECISION is an alternative• in all intrinsic relational operations, and
• as actual arguments to intrinsic procedures other than those for which it is explicitly specified that negative
zero is distinguished.
NOTE 7.7
On a processor that distinguishes 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.
In order to distinguish between 0.0 and −0.0, a program can use the intrinsic function SIGN. 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.
specifier for one kind of real type.5 If the type keyword REAL is used without a kind type parameter, the real type with default real kind is specified
and the kind value is KIND (0.0). The type specifier DOUBLE PRECISION specifies type real with double6 The decimal precision of double precision real shall be at least 10, and its decimal exponent range shall be atprecision kind; the kind value is KIND (0.0D0). The decimal precision of the double precision real approximation
method shall be greater than that of the default real method.
least 37. It is recommended that the decimal precision of default real be at least 6, and that its decimal exponent7 A real literal constant without a kind type parameter is a default real constant if it is without an exponent partrange be at least 37.
R713 signed-real-literal-constant is [ sign ] real-literal-constant
R714 real-literal-constant is significand [ exponent-letter exponent ] [ _ kind-param ]
or digit-string exponent-letter exponent [ _ kind-param ]
R715 significand is digit-string . [ digit-string ]
or . digit-string
R716 exponent-letter is E
or D
R717 exponent is signed-digit-string
C716 (R714) If both kind-param and exponent-letter appear, exponent-letter shall be E.
C717 (R714) The value of kind-param shall specify an approximation method that exists on the processor.
or has exponent letter E, and is a double precision real constant if it has exponent letter D. A real literal constant8 The exponent represents the power of ten scaling to be applied to the significand or digit string. The meaning ofwritten with a kind type parameter is a real constant with the specified kind type parameter.
these constants is as in decimal scientific notation.9 The significand may be written with more digits than a processor will use to approximate the value of the constant.
⃝c ISO/IEC 2017 – All rights reserved 631 The complex type has values that approximate the mathematical complex numbers. The values of a complex
ISO/IEC DIS 1539-1:2017 (E)
NOTE 7.8
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.
7.4.3.3 Complex type
type are ordered pairs of real values. The first real value is called the real part, and the second real value is called2 Each approximation method used to represent data entities of type real shall be available for both the real andthe imaginary part.
imaginary parts of a data entity of type complex. The (default integer) kind type parameter KIND for a complex3 The type specifier for the complex type uses the keyword COMPLEX. There is no keyword for double precisionentity specifies for both parts the real approximation method characterized by this kind type parameter value.
The kind type parameter of an approximation method is returned by the intrinsic function KIND (16.9.108).
complex. If the type keyword COMPLEX is used without a kind type parameter, the complex type with default4 If the real part and the imaginary part of a complex literal constant are both real, the kind type parameter valuecomplex kind is specified, the kind value is KIND (0.0), and both parts are default real.
R718 complex-literal-constant is ( real-part , imag-part )
R719 real-part is signed-int-literal-constant
or signed-real-literal-constant
or named-constant
R720 imag-part is signed-int-literal-constant
or signed-real-literal-constant
or named-constant
C718 (R718) Each named constant in a complex literal constant shall be of type integer or real.
of the complex literal constant is the kind type parameter value of the part with the greater decimal precision; if5 If both the real and imaginary parts are integer, they are converted to the default real approximation methodthe precisions are the same, it is the kind type parameter value of one of the parts as determined by the processor.
If a part has a kind type parameter value different from that of the complex literal constant, the part is converted
to the approximation method of the complex literal constant.
and the constant is default complex. If only one of the parts is an integer, it is converted to the approximation1 The character type has a set of values composed of character strings. A character string is a sequence of characters,method selected for the part that is real and the kind type parameter value of the complex literal constant is
that of the part that is real.
NOTE 7.9
Examples of complex literal constants are:
64 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 7.9 (cont.)
(1.0, -1.0)
(3, 3.1E6)
(4.0_4, 3.6E7_8)
( 0., PI) ! where PI is a previously declared named real constant.
7.4.4 Character type
7.4.4.1 Character sets
numbered from left to right 1, 2, 3, ... up to the number of characters in the string. The number of characters in2 The processor shall provide one or more representation methods that define sets of values for data of typethe string is called the length of the string. The length is a type parameter; its kind is processor dependent and
its value is greater than or equal to zero.
character. Each such method is characterized by a value for the (default integer) kind type parameter KIND.3 The character set specified in ISO/IEC 646:1991 (International Reference Version) is referred to as the ASCIIThe kind type parameter of a representation method is returned by the intrinsic function KIND (16.9.108). The
intrinsic function SELECTED_CHAR_KIND (16.9.168) returns a kind value based on the name of a character
type. Any character of a particular representation method representable in the processor may occur in a character
string of that representation method.
character set and its corresponding representation method is ASCII character kind. The character set UCS-4 as1 The type specifier for the character type uses the keyword CHARACTER.specified in ISO/IEC 10646 is referred to as the ISO 10646 character set and its corresponding representation
method is the ISO 10646 character kind.
7.4.4.2 Character type specifier
2 If the type keyword CHARACTER is used without a kind type parameter, the character type with default
character kind is specified and the kind value is KIND (’A’).3 The default character kind shall support a character set that includes the characters in the Fortran character
set (6.1). By supplying nondefault character kinds, the processor may support additional character sets. The4 The char-selector in a CHARACTER intrinsic-type-spec and the * char-length in an entity-decl or in a component-characters available in nondefault character kinds are not specified by this document, except that one character
in each nondefault character set shall be designated as a blank character to be used as a padding character.
R721 char-selector is length-selector
or ( LEN = type-param-value ,
KIND = scalar-int-constant-expr )
or ( type-param-value ,
[ KIND = ] scalar-int-constant-expr )
or ( KIND = scalar-int-constant-expr
[ , LEN =type-param-value ] )
R722 length-selector is ( [ LEN = ] type-param-value )
or * char-length [ , ]
R723 char-length is ( type-param-value )
or int-literal-constant
C719 (R721) The value of scalar-int-constant-expr shall be nonnegative and shall specify a representation
method that exists on the processor.
C720 (R723) The int-literal-constant shall not include a kind-param.
⃝c ISO/IEC 2017 – All rights reserved 65
ISO/IEC DIS 1539-1:2017 (E)
C721 (R723) A type-param-value in a char-length shall be a colon, asterisk, or specification-expr.
C722 (R721 R722 R723) A type-param-value of * shall be used only
• to declare a dummy argument,
• to declare a named constant,
• in the type-spec of an ALLOCATE statement wherein each allocate-object is a dummy argument of
type CHARACTER with an assumed character length,
• in the type-spec or derived-type-spec of a type guard statement (11.1.11), or
• in an external function, to declare the character length parameter of the function result.
C723 A function name shall not be declared with an asterisk type-param-value unless it is of type CHARACTER
and is the name of a dummy function or the name of the result of an external function.
C724 A function name declared with an asterisk type-param-value shall not be an array, a pointer, elemental, or pure. A function
name declared with an asterisk type-param-value shall not have the RECURSIVE attribute.
C725 (R722) The optional comma in a length-selector is permitted only in a declaration-type-spec in a type-declaration-stmt.
C726 (R722) The optional comma in a length-selector is permitted only if no double-colon separator appears in the type-
declaration-stmt.
C727 (R721) The length specified for a character statement function or for a statement function dummy argument of type
character shall be a constant expression.
decl of a type definition specify character length. The * char-length in an entity-decl or a component-decl specifies5 If the character length parameter value evaluates to a negative value, the length of character entities declaredan individual length and overrides the length specified in the char-selector, if any. If a * char-length is not specified
in an entity-decl or a component-decl, the length-selector or type-param-value specified in the char-selector is the
character length. If the length is not specified in a char-selector or a * char-length, the length is 1.
is zero. A character length parameter value of : indicates a deferred type parameter (7.2). A char-length type1 The syntax of a character literal constant is given by R724.parameter value of * has the following meanings.
• If used to declare a dummy argument of a procedure, the dummy argument assumes its length from its
effective argument.
• If used to declare a named constant, the length is that of the constant value.
• If used in the type-spec of an ALLOCATE statement, each allocate-object assumes its length from its effective
argument.
• If used in the type-spec of a type guard statement, the associating entity assumes its length from the selector.
• If used to specify the character length parameter of a function result, any scoping unit invoking the function or passing it as
an actual argument shall declare the function name with a character length parameter value other than * or access such a
definition by argument, host, or use association. When the function is invoked, the length of the function result is assumed
from the value of this type parameter.
7.4.4.3 Character literal constant
R724 char-literal-constant is [ kind-param _ ] ’ [ rep-char ] ... ’2 The optional kind type parameter preceding the leading delimiter specifies the kind type parameter of the char-or [ kind-param _ ] " [ rep-char ] ... "
C728 (R724) The value of kind-param shall specify a representation method that exists on the processor.
acter constant; if it does not appear, the constant is default character.3 For the type character with kind kind-param, if it appears, and for default character otherwise, a representable66 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
character, rep-char, is defined as follows.4 The delimiting apostrophes or quotation marks are not part of the value of the character literal constant.• In free source form, it is any graphic character in the processor-dependent character set.
• In fixed source form, it is any character in the processor-dependent character set. A processor may restrict the occurrence of
some or all of the control characters.
5 An apostrophe character within a character constant delimited by apostrophes is represented by two consecutive
apostrophes (without intervening blanks); in this case, the two apostrophes are counted as one character. Sim-6 A zero-length character literal constant is represented by two consecutive apostrophes (without intervening blanks)ilarly, a quotation mark character within a character constant delimited by quotation marks is represented by
two consecutive quotation marks (without intervening blanks) and the two quotation marks are counted as one
character.
or two consecutive quotation marks (without intervening blanks) outside of a character context.1 The processor defines a collating sequence for the character set of each kind of character. The collating sequenceNOTE 7.10
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 7.11
An example of a nondefault character literal constant, where the processor supports the corresponding
character set, is:
NIHONGO_’ ’
where NIHONGO is a named constant whose value is the kind type parameter for Nihongo (Japanese)
characters. This means “Without her, nothing is possible”.
7.4.4.4 Collating sequence
is an isomorphism between the character set and the set of integers {I : 0 ≤ I < N }, where N is the number of2 The collating sequence of the default character kind shall satisfy the following constraints.characters in the set. The intrinsic functions CHAR (16.9.44) and ICHAR (16.9.95) provide conversions between
the characters and the integers according to this mapping.
NOTE 7.12
For example:
ICHAR ( ’X’ )
returns the integer value of the character ’X’ according to the collating sequence of the processor.
• ICHAR (’A’) < ICHAR (’B’) < ... < ICHAR (’Z’) for the twenty-six upper-case letters.
⃝c ISO/IEC 2017 – All rights reserved 67
ISO/IEC DIS 1539-1:2017 (E)
• ICHAR (’0’) < ICHAR (’1’) < ... < ICHAR (’9’) for the ten digits.3 There are no constraints on the location of any other character in the collating sequence, nor is there any specified• ICHAR (’ ’) < ICHAR (’0’) < ICHAR (’9’) < ICHAR (’A’) or
ICHAR (’ ’) < ICHAR (’A’) < ICHAR (’Z’) < ICHAR (’0’).
• ICHAR (’a’) < ICHAR (’b’) < ... < ICHAR (’z’) for the twenty-six lower-case letters.
• ICHAR (’ ’) < ICHAR (’0’) < ICHAR (’9’) < ICHAR (’a’) or
ICHAR (’ ’) < ICHAR (’a’) < ICHAR (’z’) < ICHAR (’0’).
collating sequence relationship between the upper-case and lower-case letters.4 The collating sequence for the ASCII character kind is as specified in ISO/IEC 646:1991 (International Reference
Version); this collating sequence is called the ASCII collating sequence in this document. The collating sequence5 The intrinsic functions LGT, LGE, LLE, and LLT (16.9.114-16.9.117) provide comparisons between strings basedfor the ISO 10646 character kind is as specified in ISO/IEC 10646.
NOTE 7.13
The intrinsic functions ACHAR (16.9.3) and IACHAR (16.9.88) provide conversions between characters
and corresponding integer values according to the ASCII collating sequence.
on the ASCII collating sequence. International portability is guaranteed if the set of characters used is limited1 The logical type has two values, which represent true and false.to the Fortran character set (6.1).
7.4.5 Logical type
2 The processor shall provide one or more representation methods for data of type logical. Each such method
is characterized by a value for the (default integer) kind type parameter KIND. The kind type parameter of a3 The type specifier for the logical type uses the keyword LOGICAL.representation method is returned by the intrinsic function KIND (16.9.108).
4 The keyword LOGICAL with no kind-selector specifies type logical with default kind; the kind type parameter
value is equal to KIND (.FALSE.).5 The optional kind type parameter specifies the kind type parameter of the logical constant; if it does not appear,R725 logical-literal-constant is .TRUE. [ _ kind-param ]
or .FALSE. [ _ kind-param ]
C729 (R725) The value of kind-param shall specify a representation method that exists on the processor.
the constant has the default logical kind.1 Additional types can be derived from the intrinsic types and other derived types. A type definition defines the7.5 Derived types
7.5.1 Derived type concepts
name of the type and the names and attributes of its components and type-bound procedures.2 A derived type can be parameterized by one or more type parameters, each of which is defined to be either a
kind or length type parameter and can have a default value.3 The ultimate components of a derived type are the components that are of intrinsic type or have the ALLOC-
ATABLE or POINTER attribute, plus the ultimate components of the components that are of derived type and4 The direct components of a derived type are the components of that type, plus the direct components of thehave neither the ALLOCATABLE nor POINTER attribute.
68 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
components that are of derived type and have neither the ALLOCATABLE nor POINTER attribute.5 The potential subobject components of a derived type are the nonpointer components of that type together with
the potential subobject components of the nonpointer components that are of derived type. This includes all the6 The components, direct components, potential subobject components, and ultimate components of an object ofcomponents that could be a subobject of an object of the type (9.4.2).
derived type are the components, direct components, potential subobject components, and ultimate components7 By default, no storage sequence is implied by the order of the component definitions. However, a storage sequenceof its type, respectively.
is implied for a sequence type (7.5.2.3). If the derived type has the BIND attribute, the storage sequence is that8 A scalar entity of derived type is a structure. If a derived type has the SEQUENCE attribute, a scalar entity ofrequired by the companion processor (5.5.7, 18.3.4).
the type is a sequence structure.1 Derived types with the BIND attribute are subject to additional constraints as specified in 18.3.4.NOTE 7.14
The ultimate components of an object of the derived type kids defined below are oldest_child%name,
oldest_child%age, and other_kids. The direct components of such an object are oldest_child%name,
oldest_child%age, other_kids, and oldest_child.
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
7.5.2 Derived-type definition
7.5.2.1 Syntax of a derived-type definition
R726 derived-type-def is derived-type-stmt
[ type-param-def-stmt ] ...
[ private-or-sequence ] ...
[ component-part ]
[ type-bound-procedure-part ]
end-type-stmt
R727 derived-type-stmt is TYPE [ [ , type-attr-spec-list ] :: ] type-name
[ ( type-param-name-list ) ]
R728 type-attr-spec is ABSTRACT
or access-spec
or BIND (C)
or EXTENDS ( parent-type-name )
C730 (R727) A derived type type-name shall not be DOUBLEPRECISION or the same as the name of any
intrinsic type defined in this document.
C731 (R727) The same type-attr-spec shall not appear more than once in a given derived-type-stmt.
C732 The same type-param-name shall not appear more than once in a given derived-type-stmt.
⃝c ISO/IEC 2017 – All rights reserved 69
ISO/IEC DIS 1539-1:2017 (E)
C733 (R728) A parent-type-name shall be the name of a previously defined extensible type (7.5.7).
C734 (R726) If the type definition contains or inherits (7.5.7.2) a deferred type-bound procedure (7.5.5), AB-
STRACT shall appear.
C735 (R726) If ABSTRACT appears, the type shall be extensible.
C736 (R726) If EXTENDS appears, SEQUENCE shall not appear.
C737 (R726) If EXTENDS appears and the type being defined has a coarray ultimate component, its parent
type shall have a coarray ultimate component.
C738 (R726) If EXTENDS appears and the type being defined has a potential subobject component of type
EVENT_TYPE or LOCK_TYPE from the intrinsic module ISO_FORTRAN_ENV, its parent type
shall be EVENT_TYPE or LOCK_TYPE or have a potential subobject component of type EVENT_-
TYPE or LOCK_TYPE.
R729 private-or-sequence is private-components-stmt
or sequence-stmt
C739 (R726) The same private-or-sequence shall not appear more than once in a given derived-type-def .
R730 end-type-stmt is END TYPE [ type-name ]
C740 (R730) If END TYPE is followed by a type-name, the type-name shall be the same as that in the
corresponding derived-type-stmt.
NOTE 7.15An example of a derived-type definition is:
CHARACTER (LEN = 50) NAME
An example of declaring a variable CHAIRMAN of type PERSON is:
TYPE (PERSON) :: CHAIRMAN
7.5.2.2 |
Accessibility
1 The accessibility of a type name is determined as specified in 8.5.2. The accessibility of a type name does not
affect, and is not affected by, the accessibility of its components and type-bound procedures.2 If a derived type is defined in the scoping unit of a module, and its name is private in that module, then the type
name, and thus the structure constructor (7.5.10) for the type, are accessible only within that module and its |
Such a type would be accessible only within the module in which it is defined, and within its descendants.
70 | |||||||
c ISO/IEC 2017 – All rights reserved | |||||||
be declared to be of an intrinsic type or of a sequence type, the derived type shall not have any type1 If the SEQUENCE statement appears, the type has the SEQUENCE attribute and is a sequence type. The order
of the component definitions in a sequence type specifies a storage sequence for objects of that type. The type | |||||||
INTEGER :: INT_VAL
LOGICAL :: LOG_VAL
REAL :: REAL_VAL
NOTE 7.18
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 object 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.
7.5.2.4 |
Determination of derived types
1 Derived-type definitions with the same type name may appear in different scoping units, in which case they might
be independent and describe different derived types or they might describe the same type.2 Two data entities have the same type if they are declared with reference to the same derived-type definition. Data
entities also have the same type if they are declared with reference to different derived-type definitions that specify |
REAL X,
⃝c ISO/IEC 2017 – All rights reserved | |
71 | |
| |
ISO/IEC DIS 1539-1:2017 (E)
NOTE 7.19 (cont.) | |
TYPE (POINT) :: X1
CALL SUB (X1)
...
SUBROUTINE SUB (A)
TYPE (POINT) :: A...
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 accessed that derived type from the module.
NOTE 7.20
An example of data entities in different scoping units having the same type is:
CHARACTER (50) NAME
TYPE (EMPLOYEE) PROGRAMMER
CALL SUB (PROGRAMMER)
...
SUBROUTINE SUB (POSITION)
CHARACTER (50) NAME
TYPE (EMPLOYEE) POSITION
...
The actual argument PROGRAMMER and the dummy argument POSITION have the same type because
they are declared with reference to a derived-type definition with the same name, the SEQUENCE attribute,
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 7.21
The requirement that the two types have the same name applies to the type-names in the respective derived
type definitions, not to local names introduced via renaming in USE statements.
72 | ⃝c ISO/IEC 2017 – All rights reserved | ||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||
or LEN1 The derived type is parameterized if the derived-type-stmt has any type-param-names. | |||||||||||||||||||||
2 Each type parameter is itself of type integer. If its kind selector is omitted, the kind type parameter is default | |||||||||||||||||||||
integer.3 The type-param-attr-spec explicitly specifies whether a type parameter is a kind parameter or a length parameter. | |||||||||||||||||||||
4 If a type-param-decl has a scalar-int-constant-expr, the type parameter has a default value which is specified by
the expression. If necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a5 A type parameter may be used as a primary in a specification expression (10.1.11) in the derived-type-def . A
kind type parameter may also be used as a primary in a constant expression (10.1.12) in the derived-type-def . | |||||||||||||||||||||
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)
7.5.3.2 Type parameter order
1 Type parameter order is an ordering of the type parameters of a derived type; it is used for derived-type specifiers.
2 The type parameter order of a nonextended type is the order of the type parameter list in the derived-type
definition. The type parameter order of an extended type (7.5.7) consists of the type parameter order of itsISO/IEC DIS 1539-1:2017 (E)parent type followed by any additional type parameters in the order of the type parameter list in the derived-type
definition.
⃝c ISO/IEC 2017 – All rights reserved 73
NOTE 7.23Given
TYPE :: t1 (k1, k2)
INTEGER, KIND :: k1, k2
REAL (k1) a (k2)
TYPE, EXTENDS(t1) :: t2 (k3)
INTEGER, KIND :: k3LOGICAL (k3) flag
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.
7.5.4 |
Components
ponents in the component-decl-list, except that the character length parameter may be specified or overridden1 A data component is an array if its component-decl contains a component-array-spec or its data-component-def-
stmt contains a DIMENSION clause. If the component-decl contains a component-array-spec, it specifies the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
An example of declaring a variable LINE_SEGMENT to be of the type LINE is:
The scalar variable LINE_SEGMENT has a component that is an array. In this case, the array is a
TYPE (LINE) :: LINE_SEGMENT subobject 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 7.27
An example of a derived type definition with an allocatable component is:
INTEGER, ALLOCATABLE :: CONTENTS (:)
INTEGER :: INDEX
For each scalar variable of type STACK, the shape of the component CONTENTS is determined by execu-
tion of an ALLOCATE statement or assignment statement, or by argument association.
NOTE 7.28
Default initialization of an explicit-shape array component can be specified by a constant expression con-
sisting of an array constructor (7.8), or of a single scalar that becomes the value of each array element.
7.5.4.3 |
Coarray components
1 A data component is a coarray if its component-decl contains a coarray-spec or its data-component-def-stmt
contains a CODIMENSION clause. If the component-decl contains a coarray-spec it specifies the corank; otherwise, |
REAL, ALLOCATABLE, CODIMENSION [:, :, :] :: GRID (:, :, :)
An object of type grid_type cannot be an array, an allocatable object, a coarray, or a pointer.
76 | ⃝c ISO/IEC 2017 – All rights reserved | ||
ISO/IEC DIS 1539-1:2017 (E) | |||
| |||
pointer component has the POINTER keyword in its proc-component-attr-spec-list.NOTE 7.30
An example of a derived type definition with a pointer component is:
INTEGER :: VOLUME, YEAR, PAGE CHARACTER (LEN = 50) :: TITLE PROCEDURE (printer_interface), POINTER :: PRINT => NULL() CHARACTER, DIMENSION (:), POINTER :: SYNOPSIS
Any object of type REFERENCE will have the four nonpointer components VOLUME, YEAR, PAGE, and
TITLE, the procedure pointer PRINT, which has an explicit interface the same as printer_interface, plus
a pointer to an array of characters holding SYNOPSIS. The size of this target array will be determined by
the length of the synopsis. The space for the target could be allocated (9.7.1) or the pointer component
could be associated with a target by a pointer assignment statement (10.2.2).
7.5.4.5 |
The passed-object dummy argument
1 A passed-object dummy argument is a distinguished dummy argument of a procedure pointer component or
type-bound procedure (7.5.5). It affects procedure overriding (7.5.7.3) and argument association (15.5.2.2).2 If NOPASS is specified, the procedure pointer component or type-bound procedure has no passed-object dummy
argument.3 If neither PASS nor NOPASS is specified or PASS is specified without arg-name, the first dummy argument of a
procedure pointer component or type-bound procedure is its passed-object dummy argument.4 If PASS (arg-name) is specified, the dummy argument named arg-name is the passed-object dummy argument of
the procedure pointer component or named type-bound procedure.1 Default initialization provides a means of automatically initializing pointer components to be disassociated or
associated with specific targets, and nonpointer nonallocatable components to have a particular value. Allocatable2 A pointer variable or component is data-pointer-initialization compatible with a target if the pointer is type
compatible with the target, they have the same rank, all nondeferred type parameters of the pointer have the3 If null-init appears for a pointer component, that component in any object of the type has an initial association
status of disassociated (3.61) or becomes disassociated as specified in 19.5.2.4.4 If initial-data-target appears for a data pointer component, that component in any object of the type is initially
associated with the target or becomes associated with the target as specified in 19.5.2.3.5 If initial-proc-target (15.4.3.6) appears in proc-decl for a procedure pointer component, that component in any
object of the type is initially associated with the target or becomes associated with the target as specified in6 If constant-expr appears for a nonpointer component, that component in any object of the type is initially defined
(19.6.3) or becomes defined as specified in 19.6.5 with the value determined from constant-expr. If necessary,7 A subcomponent (9.4.2) is default-initialized if the type of the object of which it is a component specifies default
initialization for that component, and the subcomponent is not a subobject of an object that is default-initialized8 A type has default initialization if component-initialization is specified for any direct component of the type. An
object has default initialization if it is of a type that has default initialization. |
CHARACTER (LEN = 5) MONTH
INTEGER :: YEAR = 2008 ! Partial default initialization
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.", 2009)
78 | ⃝c ISO/IEC 2017 – All rights reserved |
ISO/IEC DIS 1539-1:2017 (E)NOTE 7.33 | |
The default initial value of a component of derived type can be overridden by default initialization specified in the definition of the type. Continuing the example of NOTE 7.32: | |
TYPE(DATE) :: PLAY_DAY = TODAY
TYPE(SINGLE_SCORE), POINTER :: NEXT => NULL ( )
TYPE(SINGLE_SCORE) SETUP
The PLAY_DAY component of SETUP receives its initial value from TODAY, overriding the initialization
for the YEAR component.
NOTE 7.34
Arrays of structures can be declared with elements that are partially or totally initialized by default.
Continuing the example of NOTE 7.33 :
TYPE MEMBER (NAME_LEN)INTEGER, LEN :: NAME_LEN
CHARACTER (LEN = NAME_LEN) :: NAME = ’’
INTEGER :: TEAM_NO, HANDICAP = 0
TYPE (SINGLE_SCORE), POINTER :: HISTORY => NULL ( )
TYPE (MEMBER(9)) :: ORGANIZER = MEMBER (9) ("I. Manage",1,5,NULL ( ))
TYPE (MEMBER(9)) LEAGUE (36) ! Array of partially initialized elements
ORGANIZER is explicitly initialized, overriding the default initialization for an object of type MEMBER.
Allocated objects can also be initialized partially or totally. For example:
ALLOCATE (ORGANIZER % HISTORY) ! A partially initialized object of typeNOTE 7.35! SINGLE_SCORE is created.
A pointer component of a derived type can have as its target an object of that derived type. The type
definition can specify that in objects declared to be of this type, such a pointer is default initialized to
disassociated. For example:
TYPE (NODE), POINTER :: NEXT_NODE => NULL ( )
INTEGER :: VALUE = 0
A type such as this can be used to construct linked lists of objects of type NODE. Linked lists can also be
constructed using allocatable components.
NOTE 7.36
A pointer component of a derived type can be default initialized to have an initial target.
TYPE (NODE), POINTER :: NEXT_NODE => SENTINEL
INTEGER :: VALUE = 0
TYPE(NODE), SAVE, TARGET :: SENTINEL
⃝
c ISO/IEC 2017 – All rights reserved 79
ISO/IEC DIS 1539-1:2017 (E)1 Component order is an ordering of the nonparent components of a derived type; it is used for intrinsic format-7.5.4.7 Component order
ted input/output and structure constructors where component keywords are not used. Parent components are2 The component order of a nonextended type is the order of the declarations of the components in the derived-typeexcluded from the component order of an extended type (7.5.7).
definition. The component order of an extended type consists of the component order of its parent type followed1 The default accessibility for the components that are declared in a type’s component-part is private if the typeby any additional components in the order of their declarations in the extended derived-type definition.
NOTE 7.37
Given the same type definitions as in NOTE 7.23, 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.
7.5.4.8 Component accessibility
R745 private-components-stmt is PRIVATE
C767 (R745) A private-components-stmt is permitted only if the type definition is within the specification part
of a module.
definition contains a private-components-stmt, and public otherwise. The accessibility of a component may be2 If a component is private, that component name is accessible only within the module containing the definition,explicitly declared by an access-spec; otherwise its accessibility is the default for the type definition in which it is
declared.
and within its descendants.NOTE 7.38
Type parameters are not components. They are effectively always public.
NOTE 7.39
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 7.40
An example of a public type with private components is:
TYPE, PUBLIC :: POINT
REAL :: X, Y
Such a type definition can be accessed by use association; however, the components X and Y are accessible
only within the module and its descendants.
80 | |
c ISO/IEC 2017 – All rights reservedNOTE 7.41 | |
The following example illustrates the use of an individual component access-spec to override the default accessibility: | |
INTEGER :: I
INTEGER, PUBLIC :: J
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.
7.5.5 |
Type-bound procedures
binding-name within that derived type definition.1 If => procedure-name does not appear in a type-bound-proc-decl, it is as though => procedure-name had appeared
with a procedure name the same as the binding name.2 A type-bound procedure statement declares one or more specific type-bound procedures. A specific type-bound
procedure can have a passed-object dummy argument (7.5.4.5). A type-bound procedure with the DEFERRED3 A GENERIC statement declares a generic type-bound procedure, which is a type-bound generic interface for its
specific type-bound procedures.4 A binding of a type is a type-bound procedure (specific or generic), a generic type-bound interface, or a final
subroutine. These are referred to as specific bindings, generic bindings, and final bindings respectively.5 A type-bound procedure may be identified by a binding name in the scope of the type definition. This name is the
binding-name for a specific type-bound procedure, and the generic-name for a generic binding whose generic-spec6 The interface of a specific type-bound procedure is that of the procedure specified by procedure-name or the
interface specified by interface-name.7 The same generic-spec may be used in several GENERIC statements within a single derived-type definition. Each
additional GENERIC statement with the same generic-spec extends the generic interface.8 The default accessibility for the type-bound procedures of a type is private if the type definition contains a binding-
private-stmt, and public otherwise. The accessibility of a type-bound procedure may be explicitly declared by an9 A public type-bound procedure is accessible via any accessible object of the type. A private type-bound procedure
is accessible only within the module containing the type definition, and within its descendants. | ||||||||||||||||||||||||||||
REAL :: X, Y
PROCEDURE, PASS :: LENGTH => POINT_LENGTH
...
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 )
7.5.6 Final subroutines 7.5.6.1 FINAL statement R753 final-procedure-stmt is FINAL [ :: ] final-subroutine-name-list C787 (R753) A final-subroutine-name shall be the name of a module procedure with exactly one dummy argument. That argument shall be nonoptional and shall be a noncoarray, nonpointer, nonallocatable,nonpolymorphic variable of the derived type being defined. All length type parameters of the dummy
argument shall be assumed. The dummy argument shall not have the INTENT (OUT) or VALUE
attribute.
C788 (R753) A final-subroutine-name shall not be one previously specified as a final subroutine for that type. C789 (R753) A final subroutine shall not have a dummy argument with the same kind type parameters and rank as the dummy argument of another final subroutine of that type.
C790 (R753) If a final subroutine has an assumed-rank dummy argument, no other final subroutine of that type shall have a dummy argument with the same kind type parameters.1 The FINAL statement specifies that each procedure it names is a final subroutine. A final subroutine might be
executed when a data entity of that type is finalized (7.5.6.2).2 A derived type is finalizable if and only if it has a final subroutine or a nonpointer, nonallocatable component of
finalizable type. A nonpointer data entity is finalizable if and only if it is of finalizable type. No other entity is1 Only finalizable entities are finalized. When an entity is finalized, the following steps are carried out in sequence.finalizable.
⃝c ISO/IEC 2017 – All rights reserved 83
ISO/IEC DIS 1539-1:2017 (E)
NOTE 7.45
Final subroutines are effectively always “accessible”. They are called for entity finalization regardless of the
accessibility of the type, its other type-bound procedures, or the subroutine name itself.
NOTE 7.46
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.
7.5.6.2 The finalization process
(1) If the dynamic type of the entity has a final subroutine whose dummy argument has the same kind2 If several entities are to be finalized as a consequence of an event specified in 7.5.6.3, the order in which theytype parameters and rank as the entity being finalized, it is called with the entity as an actual
argument. Otherwise, if there is an elemental final subroutine whose dummy argument has the same
kind type parameters as the entity being finalized, or a final subroutine whose dummy argument is
assumed-rank with the same kind type parameters as the entity being finalized, it is called with the
entity as an actual argument. Otherwise, no subroutine is called at this point.
(2) All finalizable components that appear in the type definition are finalized in a processor-dependent
order. If the entity being finalized is an array, each finalizable component of each element of that
entity is finalized separately.
(3) If the entity is of extended type and the parent type is finalizable, the parent component is finalized.
are finalized is processor dependent. During this process, execution of a final subroutine for one of these entities1 When an intrinsic assignment statement is executed (10.2.1.3), if the variable is not an unallocated allocatableshall not reference or define any of the other entities that have already been finalized.
NOTE 7.47
An implementation might need to ensure that when an event causes more than one coarray to be deallocated,
they are deallocated in the same order on all images in the current team.
7.5.6.3 When finalization occurs
variable, it is finalized after evaluation of expr and before the definition of the variable. If the variable is an2 When a pointer is deallocated its target is finalized. When an allocatable entity is deallocated, it is finalizedallocated allocatable variable, or has an allocated allocatable subobject, that would be deallocated by intrinsic
assignment, the finalization occurs before the deallocation.
unless it is the variable in an intrinsic assignment statement or a subobject thereof. If an error condition occurs3 A nonpointer, nonallocatable object that is not a dummy argument or function result is finalized immediatelyduring deallocation, it is processor dependent whether finalization occurs.
before it would become undefined due to execution of a RETURN or END statement (19.6.6, item (3)).4 A nonpointer nonallocatable local variable of a BLOCK construct is finalized immediately before it would become
undefined due to termination of the BLOCK construct (19.6.6, item (23)).5 If an executable construct references a nonpointer function, the result is finalized after execution of the innermost
executable construct containing the reference.6 If a specification expression in a scoping unit references a function, the result is finalized before execution of the
executable constructs in the scoping unit.7 When a procedure is invoked, a nonpointer, nonallocatable, INTENT (OUT) dummy argument of that procedure
is finalized before it becomes undefined. The finalization caused by INTENT (OUT) is considered to occur within8 If an object is allocated via pointer allocation and later becomes unreachable due to all pointers associated with84 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
the invoked procedure; so for elemental procedures, an INTENT (OUT) argument will be finalized only if a scalar
or elemental final subroutine is available, regardless of the rank of the actual argument.
that object having their pointer association status changed, it is processor dependent whether it is finalized. If it1 If image execution is terminated, either by an error (e.g. an allocation failure) or by execution of a stop-stmt,is finalized, it is processor dependent as to when the final subroutines are called.
NOTE 7.48
If finalization is used for storage management, it often needs to be combined with defined assignment.
7.5.6.4 Entities that are not finalized
error-stop-stmt, or end-program-stmt, entities existing immediately prior to termination are not finalized.1 A derived type, other than the type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, thatNOTE 7.49
A nonpointer, nonallocatable object that has the SAVE attribute is never finalized as a direct consequence
of the execution of a RETURN or END statement.
7.5.7 Type extension
7.5.7.1 Extensible, extended, and abstract types
does not have the BIND attribute or the SEQUENCE attribute is an extensible type.2 A type with the EXTENDS attribute is an extended type; its parent type is the type named in the EXTENDS
type-attr-spec.3 An extensible type that does not have the EXTENDS attribute is an extension type of itself only. An extendedNOTE 7.50
The name of the parent type might be a local name introduced via renaming in a USE statement.
type is an extension of itself and of all types for which its parent type is an extension.4 An abstract type is a type that has the ABSTRACT attribute.
NOTE 7.51The DEFERRED attribute (7.5.5) defers the implementation of a type-bound procedure to extensions of
the type; it can appear only in an abstract type. The dynamic type of an object cannot be abstract;
therefore, a deferred type-bound procedure cannot be invoked. An extension of an abstract type need not
be abstract if it has no deferred type-bound procedures. A short example of an abstract type is:
TYPE, ABSTRACT :: FILE_HANDLE
PROCEDURE(OPEN_FILE), DEFERRED, PASS(HANDLE) :: OPEN
...
For a more elaborate example see C.2.4.
7.5.7.2 |
Inheritance
1 An extended type includes all of the type parameters, all of the components, and the nonoverridden (7.5.7.3)
type-bound procedures of its parent type. These are inherited by the extended type from the parent type. They2 An extended type has a scalar, nonpointer, nonallocatable, parent component with the type and type parameters
of the parent type. The name of this component is the parent type name. If the extended type is defined in a3 If a generic binding specified in a type definition has the same generic-spec as an inherited binding, it extends
the generic interface and shall satisfy the requirements specified in 15.4.3.4.5. |
TYPE, EXTENDS(POINT) :: COLOR_POINT ! An extension of TYPE(POINT) ! Components X and Y, and component name POINT, inherited from parentINTEGER :: COLOR
7.5.7.3 Type-bound procedure overriding
1 If a specific type-bound procedure specified in a type definition has the same binding name as an accessible
type-bound procedure from the parent type then the binding specified in the type definition overrides the one2 The overriding and overridden type-bound procedures shall satisfy the following conditions.from the parent type.
• Either both shall have a passed-object dummy argument or neither shall.• If the overridden type-bound procedure is pure then the overriding one shall also be pure.
• Either both shall be elemental or neither shall.
• They shall have the same number of dummy arguments.
• Passed-object dummy arguments, if any, shall correspond by name and position.
• Dummy arguments that correspond by position shall have the same names and characteristics, except for
the type of the passed-object dummy arguments.
• Either both shall be subroutines or both shall be functions having the same result characteristics (15.3.3).
• If the overridden type-bound procedure is PUBLIC then the overriding one shall not be PRIVATE.
86 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)3 A binding of a type and a binding of an extension of that type correspond if the latter binding is the same binding
as the former, overrides a corresponding binding, or is an inherited corresponding binding.NOTE 7.56
The following is an example of procedure overriding, expanding on the example in NOTE 7.44.
TYPE, EXTENDS (POINT) :: POINT_3D
REAL :: Z
PROCEDURE, PASS :: LENGTH => POINT_3D_LENGTH
END TYPE POINT_3D
...
and in the module-subprogram-part of the same module:
REAL FUNCTION POINT_3D_LENGTH ( A, B )
CLASS (POINT_3D), INTENT (IN) :: ACLASS (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 )
PRINT *, ’In POINT_3D_LENGTH, dynamic type of argument is incorrect.’
END FUNCTION POINT_3D_LENGTH
7.5.8 |
Derived-type values
1 The component value of
• a pointer component is its pointer association,2 The set of values of a particular derived type consists of all possible sequences of the component values of its
components.1 A derived-type specifier is used in several contexts to specify a particular derived type and type parameters.
R754 derived-type-spec is type-name [ ( type-param-spec-list ) ]2 Type parameter values that do not have type parameter keywords specified correspond to type parameters in type
parameter order (7.5.3.2). If a type parameter keyword appears, the value corresponds to the type parameter3 The value of a type parameter for which no type-param-value has been specified is its default value.
7.5.10 Construction of derived-type values1 A derived-type definition implicitly defines a corresponding structure constructor that allows construction of
scalar values of that derived type. The type and type parameters of a constructed value are specified by a derived2 In the absence of a component keyword, each component-data-source is assigned to the corresponding component
in component order (7.5.4.7). If a component keyword appears, the expr is assigned to the component named3 If a component with default initialization has no corresponding component-data-source, then the default initial-
ization is applied to that component. If an allocatable component has no corresponding component-data-source,4 A structure constructor shall not appear before the referenced type is defined. 5 For a pointer component, the corresponding component-data-source shall be an allowable data-target or proc-
target for such a pointer in a pointer assignment statement (10.2.2). If the component data source is a pointer,6 If a component of a derived type is allocatable, the corresponding constructor expression shall be a reference
to the intrinsic function NULL with no arguments, an allocatable entity of the same rank, or shall evaluate to7 If the component is allocatable and the expression is an allocatable entity, the corresponding component of the
constructor has the same allocation status as that allocatable entity. If it is allocated, it has the same bounds;8 If the component is allocatable and the expression is not an allocatable entity, the component has an allocation
status of allocated and the same bounds as the expression; if a length parameter of the component is deferred,1 Intrinsic assignment of derived-type entities is described in 10.2.1. This document does not specify any intrinsic
operations on derived-type entities. Any operation on derived-type entities or defined assignment (10.2.1.4) for1 An enumeration is a set of enumerators. An enumerator is a named integer constant. An enumeration definition
specifies the enumeration and its set of enumerators of the corresponding integer kind.2 For an enumeration, the kind is selected such that an integer type with that kind is interoperable (18.3.2) with the
corresponding C enumeration type. The corresponding C enumeration type is the type that would be declared3 The companion processor (5.5.7) shall be one that uses the same representation for the types declared by all C
enumeration specifiers that specify the same values in the same order.4 An enumerator is treated as if it were explicitly declared with the PARAMETER attribute. The enumerator is
defined in accordance with the rules of intrinsic assignment (10.2) with the value determined as follows. |
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
⃝c ISO/IEC 2017 – All rights reserved | |||||||
91 | |||||||
| |||||||
ISO/IEC DIS 1539-1:2017 (E)
NOTE 7.66
| |||||||
1 A binary, octal, or hexadecimal constant (boz-literal-constant) is a sequence of digits that represents an ordered | |||||||
sequence of bits. Such a constant has no type.2 The hex-digits A through F represent the numbers ten through fifteen, respectively; they may be represented | |||||||
by their lower-case equivalents. Each digit of a boz-literal-constant represents a sequence of bits, according to1 An array constructor constructs a rank-one array value from a sequence of scalar values, array values, and implied | |||||||
DO loops.2 If type-spec is omitted, corresponding length type parameters of the declared type of each ac-value expression | |||||||
shall have the same value; in this case, the declared type and type parameters of the array constructor are those3 If type-spec appears, it specifies the declared type and type parameters of the array constructor. Each ac-value | |||||||
expression in the array-constructor shall be compatible with intrinsic assignment to a variable of this type and4 The dynamic type of an array constructor is the same as its declared type. | |||||||
5 The character length of an ac-value in an ac-implied-do whose iteration count is zero shall not depend on the
value of the ac-do-variable and shall not depend on the value of an expression that is not a constant expression.6 If an ac-value is a scalar expression, its value specifies an element of the array constructor. If an ac-value is
an array expression, the values of the elements of the expression, in array element order (9.5.3.2), specify the7 For an ac-implied-do, the loop initialization and execution is the same as for a DO construct. 8 An empty sequence forms a zero-sized array.
⃝c ISO/IEC 2017 – All rights reserved 93ISO/IEC DIS 1539-1:2017 (E)
NOTE 7.67
| |||||||
ISO/IEC DIS 1539-1:2017 (E)8 Attribute declarations and specifications | |||||||
| |||||||
1 Every data object has a type and rank and may have type parameters and other properties that determine the | |||||||
uses of the object. Collectively, these properties are the attributes of the object. The declared type of a named2 A function has a type and rank and may have type parameters and other attributes that determine the uses of | |||||||
the function. The type, rank, and type parameters are the same as those of the function result.3 A subroutine does not have a type, rank, or type parameters, but may have other attributes that determine the | |||||||
uses of the subroutine.1 The type declaration statement specifies the declared type of the entities in the entity declaration list. The type | |||||||
and type parameters are those specified by declaration-type-spec, except that the character length type parameter2 The type declaration statement also specifies the attributes whose keywords appear in the attr-spec, except that | |||||||
the DIMENSION attribute may be specified or overridden for an entity by the appearance of array-spec in its3 A name that identifies a specific intrinsic function has a type as specified in 16.8. An explicit type declaration statement is not | |||||||
required; however, it is permitted. Specifying a type for a generic intrinsic function name in a type declaration4 If initialization appears for a nonpointer entity, | |||||||
• its type and type parameters shall conform as specified for intrinsic assignment (10.2.1.2); | |||||||
| |||||||
ISO/IEC DIS 1539-1:2017 (E)NOTE 8.1 (cont.) | |||||||
INTEGER (SHORT) K ! Range at least -9999 to 9999.(The last line above uses a type definition from NOTE 7.22.) | |||||||
| |||||||
1 An automatic data object is a nondummy data object with a type parameter or array bound that depends on | |||||||
the value of a specification-expr that is not a constant expression.2 If a type parameter in a declaration-type-spec or in a char-length in an entity-decl for a local variable of a | |||||||
subprogram or BLOCK construct is defined by an expression that is not a constant expression, the type parameter1 The appearance of initialization in an entity-decl for an entity without the PARAMETER attribute specifies that | |||||||
the entity is a variable with explicit initialization. Explicit initialization alternatively may be specified in a DATA2 If null-init appears, the initial association status of the object is disassociated. If initial-data-target appears, the | |||||||
object is initially associated with the target.3 Explicit initialization of a variable that is not in a common block implies the SAVE attribute, which may be confirmed | |||||||
by explicit specification.1 An attribute may be explicitly specified by an attr-spec in a type declaration statement or by an attribute | |||||||
specification statement (8.6). The following constraints apply to attributes.1 The accessibility attribute specifies the accessibility of an entity via a particular identifier. | |||||||
R807 access-spec is PUBLIC2 An access-spec in a type declaration statement specifies the accessibility of the names of all the entities declared | |||||||
by that statement. An access-spec in a derived-type-stmt specifies the accessibility of the derived type name.3 An identifier that is specified in a module or is accessible in a module by use association has either the PUB- | |||||||
LIC attribute or PRIVATE attribute. An identifier whose accessibility is not explicitly specified has default4 The default accessibility attribute for a module is PUBLIC unless it has been changed by a PRIVATE statement. | |||||||
Only an identifier that has the PUBLIC attribute in that module is available to be accessed from that module1 A variable with the ALLOCATABLE attribute is a variable for which space is allocated during execution. | |||||||
NOTE 8.4 | |||||||
| |||||||
1 An entity with the ASYNCHRONOUS attribute is a variable that may be subject to asynchronous input/output | |||||||
or asynchronous communication.2 The base object of a variable shall have the ASYNCHRONOUS attribute in a scoping unit if | |||||||
• the variable is a dummy argument or appears in an executable statement or specification expression in that3 Use of a variable in an asynchronous data transfer statement can imply the ASYNCHRONOUS attribute; see | |||||||
subclause 12.6.2.5.4 An object with the ASYNCHRONOUS attribute may be associated with an object that does not have the | |||||||
ASYNCHRONOUS attribute, including by use (14.2.2) or host association (19.5.1.4). If an object that is not a1 The BIND attribute for a variable or common block specifies that it is capable of interoperating with a C variable | |||||||
whose name has external linkage (18.9).2 If the value of the scalar-default-char-constant-expr after discarding leading and trailing blanks has nonzero | |||||||
length, it shall be valid as an identifier on the companion processor.3 The BIND attribute for a common block implies the SAVE attribute, which may be confirmed by explicit specification. | |||||||
8.5.6 CODIMENSION attribute1 The CODIMENSION attribute specifies that an entity is a coarray. The coarray-spec specifies its corank or | |||||||
corank and cobounds.1 A coarray with the ALLOCATABLE attribute has a specified corank, but its cobounds are determined by | |||||||
allocation or argument association.2 The corank of an allocatable coarray is equal to the number of colons in its deferred-coshape-spec-list. | |||||||
3 The cobounds of an unallocated allocatable coarray are undefined. No part of such a coarray shall be referenced
or defined; however, the coarray may appear as an argument to an intrinsic inquiry function as specified in 16.1.4 The cobounds of an allocated allocatable coarray are those specified when the coarray is allocated. 5 The cobounds of an allocatable coarray are unaffected by any subsequent redefinition or undefinition of the
variables on which the cobounds’ expressions depend.1 An explicit-coshape coarray is a named coarray that has its corank and cobounds declared by an explicit-coshape-
spec.2 The corank is equal to one plus the number of upper-cobounds.
100 ⃝3 If an explicit-coshape coarray is a local variable of a subprogram or BLOCK construct and has cobounds that are
not constant expressions, the cobounds are determined on entry to a procedure defined by the subprogram, or4 The values of each lower-cobound and upper-cobound determine the cobounds of the coarray along a particular
codimension. The cosubscript range of the coarray in that codimension is the set of integer values between and1 The CONTIGUOUS attribute specifies that an assumed-shape array is contiguous, that an array pointer can
only be pointer associated with a contiguous target, or that an assumed-rank dummy data object is contiguous.2 An object is contiguous if it is
(1) an object with the CONTIGUOUS attribute,3 An object is not contiguous if it is an array subobject, and
• the object has two or more elements,
| |||||||
| |||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||
4 It is processor dependent whether any other object is contiguous. | |||||||
NOTE 8.10 | |||||||
| |||||||
1 The DIMENSION attribute specifies that an entity is assumed-rank or an array. An assumed-rank dummy data | |||||||
object has the rank, shape, and size of its effective argument; otherwise, the rank or rank and shape is specified1 An explicit-shape array is an array whose shape is explicitly declared by an explicit-shape-spec-list. The rank is | |||||||
equal to the number of explicit-shape-specs.2 An explicit-shape array that is a named local variable of a subprogram or BLOCK construct may have bounds | |||||||
that are not constant expressions. The bounds, and hence shape, are determined on entry to a procedure defined3 The values of each lower-bound and upper-bound determine the bounds of the array along a particular dimension | |||||||
and hence the extent of the array in that dimension. If lower-bound appears it specifies the lower bound; otherwise1 An assumed-shape array is a nonallocatable nonpointer dummy argument array that takes its shape from its | |||||||
effective argument.2 The rank is equal to the number of colons in the assumed-shape-spec-list. | |||||||
3 The extent of a dimension of an assumed-shape array dummy argument is the extent of the corresponding
dimension of its effective argument. If the lower bound value is d and the extent of the corresponding dimension1 A deferred-shape array is an allocatable array or an array pointer. (An allocatable array has the ALLOCATABLE
attribute; an array pointer has the POINTER attribute.)2 The rank is equal to the number of colons in the deferred-shape-spec-list. 3 The size, bounds, and shape of an unallocated allocatable array or a disassociated array pointer are undefined.
No part of such an array shall be referenced or defined; however, the array may appear as an argument to an4 The bounds of each dimension of an allocated allocatable array are those specified when the array is allocated
or, if it is a dummy argument, when it is argument associated with an allocated effective argument.5 The bounds of each dimension of an associated array pointer, and hence its shape, may be specified
• in an ALLOCATE statement (9.7.1) when the target is allocated,
| |||||||
| |||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||
6 The bounds of an array pointer or allocatable array are unaffected by any subsequent redefinition or undefinition | |||||||
of variables on which the bounds’ expressions depend.1 An assumed-size array is a dummy argument array whose size is assumed from that of its effective argument, or | |||||||
the associate name of a RANK ( * ) block in a SELECT RANK construct. The rank and extents may differ for2 The size of an assumed-size array is determined as follows. | |||||||
• If the effective argument associated with the assumed-size dummy array is an array of any type other than3 The rank is equal to one plus the number of explicit-shape-specs. | |||||||
4 An assumed-size array has no upper bound in its last dimension and therefore has no extent in its last dimension
and no shape. An assumed-size array shall not appear in a context that requires its shape.5 If a list of explicit-shape-specs appears, it specifies the bounds of the first rank−1 dimensions. If lower-bound
appears it specifies the lower bound of the last dimension; otherwise that lower bound is 1. An assumed-size6 If an assumed-size array has bounds that are not constant expressions, the bounds are determined on entry to
the procedure. The bounds of such an array are unaffected by the redefinition or undefinition of any variable1 An implied-shape array is a named constant that takes its shape from the constant-expr in its declaration. A
named constant is declared to be an implied-shape array with an array-spec that is an implied-shape-or-assumed-2 The rank of an implied-shape array is the number of assumed-implied-specs in its array-spec. 3 The extent of each dimension of an implied-shape array is the same as the extent of the corresponding dimension
of the constant-expr. The lower bound of each dimension is lower-bound, if it appears, and 1 otherwise; the upper1 An assumed-rank entity is a dummy data object whose rank is assumed from its effective argument, or the associate
name of a RANK DEFAULT block in a SELECT RANK construct; this rank can be zero. An assumed-rank1 The EXTERNAL attribute specifies that an entity is an external procedure, dummy procedure, procedure pointer,
or block data subprogram.2 If an external procedure or dummy procedure is used as an actual argument or is the target of a procedure pointer
assignment, it shall be declared to have the EXTERNAL attribute.3 A procedure that has both the EXTERNAL and POINTER attributes is a procedure pointer.
NOTE 8.14
1 The INTENT attribute specifies the intended use of a dummy argument. An INTENT (IN) dummy argument
is suitable for receiving data from the invoking scoping unit, an INTENT (OUT) dummy argument is suitable2 The INTENT (IN) attribute for a nonpointer dummy argument specifies that it shall neither be defined nor
become undefined during the invocation and execution of the procedure. The INTENT (IN) attribute for a3 The INTENT (OUT) attribute for a nonpointer dummy argument specifies that the dummy argument becomes
undefined on invocation of the procedure, except for any subcomponents that are default-initialized (7.5.4.6). Any4 The INTENT (INOUT) attribute for a nonpointer dummy argument specifies that any actual argument that
corresponds to the dummy argument shall be definable. The INTENT (INOUT) attribute for a pointer dummy5 If no INTENT attribute is specified for a dummy argument, its use is subject to the limitations of its effective
argument (15.5.2).6 If a nonpointer object has an INTENT attribute, then all of its subobjects have the same INTENT attribute.
NOTE 8.16 | |||||||
TYPE (PERSON), INTENT (IN) :: FROM
TYPE (PERSON), INTENT (OUT) :: TO
106 | ||||||||
c ISO/IEC 2017 – All rights reservedNOTE 8.17 | ||||||||
If a dummy argument is a nonpointer derived-type object with a pointer component, then the pointer as a pointer is a subobject of the dummy argument, but the target of the pointer is not. Therefore, the restrictions on subobjects of the dummy argument 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 nonpointer dummy argument of derived type with an integer pointer component P, and X is INTENT (IN), then the statement X%P => NEW_TARGET 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 8.18Argument 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 an argument might not be redefined and it is desired to have the argument retain its value in that case, INTENT (OUT) cannot be used because it would cause the argument to become undefined; however, INTENT (INOUT) can be used, even if there is no explicit reference to the value of the dummy argument. 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 actual argument corresponding to a dummy argument without an INTENT attribute need be definable only if the dummy argument is actually redefined. | ||||||||
8.5.11 |
INTRINSIC attribute
1 The INTRINSIC attribute specifies that the entity is an intrinsic procedure. The procedure name may be a
generic name (16.7), a specific name (16.8), or both.2 If the specific name of an intrinsic procedure (16.8) is used as an actual argument, the name shall be explicitly specified to have the
INTRINSIC attribute. Note that a specific intrinsic procedure listed in Table 16.3 is not permitted to be used as an actual argument1 The OPTIONAL attribute specifies that the dummy argument need not have a corresponding actual argument
in a reference to the procedure (15.5.2.12).1 The PARAMETER attribute specifies that an entity is a named constant. The entity has the value specified by
its constant-expr, converted, if necessary, to the type, type parameters and shape of the entity.2 A named constant shall not be referenced unless it has been defined previously; it may be defined previously in
the same statement.1 Entities with the POINTER attribute can be associated with different data objects or procedures during execution
of a program. A pointer is either a data pointer or a procedure pointer.2 A data pointer shall not be referenced unless it is pointer associated with a target object that is defined. A data
pointer shall not be defined unless it is pointer associated with a target object that is definable.3 If a data pointer is associated, the values of its deferred type parameters are the same as the values of the
corresponding type parameters of its target.4 A procedure pointer shall not be referenced unless it is pointer associated with a target procedure.
NOTE 8.21
1 The PROTECTED attribute imposes limitations on the usage of module entities.
C853 The PROTECTED attribute shall be specified only in the specification part of a module.2 Other than within the module in which an entity is given the PROTECTED attribute, or within any of its
descendants,3 If an object has the PROTECTED attribute, all of its subobjects have the PROTECTED attribute.
NOTE 8.22 | |||||||
SUBROUTINE set_temperature_c(c)
REAL, INTENT(IN) :: ctemp_c = c
temp_f = temp_c*(9.0/5.0) + 32
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.
8.5.16 |
SAVE attribute
1 The SAVE attribute specifies that a local variable of a program unit or subprogram retains its association status,
allocation status, definition status, and value after execution of a RETURN or END statement unless it is a2 The SAVE attribute specifies that a local variable of a BLOCK construct retains its association status, allocation
status, definition status, and value after termination of the construct unless it is a pointer and its target becomes3 Giving a common block the SAVE attribute confers the attribute on all entities in the common block.
C858 An entity with the SAVE attribute shall be a common block, variable, or procedure pointer.4 A variable, common block, or procedure pointer declared in the scoping unit of a main program, module, or
submodule implicitly has the SAVE attribute, which may be confirmed by explicit specification. If a common block1 The TARGET attribute specifies that a data object may have a pointer associated with it (10.2.2). An object
without the TARGET attribute shall not have a pointer associated with it.2 If an object has the TARGET attribute, then all of its nonpointer subobjects also have the TARGET attribute.
NOTE 8.23
1 The VALUE attribute specifies a type of argument association (15.5.2.4) for a dummy argument.
C862 An entity with the VALUE attribute shall be a dummy data object. It shall not be an assumed-size1 The VOLATILE attribute specifies that an object may be referenced, defined, or become undefined, by means
not specified by the program. A pointer with the VOLATILE attribute may additionally have its association2 A noncoarray object that has the VOLATILE attribute may be associated with an object that does not have
the VOLATILE attribute, including by use (14.2.2) or host association (19.5.1.4). If an object that is not a3 A pointer should have the VOLATILE attribute if its target has the VOLATILE attribute. If, by means not
specified by the program, the target is referenced, defined, or becomes undefined, the pointer shall have the4 If an object has the VOLATILE attribute, then all of its subobjects also have the VOLATILE attribute. 5 The Fortran processor should use the most recent definition of a volatile object each time its value is required.
When a volatile object is defined by means of Fortran, it should make that definition available to the non-Fortran1 An access-stmt with an access-id-list specifies the accessibility attribute, PUBLIC or PRIVATE, of each access-id
in the list that is not a module name. An access-stmt without an access-id list specifies the default accessibility | ||||
specifies a default of public accessibility. The statement
specifies a default of private accessibility. If no such statement appears in a module, the default is public
accessibility.
⃝c ISO/IEC 2017 – All rights reserved 111
ISO/IEC DIS 1539-1:2017 (E)
2 If an identifier is accessed by use association and not declared in the module, and the name of every module
from which it is accessed appears in an access-stmt in the scoping unit, its default accessibility is PRIVATE ifthe access-spec in every such access-stmt is PRIVATE, or PUBLIC if the access-spec in any such access-stmt is
PUBLIC.
NOTE 8.26
Examples of accessibility statements are:
PUBLIC :: A, B, C, ASSIGNMENT (=), OPERATOR (+)
NOTE 8.27
The following is an example of using an accessibility statement on a module name.
MODULE m2USE m1
! We want to use the types and procedures in m1, but we only want to
! re-export m_type from m1, and export our own procedures.
PRIVATE m1
PUBLIC m_type
... definitions for our own entities and module procedures.
8.6.2 ALLOCATABLE statement R829 allocatable-stmt is ALLOCATABLE [ :: ] allocatable-decl-list R830 allocatable-decl is object-name [ ( array-spec ) ] [ lbracket coarray-spec rbracket ]1 The ALLOCATABLE statement specifies the ALLOCATABLE attribute (8.5.3) for a list of objects.
NOTE 8.28An example of an ALLOCATABLE statement is:
REAL A, B (:), SCALAR
ALLOCATABLE :: A (:, :), B, SCALAR
8.6.3 ASYNCHRONOUS statement R831 asynchronous-stmt is ASYNCHRONOUS [ :: ] object-name-list
1 The ASYNCHRONOUS statement specifies the ASYNCHRONOUS attribute (8.5.4) for a list of objects.
8.6.4 BIND statement1 The BIND statement specifies the BIND attribute for a list of variables and common blocks.R832 bind-stmt is language-binding-spec [ :: ] bind-entity-list
R833 bind-entity is entity-name
or / common-block-name /
C872 (R832) If the language-binding-spec has a NAME= specifier, the bind-entity-list shall consist of a single
bind-entity.
112 ⃝c ISO/IEC 2017 – All rights reserved1 The CODIMENSION statement specifies the CODIMENSION attribute (8.5.6) for a list of objects.
ISO/IEC DIS 1539-1:2017 (E)
8.6.5 CODIMENSION statement
R834 codimension-stmt is CODIMENSION [ :: ] codimension-decl-list
R835 codimension-decl is coarray-name lbracket coarray-spec rbracket
NOTE 8.29An example of a CODIMENSION statement is:
CODIMENSION a[*], b[3,*], c[:]
8.6.6 CONTIGUOUS statement R836 contiguous-stmt is CONTIGUOUS [ :: ] object-name-list
1 The CONTIGUOUS statement specifies the CONTIGUOUS attribute (8.5.7) for a list of objects.
8.6.7 DATA statement1 The DATA statement specifies explicit initialization (8.4).R837 data-stmt is DATA data-stmt-set [ [ , ] data-stmt-set ] ...
2 If a nonpointer variable has default initialization, it shall not appear in a data-stmt-object-list.
3 A variable that appears in a DATA statement and has not been typed previously may appear in a subsequent type
declaration only if that declaration confirms the implicit typing. An array name, array section, or array element4 Except for variables in named common blocks, a named variable has the SAVE attribute if any part of it is initializedthat appears in a DATA statement shall have had its array properties established by a previous specification
statement.
in a DATA statement, and this may be confirmed by explicit specification.5 The data-stmt-object-list is expanded to form a sequence of pointers and scalar variables, referred to as “sequenceR838 data-stmt-set is data-stmt-object-list / data-stmt-value-list /
R839 data-stmt-object is variable
or data-implied-do
R840 data-implied-do is ( data-i-do-object-list , [ integer-type-spec :: ] data-i-do-variable =
scalar-int-constant-expr ,
scalar-int-constant-expr
[ , scalar-int-constant-expr ] )
R841 data-i-do-object is array-element
or scalar-structure-component
or data-implied-do
R842 data-i-do-variable is do-variable
C873 A data-stmt-object or data-i-do-object shall not be a coindexed variable.
C874 (R839) A data-stmt-object that is a variable shall be a designator. Each subscript, section subscript,
substring starting point, and substring ending point in the variable shall be a constant expression.
C875 (R839) A variable whose designator appears as a data-stmt-object or a data-i-do-object shall not be a
dummy argument, accessed by use or host association, in a named common block unless the DATA statement is
in a block data program unit, in blank common, a function name, a function result name, an automatic data
object, or an allocatable variable.
⃝c ISO/IEC 2017 – All rights reserved 113
ISO/IEC DIS 1539-1:2017 (E)
C876 (R839) A data-i-do-object or a variable that appears as a data-stmt-object shall not be an object designator
in which a pointer appears other than as the entire rightmost part-ref .
C877 (R841) The array-element shall be a variable.
C878 (R841) The scalar-structure-component shall be a variable.
C879 (R841) The scalar-structure-component shall contain at least one part-ref that contains a subscript-list.
C880 (R841) In an array-element or scalar-structure-component that is a data-i-do-object, any subscript shall
be a constant expression, and any primary within that subscript that is a data-i-do-variable shall be a
DO variable of this data-implied-do or of a containing data-implied-do.
R843 data-stmt-value is [ data-stmt-repeat * ] data-stmt-constant
R844 data-stmt-repeat is scalar-int-constant
or scalar-int-constant-subobject
C881 (R844) The data-stmt-repeat shall be positive or zero. If the data-stmt-repeat is a named constant, it
shall have been defined previously.
R845 data-stmt-constant is scalar-constant
or scalar-constant-subobject
or signed-int-literal-constant
or signed-real-literal-constant
or null-init
or initial-data-target
or structure-constructor
C882 (R845) If a DATA statement constant value is a named constant or a structure constructor, the named
constant or derived type shall have been defined previously.
C883 (R845) If a data-stmt-constant is a structure-constructor, it shall be a constant expression.
R846 int-constant-subobject is constant-subobject
C884 (R846) int-constant-subobject shall be of type integer.
R847 constant-subobject is designator
C885 (R847) constant-subobject shall be a subobject of a constant.
C886 (R847) Any subscript, substring starting point, or substring ending point shall be a constant expression.
of variables” in subsequent text. A nonpointer array whose unqualified name appears as a data-stmt-object or6 The data-stmt-value-list is expanded to form a sequence of data-stmt-constants. A data-stmt-repeat indicates thedata-i-do-object is equivalent to a complete sequence of its array elements in array element order (9.5.3.2). An
array section is equivalent to the sequence of its array elements in array element order. A data-implied-do is
expanded to form a sequence of array elements and structure components, under the control of the data-i-do-
variable, as in the DO construct (11.1.7.4).
number of times the following data-stmt-constant is to be included in the sequence; omission of a data-stmt-repeat7 A zero-sized array or a data-implied-do with an iteration count of zero contributes no variables to the expandedhas the effect of a repeat factor of 1.
sequence of variables, but a zero-length scalar character variable does contribute a variable to the expanded8 The expanded sequences of variables and data-stmt-constants are in one-to-one correspondence. Each data-stmt-sequence. A data-stmt-constant with a repeat factor of zero contributes no data-stmt-constants to the expanded
sequence of scalar data-stmt-constants.
114 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
constant specifies the initial value, initial data target, or null-init for the corresponding variable. The lengths of9 A data-stmt-constant shall be null-init or initial-data-target if and only if the corresponding data-stmt-object hasthe two expanded sequences shall be the same.
the POINTER attribute. If data-stmt-constant is null-init, the initial association status of the corresponding data10 A data-stmt-constant other than boz-literal-constant, null-init, or initial-data-target shall be compatible with itsstatement object is disassociated. If data-stmt-constant is initial-data-target the corresponding data statement
object shall be data-pointer-initialization compatible (7.5.4.6) with the initial data target; the data statement
object is initially associated with the target.
corresponding variable according to the rules of intrinsic assignment (10.2.1.2). The variable is initially defined11 If a data-stmt-constant is a boz-literal-constant, the corresponding variable shall be of type integer. The boz-with the value specified by the data-stmt-constant; if necessary, the value is converted according to the rules of
intrinsic assignment (10.2.1.3) to a value that agrees in type, type parameters, and shape with the variable.
literal-constant is treated as if it were converted by the intrinsic function INT (16.9.100) to type integer with the1 The DIMENSION statement specifies the DIMENSION attribute (8.5.8) for a list of objects.kind type parameter of the variable.
NOTE 8.30
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 7.15. The pointer HEAD_OF_LIST is declared
using the derived type NODE from NOTE 7.35; it is initially disassociated. MYNAME is initialized by a
structure constructor. YOURNAME is initialized by supplying a separate value for each component.
8.6.8 DIMENSION statement
R848 dimension-stmt is DIMENSION [ :: ] array-name ( array-spec )
[ , array-name ( array-spec ) ] ...
NOTE 8.31An example of a DIMENSION statement is:
DIMENSION A (10), B (10, 70), C (:)
⃝c ISO/IEC 2017 – All rights reserved 115
ISO/IEC DIS 1539-1:2017 (E)
8.6.9 INTENT statement R849 intent-stmt is INTENT ( intent-spec ) [ :: ] dummy-arg-name-list
1 The INTENT statement specifies the INTENT attribute (8.5.10) for the dummy arguments in the list.
NOTE 8.32An example of an INTENT statement is:
SUBROUTINE EX (A, B)
INTENT (INOUT) :: A, B
8.6.10 OPTIONAL statement R850 optional-stmt is OPTIONAL [ :: ] dummy-arg-name-list
1 The OPTIONAL statement specifies the OPTIONAL attribute (8.5.12) for the dummy arguments in the list.
NOTE 8.33An example of an OPTIONAL statement is:
SUBROUTINE EX (A, B)
OPTIONAL :: B
8.6.11 PARAMETER statement
1 The PARAMETER statement specifies the PARAMETER attribute (8.5.13) and the values for the named con-
stants in the list.2 If a named constant is defined by a PARAMETER statement, it shall not be subsequently declared to have aR851 parameter-stmt is PARAMETER ( named-constant-def-list )
R852 named-constant-def is named-constant = constant-expr
type or type parameter value that differs from the type and type parameters it would have if declared implicitly3 The constant expression that corresponds to a named constant shall have type and type parameters that conform(8.7). A named array constant defined by a PARAMETER statement shall have its rank specified in a prior
specification statement.
with the named constant as specified for intrinsic assignment (10.2.1.2). If the named constant has implied shape,4 The value of each named constant is that specified by the corresponding constant expression; if necessary, thethe expression shall have the same rank as the named constant; otherwise, the expression shall either be scalar
or have the same shape as the named constant.
value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type, type1 The POINTER statement specifies the POINTER attribute (8.5.14) for a list of entities.parameters, and shape with the named constant.
NOTE 8.34
An example of a PARAMETER statement is:
PARAMETER (MODULUS = MOD (28, 3), NUMBER_OF_SENATORS = 100)
8.6.12 POINTER statement
R853 pointer-stmt is POINTER [ :: ] pointer-decl-list
R854 pointer-decl is object-name [ ( deferred-shape-spec-list ) ]
or proc-entity-name
116 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C887 A proc-entity-name shall have the EXTERNAL attribute.
NOTE 8.35An example of a POINTER statement is:
TYPE (NODE) :: CURRENT
POINTER :: CURRENT, A (:, :)
8.6.13 PROTECTED statement R855 protected-stmt is PROTECTED [ :: ] entity-name-list
1 The PROTECTED statement specifies the PROTECTED attribute (8.5.15) for a list of entities.
8.6.14 SAVE statement1 A SAVE statement with a saved entity list specifies the SAVE attribute (8.5.16) for a list of entities. A SAVER856 save-stmt is SAVE [ [ :: ] saved-entity-list ]
R857 saved-entity is object-name
or proc-pointer-name
or / common-block-name /
R858 proc-pointer-name is name
C888 (R856) If a SAVE statement with an omitted saved entity list appears in a scoping unit, no other
appearance of the SAVE attr-spec or SAVE statement is permitted in that scoping unit.
C889 A proc-pointer-name shall be the name of a procedure pointer.
statement without a saved entity list is treated as though it contained the names of all allowed items in the same1 The TARGET statement specifies the TARGET attribute (8.5.17) for a list of objects.scoping unit.
NOTE 8.36
An example of a SAVE statement is:
SAVE A, B, C, / BLOCKA /, D
8.6.15 TARGET statement
R859 target-stmt is TARGET [ :: ] target-decl-list
R860 target-decl is object-name [ ( array-spec ) ]
[ lbracket coarray-spec rbracket ]
NOTE 8.37An example of a TARGET statement is:
TARGET :: A (1000, 1000), B
8.6.16 VALUE statement R861 value-stmt is VALUE [ :: ] dummy-arg-name-list ⃝c ISO/IEC 2017 – All rights reserved 117
ISO/IEC DIS 1539-1:2017 (E)
1 The VALUE statement specifies the VALUE attribute (8.5.18) for a list of dummy arguments.
8.6.17 VOLATILE statement1 The VOLATILE statement specifies the VOLATILE attribute (8.5.19) for a list of objects.R862 volatile-stmt is VOLATILE [ :: ] object-name-list
8.7 IMPLICIT statement1 In a scoping unit, an IMPLICIT statement specifies a type, and possibly type parameters, for all implicitly
typed data entities whose names begin with one of the letters specified in the statement. An IMPLICIT NONE2 A letter-spec consisting of two letters separated by a minus is equivalent to writing a list containing all of the lettersstatement can indicate that no implicit typing rules are to apply in a particular scoping unit, or that external
and dummy procedures need to be explicitly given the EXTERNAL attribute.
R863 implicit-stmt is IMPLICIT implicit-spec-list
or IMPLICIT NONE [ ( [ implicit-none-spec-list ] ) ]
R864 implicit-spec is declaration-type-spec ( letter-spec-list )
R865 letter-spec is letter [ – letter ]
R866 implicit-none-spec is EXTERNAL
or TYPE
C890 (R863) If an IMPLICIT NONE statement appears in a scoping unit, it shall precede any PARAMETER
statements that appear in the scoping unit. No more than one IMPLICIT NONE statement shall appear
in a scoping unit.
C891 The same implicit-none-spec shall not appear more than once in a given implicit-stmt.
C892 If an IMPLICIT NONE statement in a scoping unit has an implicit-none-spec of TYPE or has no implicit-
none-spec-list, there shall be no other IMPLICIT statements in the scoping unit.
C893 (R865) If the minus and second letter appear, the second letter shall follow the first letter alphabetically.
C894 If IMPLICIT NONE with an implicit-none-spec of EXTERNAL appears within a scoping unit, the
name of an external or dummy procedure in that scoping unit or in a contained subprogram or BLOCK
construct shall have an explicit interface or be explicitly declared to have the EXTERNAL attribute.
in alphabetical order in the alphabetic sequence from the first letter through the second letter. For example, A–C3 In each scoping unit, there is a mapping, which may be null, between each of the letters A, B, ..., Z and ais equivalent to A, B, C. The same letter shall not appear as a single letter, or be included in a range of letters,
more than once in all of the IMPLICIT statements in a scoping unit.
type (and type parameters). An IMPLICIT statement specifies the mapping for the letters in its letter-spec-4 Any data entity that is not explicitly declared by a type declaration statement, is not an intrinsic function, islist. IMPLICIT NONE with an implicit-none-spec of TYPE or with no implicit-none-spec-list specifies the null
mapping for all the letters. If a mapping is not specified for a letter, the default for a program unit or an interface
body is default integer if the letter is I, J, ..., or N and default real otherwise, and the default for a BLOCK
construct, internal subprogram, or module subprogram is the mapping in the host scoping unit.
not a component, and is not accessed by use or host association is declared implicitly to be of the type (andtype parameters) mapped from the first letter of its name, provided the mapping is not null. The mapping for
the first letter of the data entity shall either have been established by a prior IMPLICIT statement or be the
default mapping for the letter. An explicit type specification in a FUNCTION statement overrides an IMPLICIT
statement for the result of that function.
118 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 8.38
The following are examples of the use of IMPLICIT statements:
...
FUNCTION FUN (I) ! Not all data entities need to INTEGER FUN ! be declared explicitly
FUNCTION JFUN (J) ! All data entities need to INTEGER JFUN, J ! be declared explicitly....
IMPLICIT COMPLEX (C)
...
C = (3.0, 2.0) ! C is implicitly declared COMPLEX
SUBROUTINE SUB1
IMPLICIT INTEGER (A, C)END SUBROUTINE SUB1C = (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
...
SUBROUTINE SUB2
Z = 2.0 ! Z is implicitly declared REAL andEND SUBROUTINE SUB2! is different from the variable of
! the same name in SUB1
...
SUBROUTINE SUB3
USE EXAMPLE_MODULE ! Accesses integer function FUNEND SUBROUTINE SUB3! by use association
Q = FUN (K) ! Q is implicitly declared REAL and
... ! K is implicitly declared INTEGER
NOTE 8.39
The following is an example of a mapping to a derived type that is inaccessible in the local scope:
IMPLICIT TYPE(BLOB) (A)
INTEGER :: I
TYPE(BLOB) :: B
⃝
c ISO/IEC 2017 – All rights reserved 119
ISO/IEC DIS 1539-1:2017 (E)
NOTE 8.39 (cont.)
INTEGER :: BLOB
...
AA = B
...
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 to type BLOB,
so AA is of type BLOB.
NOTE 8.40
Implicit typing is not affected by BLOCK constructs. For example, in
SUBROUTINE S(N)...
IF (N>0) THEN
NSQP = CEILING (SQRT (DBLE (N)))
...
IF (N>0) THEN
PRINT *,NSQP
even if the only two appearances of NSQP are within the BLOCK constructs, the scope of NSQP is the whole
subroutine S.
NOTE 8.41
In the subprogram
SUBROUTINE EXAMPLE (X, Y)IMPLICIT NONE (EXTERNAL)
REAL, EXTERNAL :: G
REAL :: X, Y
X = F (Y) ! Invalid: F lacks the EXTERNAL attribute.
X = G (Y) ! Valid: G has the EXTERNAL attribute.
the referenced function F needs to have the EXTERNAL attribute (8.5.9).
8.8 |
IMPORT statement
| |||||||||||||||||||||||
IMPORT, NONE
...
DO i=1,n ! Forces I to be locally declared.
NOTE 8.43
The IMPORT, ALL statement can be used to confirm the default rules and prevent accidental “shadowing”
of host entities:
SUBROUTINE outerREAL x
...
SUBROUTINE inner
⃝c ISO/IEC 2017 – All rights reserved | |
121 | |
| |
ISO/IEC DIS 1539-1:2017 (E)
NOTE 8.43 (cont.) | |
IMPORT, NONE
!IMPORT, ONLY: X
X = 1.0
is not conformant. The variable X is implicitly declared in the scoping unit of the main program. The
statement IMPORT, NONE makes X inaccessible in the BLOCK construct. If the IMPORT, NONE
statement is replaced with the IMPORT statement in the comment, the program is conformant.
NOTE 8.46
The IMPORT statement can be used to allow module procedures to have dummy arguments that are
procedures with assumed-shape arguments of an opaque type. For example:
...
PRIVATE ! T is an opaque type
SUBROUTINE PROCESS(X,Y,RESULT,MONITOR)
TYPE(T),INTENT(IN) :: X(:,:),Y(:,:)TYPE(T),INTENT(OUT) :: RESULT(:,:)
SUBROUTINE MONITOR(ITERATION_NUMBER,CURRENT_ESTIMATE)
INTEGER,INTENT(IN) :: ITERATION_NUMBER
TYPE(T),INTENT(IN) :: CURRENT_ESTIMATE(:,:)
...
122 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 8.46 (cont.)
The MONITOR dummy procedure requires an explicit interface because it has an assumed-shape array
argument, but TYPE(T) would not be available inside the interface body without the IMPORT statement.
8.9 |
NAMELIST statement
1 A NAMELIST statement specifies a group of named data objects, which may be referred to by a single name for
the purpose of data transfer (12.6, 13.11).2 The order in which the values appear on output is the same as the order of the namelist-group-objects in the
namelist group object list; if a variable appears more than once as a namelist-group-object for the same namelist3 Any namelist-group-name may occur more than once in the NAMELIST statements in a scoping unit. The
namelist-group-object-list following each successive appearance of the same namelist-group-name in a scoping4 A namelist group object may be a member of more than one namelist group. 5 A namelist group object shall either be accessed by use or host association or shall have its declared type, kind
type parameters of the declared type, and rank specified by previous specification statements or the procedure1 An EQUIVALENCE statement is used to specify the sharing of storage units by two or more objects in a scoping unit. This causes
storage association (19.5.3) of the objects that share the storage units.2 If the equivalenced objects have differing type or type parameters, the EQUIVALENCE statement does not cause type conversion or
imply mathematical equivalence. If a scalar and an array are equivalenced, the scalar does not have array properties and the array1 An EQUIVALENCE statement specifies that the storage sequences (19.5.3.2) of the data objects specified in an equivalence-set are
storage associated. All of the nonzero-sized sequences in the equivalence-set, if any, have the same first storage unit, and all of2 If any data object in an equivalence-set has the SAVE attribute, all other objects in the equivalence-set have the SAVE attribute;
this may be confirmed by explicit specification.1 A default character data object shall not be equivalenced to an object that is not default character and not of a character sequence
type. The lengths of equivalenced default character objects need not be the same.2 An EQUIVALENCE statement specifies that the storage sequences of all the default character data objects specified in an equivalence-
set are storage associated. All of the nonzero-sized sequences in the equivalence-set, if any, have the same first character storage unit,1 For a nonzero-sized array, the use of the array name unqualified by a subscript list as an equivalence-object has the same effect as
using an array element designator that identifies the first element of the array.1 An EQUIVALENCE statement shall not specify that the same storage unit is to occur more than once in a storage sequence. 2 An EQUIVALENCE statement shall not specify that consecutive storage units are to be nonconsecutive.
8.10.2 COMMON statement1 The COMMON statement specifies blocks of physical storage, called common blocks, that can be accessed by any of the scoping
units in a program. Thus, the COMMON statement provides a global data facility based on storage association (19.5.3).2 A common block that does not have a name is called blank common.
R873 common-stmt is COMMON3 In each COMMON statement, the data objects whose names appear in a common block object list following a common block name
are declared to be in that common block. If the first common block name is omitted, all data objects whose names appear in the4 Any common block name or an omitted common block name for blank common may occur more than once in one or more COMMON
statements in a scoping unit. The common block list following each successive appearance of the same common block name in a5 The form variable-name (array-spec) specifies the DIMENSION attribute for that variable. 6 If derived-type objects of numeric sequence type or character sequence type (7.5.2.3) appear in common, it is as if the individual
components were enumerated directly in the common list.1 For each common block in a scoping unit, a common block storage sequence is formed as follows:
(1) A storage sequence is formed consisting of the sequence of storage units in the storage sequences (19.5.3.2) of all data2 Only COMMON statements and EQUIVALENCE statements appearing in the scoping unit contribute to common block storage
sequences formed in that scoping unit.1 The size of a common block is the size of its common block storage sequence, including any extensions of the sequence resulting from
equivalence association.1 Within a program, the common block storage sequences of all nonzero-sized common blocks with the same name have the same first
storage unit, and the common block storage sequences of all zero-sized common blocks with the same name are storage associated2 A nonpointer object that is default integer, default real, double precision real, default complex, default logical, or of numeric sequence
type shall be associated only with nonpointer objects of these types and kinds.3 A nonpointer object that is default character or of character sequence type shall be associated only with nonpointer objects of these
types and kinds.4 A nonpointer object of a derived type that is not a numeric sequence or character sequence type shall be associated only with
nonpointer objects of the same type.5 A nonpointer object of intrinsic type but which is not default integer, default real, double precision real, default complex, default
logical, or default character shall be associated only with nonpointer objects of the same type and type parameters.6 A data pointer shall be storage associated only with data pointers of the same type and rank. Data pointers that are storage
associated shall have deferred the same type parameters; corresponding nondeferred type parameters shall have the same value.7 An object with the TARGET attribute shall be storage associated only with another object that has the TARGET attribute and the
same type and type parameters.1 A blank common block has the same properties as a named common block, except for the following.
• Execution of a RETURN or END statement might cause data objects in a named common block to become undefined unless
1 An EQUIVALENCE statement shall not cause the storage sequences of two different common blocks to be associated.
126 ⃝ c ISO/IEC 2017 – All rights reserved2 Equivalence association shall not cause a derived-type object with default initialization to be associated with an object in a common
block.3 Equivalence association shall not cause a common block storage sequence to be extended by adding storage units preceding the first
storage unit of the first object specified in a COMMON statement for the common block.ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)2 An allocate-object or a bound or type parameter of an allocate-object shall not depend on the value of stat-variable, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
the value of errmsg-variable, or on the value, bounds, length type parameters, allocation status, or association3 source-expr shall not be allocated within the ALLOCATE statement in which it appears; nor shall it depend on | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
the value, bounds, deferred type parameters, allocation status, or association status of any allocate-object in that4 If an ALLOCATE statement has a SOURCE= specifier and an allocate-object that is a coarray, source-expr | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shall not have a dynamic type of C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING, or5 If type-spec is specified, each allocate-object is allocated with the specified dynamic type and type parameter | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
values; if source-expr is specified, each allocate-object is allocated with the dynamic type and type parameter6 If a type-param-value in a type-spec in an ALLOCATE statement is an asterisk, it denotes the current value of | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
that assumed type parameter. If it is an expression, subsequent redefinition or undefinition of any entity in the1 When an ALLOCATE statement is executed for an array for which allocate-shape-spec-list is specified, the values | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
of the lower bound and upper bound expressions determine the bounds of the array. Subsequent redefinition2 When an ALLOCATE statement is executed for a coarray, the values of the lower cobound and upper cobound | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expressions determine the cobounds of the coarray. Subsequent redefinition or undefinition of any entities in the3 If an allocation specifies a coarray, its dynamic type and the values of corresponding type parameters shall be the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
same on every active image in the current team. The values of corresponding bounds and corresponding cobounds4 When an ALLOCATE statement is executed for which an allocate-object is a coarray, there is an implicit syn- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chronization of all active images in the current team. If the current team contains a stopped or failed image,5 If source-expr is a pointer, it shall be associated with a target. If source-expr is allocatable, it shall be allocated. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 When an ALLOCATE statement is executed for an array with no allocate-shape-spec-list, the bounds of source-
expr determine the bounds of the array. Subsequent changes to the bounds of source-expr do not affect the array7 If SOURCE= appears, source-expr shall be conformable with allocation. If an allocate-object is not polymorphic
and the source-expr is polymorphic with a dynamic type that differs from its declared type, the value provided for8 If MOLD= appears and source-expr is a variable, its value need not be defined. 9 If type-spec appears and the value of a length type parameter it specifies differs from the value of the corresponding
nondeferred type parameter specified in the declaration of any allocate-object, an error condition occurs. If the10 The set of error conditions for an ALLOCATE statement is processor dependent. If an error condition occurs
during execution of an ALLOCATE statement that does not contain the STAT= specifier, error termination is1 The allocation status of an allocatable entity is one of the following at any time.
• The status of an allocatable variable becomes “allocated” if it is allocated by an ALLOCATE statement, if2 At the beginning of execution of a program, allocatable variables are unallocated. 3 When the allocation status of an allocatable variable changes, the allocation status of any associated allocat-
able variable changes accordingly. Allocation of an allocatable variable establishes values for the deferred type4 An unsaved allocatable local variable of a procedure has a status of unallocated at the beginning of each invocation
of the procedure. An unsaved allocatable local variable of a construct has a status of unallocated at the beginningISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 When an object of derived type is created by an ALLOCATE statement, any allocatable ultimate components | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
have an allocation status of unallocated unless the SOURCE= specifier appears and the corresponding component6 If the evaluation of a function would change the allocation status of a variable and if a reference to the function | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
appears in an expression in which the value of the function is not needed to determine the value of the expression,1 Allocation of a pointer creates an object that implicitly has the TARGET attribute. Following successful execution | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
of an ALLOCATE statement for a pointer, the pointer is associated with the target and may be used to reference2 At the beginning of execution of a function whose result is a pointer, the association status of the result pointer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is undefined. Before such a function returns, it shall either associate a target with this pointer or cause the1 A pointer-object shall not depend on the value, bounds, or association status of another pointer-object in the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
same NULLIFY statement.2 Execution of a NULLIFY statement causes each pointer-object to become disassociated. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
NOTE 9.21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
deallocated and the pointers to be disassociated.2 An allocate-object shall not depend on the value, bounds, allocation status, or association status of anotherR940 deallocate-stmt is DEALLOCATE ( allocate-object-list [ , dealloc-opt-list ] )
R941 dealloc-opt is STAT = stat-variable
or ERRMSG = errmsg-variable
C952 (R941) No dealloc-opt shall appear more than once in a given dealloc-opt-list.
142 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
allocate-object in the same DEALLOCATE statement; it also shall not depend on the value of the stat-variable3 The set of error conditions for a DEALLOCATE statement is processor dependent. If an error condition occursor errmsg-variable in the same DEALLOCATE statement.
during execution of a DEALLOCATE statement that does not contain the STAT= specifier, error termination is4 When more than one allocated object is deallocated by execution of a DEALLOCATE statement, the order ofinitiated. The STAT= specifier is described in 9.7.4. The ERRMSG= specifier is described in 9.7.5.
deallocation is processor dependent.1 Deallocating an unallocated allocatable variable causes an error condition in the DEALLOCATE statement.NOTE 9.22
An example of a DEALLOCATE statement is:
DEALLOCATE (X, B)
9.7.3.2 Deallocation of allocatable variables
Deallocating an allocatable variable with the TARGET attribute causes the pointer association status of any2 When the execution of a procedure is terminated by execution of a RETURN or END statement, an unsavedpointer associated with it to become undefined. An allocatable variable shall not be deallocated if it or any
subobject of it is argument associated with a dummy argument or construct associated with an associate name.
allocatable local variable of the procedure retains its allocation and definition status if it is a function result or a3 When a BLOCK construct terminates, any unsaved allocated allocatable local variable of the construct is deal-subobject thereof; otherwise, if it is allocated it will be deallocated.
located.4 If an executable construct references a function whose result is allocatable or has an allocatable subobject, and
the function reference is executed, an allocatable result and any allocated allocatable subobject of the result is5 If a function whose result is allocatable or has an allocatable subobject is referenced in the specification part of adeallocated after execution of the innermost executable construct containing the reference.
scoping unit, and the function reference is executed, an allocatable result and any allocated allocatable subobject6 When a procedure is invoked, any allocated allocatable object that is an actual argument corresponding to anof the result is deallocated before execution of the executable constructs of the scoping unit.
INTENT (OUT) allocatable dummy argument is deallocated; any allocated allocatable object that is a subobject7 When an intrinsic assignment statement (10.2.1.3) is executed, any noncoarray allocated allocatable subobject ofof an actual argument corresponding to an INTENT (OUT) dummy argument is deallocated. If a Fortran proced-
ure that has an INTENT (OUT) allocatable dummy argument is invoked by a C function and the corresponding
argument in the C function call is a C descriptor that describes an allocated allocatable variable, the variable
is deallocated on entry to the Fortran procedure. If a C function is invoked from a Fortran procedure via an
interface with an INTENT (OUT) allocatable dummy argument and the corresponding actual argument in the
reference to the C function is an allocated allocatable variable, the variable is deallocated on invocation (before
execution of the C function begins).
the variable is deallocated before the assignment takes place.8 When a variable of derived type is deallocated, any allocated allocatable subobject is deallocated. If an error
condition occurs during deallocation, it is processor dependent whether an allocated allocatable subobject is9 If an allocatable component is a subobject of a finalizable object, that object is finalized before the component isdeallocated.
automatically deallocated.10 When a statement that deallocates a coarray is executed, there is an implicit synchronization of all active images⃝c ISO/IEC 2017 – All rights reserved 143
ISO/IEC DIS 1539-1:2017 (E)
in the current team. If the current team contains a stopped or failed image, an error condition occurs. If no11 If an allocate-object is a coarray dummy argument, its ultimate argument (15.5.2.3) shall be the same coarray onother error condition occurs, execution on the active images of the segment (11.6.2) following the statement is
delayed until all other active images in the current team have executed the same statement the same number of
times in this team. The segments that executed before the statement on an active image of this team precede
the segments that execute after the statement on another active image of this team. A coarray shall not become
deallocated on an image unless it is successfully deallocated on all active images in this team.
those images.12 The effect of automatic deallocation is the same as that of a DEALLOCATE statement without a dealloc-opt-list.
NOTE 9.23In the following example:
REAL, ALLOCATABLE :: TEMP(:)
REAL, ALLOCATABLE, SAVE :: X(:)
...
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 if it was allocated. On the
next invocation of PROCESS, TEMP will have an allocation status of unallocated.
NOTE 9.24
For example, executing a RETURN, END, or END BLOCK statement, or deallocating an object that has
an allocatable subobject, can cause deallocation of a coarray, and thus an implicit synchronization of all
active images in the current team.
9.7.3.3 |
Deallocation of pointer targets
1 If a pointer appears in a DEALLOCATE statement, its association status shall be defined. Deallocating a pointer
that is disassociated or whose target was not created by an ALLOCATE statement causes an error condition2 If a pointer appears in a DEALLOCATE statement, it shall be associated with the whole of an object that was
created by allocation. The pointer shall have the same dynamic type and type parameters as the allocated object,1 A stat-variable should have a decimal exponent range of at least four; otherwise the processor-dependent error
code might not be representable in the variable.2 This rest of this subclause applies where an alloc-opt or dealloc-opt that is a STAT= specifier appears in an
ALLOCATE or DEALLOCATE statement.3 The stat-variable shall not be allocated or deallocated within the ALLOCATE or DEALLOCATE statement
in which it appears; nor shall it depend on the value, bounds, deferred type parameters, allocation status, orassociation status of any allocate-object in that statement. The stat-variable shall not depend on the value of the
| |||||||||||||||||||||||||||||||||||||||||||||||||||
4 Successful execution of the ALLOCATE or DEALLOCATE statement causes the stat-variable to become defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||
with a value of zero.5 If an ALLOCATE or DEALLOCATE statement with a coarray allocate-object is executed when the current team | ||||||||||||||||||||||||||||||||||||||||||||||||||||
contains a stopped image, the stat-variable becomes defined with the value STAT_STOPPED_IMAGE from the6 If stat-variable became defined with the value STAT_FAILED_IMAGE, each allocate-object is successfully al- | ||||||||||||||||||||||||||||||||||||||||||||||||||||
located or deallocated on all the active images of the current team. If any other error condition occurs, each1 The errmsg-variable shall not be allocated or deallocated within the ALLOCATE or DEALLOCATE statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||
in which it appears; nor shall it depend on the value, bounds, deferred type parameters, allocation status, or2 If an error condition occurs during execution of an ALLOCATE or DEALLOCATE statement with an ERRMSG= | ||||||||||||||||||||||||||||||||||||||||||||||||||||
specifier, the errmsg-variable is assigned an explanatory message, truncated or padded according to the rules ofISO/IEC DIS 1539-1:2017 (E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
(Blank page) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
1 An intrinsic operation requires the values of its operands. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
2 Execution of a function reference in the logical expression in an IF statement (11.1.8.4), the mask expression in a
WHERE statement (10.2.3.1), or the concurrent-limits and concurrent-steps in a FORALL statement (10.2.4) is permitted to3 The appearance of an array constructor requires the evaluation of each scalar-int-expr of the ac-implied-do-control
in any ac-implied-do it may contain.4 When an elemental binary operation is applied to a scalar and an array or to two arrays of the same shape, the
operation is performed element-by-element on corresponding array elements of the array operands.5 When an elemental unary operator operates on an array operand, the operation is performed element-by-element,
and the result is the same shape as the operand. If an elemental operation is intrinsically pure or is implemented1 An intrinsic operation is either a unary or binary operation. An intrinsic unary operation is an operation of
the form intrinsic-operator x2 where x2 is of an intrinsic type (7.4) listed in Table 10.2 for the unary intrinsic2 An intrinsic binary operation is an operation of the form x1 intrinsic-operator x2 where x1 and x2 are conformable
and of the intrinsic types (7.4) listed in Table 10.2 for the binary intrinsic operator.3 A numeric intrinsic operation is an intrinsic operation for which the intrinsic-operator is a numeric operator (+,
–, *, /, or **). A numeric intrinsic operator is the operator in a numeric intrinsic operation.4 The character intrinsic operation is the intrinsic operation for which the intrinsic-operator is (//) and both
operands are of type character with the same kind type parameter. The character intrinsic operator is the5 A logical intrinsic operation is an intrinsic operation for which the intrinsic-operator is .AND., .OR., .NOT.,
.EQV., or .NEQV. and both operands are of type logical. A logical intrinsic operator is the operator in a logical6 A relational intrinsic operator is an intrinsic-operator that is .EQ., .NE., .GT., .GE., .LT., .LE., ==, /=, >,
>=, <, or <=. A relational intrinsic operation is an intrinsic operation for which the intrinsic-operator is a7 The interpretations defined in subclause 10.1.5 apply to both scalars and arrays; the interpretation for arrays is
obtained by applying the interpretation for scalars element by element. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
I I, R L, L
.GT., .GE., .LT., .LE. | |||||||||||||||||||||||||||||||||||||||||||||||
R I, R L, L | |||||||||||||||||||||||||||||||||||||||||||||||
>, >=, <, <= C C L | |||||||||||||||||||||||||||||||||||||||||||||||
character, and logical, respectively. Where more than one type for x2 isNOTE 10.14 | |||||||||||||||||||||||||||||||||||||||||||||||
For example, if X is of type real and J is of type integer, the expression X + J is of type real. | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
1 The two operands of numeric intrinsic binary operations may be of different numeric types or different kind | |||||||||||||||||||||||||||||||||||||||||||||||
type parameters. Except for a value of type real or complex raised to an integer power, if the operands have2 A numeric operation is used to express a numeric computation. Evaluation of a numeric operation produces a | |||||||||||||||||||||||||||||||||||||||||||||||
numeric value. The permitted data types for operands of the numeric intrinsic operations are specified in 10.1.5.1.3 The numeric operators and their interpretation in an expression are given in Table 10.3, where x1 denotes the | |||||||||||||||||||||||||||||||||||||||||||||||
operand to the left of the operator and x2 denotes the operand to the right of the operator.4 The interpretation of a division operation depends on the types of the operands (10.1.5.2.2). | |||||||||||||||||||||||||||||||||||||||||||||||
5 If x1 and x2 are of type integer and x2 has a negative value, the interpretation of x1 ** x2 is the same as the
interpretation of 1/(x1 ** ABS (x2 )), which is subject to the rules of integer division (10.1.5.2.2).1 One operand of type integer may be divided by another operand of type integer. Although the mathematical
quotient of two integers is not necessarily an integer, Table 10.2 specifies that an expression involving the division1 In the case of a complex value raised to a complex power, the value of the operation x1 ** x2 is the principal
value of xx1 2 .1 The execution of any numeric operation whose result is not defined by the arithmetic used by the processor is
prohibited. Raising a negative real value to a real power is prohibited.2 Once the interpretation of a numeric intrinsic operation is established, the processor may evaluate any mathem-
atically equivalent expression, provided that the integrity of parentheses is not violated.3 Two expressions of a numeric type are mathematically equivalent if, for all possible values of their primaries, their
mathematical values are equal. However, mathematically equivalent expressions of numeric type may produceISO/IEC DIS 1539-1:2017 (E)
NOTE 10.17
| |||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)NOTE 10.20 | |||||||||||||||||||||||||||||||||||||||||||||||
Each operand in a numeric intrinsic operation has a type that can depend on the order of evaluation used by the processor. For example, in the evaluation of the expression
Z + R + Iwhere Z, R, and I represent data objects of complex, real, and integer type, respectively, the type of the operand that is added to I could be either complex or real, depending on which pair of operands (Z and R, R and I, or Z and I) is added first. | |||||||||||||||||||||||||||||||||||||||||||||||
10.1.5.3 | |||||||||||||||||||||||||||||||||||||||||||||||
Character intrinsic operation
| |||||||||||||||||||||||||||||||||||||||||||||||
1 The character intrinsic operator // is used to concatenate two operands of type character with the same kind | |||||||||||||||||||||||||||||||||||||||||||||||
type parameter. Evaluation of the character intrinsic operation produces a result of type character.2 The interpretation of the character intrinsic operator // when used to form an expression is given in Table 10.4, | |||||||||||||||||||||||||||||||||||||||||||||||
where x1 denotes the operand to the left of the operator and x2 denotes the operand to the right of the operator.3 The result of the character intrinsic operation x1 // x2 is a character string whose value is the value of x1 | |||||||||||||||||||||||||||||||||||||||||||||||
concatenated on the right with the value of x2 and whose length is the sum of the lengths of x1 and x2 . Parentheses1 A processor is only required to evaluate as much of the character intrinsic operation as is required by the context | |||||||||||||||||||||||||||||||||||||||||||||||
in which the expression appears.1 A logical operation is used to express a logical computation. Evaluation of a logical operation produces a result | |||||||||||||||||||||||||||||||||||||||||||||||
of type logical. The permitted types for operands of the logical intrinsic operations are specified in 10.1.5.1.2 The logical operators and their interpretation when used to form an expression are given in Table 10.5, where x1 | |||||||||||||||||||||||||||||||||||||||||||||||
denotes the operand to the left of the operator and x2 denotes the operand to the right of the operator.3 The values of the logical intrinsic operations are shown in Table 10.6. | |||||||||||||||||||||||||||||||||||||||||||||||
Table 10.6: The values of operations involving logical intrinsic operators | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
true true | |||||||||||||||||||||||||||||||||||||||||||||||
false true true true false
| |||||||||||||||||||||||||||||||||||||||||||||||
10.1.5.4.2 | |||||||||||||||||||||||||||||||||||||||||||||||
Evaluation of logical intrinsic operations
1 Once the interpretation of a logical intrinsic operation is established, the processor may evaluate any other
expression that is logically equivalent, provided that the integrity of parentheses in any expression is not violated.2 Two expressions of type logical are logically equivalent if their values are equal for all possible values of their
primaries.1 A relational intrinsic operation is used to compare values of two operands using the relational intrinsic operators
.LT., .LE., .GT., .GE., .EQ., .NE., <, <=, >, >=, ==, and /=. The permitted types for operands of the2 The operators <, <=, >, >=, ==, and /= always have the same interpretations as the operators .LT., .LE.,
.GT., .GE., .EQ., and .NE., respectively.3 Evaluation of a relational intrinsic operation produces a default logical result. 4 The interpretation of the relational intrinsic operators is given in Table 10.7, where x1 denotes the operand to
the left of the operator and x2 denotes the operand to the right of the operator.5 A numeric relational intrinsic operation is interpreted as having the logical value true if and only if the values of
the operands satisfy the relation specified by the operator.6 In the numeric relational operation
x1 rel-op x2if the types or kind type parameters of x1 and x2 differ, their values are converted to the type and kind type
7 A character relational intrinsic operation is interpreted as having the logical value true if and only if the values
of the operands satisfy the relation specified by the operator.8 For a character relational intrinsic operation, the operands are compared one character at a time in order,
beginning with the first character of each character operand. If the operands are of unequal length, the shorter1 Once the interpretation of a relational intrinsic operation is established, the processor may evaluate any other
expression that is relationally equivalent, provided that the integrity of parentheses in any expression is not2 Two relational intrinsic operations are relationally equivalent if their logical values are equal for all possible values
of their primaries.1 A defined operation is either a unary operation or a binary operation. A unary defined operation is an operation
that has the form defined-unary-op x2 or intrinsic-operator x2 and that is defined by a function and a generic2 A function defines the unary operation op x2 if
(1) the function is specified with a FUNCTION (15.6.2.2) or ENTRY (15.6.2.6) statement that specifies one3 If d2 is an array, the shape of x2 shall match the shape of d2 . 4 A binary defined operation is an operation that has the form x1 defined-binary-op x2 or x1 intrinsic-operator x2
and that is defined by a function and a generic interface.5 A function defines the binary operation x1 op x2 if
(1) the function is specified with a FUNCTION (15.6.2.2) or ENTRY (15.6.2.6) statement that specifies
| |||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||
the operation.6 If d1 or d2 is an array, the shapes of x1 and x2 shall match the shapes of d1 and d2 , respectively.
NOTE 10.27 | |||||||||||||||||||||||||||||||||||||||||||||||
10.1.6.2 | |||||||||||||||||||||||||||||||||||||||||||||||
Interpretation of a defined operation
1 The interpretation of a defined operation is provided by the function that defines the operation. 2 The operators <, <=, >, >=, ==, and /= always have the same interpretations as the operators .LT., .LE.,
.GT., .GE., .EQ., and .NE., respectively.1 Once the interpretation of a defined operation is established, the processor may evaluate any other expression
that is equivalent, provided that the integrity of parentheses is not violated.2 Two expressions of derived type are equivalent if their values are equal for all possible values of their primaries.
10.1.7 Evaluation of operands1 It is not necessary for a processor to evaluate all of the operands of an expression, or to evaluate entirely each
operand, if the value of the expression can be determined otherwise.2 If a statement contains a function reference in a part of an expression that need not be evaluated, all entities that
would have become defined in the execution of that reference become undefined at the completion of evaluation3 If a statement contains a function reference in a part of an expression that need not be evaluated, no invocation
of that function in that part of the expression shall execute an image control statement other than CRITICAL1 The rules for evaluation specified in subclause 10.1.5 state certain conditions under which a processor may
evaluate an expression that is different from the one specified by applying the rules given in 10.1.2 and rules for1 The type, type parameters, and shape of an expression depend on the operators and on the types, type parameters,
and shapes of the primaries used in the expression, and are determined recursively from the syntactic form of the2 If an expression is a polymorphic primary or defined operation, the type parameters and the declared and dynamic
types of the expression are the same as those of the primary or defined operation. Otherwise the type parameters1 The type, type parameters, and shape of a primary are determined according to whether the primary is a literal
constant, designator, array constructor, structure constructor, function reference, type parameter inquiry, type2 If a primary is a parenthesized expression, its type, type parameters, and shape are those of the expression. 3 The associated target object is referenced if a pointer appears as
• a primary in an intrinsic or defined operation,
4 The type, type parameters, and shape of the primary are those of the target. If the pointer is not associated with
a target, it may appear as a primary only as an actual argument in a reference to a procedure whose corresponding5 A disassociated array pointer or an unallocated allocatable array has no shape but does have rank. The type,
type parameters, and rank of the result of the intrinsic function NULL (16.9.144) depend on context.1 The type of the result of an intrinsic operation [x1 ] op x2 is specified by Table 10.2. The shape of the 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 otherwise.2 The type, type parameters, and shape of the result of a defined operation [x1 ] op x2 are specified by the function
defining the operation (10.1.6).3 An expression of an intrinsic type has a kind type parameter. An expression of type character also has a character
length parameter.4 The type parameters of the result of an intrinsic operation are as follows.
• For an expression x1 // x2 where // is the character intrinsic operator and x1 and x2 are of type character,
1 An elemental operation is an intrinsic operation or a defined operation for which the function is elemental (15.8). 2 For all elemental binary operations, the two operands shall be conformable. In the case where one is a scalar and
the other an array, the scalar is treated as if it were an array of the same shape as the array operand with every1 A specification expression is an expression with limitations that make it suitable for use in specifications such as
length type parameters (C704) and array bounds (R817, R818). A specification-expr shall be a constant expression2 A restricted expression is an expression in which each operation is intrinsic or defined by a specification function
and each primary is3 where each subscript, section subscript, substring starting point, substring ending point, and type parameter
value is a restricted expression, and where any final subroutine that is invoked is pure.4 A specification inquiry is a reference to
(1) an intrinsic inquiry function other than PRESENT,
| |||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)5 A function is a specification function if it is a pure function, is not a standard intrinsic function, is not an internal | |||||||||||||||||||||||||||||||||||||||||||||||
function, is not a statement function, and does not have a dummy procedure argument.6 Evaluation of a specification expression shall not directly or indirectly cause a procedure defined by the subpro- | |||||||||||||||||||||||||||||||||||||||||||||||
gram in which it appears to be invoked.7 A variable in a specification expression shall have its type and type parameters, if any, specified by a previous | |||||||||||||||||||||||||||||||||||||||||||||||
declaration in the same scoping unit, by the implicit typing rules in effect for the scoping unit, or by host or use8 If a specification expression includes a specification inquiry that depends on a type parameter, array bound, | |||||||||||||||||||||||||||||||||||||||||||||||
or cobound of an entity specified in the same specification-part, the type parameter, array bound, or cobound9 A generic entity referenced in a specification expression in the specification-part of a scoping unit shall have no | |||||||||||||||||||||||||||||||||||||||||||||||
specific procedures defined in the scoping unit, or its host scoping unit, subsequent to the specification expression.1 A constant expression is an expression with limitations that make it suitable for use as a kind type parameter, | |||||||||||||||||||||||||||||||||||||||||||||||
initializer, or named constant. It is an expression in which each operation is intrinsic, and each primary is2 If a constant expression includes a specification inquiry that depends on a type parameter or an array bound of | |||||||||||||||||||||||||||||||||||||||||||||||
an entity specified in the same specification-part, the type parameter or array bound shall be specified in a prior3 A generic entity referenced in a constant expression in the specification-part of a scoping unit shall have no specific | |||||||||||||||||||||||||||||||||||||||||||||||
procedures defined in that scoping unit, or its host scoping unit, subsequent to the constant expression.1 An assignment-stmt shall meet the requirements of either a defined assignment statement or an intrinsic assign- | |||||||||||||||||||||||||||||||||||||||||||||||
ment statement.1 An intrinsic assignment statement is an assignment statement that is not a defined assignment statement | |||||||||||||||||||||||||||||||||||||||||||||||
(10.2.1.4). In an intrinsic assignment statement,2 If the variable in an intrinsic assignment statement is a coindexed object, | |||||||||||||||||||||||||||||||||||||||||||||||
• the variable shall not be polymorphic, | |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||
3 If the variable is a pointer, it shall be associated with a definable target such that the type, type parameters, | |||||||||||||||||||||||||||||||||||||||||||||||
and shape of the target and expr conform. If the variable is a coarray or a coindexed object, it shall not be an1 Execution of an intrinsic assignment causes, in effect, the evaluation of the expression expr and all expressions | |||||||||||||||||||||||||||||||||||||||||||||||
within variable (10.1), the possible conversion of expr to the type and type parameters of the variable (Table2 If the variable is a pointer, the value of expr is assigned to the target of the variable. | |||||||||||||||||||||||||||||||||||||||||||||||
3 If the variable is an unallocated allocatable array, expr shall have the same rank. If the variable is an allocated
allocatable variable, it is deallocated if expr is an array of different shape, any corresponding length type parameter4 Both variable and expr may contain references to any portion of the variable.
NOTE 10.375 If expr is a scalar and the variable is an array, the expr is treated as if it were an array of the same shape as the
variable with every element of the array equal to the scalar value of expr.6 If the variable is an array, the assignment is performed element-by-element on corresponding array elements of
the variable and expr.7 The processor may perform the element-by-element assignment in any order.
NOTE 10.398 For an intrinsic assignment statement where the variable is of numeric type, the expr can have a different numeric
type or kind type parameter, in which case the value of expr is converted to the type and kind type parameter9 For an intrinsic assignment statement where the variable is of type logical, the expr can have a different kind
type parameter, in which case the value of expr is converted to the kind type parameter of the variable.10 For an intrinsic assignment statement where the variable is of type character, the expr can have a different
character length parameter in which case the conversion of expr to the length of the variable is as follows.11 For an intrinsic assignment statement where the variable is of type character, if expr has a different kind type para-
meter, each character c in expr is converted to the kind type parameter of the variable by ACHAR (IACHAR(c),12 For an intrinsic assignment of the type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING,
or of the type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, the variable becomes undefined13 An intrinsic assignment where the variable is of derived type is performed as if each component of the variable
were assigned from the corresponding component of expr using pointer assignment (10.2.2) for each pointer14 The processor may perform the component-by-component assignment in any order or by any means that has the
same effect.1 A defined assignment statement is an assignment statement that is defined by a subroutine and a generic interface
(7.5.5, 15.4.3.4.3) that specifies ASSIGNMENT (=).2 A subroutine defines the defined assignment x1 = x2 if
(1) the subroutine is specified with a SUBROUTINE (15.6.2.3) or ENTRY (15.6.2.6) statement that specifies
| |||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||
(a) the ranks of x1 and x2 match those of d1 and d2 or3 If d1 or d2 is an array, the shapes of x1 and x2 shall match the shapes of d1 and d2 , respectively. If the subroutine
is elemental, x2 shall be conformable with x1 .1 The interpretation of a defined assignment is provided by the subroutine that defines it. | |||||||||||||||||||||||||||||||||||||||||||||||
2 If the defined assignment is an elemental assignment and the variable in the assignment is an array, the defined | |||||||||||||||||||||||||||||||||||||||||||||||
assignment is performed element-by-element, on corresponding elements of the variable and expr. If expr is a1 Pointer assignment causes a pointer to become associated with a target or causes its pointer association status | |||||||||||||||||||||||||||||||||||||||||||||||
to become disassociated or undefined. Any previous association between the pointer and a target is broken.2 Pointer assignment for a pointer component of a structure may also take place by execution of a derived-type | |||||||||||||||||||||||||||||||||||||||||||||||
intrinsic assignment statement (10.2.1.3).ISO/IEC DIS 1539-1:2017 (E) | |||||||||||||||||||||||||||||||||||||||||||||||
C1016 (R1033) If data-target is unlimited polymorphic, data-pointer-object shall be unlimited polymorphic, or
of a type with the BIND attribute or the SEQUENCE attribute.C1017 (R1033) If bounds-spec-list is specified, the number of bounds-specs shall equal the rank of data-pointer-
object.C1018 (R1033) If bounds-remapping-list is specified, the number of bounds-remappings shall equal the rank of
data-pointer-object.C1019 (R1033) If bounds-remapping-list is not specified, the ranks of data-pointer-object and data-target shall
be the same.C1020 (R1033) A coarray data-target shall have the VOLATILE attribute if and only if the data-pointer-object
has the VOLATILE attribute.C1021 (R1034) A variable-name shall have the POINTER attribute. C1022 (R1034) A scalar-variable shall be a data-ref . C1023 (R1034) A data-pointer-component-name shall be the name of a component of scalar-variable that is a
data pointer.C1024 (R1034) A data-pointer-object shall not be a coindexed object.
| |||||||||||||||||||||||||||||||||||||||||||||||
ISO/IEC DIS 1539-1:2017 (E)C1031 (R1040) The proc-target shall not be a nonintrinsic elemental procedure. | |||||||||||||||||||||||||||||||||||||||||||||||
1 In a pointer assignment statement, data-pointer-object or proc-pointer-object denotes the pointer object and
data-target or proc-target denotes the pointer target.2 For pointer assignment performed by a derived-type intrinsic assignment statement, the pointer object is the
pointer component of the variable and the pointer target is the corresponding component of expr.1 If the pointer object is not polymorphic (7.3.2.3) and the pointer target is polymorphic with dynamic type that
differs from its declared type, the assignment target is the ancestor component of the pointer target that has the2 If the pointer target is not a pointer, the pointer object becomes pointer associated with the assignment target;
if the pointer target is a pointer with a target that is not on the same image, the pointer association status of the3 If the pointer object is polymorphic, it assumes the dynamic type of the pointer target. If the pointer object is
of a type with the BIND attribute or the SEQUENCE attribute, the dynamic type of the pointer target shall be4 If the pointer target is a disassociated pointer, all nondeferred type parameters of the declared type of the pointer
object that correspond to nondeferred type parameters of the pointer target shall have the same values as the5 Otherwise, all nondeferred type parameters of the declared type of the pointer object shall have the same values
as the corresponding type parameters of the pointer target.6 If the pointer object has nondeferred type parameters that correspond to deferred type parameters of the pointer
target, the pointer target shall not be a pointer with undefined association status.7 If the pointer object has the CONTIGUOUS attribute, the pointer target shall be contiguous. 8 If the target of a pointer is a coarray, the pointer shall have the VOLATILE attribute if and only if the coarray
has the VOLATILE attribute.9 If bounds-remapping-list appears, it specifies the upper and lower bounds of each dimension of the pointer,
and thus the extents; the pointer target shall be simply contiguous (9.5.4) or of rank one, and shall not be a10 If no bounds-remapping-list appears, the extent of a dimension of the pointer object is the extent of the corres-
ponding dimension of the pointer target. If bounds-spec-list appears, it specifies the lower bounds; otherwise,ISO/IEC DIS 1539-1:2017 (E)
| |||||||||||||||||||||||||||||||||||||||||||||||
1 If the pointer target is not a pointer, the pointer object becomes pointer associated with the pointer target. | |||||||||||||||||||||||||||||||||||||||||||||||
Otherwise, the pointer association status of the pointer object becomes that of the pointer target; if the pointer2 The host instance (15.6.2.4) of an associated procedure pointer is the host instance of its target. | |||||||||||||||||||||||||||||||||||||||||||||||
3 If the pointer object has an explicit interface, its characteristics shall be the same as the pointer target except
that the pointer target may be pure even if the pointer object is not pure and the pointer target may be an4 If the characteristics of the pointer object or the pointer target are such that an explicit interface is required,
both the pointer object and the pointer target shall have an explicit interface.5 If the pointer object has an implicit interface and is explicitly typed or referenced as a function, the pointer target
shall be a function. If the pointer object has an implicit interface and is referenced as a subroutine, the pointer6 If the pointer object is a function with an implicit interface, the pointer target shall be a function with the same
type; corresponding type parameters shall have the same value.7 If procedure-name is a specific procedure name that is also a generic name, only the specific procedure is associated
with the pointer object.1 A masked array assignment is either a WHERE statement or a WHERE construct. It is used to mask the
evaluation of expressions and assignment of values in array assignment statements, according to the value of a2 If a where-construct contains a where-stmt, a masked-elsewhere-stmt, or another where-construct then each mask-
expr within the where-construct shall have the same shape. In each where-assignment-stmt, the mask-expr and | |||||||||||||||||||||||||||||||||||||||||||||||
RAINING = .TRUE.
10.2.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 addition,
when a WHERE construct statement is executed, a pending control mask is established. If the statement does2 Each statement in a WHERE construct is executed in sequence.not appear as part of a where-body-construct, the mask-expr of the statement is evaluated, and the control mask is
established to be the value of mask-expr. The pending control mask is established to have the value .NOT. mask-
expr upon execution of a WHERE construct statement that does not appear as part of a where-body-construct.
The mask-expr is evaluated only once.
3 Upon execution of a masked-elsewhere-stmt, the following actions take place in sequence.
(1) The control mask mc is established to have the value of the pending control mask.4 The mask-expr is evaluated at most once.(2) The pending control mask is established to have the value mc .AND. (.NOT. mask-expr).
(3) The control mask mc is established to have the value mc .AND. mask-expr.
5 Upon execution of an ELSEWHERE statement, the control mask is established to have the value of the pending
control mask. No new pending control mask value is established.6 Upon execution of an ENDWHERE statement, the control mask and pending control mask are established to
have the values they had prior to the execution of the corresponding WHERE construct statement. Followingthe execution of a WHERE statement that appears as a where-body-construct, the control mask is established to
have the value it had prior to the execution of the WHERE statement.
NOTE 10.50
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
...
Following execution of statement 1, the control mask has the value cond1 and the pending
mask has the value (.NOT. cond1) .AND. cond2 and the pending control mask has the value
control mask has the value .NOT. cond1. Following execution of statement 2, the control (.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.
7 Upon execution of a WHERE construct statement that is part of a where-body-construct, the pending control
mask is established to have the value mc .AND. (.NOT. mask-expr). The control mask is then established to8 Upon execution of a WHERE statement that is part of a where-body-construct, the control mask is establishedhave the value mc .AND. mask-expr. The mask-expr is evaluated at most once.
176 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
to have the value mc .AND. mask-expr. The pending control mask is not altered.9 If a nonelemental function reference occurs in the expr or variable of a where-assignment-stmt or in a mask-expr,
the function is evaluated without any masked control; that is, all of its argument expressions are fully evaluated10 If an elemental operation or function reference occurs in the expr or variable of a where-assignment-stmt or in aand the function is fully evaluated. If the result is an array and the reference is not within the argument list
of a nonelemental function, elements corresponding to true values in the control mask are selected for use in
evaluating the expr, variable or mask-expr.
mask-expr, and is not within the argument list of a nonelemental function reference, the operation is performed11 If an array constructor appears in a where-assignment-stmt or in a mask-expr, the array constructor is evaluatedor the function is evaluated only for the elements corresponding to true values of the control mask.
without any masked control and then the where-assignment-stmt is executed or the mask-expr is evaluated.12 When a where-assignment-stmt is executed, the values of expr that correspond to true values of the control mask
are assigned to the corresponding elements of the variable.13 The value of the control mask is established by the execution of a WHERE statement, a WHERE construct
statement, an ELSEWHERE statement, a masked ELSEWHERE statement, or an ENDWHERE statement.Subsequent changes to the value of entities in a mask-expr have no effect on the value of the control mask. The
execution of a function reference in the mask expression of a WHERE statement is permitted to affect entities in
the assignment statement.
NOTE 10.51
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
10.2.4 FORALL 10.2.4.1 Form of the FORALL Construct
1 The FORALL construct allows multiple assignments, masked array (WHERE) assignments, and nested FORALL constructs and
statements to be controlled by a single concurrent-control-list and scalar-mask-expr.ISO/IEC DIS 1539-1:2017 (E)R1050 forall-construct is forall-construct-stmt
[forall-body-construct ] ...
end-forall-stmt
R1051 forall-construct-stmt is [forall-construct-name :] FORALL concurrent-header
R1052 forall-body-construct is forall-assignment-stmt
or where-stmt
or where-construct
or forall-construct
or forall-stmt
R1053 forall-assignment-stmt is assignment-stmt
or pointer-assignment-stmt
R1054 end-forall-stmt is END FORALL [forall-construct-name ]
⃝c ISO/IEC 2017 – All rights reserved 177
C1035 (R1054) If the forall-construct-stmt has a forall-construct-name, the end-forall-stmt shall have the same forall-construct- name. If the end-forall-stmt has a forall-construct-name, the forall-construct-stmt shall have the same forall-construct-name.
C1036 (R1052) A statement in a forall-body-construct shall not define an index-name of the forall-construct. C1037 (R1052) Any procedure referenced in a forall-body-construct, including one referenced by a defined operation, assignment, or finalization, shall be a pure procedure.
C1038 (R1052) A forall-body-construct shall not be a branch target.
2 The scope and attributes of an index-name in a concurrent-header in a FORALL construct or statement are described in 19.4.
10.2.4.2 Execution of the FORALL construct1 There are three stages in the execution of a FORALL construct:10.2.4.2.1 Execution stages
(1) determination of the values for index-name variables,(2) evaluation of the scalar-mask-expr, and
(3) execution of the FORALL body constructs.
10.2.4.2.2 Determination of the values for index variables
1 The values of the index variables are determined as they are for the DO CONCURRENT statement (11.1.7.4.2).
10.2.4.2.3 Evaluation of the mask expression1 The mask expression is evaluated as it is for the DO CONCURRENT statement (11.1.7.4.2).
10.2.4.2.4 Execution of the FORALL body constructs1 The forall-body-constructs are executed in the order in which they appear. Each construct is executed for all active combinations of
the index-name values with the following interpretation:2 Execution of a forall-assignment-stmt that is an assignment-stmt causes the evaluation of expr and all expressions within variable
for all active combinations of index-name values. These evaluations may be done in any order. After all these evaluations have been3 Execution of a forall-assignment-stmt that is a pointer-assignment-stmt causes the evaluation of all expressions within data-targetperformed, each expr value is assigned to the corresponding variable. The assignments may occur in any order.
and data-pointer-object or proc-target and proc-pointer-object, the determination of any pointers within data-pointer-object or proc-4 In a forall-assignment-stmt, a defined assignment subroutine shall not reference any variable that becomes defined by the statement.pointer-object, and the determination of the target for all active combinations of index-name values. These evaluations may be done
in any order. After all these evaluations have been performed, each data-pointer-object or proc-pointer-object is associated with the
corresponding target. These associations may occur in any order.
NOTE 10.525 Each statement in a where-construct (10.2.3) within a forall-construct is executed in sequence. When a where-stmt, where-construct-If a variable defined in an assignment statement within a FORALL construct is referenced in a later statement in that construct,
the later statement uses the value(s) computed in the preceding assignment statement, not the value(s) the variable had prior
to execution of the FORALL.
stmt or masked-elsewhere-stmt is executed, the statement’s mask-expr is evaluated for all active combinations of index-name values6 Execution of a forall-stmt or forall-construct causes the evaluation of the concurrent-limit and concurrent-step expressions in theas determined by the outer forall-constructs, masked by any control mask corresponding to outer where-constructs. Any where-
assignment-stmt is executed for all active combinations of index-name values, masked by the control mask in effect for the where-
assignment-stmt.
concurrent-control-list for all active combinations of the index-name values of the outer FORALL construct. The set of combinations1 The FORALL statement allows a single assignment statement or pointer assignment statement to be controlled by a set of index178 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
of index-name values for the inner FORALL is the union of the sets defined by these limits and steps for each active combination of the
outer index-name values; it also includes the outer index-name values. The scalar-mask-expr is then evaluated for all combinations
of the index-name values of the inner construct to produce a set of active combinations for the inner construct. If there is no
scalar-mask-expr, it is as if it appeared with the value true. Each statement in the inner FORALL is then executed for each active
combination of the index-name values.
10.2.4.3 The FORALL statement
values and an optional mask expression.2 A FORALL statement is equivalent to a FORALL construct containing a single forall-body-construct that is a forall-assignment-stmt.R1055 forall-stmt is FORALL concurrent-header forall-assignment-stmt
3 The scope of an index-name in a forall-stmt is the statement itself (19.4).
10.2.4.4 Restrictions on FORALL constructs and statements1 A many-to-one assignment is more than one assignment to the same object, or association of more than one target with the same
pointer, whether the object is referenced directly or indirectly through a pointer. A many-to-one assignment shall not occur withina single statement in a FORALL construct or statement. It is possible to assign or pointer-assign to the same object in different
assignment or pointer assignment statements in a FORALL construct.
NOTE 10.53
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)
if and only if INDEX(1:10) contains no repeated values.
2 Within the scope of a FORALL construct, a nested FORALL statement or FORALL construct shall not have the same index-name.
The concurrent-header expressions within a nested FORALL may depend on the values of outer index-name variables.ISO/IEC DIS 1539-1:2017 (E)⃝c ISO/IEC 2017 – All rights reserved 179
(Blank page)
2 Executable constructs may be used to control which blocks of a program are executed or how many times a block
180 c ISO/IEC 2017 – All rights reserved11 Execution control
ISO/IEC DIS 1539-1:2017 (E)
11.1 Executable constructs containing blocks 11.1.1 Blocks 1 The following are executable constructs that contain blocks: • ASSOCIATE construct;• BLOCK construct;
• CHANGE TEAM construct;
• CRITICAL construct;
• DO construct;
• IF construct;
• SELECT CASE construct;
• SELECT RANK construct;
• SELECT TYPE construct.
R1101 block is [ execution-part-construct ] ...
is executed. Blocks are always bounded by statements that are particular to the construct in which they areembedded.
NOTE 11.1
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.
11.1.2 Rules governing blocks 11.1.2.1 Control flow in blocks
1 Transfer of control to the interior of a block from outside the block is prohibited, except for the return from a
procedure invoked within the block. Transfers within a block and transfers from the interior of a block to outside2 Subroutine and function references (15.5.3, 15.5.4) may appear in a block.the block may occur.
11.1.2.2 Execution of a block1 Execution of a block begins with the execution of the first executable construct in the block.
2 Execution of the block is completed when
• execution of the last executable construct in the block completes without branching to a statement withinthe block,
• a branch (11.2) within the block that has a branch target outside the block occurs,
⃝c ISO/IEC 2017 – All rights reserved 181
ISO/IEC DIS 1539-1:2017 (E)
• a RETURN statement within the block is executed, or• an EXIT statement or CYCLE statement statement that belongs to a construct that contains the block is
executed.
NOTE 11.2
The action that takes place at the terminal boundary depends on the particular construct and on the block
within that construct.
11.1.3 ASSOCIATE construct 11.1.3.1 Purpose and form of the ASSOCIATE construct
1 The ASSOCIATE construct associates named entities with expressions or variables during the execution of its
block. These named construct entities (19.4) are associating entities (19.5.1.6). The names are associate names.1 Execution of an ASSOCIATE construct causes evaluation of every expression within every selector that is aR1102 associate-construct is associate-stmt
block
end-associate-stmt
R1103 associate-stmt is [ associate-construct-name : ] ASSOCIATE
(association-list )
R1104 association is associate-name => selector
R1105 selector is expr
or variable
C1101 (R1104) If selector is not a variable or is a variable that has a vector subscript, neither associate-name
nor any subobject thereof shall appear in a variable definition context (19.6.7).
C1102 (R1104) An associate-name shall not be the same as another associate-name in the same associate-stmt.
C1103 (R1105) variable shall not be a coindexed object.
C1104 (R1105) expr shall not be a variable.
C1105 (R1105) expr shall not be a designator of a procedure pointer or a function reference that returns a
procedure pointer.
R1106 end-associate-stmt is END ASSOCIATE [ associate-construct-name ]
C1106 (R1106) If the associate-stmt of an associate-construct specifies an associate-construct-name, the corres-
ponding end-associate-stmt shall specify the same associate-construct-name. If the associate-stmt of an
associate-construct does not specify an associate-construct-name, the corresponding end-associate-stmt
shall not specify an associate-construct-name.
11.1.3.2 Execution of the ASSOCIATE construct
variable designator and evaluation of every other selector, followed by execution of its block. During execution of2 The other attributes of the associating entity are described in 11.1.3.3.that block each associate name identifies an entity which is associated (19.5.1.6) with the corresponding selector.
The associating entity assumes the declared type and type parameters of the selector. If and only if the selector
is polymorphic, the associating entity is polymorphic.
3 It is permissible to branch to an end-associate-stmt only from within its ASSOCIATE construct.
182 ⃝1 Within an ASSOCIATE, CHANGE TEAM, or SELECT TYPE construct, each associating entity has the samec ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
11.1.3.3 Other attributes of associate names
rank as its associated selector. The lower bound of each dimension is the result of the intrinsic function LBOUND2 Within an ASSOCIATE, SELECT RANK, or SELECT TYPE construct, each associating entity has the same(16.9.109) applied to the corresponding dimension of selector. The upper bound of each dimension is one less
than the sum of the lower bound and the extent. The associating entity does not have the ALLOCATABLE or
POINTER attributes; it has the TARGET attribute if and only if the selector is a variable and has either the
TARGET or POINTER attribute.
corank as its associated selector. If the selector is a coarray, the cobounds of each codimension of the associating3 Within a CHANGE TEAM construct, the associating entity is a coarray. Its corank and cobounds are as specifiedentity are the same as those of the selector.
in its codimension-decl.4 Within an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT TYPE construct, the associating
entity has the ASYNCHRONOUS or VOLATILE attribute if and only if the selector is a variable and has the5 The associating entity itself is a variable, but if the selector is not a definable variable, the associating entityattribute. If the associating entity is polymorphic, it assumes the dynamic type and type parameter values of the
selector. If the selector has the OPTIONAL attribute, it shall be present. The associating entity is contiguous if
and only if the selector is contiguous.
is not definable and shall not be defined or become undefined. If a selector is not permitted to appear ina variable definition context (19.6.7), neither the associate name nor any subobject thereof shall appear in a
variable definition context.
11.1.3.4 Examples of the ASSOCIATE construct
NOTE 11.3
The following example illustrates an association with an expression.
ASSOCIATE ( Z => EXP (-(X**2+Y**2)) * COS (THETA) )
PRINT *, A+Z, A-Z
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))
The following example illustrates association with an array section.
ASSOCIATE ( ARRAY => AX%B(I,:)%C )
ARRAY(N)%EV = ARRAY(N-1)%EV
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
11.1.4 BLOCK construct
1 The BLOCK construct is an executable construct that may contain declarations.
⃝c ISO/IEC 2017 – All rights reserved 1832 Except for the ASYNCHRONOUS and VOLATILE statements, specifications in a BLOCK construct declare
ISO/IEC DIS 1539-1:2017 (E)
R1107 block-construct is block-stmt
[ block-specification-part ]
block
end-block-stmt
R1108 block-stmt is [ block-construct-name : ] BLOCK
R1109 block-specification-part is [ use-stmt ]...
[ import-stmt ] ...
[ [ declaration-construct ] ...
specification-construct ]
R1110 end-block-stmt is END BLOCK [ block-construct-name ]
C1107 (R1107) A block-specification-part shall not contain a COMMON, EQUIVALENCE, INTENT, NAMELIST,
OPTIONAL, statement function, or VALUE statement.
C1108 (R1107) A SAVE statement in a BLOCK construct shall contain a saved-entity-list that does not specify a
common-block-name .
C1109 (R1107) If the block-stmt of a block-construct specifies a block-construct-name, the corresponding end-
block-stmt shall specify the same block-construct-name. If the block-stmt does not specify a block-
construct-name, the corresponding end-block-stmt shall not specify a block-construct-name.
construct entities whose scope is that of the BLOCK construct (19.4). The appearance of the name of an object3 Execution of a BLOCK construct causes evaluation of the specification expressions within its specification partthat is not a construct entity in an ASYNCHRONOUS or VOLATILE statement in a BLOCK construct specifies
that the object has the attribute within the construct even if it does not have the attribute outside the construct.
in a processor-dependent order, followed by execution of its block.4 It is permissible to branch to an end-block-stmt only from within its BLOCK construct.
NOTE 11.4The following is an example of a BLOCK construct.
IF (swapxy) THEN
REAL (KIND (x)) tmp
tmp = x
x = y
y = tmp
Actions on a variable local to a BLOCK construct do not affect any variable of the same name outside the
construct. For example,
F = 254E-2
F = 39.37
! F is still equal to 254E-2.
A SAVE statement outside a BLOCK construct does not affect variables local to the BLOCK construct,
because a SAVE statement affects variables in its scoping unit rather than in its inclusive scope. For
184 | ⃝c ISO/IEC 2017 – All rights reserved |
ISO/IEC DIS 1539-1:2017 (E)NOTE 11.4 (cont.) | |
example, | |
...
...
...
REAL X ! Not saved. REAL,SAVE :: Y(100) ! SAVE attribute is allowed. Z = 3 ! Implicitly declared in S, thus saved.
...
11.1.5 CHANGE TEAM construct 11.1.5.1 Purpose and form of the CHANGE TEAM construct
1 The CHANGE TEAM construct changes the current team. Named construct entities (19.4) can be associated
(19.5.1.6) with coarrays in the containing scoping unit, in the same way as for the ASSOCIATE construct.2 Each coarray-name in a codimension-decl in the CHANGE TEAM statement is an associate name which isR1111 change-team-construct is change-team-stmt
block
end-change-team-stmt
R1112 change-team-stmt is [ team-construct-name : ] CHANGE TEAM ( team-value
[ , coarray-association-list ] [ , sync-stat-list ] )
R1113 coarray-association is codimension-decl => selector
R1114 end-change-team-stmt is END TEAM [ ( [ sync-stat-list ] ) ] [ team-construct-name ]
R1115 team-value is scalar-expr
C1110 A branch (11.2) within a CHANGE TEAM construct shall not have a branch target that is outside the
construct.
C1111 A RETURN statement shall not appear within a CHANGE TEAM construct.
C1112 If the change-team-stmt of a change-team-construct specifies a team-construct-name, the corresponding
end-change-team-stmt shall specify the same team-construct-name. If the change-team-stmt of a change-
team-construct does not specify a team-construct-name, the corresponding end-change-team-stmt shall
not specify a team-construct-name.
C1113 In a change-team-stmt, a coarray-name in a codimension-decl shall not be the same as a selector, or
another coarray-name, in that statement.
C1114 A team-value shall be of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.
C1115 No selector shall appear more than once in a given change-team-stmt.
C1116 A selector in a coarray-association shall be a named coarray.
associated with the corresponding selector. Each associating entity assumes the type and type parameters of1 The team-values on the active images that execute the CHANGE TEAM statement shall be those of team variablesits selector; it is polymorphic if and only if the selector is polymorphic. The other attributes of the associating
entities are described in 11.1.3.3.
⃝c ISO/IEC 2017 – All rights reserved 185
ISO/IEC DIS 1539-1:2017 (E)
11.1.5.2 Execution of a CHANGE TEAM construct
defined by corresponding executions of the same FORM TEAM statement (11.6.9). When the CHANGE TEAM2 Execution of a CHANGE TEAM construct causes evaluation of the expressions within each codimension-decl instatement is executed, the current team shall be the team that was current when those team variables were defined.
The current team for the statements of the CHANGE TEAM block is the team identified by the team-value. If
team-value is a variable, the variable shall not be defined or become undefined during execution of the CHANGE
TEAM construct. A CHANGE TEAM construct completes execution by executing its END TEAM statement,
which restores the current team to the original team that was current for the CHANGE TEAM statement.
the CHANGE TEAM statement, followed by execution of its block. Each selector shall be an established coarray3 It is permissible to branch to an end-change-team-stmt only from within its CHANGE TEAM construct.when the CHANGE TEAM statement begins execution.
4 An allocatable coarray that was allocated immediately before executing a CHANGE TEAM statement shall not
be deallocated during execution of the construct. An allocatable coarray that was unallocated immediately before5 Successful execution of a CHANGE TEAM statement performs an implicit synchronization of all images of theexecuting a CHANGE TEAM statement, and which is allocated immediately before executing the corresponding
END TEAM statement, is deallocated by the execution of the END TEAM statement.
new team that is identified by team-value. All active images of the new team shall execute the same CHANGE6 If the new team contains a failed image and no other error condition occurs, there is an implicit synchronizationTEAM statement. On each image of the new team, execution of the segment following the CHANGE TEAM
statement is delayed until all other images of that team have executed the same statement the same number of
times in the original team.
of all active images of the new team. On each active image of the new team, execution of the segment following7 If no error condition other than the new team containing a failed image occurs, the segments that executed beforethe CHANGE TEAM statement is delayed until all other active images of that team have executed the same
statement the same number of times in the original team.
the CHANGE TEAM statement on an active image of the new team precede the segments that execute after the8 When a CHANGE TEAM construct completes execution, there is an implicit synchronization of all active imagesCHANGE TEAM statement on another active image of that team.
in the new team. On each active image of the new team, execution of the segment following the END TEAM1 A CRITICAL construct limits execution of a block to one image at a time.statement is delayed until all other active images of this team have executed the same construct the same number
of times in this team. The segments that executed before the END TEAM statement on an active image of the
new team precede the segments that execute after the END TEAM statement on another active image of that
team.
NOTE 11.5
Deallocation of an allocatable coarray that was not allocated at the beginning of a CHANGE TEAM
construct, but is allocated at the end of execution of the construct, occurs even for allocatable coarrays
with the SAVE attribute.
NOTE 11.6
Execution of a CHANGE TEAM statement includes a synchronization of the executing image with the other
images that will be in the same team after execution of the CHANGE TEAM statement. Synchronization
of these images occurs again when the corresponding END TEAM statement is executed.
If it is desired to synchronize all of the images in the team that was current when the CHANGE TEAM
statement was executed, a SYNC TEAM statement that specifies the parent team can be executed imme-
diately after the CHANGE TEAM statement. If similar semantics are desired following the END TEAM
statement, a SYNC ALL statement could immediately follow the END TEAM statement.
186 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 11.7
A coarray that is established when a CHANGE TEAM statement is executed retains its corank and cobounds
inside the block. If it is desired to perform remote accesses based on corank or cobounds different from
those of the original coarray, an associating coarray can be used. An example of this is in C.6.7.
11.1.6 CRITICAL construct
R1116 critical-construct is critical-stmt2 Execution of the CRITICAL construct is completed when execution of its block is completed, or the executingblock
end-critical-stmt
R1117 critical-stmt is [ critical-construct-name : ] CRITICAL [ ( [ sync-stat-list ] ) ]
R1118 end-critical-stmt is END CRITICAL [ critical-construct-name ]
C1117 (R1116) If the critical-stmt of a critical-construct specifies a critical-construct-name, the corresponding
end-critical-stmt shall specify the same critical-construct-name. If the critical-stmt of a critical-construct
does not specify a critical-construct-name, the corresponding end-critical-stmt shall not specify a critical-
construct-name.
C1118 (R1116) The block of a critical-construct shall not contain a RETURN statement or an image control
statement.
C1119 A branch (11.2) within a CRITICAL construct shall not have a branch target that is outside the construct.
image fails (5.3.6). A procedure invoked, directly or indirectly, from a CRITICAL construct shall not execute an3 The processor shall ensure that once an image has commenced executing block, no other image shall commenceimage control statement.
executing block until this image has completed execution of the construct. The image shall not execute an image4 The effect of a STAT= or ERRMSG= specifier in a CRITICAL statement is specified in subclause 11.6.11.control statement during the execution of block. The sequence of executed statements is therefore a segment
(11.6.2). If image M completes execution of the construct without failing and image T is the next to execute the
construct, the segment on image M precedes the segment on image T. Otherwise, if image M completes execution
of the construct by failing, and image T is the next to execute the construct, the previous segment on image M
precedes the segment on image T.
5 It is permissible to branch to an end-critical-stmt only from within its CRITICAL construct.
NOTE 11.8If more than one image executes the block of a CRITICAL construct without failing, its execution by one
image always either precedes or succeeds its execution by another nonfailed image. Typically no other
statement ordering is needed. Consider the following example:
GLOBAL_COUNTER[1] = GLOBAL_COUNTER[1] + 1
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.
⃝c ISO/IEC 2017 – All rights reserved | |
187 | |
| |
ISO/IEC DIS 1539-1:2017 (E)
NOTE 11.9 | |
JOB = NUM_JOBS[1]
NUM_JOBS[1] = JOB - 1
IF (JOB > 0) THEN
! Work on JOB
11.1.7 DO construct 11.1.7.1 Purpose and form of the DO construct
1 The DO construct specifies the repeated execution of a sequence of executable constructs. Such a repeated
sequence is called a loop.2 The number of iterations of a loop can be determined at the beginning of execution of the DO construct, or can
be left indefinite (“DO forever” or DO WHILE). The execution order of the iterations can be left indeterminate3 There are three phases in the execution of a DO construct: initiation of the loop, execution of each iteration of(DO CONCURRENT); except in this case, the loop can be terminated immediately (11.1.7.4.5). An iteration of
the loop can be curtailed by executing a CYCLE statement (11.1.7.4.4).
the loop, and termination of the loop.4 The scope and attributes of an index-name in a concurrent-header (DO CONCURRENT) are described in 19.4.
11.1.7.2 Form of the DO constructC1120 (R1124) The do-variable shall be a variable of type integer.R1119 do-construct is do-stmt
block
end-do
R1120 do-stmt is nonlabel-do-stmt
or label-do-stmt
R1121 label-do-stmt is [ do-construct-name : ] DO label [ loop-control ]
R1122 nonlabel-do-stmt is [ do-construct-name : ] DO [ loop-control ]
R1123 loop-control is [ , ] do-variable = scalar-int-expr, scalar-int-expr
[ , scalar-int-expr ]
or [ , ] WHILE ( scalar-logical-expr )
or [ , ] CONCURRENT concurrent-header concurrent-locality
R1124 do-variable is scalar-int-variable-name
188 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
R1125 concurrent-header is ( [ integer-type-spec :: ] concurrent-control-list [ , scalar-mask-expr ] ) R1126 concurrent-control is index-name = concurrent-limit : concurrent-limit [ : concurrent-step ] R1127 concurrent-limit is scalar-int-expr R1128 concurrent-step is scalar-int-expr R1129 concurrent-locality is [ locality-spec ]... R1130 locality-spec is LOCAL ( variable-name-list ) or LOCAL_INIT ( variable-name-list )C1121 (R1125) Any procedure referenced in the scalar-mask-expr, including one referenced by a defined opera-or SHARED ( variable-name-list )
or DEFAULT ( NONE )
tion, shall be a pure procedure (15.7).C1122 (R1126) The index-name shall be a named scalar variable of type integer.
C1123 (R1126) A concurrent-limit or concurrent-step in a concurrent-control shall not contain a reference to any index-name in the concurrent-control-list in which it appears.C1124 A variable-name in a locality-spec shall be the name of a variable in the innermost executable construct
or scoping unit that includes the DO CONCURRENT statement.C1125 A variable-name in a locality-spec shall not be the same as an index-name in the concurrent-header of
the same DO CONCURRENT statement.C1126 The name of a variable shall not appear in more than one variable-name-list, or more than once in a
variable-name-list, in a given concurrent-locality.C1127 The DEFAULT ( NONE ) locality-spec shall not appear more than once in a given concurrent-locality.
C1128 A variable-name that appears in a LOCAL or LOCAL_INIT locality-spec shall not have the ALLOCAT- ABLE, INTENT (IN), or OPTIONAL attribute, shall not be of finalizable type, shall not be a nonpointerC1129 A variable that is referenced by the scalar-mask-expr of a concurrent-header or by any concurrent-limitpolymorphic dummy argument, and shall not be a coarray or an assumed-size array. A variable-name that
is not permitted to appear in a variable definition context shall not appear in a LOCAL or LOCAL_INIT
locality-spec.
or concurrent-step in that concurrent-header shall not appear in a LOCAL locality-spec in the same DOC1130 If the locality-spec DEFAULT ( NONE ) appears in a DO CONCURRENT statement, a variable that isCONCURRENT statement.
a local or construct entity of a scope containing the DO CONCURRENT construct, and that appears inthe block of the construct, shall have its locality explicitly specified by that statement.
R1131 end-do is end-do-stmt or continue-stmt
R1132 end-do-stmt is END DO [ do-construct-name ] ⃝ c ISO/IEC 2017 – All rights reserved 189
ISO/IEC DIS 1539-1:2017 (E)1 It is permissible to branch to an end-do only from within its DO construct.C1131 (R1119) If the do-stmt of a do-construct specifies a do-construct-name, the corresponding end-do shall be
an end-do-stmt specifying the same do-construct-name. If the do-stmt of a do-construct does not specify
a do-construct-name, the corresponding end-do shall not specify a do-construct-name.
C1132 (R1119) If the do-stmt is a nonlabel-do-stmt, the corresponding end-do shall be an end-do-stmt.
C1133 (R1119) If the do-stmt is a label-do-stmt, the corresponding end-do shall be identified with the same label.
11.1.7.3 Active and inactive DO constructs1 A DO construct is either active or inactive. Initially inactive, a DO construct becomes active only when its DO
statement is executed.2 Once active, the DO construct becomes inactive only when it terminates (11.1.7.4.5).
11.1.7.4 Execution of a DO construct1 When the DO statement is executed, the DO construct becomes active. If loop-control is11.1.7.4.1 Loop initiation
[ , ] do-variable = scalar-int-expr 1 , scalar-int-expr 2 [ , scalar-int-expr 3 ]the following steps are performed in sequence.
(1) The initial parameter m1 , the terminal parameter m2 , and the incrementation parameter m3 areNOTE 11.10of type integer with the same kind type parameter as the do-variable. Their values are established
by evaluating scalar-int-expr 1 , scalar-int-expr 2 , and scalar-int-expr 3 , respectively, including, if ne-
cessary, conversion to the kind type parameter of the do-variable according to the rules for numeric
conversion (Table 10.9). If scalar-int-expr 3 does not appear, m3 has the value 1. The value of m3
shall not be zero.
(2) The DO variable becomes defined with the value of the initial parameter m1 .
(3) The iteration count is established and is the value of the expression (m2 − m1 + m3 )/m3 , unless that
value is negative, in which case the iteration count is 0.
The iteration count is zero whenever:
m1 > m2 and m3 > 0, or2 If loop-control is omitted, no iteration count is calculated. The effect is as if a large positive iteration count,m1 < m2 and m3 < 0.
impossible to decrement to zero, were established. If loop-control is [ , ] WHILE (scalar-logical-expr), the effect3 For a DO CONCURRENT construct, the values of the index variables for the iterations of the construct areis as if loop-control were omitted and the following statement inserted as the first statement of the block:
IF (.NOT. (scalar- logical-expr )) EXIT
determined by the rules in 11.1.7.4.2.4 At the completion of the execution of the DO statement, the execution cycle begins.
11.1.7.4.2 DO CONCURRENT loop control1 The concurrent-limit and concurrent-step expressions in the concurrent-control-list are evaluated. These ex-
pressions may be evaluated in any order. The set of values that a particular index-name variable assumes is2 The set of combinations of index-name values is the Cartesian product of the sets defined by each triplet specific-determined as follows.
190 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
(1) The lower bound m1 , the upper bound m2 , and the step m3 are of type integer with the same kind
type parameter as the index-name. Their values are established by evaluating the first concurrent-
limit, the second concurrent-limit, and the concurrent-step expressions, respectively, including, if
necessary, conversion to the kind type parameter of the index-name according to the rules for numeric
conversion (Table 10.9). If concurrent-step does not appear, m3 has the value 1. The value m3 shall
not be zero.
(2) Let the value of max be (m2 − m1 + m3 )/m3 . If max≤ 0 for some index-name, the execution of the
construct is complete. Otherwise, the set of values for the index-name is
m1 + (k − 1) × m3 where k = 1, 2, ..., max.
ation. An index-name becomes defined when this set is evaluated.3 The scalar-mask-expr, if any, is evaluated for each combination of index-name values. If there is no scalar-
mask-expr, it is as if it appeared with the value true. The index-name variables may be primaries in the4 The set of active combinations of index-name values is the subset of all possible combinations for which thescalar-mask-expr.
scalar-mask-expr has the value true.1 The execution cycle of a DO construct that is not a DO CONCURRENT construct consists of the following stepsNOTE 11.11
The index-name variables can appear in the mask, for example
DO CONCURRENT (I=1:10, J=1:10, A(I) > 0.0 .AND. B(J) < 1.0)
. . .
11.1.7.4.3 The execution cycle
performed in sequence repeatedly until termination.2 Except for the incrementation of the DO variable that occurs in step (3), the DO variable shall neither be redefined(1) The iteration count, if any, is tested. If it is zero, the loop terminates and the DO construct becomes
inactive. If loop-control is [ , ] WHILE (scalar-logical-expr), the scalar-logical-expr is evaluated; if
the value of this expression is false, the loop terminates and the DO construct becomes inactive.
(2) The block of the loop is executed.
(3) The iteration count, if any, is decremented by one. The DO variable, if any, is incremented by the
value of the incrementation parameter m3 .
nor become undefined while the DO construct is active.3 The block of a DO CONCURRENT construct is executed for every active combination of the index-name values.
Each execution of the block is an iteration. The executions may occur in any order.1 Execution of a loop iteration can be curtailed by executing a CYCLE statement that belongs to the construct.11.1.7.4.4 CYCLE statement
R1133 cycle-stmt is CYCLE [ do-construct-name ]2 A CYCLE statement belongs to a particular DO construct. If the CYCLE statement contains a DO constructC1134 If a do-construct-name appears on a CYCLE statement, the CYCLE statement shall be within that
do-construct; otherwise, it shall be within at least one do-construct.
C1135 A cycle-stmt shall not appear within a CHANGE TEAM, CRITICAL, or DO CONCURRENT construct
if it belongs to an outer construct.
name, it belongs to that DO construct; otherwise, it belongs to the innermost DO construct in which it appears.3 Execution of a CYCLE statement that belongs to a DO construct that is not a DO CONCURRENT construct⃝c ISO/IEC 2017 – All rights reserved 191
ISO/IEC DIS 1539-1:2017 (E)
causes immediate progression to step (3) of the execution cycle of the DO construct to which it belongs.4 Execution of a CYCLE statement that belongs to a DO CONCURRENT construct completes execution of that
iteration of the construct.5 In a DO construct, a transfer of control to the end-do has the same effect as execution of a CYCLE statement
belonging to that construct.1 For a DO construct that is not a DO CONCURRENT construct, the loop terminates, and the DO construct11.1.7.4.5 Loop termination
becomes inactive, when any of the following occurs.2 For a DO CONCURRENT construct, the loop terminates, and the DO construct becomes inactive when all of• The iteration count is determined to be zero or the scalar-logical-expr is false, when tested during step (1)
of the above execution cycle.
• An EXIT statement that belongs to the DO construct is executed.
• An EXIT or CYCLE statement that belongs to an outer construct and is within the DO construct is
executed.
• A branch occurs within the DO construct and the branch target statement is outside the construct.
• A RETURN statement within the DO construct is executed.
the iterations have completed execution.3 When a DO construct becomes inactive, the DO variable, if any, of the DO construct retains its last defined
value.1 The locality of a variable that appears in a DO CONCURRENT construct is LOCAL, LOCAL_INIT, SHARED,11.1.7.5 Additional semantics for DO CONCURRENT constructs
C1136 A RETURN statement shall not appear within a DO CONCURRENT construct.
C1137 An image control statement shall not appear within a DO CONCURRENT construct.
C1138 A branch (11.2) within a DO CONCURRENT construct shall not have a branch target that is outside
the construct.
C1139 A reference to an impure procedure shall not appear within a DO CONCURRENT construct.
C1140 A statement that might result in the deallocation of a polymorphic entity shall not appear within a DO
CONCURRENT construct.
C1141 A reference to the procedure IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, or IEEE_GET_-
HALTING_MODE from the intrinsic module IEEE_EXCEPTIONS, shall not appear within a DO
CONCURRENT construct.
or unspecified. A construct or statement entity of a construct or statement within the DO CONCURRENT2 A variable that has LOCAL or LOCAL_INIT locality is a construct entity with the same type, type parameters,construct has SHARED locality if it has the SAVE attribute. If it does not have the SAVE attribute, it is a
different entity in each iteration, similar to LOCAL locality.
and rank as the variable with the same name in the innermost executable construct or scoping unit that includes3 If a variable has SHARED locality, appearances of the variable within the DO CONCURRENT construct referthe DO CONCURRENT construct, and the outside variable is inaccessible by that name within the construct. The
construct entity has the ASYNCHRONOUS, CONTIGUOUS, POINTER, TARGET, or VOLATILE attribute if
and only if the outside variable has that attribute; it does not have the BIND, INTENT, PROTECTED, SAVE
or VALUE attribute, even if the outside variable has that attribute. If it is not a pointer, it has the same bounds
as the outside variable. At the beginning of execution of each iteration,
192 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
• if a variable with LOCAL locality is a pointer it has undefined pointer association status, and otherwise it
is undefined except for any subobjects that are default-initialized;
• a variable with LOCAL_INIT locality has the pointer association status and definition status of the out-
side variable with that name; the outside variable shall not be an undefined pointer or a nonallocatable
nonpointer variable that is undefined.
If a variable with LOCAL or LOCAL_INIT locality becomes an affector of a pending input/output operation,
the operation shall have completed before the end of the iteration. If a variable with LOCAL or LOCAL_INIT
locality has the TARGET attribute, a pointer associated with it during an iteration becomes undefined when
execution of that iteration completes.
to the variable in the innermost executable construct or scoping unit that includes the DO CONCURRENT4 If a variable has unspecified locality,construct. If it is defined or becomes undefined during any iteration, it shall not be referenced, defined, or
become undefined during any other iteration. If it is allocated, deallocated, nullified, or pointer-assigned during
an iteration it shall not have its allocation or association status, dynamic type, array bounds, shape, or a deferred
type parameter value inquired about in any other iteration. A noncontiguous array with SHARED locality shall
not be supplied as an actual argument corresponding to a contiguous INTENT (INOUT) dummy argument.
• if it is referenced in an iteration it shall either be previously defined during that iteration, or shall not be5 A DO CONCURRENT construct shall not contain an input/output statement that has an ADVANCE= specifier.defined or become undefined during any other iteration; if it is defined or becomes undefined by more than
one iteration it becomes undefined when the loop terminates;
• if it is noncontiguous and is supplied as an actual argument corresponding to a contiguous INTENT (IN-
OUT) dummy argument in an iteration, it shall either be previously defined in that iteration or shall not
be defined in any other iteration;
• if it is a pointer and is used in an iteration other than as the pointer in pointer assignment, allocation,
or nullification, it shall either be previously pointer associated during that iteration or shall not have its
pointer association changed during any iteration;
• if it is a pointer whose pointer association is changed in more than one iteration, it has an association status
of undefined when the construct terminates;
• if it is allocatable and is allocated in more than one iteration, it shall have an allocation status of unallocated
at the end of every iteration;
• if it is allocatable and is referenced, defined, deallocated, or has its allocation status, dynamic type, or a
deferred type parameter value inquired about, in any iteration, it shall either be previously allocated in
that iteration or shall not be allocated or deallocated in any other iteration.
6 If data are written to a file record or position in one iteration, that record or position in that file shall not be
read from or written to in a different iteration. If records are written to a file connected for sequential access byISO/IEC DIS 1539-1:2017 (E)more than one iteration, the ordering of records written by different iterations is processor dependent.
NOTE 11.12
The restrictions on referencing variables defined in an iteration of a DO CONCURRENT construct apply
to any procedure invoked within the loop.
NOTE 11.13
The restrictions on the statements in 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 properties of the program not visible to the compiler.
⃝c ISO/IEC 2017 – All rights reserved 193
11.1.7.6 Examples of DO constructs NOTE 11.14The following program fragment computes a tensor product of two arrays:
DO I = 1, M
DO J = 1, N
C (I, J) = DOT_PRODUCT (A (I, J, :), B(:, I, J))
NOTE 11.15
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 block of the loop.
READ (IUN, ’(1X, G14.7)’, IOSTAT = IOS) X
DO WHILE (IOS == 0)
IF (X >= 0.) THENCALL SUBA (X)
CALL SUBB (X)
...
CALL SUBZ (X)
READ (IUN, ’(1X, G14.7)’, IOSTAT = IOS) X
NOTE 11.16
The following example behaves exactly the same as the one in NOTE 11.15. However, the READ statement
has been moved to the interior of the loop, 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) XIF (IOS /= 0) EXIT
IF (X < 0.) CYCLE
CALL SUBA (X)
CALL SUBB (X)
. . .
CALL SUBZ (X)
NOTE 11.17
The following example illustrates a case in which the user knows that there are no repeated values in the
index array IND. The DO CONCURRENT construct makes it easier for the processor to generate vector
gather/scatter code, unroll the loop, or parallelize the code for this loop, potentially improving performance.
INTEGER :: A(N),IND(N)
DO CONCURRENT (I=1:M)
A(IND(I)) = I
194 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 11.18
The following code demonstrates the use of the LOCAL clause so that the X inside the DO CONCURRENT
construct is a temporary variable, and will not affect the X outside the construct.
X = 1.0DO CONCURRENT (I=1:10) LOCAL (X)
IF (A (I) > 0) THEN
X = SQRT (A (I))
A (I) = A (I) - X**2
B (I) = B (I) - A (I)
PRINT *, X ! Always prints 1.0.
NOTE 11.19
Additional examples of DO constructs are in C.6.3.
11.1.8 |
IF construct and statement
| ||||
of logical expressions.1 At most one of the blocks in the IF construct is executed. If there is an ELSE statement in the construct,R1134 if-construct is if-then-stmt
block
[ else-if-stmt
block ] ...
[ else-stmt
block ]
end-if-stmt
R1135 if-then-stmt is [ if-construct-name : ] IF ( scalar-logical-expr ) THEN
R1136 else-if-stmt is ELSE IF ( scalar-logical-expr ) THEN [ if-construct-name ]
R1137 else-stmt is ELSE [ if-construct-name ]
R1138 end-if-stmt is END IF [ if-construct-name ]
C1142 (R1134) If the if-then-stmt of an if-construct specifies an if-construct-name, the corresponding end-if-
stmt shall specify the same if-construct-name. If the if-then-stmt of an if-construct does not specify an
if-construct-name, the corresponding end-if-stmt shall not specify an if-construct-name. If an else-if-
stmt or else-stmt specifies an if-construct-name, the corresponding if-then-stmt shall specify the same
if-construct-name.
11.1.8.2 Execution of an IF construct
exactly one of the blocks in the construct is executed. The scalar logical expressions are evaluated in the order2 It is permissible to branch to an END IF statement only from within its IF construct. Execution of an END IFof their appearance in the construct until a true value is found or an ELSE statement or END IF statement is
encountered. If a true value or an ELSE statement is found, the block immediately following is executed and this
completes the execution of the construct. The scalar logical expressions in any remaining ELSE IF statements of
the IF construct are not evaluated. If none of the evaluated expressions is true and there is no ELSE statement,
the execution of the construct is completed without the execution of any block within the construct.
⃝c ISO/IEC 2017 – All rights reserved 195
ISO/IEC DIS 1539-1:2017 (E)
statement has no effect.11.1.8.3 Examples of IF constructs
NOTE 11.20
IF (CVAR == ’RESET’) THEN
I = 0; J = 0; K = 0
PROOF_DONE: IF (PROP) THEN
WRITE (3, ’(’’QED’’)’)
PROP = NEXTPROP
IF (A > 0) THEN
B = C/AIF (B > 0) THEN
D = 1.0
ELSE IF (C > 0) THEN
B = A/CD = -1.0
B = ABS (MAX (A, C))
D = 0
11.1.8.4 IF statement
1 The IF statement controls the execution of a single action statement based on a single logical expression.
R1139 if-stmt is IF ( scalar-logical-expr ) action-stmt2 Execution of an IF statement causes evaluation of the scalar logical expression. If the value of the expression isC1143 (R1139) The action-stmt in the if-stmt shall not be an if-stmt.
true, the action statement is executed. If the value is false, the action statement is not executed.3 The execution of a function reference in the scalar logical expression may affect entities in the action statement.
NOTE 11.21An example of an IF statement is:
IF (A > 0.0) A = LOG (A)
11.1.9 SELECT CASE construct 11.1.9.1 Purpose and form of the SELECT CASE construct
1 The SELECT CASE construct selects for execution at most one of its constituent blocks. The selection is based
on the value of an expression.1 The execution of the SELECT CASE statement causes the case expression to be evaluated. For a case valueR1140 case-construct is select-case-stmt
[ case-stmt
block ] ...
end-select-stmt
196 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
R1141 select-case-stmt is [ case-construct-name : ] SELECT CASE ( case-expr )
R1142 case-stmt is CASE case-selector [case-construct-name]
R1143 end-select-stmt is END SELECT [ case-construct-name ]
C1144 (R1140) If the select-case-stmt of a case-construct specifies a case-construct-name, the corresponding end-
select-stmt shall specify the same case-construct-name. If the select-case-stmt of a case-construct does
not specify a case-construct-name, the corresponding end-select-stmt shall not specify a case-construct-
name. If a case-stmt specifies a case-construct-name, the corresponding select-case-stmt shall specify the
same case-construct-name.
R1144 case-expr is scalar-expr
C1145 case-expr shall be of type character, integer, or logical.
R1145 case-selector is ( case-value-range-list )
or DEFAULT
C1146 (R1140) No more than one of the selectors of one of the CASE statements shall be DEFAULT.
R1146 case-value-range is case-value
or case-value :
or : case-value
or case-value : case-value
R1147 case-value is scalar-constant-expr
C1147 (R1140) For a given case-construct, each case-value shall be of the same type as case-expr. For character
type, the kind type parameters shall be the same; character length differences are allowed.
C1148 (R1140) A case-value-range using a colon shall not be used if case-expr is of type logical.
C1149 (R1140) For a given case-construct, there shall be no possible value of the case-expr that matches more
than one case-value-range.
11.1.9.2 Execution of a SELECT CASE construct
range list, a match occurs if the case expression value matches any of the case value ranges in the list. For a case2 The block following the CASE statement containing the matching selector, if any, is executed. This completesexpression with a value of c, a match is determined as follows.
(1) If the case value range contains a single value v without a colon, a match occurs for type logical if
the expression c .EQV. v is true, and a match occurs for type integer or character if the expression
c == v is true.
(2) If the case value range is of the form low : high, a match occurs if the expression low <= c .AND.
c <= high is true.
(3) If the case value range is of the form low :, a match occurs if the expression low <= c is true.
(4) If the case value range is of the form : high, a match occurs if the expression c <= high is true.
(5) If no other selector matches and a DEFAULT selector appears, it matches the case index.
(6) If no other selector matches and the DEFAULT selector does not appear, there is no match.
execution of the construct.3 It is permissible to branch to an end-select-stmt only from within its SELECT CASE construct.
⃝c ISO/IEC 2017 – All rights reserved 197ISO/IEC DIS 1539-1:2017 (E)
11.1.9.3 Examples of SELECT CASE constructs NOTE 11.22An integer signum function:
INTEGER FUNCTION SIGNUM (N)
SELECT CASE (N)
CASE (:-1)
SIGNUM = -1
CASE (0)
SIGNUM = 0
CASE (1:)
SIGNUM = 1
NOTE 11.23
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’
! Ignore all other characters
IF (LEVEL > 0) THEN
PRINT *, ’MISSING RIGHT PARENTHESIS’
NOTE 11.24
The following three fragments are equivalent:
IF (SILLY == 1) THEN
SELECT CASE (SILLY == 1)
CASE (.TRUE.)
CASE (.FALSE.)
SELECT CASE (SILLY)
198 | ⃝c ISO/IEC 2017 – All rights reserved |
ISO/IEC DIS 1539-1:2017 (E)NOTE 11.24 (cont.)
CASE (1)
NOTE 11.25
A code fragment showing several selections of one block:
SELECT CASE (N)CASE (1, 3:5, 8) ! Selects 1, 3, 4, 5, 8
11.1.10 SELECT RANK construct 11.1.10.1 Purpose and form of the SELECT RANK construct
1 The SELECT RANK construct selects for execution at most one of its constituent blocks. The selection is based
on the rank of an assumed-rank variable. A name is associated with the variable (19.4, 19.5.1.6), in the same2 The associate name of a SELECT RANK construct is the associate-name if specified; otherwise it is the nameway as for the ASSOCIATE construct.
R1148 select-rank-construct is select-rank-stmt
[ select-rank-case-stmt
block ]...
end-select-rank-stmt
R1149 select-rank-stmt is [ select-construct-name : ] SELECT RANK
( [ associate-name => ] selector )
C1150 The selector in a select-rank-stmt shall be the name of an assumed-rank array.
R1150 select-rank-case-stmt is RANK ( scalar-int-constant-expr ) [ select-construct-name ]
or RANK ( * ) [ select-construct-name ]
or RANK DEFAULT [ select-construct-name ]
C1151 A scalar-int-constant-expr in a select-rank-case-stmt shall be nonnegative and less than or equal to the
maximum possible rank of selector.
C1152 For a given select-rank-construct, the same rank value shall not be specified in more than one select-rank-
case-stmt.
C1153 For a given select-rank-construct, there shall be at most one RANK ( * ) select-rank-case-stmt and at
most one RANK DEFAULT select-rank-case-stmt.
C1154 If select-construct-name appears on a select-rank-case-stmt the corresponding select-rank-stmt shall spe-
cify the same select-construct-name.
C1155 A SELECT RANK construct shall not have a select-rank-case-stmt that is RANK ( * ) if the selector
has the ALLOCATABLE or POINTER attribute.
R1151 end-select-rank-stmt is END SELECT [ select-construct-name ]
⃝c ISO/IEC 2017 – All rights reserved 199
ISO/IEC DIS 1539-1:2017 (E)
C1156 If the select-rank-stmt of a select-rank-construct specifies a select-construct-name, the corresponding
end-select-rank-stmt shall specify the same select-construct-name. If the select-rank-stmt of a select-
rank-construct does not specify a select-construct-name, the corresponding end-select-rank-stmt shall not
specify a select-construct-name.
that constitutes the selector.1 A SELECT RANK construct selects at most one block to be executed. During execution of that block, the11.1.10.2 Execution of the SELECT RANK construct
associate name identifies an entity which is associated (19.5.1.6) with the selector. A RANK ( * ) statement2 It is permissible to branch to an end-select-rank-stmt only from within its SELECT RANK construct.matches the selector if the selector is argument associated with an assumed-size array. A RANK ( scalar-int-
constant-expr ) statement matches the selector if the selector has that rank and is not argument associated with
an assumed-size array. A RANK DEFAULT statement matches the selector if no other select-rank-case-stmt
of the construct matches the selector. If a select-rank-case-stmt matches the selector, the block following that
statement is executed; otherwise, control is transferred to the end-select-rank-stmt.
11.1.10.3 Attributes of a SELECT RANK associate name1 Within the block following a RANK DEFAULT statement, the associating entity (19.5.5) is assumed-rank and has
exactly the same attributes as the selector. Within the block following a RANK ( * ) statement, the associating2 The associating entity has the ALLOCATABLE, POINTER, or TARGET attribute if the selector has thatentity has rank 1 and is assumed-size, as if it were declared with DIMENSION(1:*). Within the block following
a RANK ( scalar-int-constant-expr ) statement, the associating entity has the specified rank; the lower bound of
each dimension is the result of the intrinsic function LBOUND (16.9.109) applied to the corresponding dimension
of the selector, and the upper bound of each dimension is the result of the intrinsic function UBOUND (16.9.196)
applied to the corresponding dimension of the selector.
attribute. The other attributes of the associating entity are described in 11.1.3.3.11.1.10.4 Examples of the SELECT RANK construct
NOTE 11.26
This example shows how to use a SELECT RANK construct to process scalars and rank-2 arrays; anything
else will be rejected as an error.
SUBROUTINE process(x)
REAL x(..)
!
SELECT RANK(x)
RANK (0)
x = 0
RANK (2)
IF (SIZE(x,2)>=2) x(:,2) = 2
Print *, ’I did not expect rank’, RANK(x), ’shape’, SHAPE(x)
ERROR STOP ’process bad arg’
NOTE 11.27
The following example shows how to process assumed-size arrays, including how to use sequence association
if you want to do multi-dimensional processing of an assumed-size array.
200 | ⃝c ISO/IEC 2017 – All rights reserved |
ISO/IEC DIS 1539-1:2017 (E)NOTE 11.27 (cont.)
SELECT RANK (y => x)RANK (*)
IF (RANK(x)==2) THEN
! Special code for the rank two case.
CALL sequence_assoc_2(y, LBOUND(x,1), UBOUND(x,1), LBOUND(x,2))
! We just do all the other ranks in array element order.
i = 1
IF (y(i)==0) Exit
y(i) = -y(i)
i = i + 1
...
...
SUBROUTINE sequence_assoc_2(a, lb1, ub1, lb2)
INTEGER, INTENT (IN) :: lb1, ub1, lb2outer: DOREAL a(lb1:ub1,lb2:*)
j = lb2
DO i=lb1,ub1IF (a(i,j)==0) EXIT outer
a(i,j) = a(i,j)**2
j = j + 1
IF (ANY(a(:,j)==0)) EXIT
j = j + 1
END DO outer
END SUBROUTINE
11.1.11 SELECT TYPE construct 11.1.11.1 Purpose and form of the SELECT TYPE construct
1 The SELECT TYPE construct selects for execution at most one of its constituent blocks. The selection is based
on the dynamic type of an expression. A name is associated with the expression or variable (19.4, 19.5.1.6), in2 The associate name of a SELECT TYPE construct is the associate-name if specified; otherwise it is the namethe same way as for the ASSOCIATE construct.
R1152 select-type-construct is select-type-stmt
[ type-guard-stmt
block ] ...
end-select-type-stmt
R1153 select-type-stmt is [ select-construct-name : ] SELECT TYPE
( [ associate-name => ] selector )
C1157 (R1153) If selector is not a named variable, associate-name => shall appear.
C1158 (R1153) If selector is not a variable or is a variable that has a vector subscript, neither associate-name
nor any subobject thereof shall appear in a variable definition context (19.6.7).
C1159 (R1153) The selector in a select-type-stmt shall be polymorphic.
⃝c ISO/IEC 2017 – All rights reserved 201
ISO/IEC DIS 1539-1:2017 (E)
R1154 type-guard-stmt is TYPE IS ( type-spec ) [ select-construct-name ]
or CLASS IS ( derived-type-spec ) [ select-construct-name ]
or CLASS DEFAULT [ select-construct-name ]
C1160 (R1154) The type-spec or derived-type-spec shall specify that each length type parameter is assumed.
C1161 (R1154) The type-spec or derived-type-spec shall not specify a type with the BIND attribute or the
SEQUENCE attribute.
C1162 (R1152) If selector is not unlimited polymorphic, each TYPE IS or CLASS IS type-guard-stmt shall
specify an extension of the declared type of selector.
C1163 (R1152) For a given select-type-construct, the same type and kind type parameter values shall not be
specified in more than one TYPE IS type-guard-stmt and shall not be specified in more than one CLASS
IS type-guard-stmt.
C1164 (R1152) For a given select-type-construct, there shall be at most one CLASS DEFAULT type-guard-stmt.
R1155 end-select-type-stmt is END SELECT [ select-construct-name ]
C1165 (R1152) If the select-type-stmt of a select-type-construct specifies a select-construct-name, the correspond-
ing end-select-type-stmt shall specify the same select-construct-name. If the select-type-stmt of a select-
type-construct does not specify a select-construct-name, the corresponding end-select-type-stmt shall not
specify a select-construct-name. If a type-guard-stmt specifies a select-construct-name, the corresponding
select-type-stmt shall specify the same select-construct-name.
that constitutes the selector.1 Execution of a SELECT TYPE construct causes evaluation of every expression within a selector that is a variable11.1.11.2 Execution of the SELECT TYPE construct
designator, or evaluation of a selector that is not a variable designator.2 A SELECT TYPE construct selects at most one block to be executed. During execution of that block, the
associate name identifies an entity which is associated (19.5.1.6) with the selector.3 A TYPE IS type guard statement matches the selector if the dynamic type and kind type parameter values of
the selector are the same as those specified by the statement. A CLASS IS type guard statement matches the4 The block to be executed is selected as follows.selector if the dynamic type of the selector is an extension of the type specified by the statement and the kind
type parameter values specified by the statement are the same as the corresponding type parameter values of the
dynamic type of the selector.
(1) If a TYPE IS type guard statement matches the selector, the block following that statement isexecuted.
(2) Otherwise, if exactly one CLASS IS type guard statement matches the selector, the block following
that statement is executed.
(3) Otherwise, if several CLASS IS type guard statements match the selector, one of these statements
will inevitably specify a type that is an extension of all the types specified in the others; the block
following that statement is executed.
(4) Otherwise, if there is a CLASS DEFAULT type guard statement, the block following that statement
is executed.
(5) Otherwise, no block is executed.
202 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 11.28
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.
5 Within the block following a TYPE IS type guard statement, the associating entity (19.5.5) is not polymorphic
(7.3.2.3), has the type named in the type guard statement, and has the type parameter values of the selector.6 Within the block following a CLASS IS type guard statement, the associating entity is polymorphic and has the
declared type named in the type guard statement. The type parameter values of the associating entity are the7 Within the block following a CLASS DEFAULT type guard statement, the associating entity is polymorphic andcorresponding type parameter values of the selector.
has the same declared type as the selector. The type parameter values of the associating entity are those of the8 The other attributes of the associating entity are described in 11.1.3.3.declared type of the selector.
NOTE 11.29
If the declared type of the selector is T, specifying CLASS DEFAULT has the same effect as specifying
CLASS IS (T).
9 It is permissible to branch to an end-select-type-stmt only from within its SELECT TYPE construct.
11.1.11.3 Examples of the SELECT TYPE constructNOTE 11.30
REAL :: X, Y
TYPE, EXTENDS(POINT) :: POINT_3D
REAL :: ZEND TYPE POINT_3D
TYPE, EXTENDS(POINT) :: COLOR_POINT
INTEGER :: COLOR
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 hereTYPE IS ( POINT_3D )PRINT *, A%X, A%Y ! This block gets executed
! "TYPE ( POINT_3D ) :: A" implied herePRINT *, A%X, A%Y, A%Z
NOTE 11.31
The following example illustrates the omission of associate-name. It uses the declarations from NOTE
11.30.
⃝c ISO/IEC 2017 – All rights reserved | |
203 | |
| |
ISO/IEC DIS 1539-1:2017 (E)
NOTE 11.31 (cont.) | |
11.1.12 EXIT statement
1 The EXIT statement provides one way of terminating a loop, or completing execution of another construct.
R1156 exit-stmt is EXIT [ construct-name ]2 An EXIT statement belongs to a particular construct. If a construct name appears, the EXIT statement belongsC1166 If a construct-name appears on an EXIT statement, the EXIT statement shall be within that construct;
otherwise, it shall be within at least one do-construct.
to that construct; otherwise, it belongs to the innermost DO construct in which it appears.3 When an EXIT statement that belongs to a DO construct is executed, it terminates the loop (11.1.7.4.5) andC1167 An exit-stmt shall not appear within a CHANGE TEAM, CRITICAL, or DO CONCURRENT construct
if it belongs to that construct or an outer construct.
any active loops contained within the terminated loop. When an EXIT statement that belongs to a non-DO1 Branching is used to alter the normal execution sequence. A branch causes a transfer of control from one statementconstruct is executed, it terminates any active loops contained within that construct, and completes execution of
that construct.
11.2 Branching
11.2.1 Branch concepts
to a labeled branch target statement in the same inclusive scope. Branching may be caused by a GO TO state-1 Execution of a GO TO statement causes a branch to the branch target statement identified by the label.ment, a computed GO TO statement, a CALL statement that has an alt-return-spec, or an input/output statement that has
an END=, EOR=, or ERR= specifier. Although procedure references and control constructs can cause transfer
of control, they are not branches. A branch target statement is an action-stmt, associate-stmt, end-associate-
stmt, if-then-stmt, end-if-stmt, select-case-stmt, end-select-stmt, select-rank-stmt, end-select-rank-stmt, select-
type-stmt, end-select-type-stmt, do-stmt, end-do-stmt, block-stmt, end-block-stmt, critical-stmt, end-critical-stmt,
forall-construct-stmt, forall-stmt, where-construct-stmt, end-function-stmt, end-mp-subprogram-stmt, end-program-
stmt, or end-subroutine-stmt.
11.2.2 GO TO statement
R1157 goto-stmt is GO TO label
C1168 (R1157) The label shall be the statement label of a branch target statement that appears in the same
inclusive scope as the goto-stmt.
204 ⃝c ISO/IEC 2017 – All rights reserved1 Execution of a computed GO TO statement causes evaluation of the scalar integer expression. If this value is i such that 1 ≤ i ≤ n
ISO/IEC DIS 1539-1:2017 (E)
11.2.3 Computed GO TO statement
R1158 computed-goto-stmt is GO TO ( label-list ) [ , ] scalar-int-expr
C1169 (R1158) Each label in label-list shall be the statement label of a branch target statement that appears in the same inclusive
scope as the computed-goto-stmt.
where n is the number of labels in label-list, a branch occurs to the branch target statement identified by the ith label in the list of1 Execution of a CONTINUE statement has no effect.labels. If i is less than 1 or greater than n, the execution sequence continues as though a CONTINUE statement were executed.
11.3 CONTINUE statement
R1159 continue-stmt is CONTINUE1 Execution of a STOP statement initiates normal termination of execution. Execution of an ERROR STOP11.4 STOP and ERROR STOP statements
R1160 stop-stmt is STOP [ stop-code ] [ , QUIET = scalar-logical-expr]
R1161 error-stop-stmt is ERROR STOP [ stop-code ] [ , QUIET = scalar-logical-expr]
R1162 stop-code is scalar-default-char-expr
or scalar-int-expr
C1170 (R1162) The scalar-int-expr shall be of default kind.
statement initiates error termination of execution.2 When an image is terminated by a STOP or ERROR STOP statement, its stop code, if any, is made available
in a processor-dependent manner. If the stop-code is an integer, it is recommended that the value be used as3 If QUIET= is omitted or the scalar-logical-expr has the value false:the process exit status, if the processor supports that concept. If the stop-code in a STOP statement is of type
character or does not appear, or if an end-program-stmt is executed, it is recommended that the value zero be
supplied as the process exit status, if the processor supports that concept. If the stop-code in an ERROR STOP
statement is of type character or does not appear, it is recommended that a processor-dependent nonzero value
be supplied as the process exit status, if the processor supports that concept.
• if any exception (17) is signaling on that image, the processor shall issue a warning indicating which4 If QUIET= appears and the scalar-logical-expr has the value true, no output of signaling exceptions or stop codeexceptions are signaling, and this warning shall be on the unit identified by the named constant ERROR_-
UNIT from the intrinsic module ISO_FORTRAN_ENV (16.10.2.9);
• if a stop code is specified, it is recommended that it be made available by formatted output to the same
unit.
shall be produced.1 Execution of a FAIL IMAGE statement causes the executing image to cease participating in program executionNOTE 11.32
When normal termination occurs on more than one image, it is expected that a processor-dependent sum-
mary of any stop codes and signaling exceptions will be made available.
⃝c ISO/IEC 2017 – All rights reserved 205
ISO/IEC DIS 1539-1:2017 (E)
NOTE 11.33
If the integer stop-code is used as the process exit status, the processor 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).
11.5 FAIL IMAGE statement
R1163 fail-image-stmt is FAIL IMAGE
without initiating termination. No further statements are executed by that image.NOTE 11.34
The FAIL IMAGE statement allows a program to test a recovery algorithm without needing an actual
failure.
On a processor that does not have the ability to detect that an image has failed, execution of a FAIL
IMAGE statement might provide a simulated failure environment that provides debug information.
In a piece of code that executes about once a second, invoking this subroutine on an image
REAL :: X
CALL RANDOM_NUMBER (X)
IF (X<0.001) FAIL IMAGE
will cause that image to have an independent 1/1000 chance of failure every second if the random number
generators on different images are independent.
Note that FAIL IMAGE is not an image control statement.
11.6 |
Image execution control
| ||
1 The execution sequence on each image is specified in 5.3.5. | |||
2 Execution of an image control statement divides the execution sequence on an image into segments. Each of the
following is an image control statement:3 All image control statements except CRITICAL, END CRITICAL, EVENT POST, EVENT WAIT, FORM
TEAM, LOCK, and UNLOCK include the effect of executing a SYNC MEMORY statement (11.6.5).4 During an execution of a statement that invokes more than one procedure, at most one invocation shall cause
execution of an image control statement other than CRITICAL or END CRITICAL.1 On each image, the sequence of statements executed before the first execution of an image control statement,
between the execution of two image control statements, or after the last execution of an image control statement2 By execution of image control statements or user-defined ordering (11.6.5), the program can ensure that the
execution of the ith segment on image P, Pi , either precedes or succeeds the execution of the j th segment on3 A coarray may be referenced or defined by execution of an atomic subroutine during the execution of a segment
that is unordered relative to the execution of a segment in which the coarray is referenced or defined by execution1 The STAT= and ERRMSG= specifiers for image control statements are described in 11.6.11. 2 Successful execution of a SYNC ALL statement performs a synchronization of all images in the current team.
Execution on an image, M, of the segment following the SYNC ALL statement is delayed until each other image | |||
IF (THIS_IMAGE()==1) THEN
READ (*,*) PDO I = 2, NUM_IMAGES()
P[I] = P
208 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
11.6.4 SYNC IMAGES statement R1166 sync-images-stmt is SYNC IMAGES ( image-set [ , sync-stat-list ] ) R1167 image-set is int-expr or *C1173 An image-set that is an int-expr shall be scalar or of rank one.
C1174 The value of image-set shall not depend on the value of stat-variable or errmsg-variable.
1 If image-set is an array expression, the value of each element shall be positive and not greater than the number
of images in the current team, and there shall be no repeated values.2 If image-set is a scalar expression, its value shall be positive and not greater than the number of images in the
current team.3 An image-set that is an asterisk specifies all images in the current team.
4 Execution of a SYNC IMAGES statement performs a synchronization of the image with each of the other images
in the image-set. Executions of SYNC IMAGES statements on images M and T correspond if the number oftimes image M has executed a SYNC IMAGES statement in the current team with T in its image set is the same
as the number of times image T has executed a SYNC IMAGES statement with M in its image set in this team.
The segments that executed before the SYNC IMAGES statement on either image precede the segments that
execute after the corresponding SYNC IMAGES statement on the other image.
NOTE 11.41
A SYNC IMAGES statement that specifies the single image index value THIS_IMAGE ( ) in its image set
is allowed. This simplifies writing programs for an arbitrary number of images by allowing correct execution
in the limiting case of the number of images being equal to one.
NOTE 11.42
In a program that uses SYNC ALL as its only synchronization mechanism, every SYNC ALL statement
could be replaced by a SYNC IMAGES (*) statement, but SYNC ALL might give better performance.
SYNC IMAGES statements are not required to specify the entire image set, or even the same image set,
on all images participating in the synchronization. In the following example, image 1 will wait for each of
the other images to execute the statement SYNC IMAGES (1). The other images wait for image 1 to set
up the data, but do not wait on any other image.
IF (THIS_IMAGE() == 1) then
! Set up coarray data needed by all other images.
SYNC IMAGES(*)
SYNC IMAGES(1)
! Use the data set up by image 1.
When the following example runs on five or more images, each image synchronizes with both of its neighbors,
in a circular fashion.
INTEGER :: up, down...
IF (NUM_IMAGES () > 1) THEN
up = THIS_IMAGE () + 1; IF (up>NUM_IMAGES ()) up = 1
down = THIS_IMAGE () - 1; IF (down==0) down = NUM_IMAGES ()
SYNC IMAGES ( (/ up, down /) )
⃝c ISO/IEC 2017 – All rights reserved 209
ISO/IEC DIS 1539-1:2017 (E)
NOTE 11.42 (cont.)This might appear to have the same effect as SYNC ALL but there is no ordering between the preceding
and succeeding segments on non-adjacent images. For example, the segment preceding the SYNC IMAGES
statement on image 3 will be ordered before those succeeding it on images 2 and 4, but not those on images
1 and 5.
NOTE 11.43
In the following example, each image synchronizes with its neighbor.
INTEGER :: ME, NE, STEP, NSTEPS
NE = NUM_IMAGES()
ME = THIS_IMAGE()
... ! Initial calculation
DO STEP = 1, NSTEPS
IF (ME > 1) SYNC IMAGES(ME-1)... ! Perform calculation
IF (ME < NE) SYNC IMAGES(ME+1)
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.
11.6.5 |
SYNC MEMORY statement
1 Execution of a SYNC MEMORY statement ends one segment and begins another; those two segments can be
ordered by a user-defined way with respect to segments on other images.2 If, by execution of statements on image P,
• a variable X on image Q is defined, referenced, becomes undefined, or has its allocation status, pointerthen the action regarding X on image Q precedes the action regarding Y on image Q. 3 User-defined ordering of segment Pi on image P to precede segment Qj on image Q occurs when
• image P executes an image control statement that ends segment Pi , and then executes statements that4 Execution of the cooperative synchronization between images P and Q shall include a dependency that forces
execution on image P of the statements that initiate the synchronization to precede the execution on image Q of |
CALL EXTERNAL_SYNC ()
IF (IAM == 2) WRITE (*,*) X[1]
where executing the subroutine EXTERNAL_SYNC has an image synchronization effect similar to execut-
ing a SYNC ALL statement.
11.6.6 |
SYNC TEAM statement
| ||||||||
1 The team-value shall identify an ancestor team, the current team, or a team whose parent is the current team. | |||||||||
The executing image shall be a member of the specified team.2 Successful execution of a SYNC TEAM statement performs a synchronization of the team identified by team- | |||||||||
value. Execution on an image, M, of the segment following the SYNC TEAM statement is delayed until each1 The EVENT POST statement posts an event. | |||||||||
R1170 event-post-stmt is EVENT POST ( event-variable [ , sync-stat-list ] )2 The event-variable shall not depend on the value of stat-variable or errmsg-variable. | |||||||||
3 Successful execution of an EVENT POST statement atomically increments the count of the event variable by
one. If an error condition occurs during execution of an EVENT POST statement, the value of the count of the1 The EVENT WAIT statement waits until an event is posted.
R1172 event-wait-stmt is EVENT WAIT ( event-variable [ , event-wait-spec-list ] )2 The event-variable shall not depend on the value of stat-variable or errmsg-variable. 3 Execution of an EVENT WAIT statement consists of the following sequence of actions:
| |||||||||
! Process the next item in your work queue
LOCK (queue_lock) ! New segment A starts
! This segment A is ordered with respect to
! segment B executed by image me-1 below because of lock exclusion
IF (work_queue_size>0) THEN
! Fetch the next job from the queuejob = work_queue(work_queue_size)
work_queue_size = work_queue_size-1
UNLOCK (queue_lock) ! Segment ends
... ! Actually process the task
! Add a new task on neighbors queue:
LOCK(queue_lock[me+1]) ! Starts segment B
! This segment B is ordered with respect to
! segment A executed by image me+1 above because of lock exclusion
IF (work_queue_size[me+1]<SIZE (work_queue)) THEN
work_queue_size[me+1] = work_queue_size[me+1]+1work_queue(work_queue_size[me+1])[me+1] = job
UNLOCK (queue_lock[me+1]) ! Ends segment B
11.6.11 STAT= and ERRMSG= specifiers in image control statements 1 In an image control statement, the stat-variable in a sync-stat shall not depend on the value of an errmsg-variable
in a sync-stat, event-variable, lock-variable, team-variable, or the scalar-logical-variable in the ACQUIRED_-2 If a STAT= specifier appears in a sync-stat in an image control statement, the stat-variable is assigned the valueLOCK= specifier. The errmsg-variable in a sync-stat shall not depend on the value of a stat-variable in a
sync-stat, event-variable, lock-variable, team-variable, or the scalar-logical-variable in the ACQUIRED_LOCK=
specifier.
zero if execution of the statement is successful.3 If the STAT= specifier appears in a sync-stat in an EVENT WAIT or SYNC MEMORY statement and an error
condition occurs, stat-variable is assigned a processor-dependent positive value that is different from the value4 The images involved in execution of an END TEAM, FORM TEAM, or SYNC ALL statement are those in theof STAT_FAILED_IMAGE (16.10.2.26) and STAT_STOPPED_IMAGE (16.10.2.29) from the intrinsic module
ISO_FORTRAN_ENV (16.10.2).
current team. The images involved in execution of a CHANGE TEAM or SYNC TEAM statement are those of5 If the STAT= specifier appears in a sync-stat in a CHANGE TEAM, END TEAM, EVENT POST, FORMthe specified team. The images involved in execution of a SYNC IMAGES statement are the images specified
and the executing image. The images involved in execution of an EVENT POST statement are the image on
which the event variable is located and the executing image.
TEAM, SYNC ALL, SYNC IMAGES, or SYNC TEAM statement,6 If the STAT= specifier appears in a sync-stat in a SYNC ALL, SYNC IMAGES, or SYNC TEAM statement⃝c ISO/IEC 2017 – All rights reserved 215
ISO/IEC DIS 1539-1:2017 (E)
• if one of the images involved has stopped, stat-variable is assigned the value STAT_STOPPED_IMAGE
(16.10.2.29) from the intrinsic module ISO_FORTRAN_ENV;
• otherwise, if one of the images involved has failed and no other error condition occurs, the intended action
is performed on the active images involved and stat-variable is assigned the value STAT_FAILED_IMAGE
(16.10.2.26) from the intrinsic module ISO_FORTRAN_ENV;
• otherwise, if any other error condition occurs, stat-variable is assigned a processor-dependent positive value
that is different from the values of STAT_STOPPED_IMAGE and STAT_FAILED_IMAGE.
and the error condition STAT_STOPPED_IMAGE occurs, the effect is the same as that of executing the SYNC7 If the STAT= specifier appears in a sync-stat in a LOCK statement,MEMORY statement, except for defining the stat-variable.
• if the image on which the lock variable is located has failed, the stat-variable becomes defined with the8 If the STAT= specifier appears in a sync-stat in an UNLOCK statement,value STAT_FAILED_IMAGE;
• otherwise, if the lock variable is locked by the executing image, the stat-variable becomes defined with the
value of STAT_LOCKED (16.10.2.27) from the intrinsic module ISO_FORTRAN_ENV;
• otherwise, if the lock variable is unlocked because of the failure of the image that locked it, stat-variable
becomes defined with the value STAT_UNLOCKED_FAILED_IMAGE (16.10.2.31) from the intrinsic
module ISO_FORTRAN_ENV.
• if the image on which the lock variable is located has failed, the stat-variable becomes defined with the9 If the STAT= specifier appears in a sync-stat in a LOCK or UNLOCK statement and any other error condi-value STAT_FAILED_IMAGE;
• otherwise, if the lock variable has the value unlocked, the stat-variable becomes defined with the value of
STAT_UNLOCKED (16.10.2.30) from the intrinsic module ISO_FORTRAN_ENV;
• otherwise, if the lock variable is locked by a different image, the stat-variable becomes defined with the
value STAT_LOCKED_OTHER_IMAGE (16.10.2.28) from the intrinsic module ISO_FORTRAN_ENV.
tion occurs during execution of that statement, the stat-variable becomes defined with a processor-dependent10 If an image completes execution of a CRITICAL statement that has a sync-stat that is a STAT= specifier and thepositive integer value that is different from STAT_LOCKED, STAT_LOCKED_OTHER_IMAGE, STAT_UN-
LOCKED, and STAT_UNLOCKED_FAILED_IMAGE.
previous image to have entered the construct failed while executing it, the stat-variable becomes defined with the11 If an error condition occurs during execution of an image control statement that does not contain the STAT=value STAT_FAILED_IMAGE and execution of the construct continues normally. If any other error condition
occurs during execution of a CRITICAL statement that has a STAT= specifier, the stat-variable becomes defined
with a processor-dependent value other than STAT_FAILED_IMAGE.
specifier in a sync-stat, error termination is initiated.12 If an ERRMSG= specifier appears in an image control statement and an error condition occurs, errmsg-variable
is assigned an explanatory message, truncated or padded according to the rules of intrinsic assignment. If no13 The set of error conditions that can occur in an image control statement is processor dependent.such condition occurs, the definition status and value of errmsg-variable are unchanged.
NOTE 11.52A processor might detect communication failure between images and treat it as an error condition. A
processor might also treat an invalid set of images in a SYNC IMAGES statement as an error condition.
216 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)12 Input/output statements
12.1 Input/output concepts 1 Input statements provide the means of transferring data from external media to internal storage or from an internal
file to internal storage. This process is called reading. Output statements provide the means of transferring data2 In addition to the statements that transfer data, there are auxiliary input/output statements to manipulate thefrom internal storage to external media or from internal storage to an internal file. This process is called writing.
Some input/output statements specify that editing of the data is to be performed.
external medium, or to describe or inquire about the properties of the connection to the external medium.3 The input/output statements are the BACKSPACE, CLOSE, ENDFILE, FLUSH, INQUIRE, OPEN, PRINT,
READ, REWIND, WAIT, and WRITE statements.4 A file is composed of either a sequence of file storage units (12.3.5) or a sequence of records, which provide an
extra level of organization to the file. A file composed of records is called a record file. A file composed of file5 A file is either an external file (12.3) or an internal file (12.4).storage units is called a stream file. A processor may allow a file to be viewed both as a record file and as a stream
file; in this case the relationship between the file storage units when viewed as a stream file and the records when
viewed as a record file is processor dependent.
12.2 Records1 A record is a sequence of values or a sequence of characters. For example, a line on a terminal is usually considered12.2.1 Definition of a record
to be a record. However, a record does not necessarily correspond to a physical entity. There are three kinds of1 A formatted record consists of a sequence of characters that are representable in the processor; however, arecords:
(1) formatted;
(2) unformatted;
(3) endfile.
NOTE 12.1
What is called a “record” in Fortran is commonly called a “logical record”. There is no concept in Fortran
of a “physical record.”
12.2.2 Formatted record
processor may prohibit some control characters (6.1.1) from appearing in a formatted record. The length of a1 An unformatted record consists of a sequence of values in a processor-dependent form and may contain dataformatted record is measured in characters and depends primarily on the number of characters put into the record
when it is written; however, it may depend on the processor and the external medium. The length may be zero.
Formatted records shall be read or written only by formatted input/output statements.
12.2.3 Unformatted record
of any type or may contain no data. The length of an unformatted record is measured in file storage units1 An endfile record is written explicitly by the ENDFILE statement; the file shall be connected for sequential⃝c ISO/IEC 2017 – All rights reserved 217
ISO/IEC DIS 1539-1:2017 (E)
(12.3.5) and depends on the output list (12.6.3) used when it is written, as well as on the processor and the
external medium. The length may be zero. Unformatted records may be read or written only by unformatted
input/output statements.
12.2.4 Endfile record
access. An endfile record is written implicitly to a file connected for sequential access when the most recent data2 An endfile record may occur only as the last record of a file. An endfile record does not have a length property.transfer statement referring to the file is an output statement, no intervening file positioning statement referring
to the file has been executed, and
• a REWIND or BACKSPACE statement references the unit to which the file is connected, or
• the unit is closed, either explicitly by a CLOSE statement, implicitly by normal termination, or implicitly
by another OPEN statement for the same unit.
NOTE 12.2An endfile record does not necessarily have any physical embodiment. The processor can use a record count
or any 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 (12.8.2).
12.3 External files 12.3.1 External file concepts 1 An external file is any file that exists in a medium external to the program.
2 At any given time, there is a processor-dependent set of allowed access methods, a processor-dependent set of
allowed forms, a processor-dependent set of allowed actions, and a processor-dependent set of allowed record3 A file may have a name; a file that has a name is called a named file. The name of a named file is represented bylengths for a file.
NOTE 12.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 character string value. The set of allowable names for a file is processor dependent. Whether a named file on4 An external file that is connected to a unit has a position property (12.3.4).one image is the same as a file with the same name on another image is processor dependent.
NOTE 12.4
If different files are needed on each image, using a different file name on each image will improve portability
of the code. One technique is to incorporate the image index as part of the name.
NOTE 12.5For more explanatory information on external files, see C.7.1.
12.3.2 File existence 1 At any given time, there is a processor-dependent set of external files that exist for a program. A file may be
known to the processor, yet not exist for a program at a particular time.2 To create a file means to cause a file to exist that did not exist previously. To delete a file means to terminate218 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
the existence of the file.3 All input/output statements may refer to files that exist. A CLOSE, ENDFILE, FLUSH, INQUIRE, OPEN,
PRINT, REWIND, or WRITE statement is permitted to refer to a file that does not exist. No other input/output1 There are three methods of accessing the data of an external file: sequential, direct, and stream. Some files maystatement shall refer to a file that does not exist. Execution of a WRITE, PRINT, or ENDFILE statement
referring to a preconnected file that does not exist creates the file. This file is a different file from one preconnected
on any other image.
12.3.3 File access
12.3.3.1 File access methods
have more than one allowed access method; other files may be restricted to one access method.2 The method of accessing a file is determined when the file is connected to a unit (12.5.4) or when the file isNOTE 12.6
For example, a processor might provide only sequential access to a file on magnetic tape. Thus, the set of
allowed access methods depends on the file and the processor.
created if the file is preconnected (12.5.5).1 Sequential access is a method of accessing the records of an external record file in order.12.3.3.2 Sequential access
2 While connected for sequential access, an external file has the following properties.
• The order of the records is the order in which they were written if the direct access method is not a memberof the set of allowed access methods for the file. If the direct access method is also a member of the set of
allowed access methods for the file, the order of the records is the same as that specified for direct access.
In this case, the first record accessible by sequential access is the record whose record number is 1 for direct
access. The second record accessible by sequential access is the record whose record number is 2 for direct
access, etc. A record that has not been written since the file was created shall not be read.
• The records of the file are either all formatted or all unformatted, except that the last record of the file may
be an endfile record. Unless the previous reference to the file was an output statement, the last record, if
any, of the file shall be an endfile record.
• The records of the file shall be read or written only by sequential access data transfer statements.
12.3.3.3 Direct access 1 Direct access is a method of accessing the records of an external record file in arbitrary order.
2 While connected for direct access, an external file has the following properties.
• Each record of the file is uniquely identified by a positive integer called the record number. The recordnumber of a record is specified when the record is written. Once established, the record number of a record
can never be changed. The order of the records is the order of their record numbers.
• The records of the file are either all formatted or all unformatted. If the sequential access method is also a
member of the set of allowed access methods for the file, its endfile record, if any, is not considered to be
part of the file while it is connected for direct access. If the sequential access method is not a member of
the set of allowed access methods for the file, the file shall not contain an endfile record.
• The records of the file shall be read or written only by direct access data transfer statements.
• All records of the file have the same length.
⃝c ISO/IEC 2017 – All rights reserved 219
ISO/IEC DIS 1539-1:2017 (E)
• Records need not be read or written in the order of their record numbers. Any record may be writteninto the file while it is connected to a unit. For example, it is permissible to write record 3, even though
records 1 and 2 have not been written. Any record may be read from the file while it is connected to a
unit, provided that the record has been written since the file was created, and if a READ statement for this
connection is permitted.
• The records of the file shall not be read or written using list-directed formatting (13.10), namelist formatting
(13.11), or a nonadvancing data transfer statement (12.3.4.2).
NOTE 12.7
A record cannot be deleted; however, a record can be rewritten.
12.3.3.4 Stream access 1 Stream access is a method of accessing the file storage units (12.3.5) of an external stream file.
1 A unit, specified by an io-unit, provides a means for referring to a file.
2 The properties of an external file connected for stream access depend on whether the connection is for unformatted
or formatted access. While connected for stream access, the file storage units of the file shall be read or written3 While connected for unformatted stream access, an external file has the following properties.only by stream access data transfer statements.
• Each file storage unit in the file is uniquely identified by a positive integer called the position. The first file4 While connected for formatted stream access, an external file has the following properties.storage unit in the file is at position 1. The position of each subsequent file storage unit is one greater than
that of its preceding file storage unit.
• If it is possible to position the file, the file storage units need not be read or written in order of their position.
For example, it might be permissible to write the file storage unit at position 3, even though the file storage
units at positions 1 and 2 have not been written. Any file storage unit may be read from the file while it is
connected to a unit, provided that the file storage unit has been written since the file was created, and if a
READ statement for this connection is permitted.
• Some file storage units of the file may contain record markers; this imposes a record structure on the filein addition to its stream structure. There might or might not be a record marker at the end of the file. If
there is no record marker at the end of the file, the final record is incomplete.
• No maximum length (12.5.6.15) is applicable to these records.
• Writing an empty record with no record marker has no effect.
• Each file storage unit in the file is uniquely identified by a positive integer called the position. The first file
storage unit in the file is at position 1. The relationship between positions of successive file storage units is
processor dependent; not all positive integers need correspond to valid positions.
• If it is possible to position the file, the file position can be set to a position that was previously identified
by the POS= specifier in an INQUIRE statement.
• A processor may prohibit some control characters (6.1.1) from appearing in a formatted stream file.
NOTE 12.8
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.
NOTE 12.9
There might be some character positions in the file that do not correspond to characters written; this is
because on some processors a record marker could 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 (12.10.2.22).
220 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
12.3.4 File position 12.3.4.1 General 1 Execution of certain input/output statements affects the position of an external file. Certain circumstances can cause the position of a file to become indeterminate.2 The initial point of a file is the position just before the first record or file storage unit. The terminal point is the
position just after the last record or file storage unit. If there are no records or file storage units in the file, the3 If a record file is positioned within a record, that record is the current record; otherwise, there is no currentinitial point and the terminal point are the same position.
record.4 Let n be the number of records in the file. If 1 < i ≤ n and a file is positioned within the ith record or between
the (i − 1)th record and the ith record, the (i − 1)th record is the preceding record. If n ≥ 1 and the file is5 If 1 ≤ i < n and a file is positioned within the ith record or between the ith and (i + 1)th record, the (i + 1)thpositioned at its terminal point, the preceding record is the nth and last record. If n = 0 or if a file is positioned
at its initial point or within the first record, there is no preceding record.
record is the next record. If n ≥ 1 and the file is positioned at its initial point, the first record is the next record.6 For a file connected for stream access, the file position is either between two file storage units, at the initial pointIf n = 0 or if a file is positioned at its terminal point or within the nth (last) record, there is no next record.
of the file, at the terminal point of the file, or undefined.1 An advancing input/output statement always positions a record file after the last record read or written, unless12.3.4.2 Advancing and nonadvancing input/output
there is an error condition.2 A nonadvancing input/output statement may position a record file at a character position within the current
record, or a subsequent record (13.8.2). Using nonadvancing input/output, it is possible to read or write a record1 The positioning of the file prior to data transfer depends on the method of access: sequential, direct, or stream.of the file by a sequence of data transfer statements, each accessing a portion of the record. If a nonadvancing
output statement leaves a file positioned within a current record and no further output statement is executed for
the file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement is executed for it, the effect is
as if the output statement were the corresponding advancing output statement.
12.3.4.3 File position prior to data transfer
2 For sequential access on input, if there is a current record, the file position is not changed. Otherwise, the file is positioned at the beginning of the next record and this record becomes the current record. Input shall not occur3 If the file contains an endfile record, the file shall not be positioned after the endfile record prior to data transfer.if there is no next record or if there is a current record and the last data transfer statement accessing the file
performed output.
However, a REWIND or BACKSPACE statement may be used to reposition the file.4 For sequential access on output, if there is a current record, the file position is not changed and the current record
becomes the last record of the file. Otherwise, a new record is created as the next record of the file; this new5 For direct access, the file is positioned at the beginning of the record specified by the REC= specifier. This recordrecord becomes the last and current record of the file and the file is positioned at the beginning of this record.
becomes the current record.6 For stream access, the file is positioned immediately before the file storage unit specified by the POS= specifier;
if there is no POS= specifier, the file position is not changed.7 File positioning for child data transfer statements is described in 12.6.4.8.⃝c ISO/IEC 2017 – All rights reserved 221
ISO/IEC DIS 1539-1:2017 (E)
12.3.4.4 File position after data transfer1 If an error condition (12.11) occurred, the position of the file is indeterminate. If no error condition occurred,
but an end-of-file condition (12.11) occurred as a result of reading an endfile record, the file is positioned afterthe endfile record.
2 For unformatted stream input/output, if no error condition occurred, the file position is not changed. For unformatted stream output, if the file position exceeds the previous terminal point of the file, the terminal point3 For formatted stream input, if an end-of-file condition occurred, the file position is not changed.is set to the file position.
NOTE 12.10
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.
4 For nonadvancing input, if no error condition or end-of-file condition occurred, but an end-of-record condition (12.11) occurred, the file is positioned after the record just read. If no error condition, end-of-file condition, or5 In all other cases, the file is positioned after the record just read or written and that record becomes the precedingend-of-record condition occurred in a nonadvancing input statement, the file position is not changed. If no error
condition occurred in a nonadvancing output statement, the file position is not changed.
record.6 For a formatted stream output statement, if no error condition occurred, the terminal point of the file is set to
the next position after the highest-numbered position to which a datum was transferred by the statement.1 A file storage unit is the basic unit of storage in a stream file or an unformatted record file. It is the unit of fileNOTE 12.11
The highest-numbered position might not be the current one if the output involved a T, TL, TR, or X edit
descriptor (13.8.1) and the statement is a nonadvancing output statement.
12.3.5 File storage units
position for stream access, the unit of record length for unformatted files, and the unit of file size for all external2 Every value in a stream file or an unformatted record file shall occupy an integer number of file storage units; iffiles.
the stream or record file is unformatted, this number shall be the same for all scalar values of the same type and3 For a file connected for unformatted stream access, the processor shall not have alignment restrictions that preventtype parameters. The number of file storage units required for an item of a given type and type parameters may
be determined using the IOLENGTH= specifier of the INQUIRE statement (12.10.3).
a value of any type from being stored at any positive integer file position.4 The number of bits in a file storage unit is given by the constant FILE_STORAGE_SIZE (16.10.2.11) defined
in the intrinsic module ISO_FORTRAN_ENV. It is recommended that the file storage unit be an 8-bit octet1 Internal files provide a means of transferring and converting data from internal storage to internal storage.where this choice is practical.
NOTE 12.12
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.
222 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.12 (cont.)
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 require-
ments of many applications, yet not so small that the data alignment requirements are likely to cause
significant performance problems.
12.4 Internal files
2 An internal file is a record file with the following properties. • The file is a variable of default, ASCII, or ISO 10646 character kind that is not an array section with avector subscript.
• A record of an internal file is a scalar character variable.
• If the file is a scalar character variable, it consists of a single record whose length is the same as the length
of the scalar character variable. If the file is a character array, it is treated as a sequence of character array
elements. Each array element, if any, is a record of the file. The ordering of the records of the file is the
same as the ordering of the array elements in the array (9.5.3.2) or the array section (9.5.3.3). Every record
of the file has the same length, which is the length of an array element in the array.
• A record of the internal file becomes defined by writing the record. If the number of characters written in
a record is less than the length of the record, the remaining portion of the record is filled with blanks. The
number of characters to be written shall not exceed the length of the record.
• A record may be read only if the record is defined.
• A record of an internal file may become defined (or undefined) by means other than an output statement.
For example, the character variable may become defined by a character assignment statement.
• An internal file is always positioned at the beginning of the first record prior to data transfer, except for
child data transfer statements (12.6.4.8). This record becomes the current record.
• The initial value of a connection mode (12.5.2) is the value that would be implied by an initial OPEN
statement without the corresponding keyword.
• Reading and writing records shall be accomplished only by sequential access formatted data transfer state-
ments.
• An internal file shall not be specified as the unit in a CLOSE, INQUIRE, or OPEN statement.
12.5 File connection 12.5.1 Referring to a file
R1201 io-unit is file-unit-number2 A unit is either an external unit or an internal unit. An external unit is used to refer to an external file andor *
or internal-file-variable
R1202 file-unit-number is scalar-int-expr
R1203 internal-file-variable is char-variable
C1201 (R1203) The char-variable shall not be an array section with a vector subscript.
C1202 (R1203) The char-variable shall be default character, ASCII character, or ISO 10646 character.
⃝c ISO/IEC 2017 – All rights reserved 223
ISO/IEC DIS 1539-1:2017 (E)
is specified by an asterisk or a file-unit-number. The value of file-unit-number shall be nonnegative, equal to3 On an image, the external unit identified by a particular value of a scalar-int-expr is the same external unit inone of the named constants INPUT_UNIT, OUTPUT_UNIT, or ERROR_UNIT of the intrinsic module ISO_-
FORTRAN_ENV (16.10.2), the unit argument of an active defined input/output procedure (12.6.4.8), or a
NEWUNIT value (12.5.6.12). An internal unit is used to refer to an internal file and is specified by an internal-
file-variable or a file-unit-number whose value is equal to the unit argument of an active defined input/output
procedure. The value of a file-unit-number shall identify a valid unit.
all program units.NOTE 12.13
In the example:
READ (6) X
...
N = 6
the value 6 used in both program units identifies the same external unit.
4 In a READ statement, an io-unit that is an asterisk identifies an external unit that is preconnected for sequential
formatted input on image 1 in the initial team only (12.6.4.3). This unit is also identified by the value of5 This document identifies a processor-dependent external unit for the purpose of error reporting. This unit shallthe named constant INPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2.13). In a WRITE
statement, an io-unit that is an asterisk identifies an external unit that is preconnected for sequential formatted
output. This unit is also identified by the value of the named constant OUTPUT_UNIT of the intrinsic module
ISO_FORTRAN_ENV (16.10.2.22).
be preconnected for sequential formatted output. The processor may define this to be the same as the output1 A connection for formatted input/output has several changeable modes: these are the blank interpretation modeunit identified by an asterisk. This unit is also identified by a unit number defined by the named constant
ERROR_UNIT of the intrinsic module ISO_FORTRAN_ENV.
NOTE 12.14
Even though OUTPUT_UNIT is connected to a separate file on each image, it is expected that the processor
could merge the sequences of records from these files into a single sequence of records that is sent to the
physical device associated with this unit, such as the user’s terminal. If ERROR_UNIT is associated with
the same physical device, the sequences of records from files connected to ERROR_UNIT on each of the
images could be merged into the same sequence generated from the OUTPUT_UNIT files. Otherwise, it
is expected that the sequence of records in the files connected to ERROR_UNIT on each image could be
merged into a single sequence of records that is sent to the physical device associated with ERROR_UNIT.
12.5.2 Connection modes
(13.8.6), delimiter mode (13.10.4, 13.11.4.2), sign mode (13.8.4), decimal edit mode (13.8.8), input/output round-2 Values for the modes of a connection are established when the connection is initiated. If the connection is initiateding mode (13.7.2.3.8), pad mode (12.6.4.5.3), and scale factor (13.8.5). A connection for unformatted input/output
has no changeable modes.
by an OPEN statement, the values are as specified, either explicitly or implicitly, by the OPEN statement. If the3 The scale factor cannot be explicitly specified in an OPEN statement; it is implicitly 0.connection is initiated other than by an OPEN statement (that is, if the file is an internal file or preconnected file)
the values established are those that would be implied by an initial OPEN statement without the corresponding
keywords.
224 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
4 The modes of a connection to an external file may be changed by a subsequent OPEN statement that modifies
the connection.5 The modes of a connection may be temporarily changed by a corresponding keyword specifier in a data transfer
statement or by an edit descriptor. Keyword specifiers take effect at the beginning of execution of the data1 At any given time, there is a processor-dependent set of external units that exist for an image.transfer statement. Edit descriptors take effect when they are encountered in format processing. When a data
transfer statement terminates, the values for the modes are reset to the values in effect immediately before the
data transfer statement was executed.
12.5.3 Unit existence
2 All input/output statements are permitted to refer to units that exist. The CLOSE, INQUIRE, and WAIT
statements are also permitted to refer to units that do not exist. No other input/output statement shall refer to1 An external unit has a property of being connected or not connected. If connected, it refers to an external file. Ana unit that does not exist.
12.5.4 Connection of a file to a unit
external unit may become connected by preconnection or by the execution of an OPEN statement. The property2 Every input/output statement except an OPEN, CLOSE, INQUIRE, or WAIT statement shall refer to a unitof connection is symmetric; the unit is connected to a file if and only if the file is connected to the unit.
that is connected to a file and thereby make use of or affect that file.3 A file may be connected and not exist (12.3.2).
NOTE 12.154 A unit shall not be connected to more than one file at the same time. However, means are provided to changeAn example is a preconnected external file that has not yet been written.
the status of an external unit and to connect a unit to a different file. It is processor dependent whether a file5 This document defines means of portable interoperation with C. C streams are described in 7.21.2 of ISO/IECcan be connected to more than one unit at the same time.
9899:2011. Whether a unit can be connected to a file that is also connected to a C stream is processor dependent.6 If input/output operations are performed on more than one unit while they are connected to the same externalIf a unit is connected to a file that is also connected to a C stream, the results of performing input/output
operations on such a file are processor dependent. It is processor dependent whether the files connected to
the units INPUT_UNIT, OUTPUT_UNIT, and ERROR_UNIT correspond to the predefined C text streams
standard input, standard output, and standard error. If a main program or procedure defined by means of Fortran
and a main program or procedure defined by means other than Fortran perform input/output operations on the
same external file, the results are processor dependent. A main program or procedure defined by means of Fortran
and a main program or procedure defined by means other than Fortran can perform input/output operations on
different external files without interference.
file, the results are processor dependent.7 After an external unit has been disconnected by the execution of a CLOSE statement, it may be connected again
within the same program to the same file or to a different file. After an external file has been disconnected by8 An internal unit is always connected to the internal file designated by the variable that identifies the unit.the execution of a CLOSE statement, it may be connected again within the same program to the same unit or
to a different unit.
⃝c ISO/IEC 2017 – All rights reserved 225
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.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.
NOTE 12.17For more explanatory information on file connection properties, see C.7.4.
12.5.5 Preconnection 1 Preconnection means that the unit is connected to a file at the beginning of execution of the program and therefore
it may be specified in input/output statements without the prior execution of an OPEN statement.1 An OPEN statement initiates or modifies the connection between an external file and a specified unit. The OPEN12.5.6 OPEN statement
12.5.6.1 General
statement may be used to connect an existing file to a unit, create a file that is preconnected, create a file and2 An external unit may be connected by an OPEN statement in the main program or any subprogram.connect it to a unit, or change certain modes of a connection between a file and a unit.
3 If the file to be connected to the unit does not exist but is the same as the file to which the unit is preconnected,
the modes specified by an OPEN statement become a part of the connection.4 If the file to be connected to the unit is not the same as the file to which the unit is connected, the effect is as
if a CLOSE statement without a STATUS= specifier had been executed for the unit immediately prior to the5 If a unit is connected to a file that exists, execution of an OPEN statement for that unit is permitted. If theexecution of an OPEN statement.
FILE= specifier is not included in such an OPEN statement, the file to be connected to the unit is the same as6 If the file to be connected to the unit is the same as the file to which the unit is connected, a new connection is notthe file to which the unit is already connected.
established and values for any changeable modes (12.5.2) specified come into effect for the established connection;7 A STATUS= specifier with a value of OLD is always allowed when the file to be connected to the unit is the samethe current file position is unaffected. Before any effect on changeable modes, a wait operation is performed for
any pending asynchronous data transfer operations for the specified unit. If the POSITION= specifier appears
in such an OPEN statement, the value specified shall not disagree with the current position of the file. If the
STATUS= specifier is included in such an OPEN statement, it shall be specified with the value OLD. Other than
ERR=, IOSTAT=, and IOMSG=, and the changeable modes, the values of all other specifiers in such an OPEN
statement shall not differ from those in effect for the established connection.
as the file to which the unit is connected. In this case, if the status of the file was SCRATCH before execution of1 A specifier that requires a scalar-default-char-expr may have a limited list of character values. These values arethe OPEN statement, the file will still be deleted when the unit is closed, and the file is still considered to have
a status of SCRATCH.
12.5.6.2 Syntax of the OPEN statement
R1204 open-stmt is OPEN ( connect-spec-list )
R1205 connect-spec is [ UNIT = ] file-unit-number
or ACCESS = scalar-default-char-expr
or ACTION = scalar-default-char-expr
226 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
or ASYNCHRONOUS = scalar-default-char-expr
or BLANK = scalar-default-char-expr
or DECIMAL = scalar-default-char-expr
or DELIM = scalar-default-char-expr
or ENCODING = scalar-default-char-expr
or ERR = label
or FILE = file-name-expr
or FORM = scalar-default-char-expr
or IOMSG = iomsg-variable
or IOSTAT = stat-variable
or NEWUNIT = scalar-int-variable
or PAD = scalar-default-char-expr
or POSITION = scalar-default-char-expr
or RECL = scalar-int-expr
or ROUND = scalar-default-char-expr
or SIGN = scalar-default-char-expr
or STATUS = scalar-default-char-expr
R1206 file-name-expr is scalar-default-char-expr
R1207 iomsg-variable is scalar-default-char-variable
C1203 No specifier shall appear more than once in a given connect-spec-list.
C1204 (R1204) If the NEWUNIT= specifier does not appear, a file-unit-number shall be specified; if the optional
characters UNIT= are omitted, the file-unit-number shall be the first item in the connect-spec-list.
C1205 (R1204) If a NEWUNIT= specifier appears, a file-unit-number shall not appear.
C1206 (R1204) The label used in the ERR= specifier shall be the statement label of a branch target statement
that appears in the same inclusive scope as the OPEN statement.
listed for each such specifier. Any trailing blanks are ignored. The value specified is without regard to case. Some2 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.specifiers have a default value if the specifier is omitted.
NOTE 12.18An example of an OPEN statement is:
OPEN (10, FILE = ’employee.names’, ACTION = ’READ’, PAD = ’YES’)
NOTE 12.19
For more explanatory information on the OPEN statement, see C.7.3.
12.5.6.3 ACCESS= specifier in the OPEN statement 1 The scalar-default-char-expr shall evaluate to SEQUENTIAL, DIRECT, or STREAM. The ACCESS= specifier
specifies the access method for the connection of the file as being sequential, direct, or stream. If this specifier is1 The scalar-default-char-expr shall evaluate to READ, WRITE, or READWRITE. READ specifies that theomitted, the default value is SEQUENTIAL. For an existing file, the specified access method shall be included in
the set of allowed access methods for the file. For a new file, the processor creates the file with a set of allowed
access methods that includes the specified method.
⃝c ISO/IEC 2017 – All rights reserved 227
ISO/IEC DIS 1539-1:2017 (E)
12.5.6.4 ACTION= specifier in the OPEN statement
WRITE, PRINT, and ENDFILE statements shall not refer to this connection. WRITE specifies that READ1 The scalar-default-char-expr shall evaluate to YES or NO. If YES is specified, asynchronous input/output onstatements shall not refer to this connection. READWRITE permits any input/output statements to refer to this
connection. If this specifier is omitted, the default value is processor dependent. If READWRITE is included in
the set of allowable actions for a file, both READ and WRITE also shall be included in the set of allowed actions
for that file. For an existing file, the specified action shall be included in the set of allowed actions for the file.
For a new file, the processor creates the file with a set of allowed actions that includes the specified action.
12.5.6.5 ASYNCHRONOUS= specifier in the OPEN statement
the unit is allowed. If NO is specified, asynchronous input/output on the unit is not allowed. If this specifier is1 The scalar-default-char-expr shall evaluate to NULL or ZERO. The BLANK= specifier is permitted only for aomitted, the default value is NO.
12.5.6.6 BLANK= specifier in the OPEN statement
connection for formatted input/output. It specifies the blank interpretation mode (13.8.6, 12.6.2.6) for input for1 The scalar-default-char-expr shall evaluate to COMMA or POINT. The DECIMAL= specifier is permitted onlythis connection. This mode has no effect on output. It is a changeable mode (12.5.2). If this specifier is omitted
in an OPEN statement that initiates a connection, the default value is NULL.
12.5.6.7 DECIMAL= specifier in the OPEN statement
for a connection for formatted input/output. It specifies the decimal edit mode (13.6, 13.8.8, 12.6.2.7) for this1 The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE. The DELIM= specifier isconnection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a
connection, the default value is POINT.
12.5.6.8 DELIM= specifier in the OPEN statement
permitted only for a connection for formatted input/output. It specifies the delimiter mode (12.6.2.8) for list-1 The scalar-default-char-expr shall evaluate to UTF-8 or DEFAULT. The ENCODING= specifier is permitteddirected (13.10.4) and namelist (13.11.4.2) output for the connection. This mode has no effect on input. It is
a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the
default value is NONE.
12.5.6.9 ENCODING= specifier in the OPEN statement
only for a connection for formatted input/output. The value UTF-8 specifies that the encoding form of the file1 The value of the FILE= specifier is the name of the file to be connected to the specified unit. Any trailing blanksis UTF-8 as specified in ISO/IEC 10646. Such a file is called a Unicode file, and all characters therein are of ISO
10646 character kind. The value UTF-8 shall not be specified if the processor does not support the ISO 10646
character kind. The value DEFAULT specifies that the encoding form of the file is processor dependent. If this
specifier is omitted in an OPEN statement that initiates a connection, the default value is DEFAULT.
12.5.6.10 FILE= specifier in the OPEN statement
are ignored. The file-name-expr shall be a name that is allowed by the processor. The interpretation of case is2 This specifier shall appear if the STATUS= specifier has the value NEW or REPLACE. This specifier shall notprocessor dependent.
appear if the STATUS= specifier has the value SCRATCH. If the STATUS= specifier has the value OLD, this1 The scalar-default-char-expr shall evaluate to FORMATTED or UNFORMATTED. The FORM= specifier de-specifier shall appear unless the unit is connected and the file connected to the unit exists. If this specifier
228 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
is omitted and the unit is not connected to a file, the STATUS= specifier shall be specified with a value of
SCRATCH; in this case, the connection is made to a processor-dependent file.
12.5.6.11 FORM= specifier in the OPEN statement
termines whether the file is being connected for formatted or unformatted input/output. If this specifier is1 If this specifier appears in an OPEN statement, either the FILE= specifier shall appear, or the STATUS= specifieromitted, the default value is UNFORMATTED if the file is being connected for direct access or stream access,
and the default value is FORMATTED if the file is being connected for sequential access. For an existing file,
the specified form shall be included in the set of allowed forms for the file. For a new file, the processor creates
the file with a set of allowed forms that includes the specified form.
12.5.6.12 NEWUNIT= specifier in the OPEN statement
shall appear with a value of SCRATCH.2 The variable is defined with a processor determined NEWUNIT value if no error condition occurs during the
execution of the OPEN statement. If an error condition occurs, the processor shall not change the value of the3 A NEWUNIT value is a negative number, and shall not be equal to −1, any of the named constants ER-variable.
ROR_UNIT, INPUT_UNIT, or OUTPUT_UNIT from the intrinsic module ISO_FORTRAN_ENV (16.10.2),1 The scalar-default-char-expr shall evaluate to YES or NO. The PAD= specifier is permitted only for a connectionany value used by the processor for the unit argument to a defined input/output procedure, nor any previous
NEWUNIT value that identifies a file that is connected. The unit identified by a NEWUNIT value shall not be
preconnected.
12.5.6.13 PAD= specifier in the OPEN statement
for formatted input/output. It specifies the pad mode (12.6.4.5.3, 12.6.2.10) for input for this connection. This1 The scalar-default-char-expr shall evaluate to ASIS, REWIND, or APPEND. The connection shall be for sequen-mode has no effect on output. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN statement
that initiates a connection, the default value is YES.
12.5.6.14 POSITION= specifier in the OPEN statement
tial or stream access. A new file is positioned at its initial point. REWIND positions an existing file at its initial1 The value of the RECL= specifier shall be positive. It specifies the length of each record in a file being connectedpoint. APPEND positions an existing file such that the endfile record is the next record, if it has one. If an
existing file does not have an endfile record, APPEND positions the file at its terminal point. ASIS leaves the
position unchanged if the file exists and already is connected. If the file exists but is not connected, the position
resulting from ASIS is processor dependent. If this specifier is omitted, the default value is ASIS.
12.5.6.15 RECL= specifier in the OPEN statement
for direct access, or specifies the maximum length of a record in a file being connected for sequential access. This1 The scalar-default-char-expr shall evaluate to one of UP, DOWN, ZERO, NEAREST, COMPATIBLE, or PRO-specifier shall not appear when a file is being connected for stream access. This specifier shall appear when a
file is being connected for direct access. If this specifier is omitted when a file is being connected for sequential
access, the default value is processor dependent. If the file is being connected for formatted input/output, the
length is the number of characters for all records that contain only characters of default kind. When a record
contains any nondefault characters, the effect of the RECL= specifier is processor dependent. If the file is being
connected for unformatted input/output, the length is measured in file storage units. For an existing file, the
value of the RECL= specifier shall be included in the set of allowed record lengths for the file. For a new file, the
processor creates the file with a set of allowed record lengths that includes the specified value.
⃝c ISO/IEC 2017 – All rights reserved 229
ISO/IEC DIS 1539-1:2017 (E)
12.5.6.16 ROUND= specifier in the OPEN statement
CESSOR_DEFINED. The ROUND= specifier is permitted only for a connection for formatted input/output.1 The scalar-default-char-expr shall evaluate to one of PLUS, SUPPRESS, or PROCESSOR_DEFINED. TheIt specifies the input/output rounding mode (13.7.2.3.8, 12.6.2.13) for this connection. It is a changeable mode
(12.5.2). If this specifier is omitted in an OPEN statement that initiates a connection, the input/output rounding
mode is processor dependent; it shall be one of the above modes.
NOTE 12.20
A processor is free to select any input/output rounding mode for the default mode. The mode might
correspond to UP, DOWN, ZERO, NEAREST, or COMPATIBLE; or it might be a completely different
input/output rounding mode.
12.5.6.17 SIGN= specifier in the OPEN statement
SIGN= specifier is permitted only for a connection for formatted input/output. It specifies the sign mode1 The scalar-default-char-expr shall evaluate to OLD, NEW, SCRATCH, REPLACE, or UNKNOWN. If OLD is(13.8.4, 12.6.2.14) for this connection. It is a changeable mode (12.5.2). If this specifier is omitted in an OPEN
statement that initiates a connection, the default value is PROCESSOR_DEFINED.
12.5.6.18 STATUS= specifier in the OPEN statement
specified, the file shall exist. If NEW is specified, the file shall not exist.2 Successful execution of an OPEN statement with NEW specified creates the file and changes the status to OLD.
If REPLACE is specified and the file does not already exist, the file is created and the status is changed to OLD.3 If UNKNOWN is specified, the status is processor dependent. If this specifier is omitted, the default value isIf REPLACE is specified and the file does exist, the file is deleted, a new file is created with the same name, and
the status is changed to OLD. If SCRATCH is specified, the file is created and connected to the specified unit
for use by the program but is deleted at the execution of a CLOSE statement referring to the same unit or at
the normal termination of the program.
UNKNOWN.1 The CLOSE statement is used to terminate the connection of a specified unit to an external file.NOTE 12.21
SCRATCH cannot be specified if the FILE= specifier appears (12.5.6.10).
12.5.7 CLOSE statement
12.5.7.1 General
2 Execution of a CLOSE statement for a unit may occur in any program unit of a program and need not occur in
the same program unit as the execution of an OPEN statement referring to that unit.3 Execution of a CLOSE statement performs a wait operation for any pending asynchronous data transfer operations
for the specified unit.4 Execution of a CLOSE statement specifying a unit that does not exist, exists but is connected to a file that does
not exist, or has no file connected to it, is permitted and affects no file or unit.5 After a unit has been disconnected by execution of a CLOSE statement, it may be connected again within the
same program, either to the same file or to a different file. After a named file has been disconnected by execution6 During the completion step (5.3.7) of normal termination, all units that are connected are closed. Each unit isof a CLOSE statement, it may be connected again within the same program, either to the same unit or to a
different unit, provided that the file still exists.
230 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
closed with status KEEP unless the file status prior to termination of execution was SCRATCH, in which case1 The scalar-default-char-expr has a limited list of character values. Any trailing blanks are ignored. The valuethe unit is closed with status DELETE.
NOTE 12.22
The effect is as though a CLOSE statement without a STATUS= specifier were executed on each connected
unit.
12.5.7.2 Syntax
R1208 close-stmt is CLOSE ( close-spec-list )
R1209 close-spec is [ UNIT = ] file-unit-number
or IOSTAT = stat-variable
or IOMSG = iomsg-variable
or ERR = label
or STATUS = scalar-default-char-expr
C1207 No specifier shall appear more than once in a given close-spec-list.
C1208 A file-unit-number shall be specified in a close-spec-list; if the optional characters UNIT= are omitted,
the file-unit-number shall be the first item in the close-spec-list.
C1209 (R1209) The label used in the ERR= specifier shall be the statement label of a branch target statement
that appears in the same inclusive scope as the CLOSE statement.
specified is without regard to case.2 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.
NOTE 12.23An example of a CLOSE statement is:
CLOSE (10, STATUS = ’KEEP’)
12.5.7.3 STATUS= specifier in the CLOSE statement 1 The scalar-default-char-expr shall evaluate to KEEP or DELETE. The STATUS= specifier determines the dis- position of the file that is connected to the specified unit. KEEP shall not be specified for a file whose status prior1 The READ statement is the data transfer input statement. The WRITE statement and the PRINT statementto execution of a CLOSE statement is SCRATCH. If KEEP is specified for a file that exists, the file continues
to exist after the execution of a CLOSE statement. If KEEP is specified for a file that does not exist, the file
will not exist after the execution of a CLOSE statement. If DELETE is specified, the file will not exist after the
execution of a CLOSE statement. If this specifier is omitted, the default value is KEEP, unless the file status
prior to execution of the CLOSE statement is SCRATCH, in which case the default value is DELETE.
12.6 Data transfer statements
12.6.1 Form of input and output statements
are the data transfer output statements.1 A control information list is an io-control-spec-list. It governs data transfer.R1210 read-stmt is READ ( io-control-spec-list ) [ input-item-list ]
or READ format [ , input-item-list ]
R1211 write-stmt is WRITE ( io-control-spec-list ) [ output-item-list ]
⃝c ISO/IEC 2017 – All rights reserved 231
ISO/IEC DIS 1539-1:2017 (E)
R1212 print-stmt is PRINT format [ , output-item-list ]
NOTE 12.24
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)
12.6.2 Control information list
12.6.2.1 Syntax
R1213 io-control-spec is [ UNIT = ] io-unit2 If an EOR= specifier appears, an ADVANCE= specifier with the value NO shall also appear.or [ FMT = ] format
or [ NML = ] namelist-group-name
or ADVANCE = scalar-default-char-expr
or ASYNCHRONOUS = scalar-default-char-constant-expr
or BLANK = scalar-default-char-expr
or DECIMAL = scalar-default-char-expr
or DELIM = scalar-default-char-expr
or END = label
or EOR = label
or ERR = label
or ID = id-variable
or IOMSG = iomsg-variable
or IOSTAT = stat-variable
or PAD = scalar-default-char-expr
or POS = scalar-int-expr
or REC = scalar-int-expr
or ROUND = scalar-default-char-expr
or SIGN = scalar-default-char-expr
or SIZE = scalar-int-variable
R1214 id-variable is scalar-int-variable
C1210 No specifier shall appear more than once in a given io-control-spec-list.
C1211 An io-unit shall be specified in an io-control-spec-list; if the optional characters UNIT= are omitted, the
io-unit shall be the first item in the io-control-spec-list.
C1212 (R1213) A DELIM= or SIGN= specifier shall not appear in a read-stmt.
C1213 (R1213) A BLANK=, PAD=, END=, EOR=, or SIZE= specifier shall not appear in a write-stmt.
C1214 (R1213) The label in the ERR=, EOR=, or END= specifier shall be the statement label of a branch
target statement that appears in the same inclusive scope as the data transfer statement.
C1215 (R1213) A namelist-group-name shall be the name of a namelist group.
C1216 (R1213) A namelist-group-name shall not appear if a REC= specifier, format, input-item-list, or an
output-item-list appears in the data transfer statement.
C1217 (R1213) If format appears without a preceding FMT=, it shall be the second item in the io-control-spec-
232 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
list and the first item shall be io-unit.
C1218 (R1213) If namelist-group-name appears without a preceding NML=, it shall be the second item in the
io-control-spec-list and the first item shall be io-unit.
C1219 (R1213) If io-unit is not a file-unit-number, the io-control-spec-list shall not contain a REC= specifier or
a POS= specifier.
C1220 (R1213) If the REC= specifier appears, an END= specifier shall not appear, and the format, if any, shall
not be an asterisk.
C1221 (R1213) An ADVANCE= specifier may appear only in a formatted sequential or stream data transfer
statement with explicit format specification (13.2) whose io-control-spec-list does not contain an internal-
file-variable as the io-unit.
C1222 (R1213) If an EOR= specifier appears, an ADVANCE= specifier also shall appear.
C1223 (R1213) The scalar-default-char-constant-expr in an ASYNCHRONOUS= specifier shall have the value
YES or NO.
C1224 (R1213) An ASYNCHRONOUS= specifier with a value YES shall not appear unless io-unit is a file-
unit-number.
C1225 (R1213) If an ID= specifier appears, an ASYNCHRONOUS= specifier with the value YES shall also
appear.
C1226 (R1213) If a POS= specifier appears, the io-control-spec-list shall not contain a REC= specifier.
C1227 (R1213) If a DECIMAL=, BLANK=, PAD=, SIGN=, or ROUND= specifier appears, a format or
namelist-group-name shall also appear.
C1228 (R1213) If a DELIM= specifier appears, either format shall be an asterisk or namelist-group-name shall
appear.
C1229 (R1214) The scalar-int-variable shall have a decimal exponent range no smaller than that of default
integer.
3 If the data transfer statement contains a format or namelist-group-name, the statement is a formatted in- put/output statement; otherwise, it is an unformatted input/output statement.4 The ADVANCE=, ASYNCHRONOUS=, DECIMAL=, BLANK=, DELIM=, PAD=, SIGN=, and ROUND=
specifiers have a limited list of character values. Any trailing blanks are ignored. The values specified are without5 The IOSTAT=, ERR=, EOR=, END=, and IOMSG= specifiers are described in 12.11.regard to case.
NOTE 12.25An example of a READ statement is:
READ (IOSTAT = IOS, UNIT = 6, FMT = ’(10F8.2)’) A, B
12.6.2.2 Format specification in a data transfer statement 1 The format specifier supplies a format specification or specifies list-directed formatting for a formatted in- put/output statement.2 The default-char-expr shall evaluate to a valid format specification (13.2.1 and 13.2.2).⃝c ISO/IEC 2017 – All rights reserved 233
ISO/IEC DIS 1539-1:2017 (E)
R1215 format is default-char-expr
or label
or *
C1230 (R1215) The label shall be the label of a FORMAT statement that appears in the same inclusive scope
as the statement containing the FMT= specifier.
3 If default-char-expr is an array, it is treated as if all of the elements of the array were specified in array element order and were concatenated.4 If format is *, the statement is a list-directed input/output statement.
NOTE 12.26An 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.
12.6.2.3 NML= specifier in a data transfer statement 1 The NML= specifier supplies the namelist-group-name (8.9). This name identifies a particular collection of data objects on which transfer is to be performed.2 If a namelist-group-name appears, the statement is a namelist input/output statement.
12.6.2.4 ADVANCE= specifier in a data transfer statement1 The scalar-default-char-expr shall evaluate to YES or NO. The ADVANCE= specifier determines whether advan-
cing input/output occurs for a nonchild data transfer statement. If YES is specified for a nonchild data transfer1 The ASYNCHRONOUS= specifier determines whether this data transfer statement is synchronous or asynchron-statement, advancing input/output occurs. If NO is specified, nonadvancing input/output occurs (12.3.4.2). If
this specifier is omitted from a nonchild data transfer statement that allows the specifier, the default value is
YES. A formatted child data transfer statement is a nonadvancing input/output statement, and any ADVANCE=
specifier is ignored.
12.6.2.5 ASYNCHRONOUS= specifier in a data transfer statement
ous. If YES is specified, the statement and the input/output operation are asynchronous. If NO is specified or if2 Asynchronous input/output is permitted only for external files opened with an ASYNCHRONOUS= specifierthe specifier is omitted, the statement and the input/output operation are synchronous.
with the value YES in the OPEN statement.3 The processor may perform an asynchronous data transfer operation asynchronously, but it is not required to doNOTE 12.27
Both synchronous and asynchronous input/output are allowed for files opened with an ASYNCHRONOUS=
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 ASYNCHRONOUS= specifier, preconnected
files accessed without an OPEN statement, and internal files.
The ASYNCHRONOUS= specifier value in a data transfer statement is a constant expression because it
effects compiler optimizations and, therefore, needs to be known at compile time.
so. For each external file, records and file storage units read or written by asynchronous data transfer statements4 If a variable is used in an asynchronous data transfer statement as234 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
are read, written, and processed in the same order as they would have been if the data transfer statements were
synchronous. The documentation of the Fortran processor should describe when input/output will be performed
asynchronously.
• an item in an input/output list,the base object of the data-ref is implicitly given the ASYNCHRONOUS attribute in the scoping unit of the data• a group object in a namelist, or
• a SIZE= specifier,
transfer statement. This attribute may be confirmed by explicit declaration.
5 When an asynchronous input/output statement is executed, the set of storage units specified by the item list or NML= specifier, plus the storage units specified by the SIZE= specifier, is defined to be the pending input/output6 A pending input/output storage sequence affector is a variable of which any part is associated with a storage unitstorage sequence for the data transfer operation.
NOTE 12.28
A pending input/output storage sequence is not necessarily a contiguous set of storage units.
in a pending input/output storage sequence.1 The scalar-default-char-expr shall evaluate to NULL or ZERO. The BLANK= specifier temporarily changes12.6.2.6 BLANK= specifier in a data transfer statement
(12.5.2) the blank interpretation mode (13.8.6, 12.5.6.6) for the connection. If the specifier is omitted, the mode1 The scalar-default-char-expr shall evaluate to COMMA or POINT. The DECIMAL= specifier temporarily changesis not changed.
12.6.2.7 DECIMAL= specifier in a data transfer statement
(12.5.2) the decimal edit mode (13.6, 13.8.8, 12.5.6.7) for the connection. If the specifier is omitted, the mode is1 The scalar-default-char-expr shall evaluate to APOSTROPHE, QUOTE, or NONE. The DELIM= specifier tem-not changed.
12.6.2.8 DELIM= specifier in a data transfer statement
porarily changes (12.5.2) the delimiter mode (13.10.4, 13.11.4.2, 12.5.6.8) for the connection. If the specifier is1 Successful execution of an asynchronous data transfer statement containing an ID= specifier causes the variableomitted, the mode is not changed.
12.6.2.9 ID= specifier in a data transfer statement
specified in the ID= specifier to become defined with a processor determined value. If this value is zero, the2 If an error condition occurs during the execution of a data transfer statement containing an ID= specifier, thedata transfer operation has been completed. A nonzero value is referred to as the identifier of the data transfer
operation. This identifier is different from the identifier of any other pending data transfer operation for this unit.
It can be used in a subsequent WAIT or INQUIRE statement to identify the particular data transfer operation.
variable specified in the ID= specifier becomes undefined.3 A child data transfer statement shall not specify the ID= specifier.
⃝c ISO/IEC 2017 – All rights reserved 2351 The scalar-default-char-expr shall evaluate to YES or NO. The PAD= specifier temporarily changes (12.5.2) the
ISO/IEC DIS 1539-1:2017 (E)
12.6.2.10 PAD= specifier in a data transfer statement
pad mode (12.6.4.5.3, 12.5.6.13) for the connection. If the specifier is omitted, the mode is not changed.1 The POS= specifier specifies the file position in file storage units. This specifier may appear in a data transfer12.6.2.11 POS= specifier in a data transfer statement
statement only if the statement specifies a unit connected for stream access. A child data transfer statement shall2 A processor may prohibit the use of POS= with particular files that do not have the properties necessary tonot specify this specifier.
support random positioning. A processor may also prohibit positioning a particular file to any position prior to3 If the file is connected for formatted stream access, the file position specified by POS= shall be equal to either 1its current file position if the file does not have the properties necessary to support such positioning.
NOTE 12.29
A unit that is connected to a device or data stream might not be positionable.
(the beginning of the file) or a value previously returned by a POS= specifier in an INQUIRE statement for the1 The REC= specifier specifies the number of the record that is to be read or written. This specifier may appearfile.
12.6.2.12 REC= specifier in a data transfer statement
only in a data transfer statement that specifies a unit connected for direct access; it shall not appear in a child1 The scalar-default-char-expr shall evaluate to one of UP, DOWN, ZERO, NEAREST, COMPATIBLE or PRO-data transfer statement. If the io-control-spec-list contains a REC= specifier, the statement is a direct access
data transfer statement. A child data transfer statement is a direct access data transfer statement if the parent
is a direct access data transfer statement. Any other data transfer statement is a sequential access data transfer
statement or a stream access data transfer statement, depending on whether the file connection is for sequential
access or stream access.
12.6.2.13 ROUND= specifier in a data transfer statement
CESSOR_DEFINED. The ROUND= specifier temporarily changes (12.5.2) the input/output rounding mode1 The scalar-default-char-expr shall evaluate to PLUS, SUPPRESS, or PROCESSOR_DEFINED. The SIGN=(13.7.2.3.8, 12.5.6.16) for the connection. If the specifier is omitted, the mode is not changed.
12.6.2.14 SIGN= specifier in a data transfer statement
specifier temporarily changes (12.5.2) the sign mode (13.8.4, 12.5.6.17) for the connection. If the specifier is1 The SIZE= specifier in an input statement causes the variable specified to become defined with the count ofomitted, the mode is not changed.
12.6.2.15 SIZE= specifier in a data transfer statement
the characters transferred from the file by data edit descriptors during the input operation. Blanks inserted as2 For a synchronous input statement, this definition occurs when execution of the statement completes. For anpadding are not counted.
asynchronous input statement, this definition occurs when the corresponding wait operation is performed.1 An input/output list specifies the entities whose values are transferred by a data transfer statement.12.6.3 Data transfer input/output list
236 ⃝2 An input-item shall not appear as, nor be associated with, the do-variable of any io-implied-do that contains thec ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
R1216 input-item is variable
or io-implied-do
R1217 output-item is expr
or io-implied-do
R1218 io-implied-do is ( io-implied-do-object-list , io-implied-do-control )
R1219 io-implied-do-object is input-item
or output-item
R1220 io-implied-do-control is do-variable = scalar-int-expr ,
scalar-int-expr [ , scalar-int-expr ]
C1231 (R1216) A variable that is an input-item shall not be a whole assumed-size array.
C1232 (R1219) In an input-item-list, an io-implied-do-object shall be an input-item. In an output-item-list, an
io-implied-do-object shall be an output-item.
C1233 (R1217) An expression that is an output-item shall not have a value that is a procedure pointer.
input-item.3 If an input item is a pointer, it shall be associated with a definable target and data are transferred from the file toNOTE 12.30
A constant, an expression involving operators or function references that does not have a pointer result, or
an expression enclosed in parentheses shall not appear as an input list item.
the associated target. If an output item is a pointer, it shall be associated with a target and data are transferred4 If an input item or an output item is allocatable, it shall be allocated.from the target to the file.
NOTE 12.31
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).
5 A list item shall not be polymorphic unless it is processed by a defined input/output procedure (12.6.4.8). 6 The do-variable of an io-implied-do that is in another io-implied-do shall not appear as, nor be associated with, the do-variable of the containing io-implied-do.7 The following rules describing whether to expand an input/output list item are re-applied to each expanded list
item until none of the rules apply.8 The scalar objects resulting when a data transfer statement’s list items are expanded according to the rules in• If an array appears as an input/output list item, it is treated as if the elements, if any, were specified in
array element order (9.5.3.2). However, no element of that array may affect the value of any expression in
the input-item, nor may any element appear more than once in a given input-item.
NOTE 12.32
For example:
INTEGER A (100), J (100)
...
READ *, A (A) ! Not allowed
READ *, A (LBOUND (A, 1) : UBOUND (A, 1)) ! Allowed
⃝c ISO/IEC 2017 – All rights reserved 237
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.32 (cont.)
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 defined
input/output procedure (12.6.4.8), and if any subobject of that list item would be processed by a defined
input/output procedure, the list item is treated as if all of the components of the object were specified in
the list in component order (7.5.4.7); those components shall be accessible in the scoping unit containing
the data transfer statement and shall not be pointers or allocatable.
• An effective item of derived type in an unformatted input/output statement is treated as a single value in a
processor-dependent form unless the list item or a subobject thereof is processed by a defined input/output
procedure (12.6.4.8).
NOTE 12.33
The appearance of a derived-type object as an input/output list item in an unformatted input/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 object to similar sequences for
aggregate objects 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 defined in-
put/output procedure, that list item is treated as if all of the components of the list item were specified
in the list in component order; those components shall be accessible in the scoping unit containing the
input/output statement and shall not be pointers or allocatable.
• If a derived-type list item is not processed by a defined input/output procedure and is not treated as a list
of its individual components, all the subcomponents of that list item shall be accessible in the scoping unit
containing the data transfer statement and shall not be pointers or allocatable.
• For an io-implied-do, the loop initialization and execution are the same as for a DO construct (11.1.7.4).
NOTE 12.34
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
this subclause for handling array and derived-type list items are called effective items. Zero-sized arrays and9 An input/output list shall not contain an effective item of nondefault character kind if the data transfer statementio-implied-dos with an iteration count of zero do not contribute to the list of effective items. A scalar character
item of zero length is an effective item.
NOTE 12.35
In a formatted input/output statement, edit descriptors are associated with effective items, which are always
scalar. The rules in 12.6.3 determine the set of effective items corresponding to each actual list item in the
statement. These rules might have to be applied repetitively until all of the effective items are scalar items.
specifies an internal file of default character kind. An input/output list shall not contain an effective item that is1 Execution of a WRITE or PRINT statement for a unit connected to a file that does not exist creates the filenondefault character except for ISO 10646 or ASCII character if the data transfer statement specifies an internal
file of ISO 10646 character kind. An input/output list shall not contain an effective item of type character of any
kind other than ASCII if the data transfer statement specifies an ASCII character internal file.
238 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
12.6.4 Execution of a data transfer input/output statement
12.6.4.1 Data transfer sequence of operations
unless an error condition occurs.2 The effect of executing a synchronous data transfer statement shall be as if the following operations were performed
in the order specified.3 The effect of executing an asynchronous data transfer statement shall be as if the following operations were(1) Determine the direction of data transfer (12.6.4.2).
(2) Identify the unit (12.6.4.3).
(3) Perform a wait operation for all pending input/output operations for the unit. If an error, end-of-file,
or end-of-record condition occurs during any of the wait operations, steps 4 through 8 are skipped.
(4) Establish the format if one is specified.
(5) If the statement is not a child data transfer statement (12.6.4.8),
(a) position the file prior to data transfer (12.3.4.3), and
(b) for formatted data transfer, set the left tab limit (13.8.1.2).
(6) Transfer data between the file and the entities specified by the input/output list (if any) or namelist,
possibly mediated by defined input/output procedures (12.6.4.8).
(7) Determine whether an error, end-of-file, or end-of-record condition has occurred.
(8) Position the file after data transfer (12.3.4.4) unless the statement is a child data transfer statement
(12.6.4.8).
(9) Cause any variable specified in a SIZE= specifier to become defined.
(10) If an error, end-of-file, or end-of-record condition occurred, processing continues as specified in 12.11;
otherwise, any variable specified in an IOSTAT= specifier is assigned the value zero.
performed in the order specified.4 For an asynchronous data transfer statement, the data transfers may occur during execution of the statement,(1) Determine the direction of data transfer (12.6.4.2).
(2) Identify the unit (12.6.4.3).
(3) Optionally, perform wait operations for one or more pending input/output operations for the unit.
If an error, end-of-file, or end-of-record condition occurs during any of the wait operations, steps 4
through 9 are skipped.
(4) Establish the format if one is specified.
(5) Position the file prior to data transfer (12.3.4.3) and, for formatted data transfer, set the left tab
limit (13.8.1.2).
(6) Establish the set of storage units identified by the input/output list. For an input statement, this
might require some or all of the data in the file to be read if an input variable is used as a scalar-
int-expr in an io-implied-do-control in the input/output list, as a subscript, substring-range, stride,
or is otherwise referenced.
(7) Initiate an asynchronous data transfer between the file and the entities specified by the input/output
list (if any) or namelist. The asynchronous data transfer may complete (and an error, end-of-file, or
end-of-record condition may occur) during the execution of this data transfer statement or during a
later wait operation.
(8) Determine whether an error, end-of-file, or end-of-record condition has occurred. The conditions
may occur during the execution of this data transfer statement or during the corresponding wait
operation, but not both.
(9) Position the file as if the data transfer had finished (12.3.4.4).
(10) Cause any variable specified in a SIZE= specifier to become undefined.
(11) If an error, end-of-file, or end-of-record condition occurred, processing continues as specified in 12.11;
otherwise, any variable specified in an IOSTAT= specifier is assigned the value zero.
⃝c ISO/IEC 2017 – All rights reserved 239
ISO/IEC DIS 1539-1:2017 (E)
during execution of the corresponding wait operation, or anywhere between. The data transfer operation is5 For asynchronous output, a pending input/output storage sequence affector (12.6.2.5) shall not be redefined,considered to be pending until a corresponding wait operation is performed.
become undefined, or have its pointer association status changed.6 For asynchronous input, a pending input/output storage sequence affector shall not be referenced, become defined,
become undefined, become associated with a dummy argument that has the VALUE attribute, or have its pointer7 Error, end-of-file, and end-of-record conditions in an asynchronous data transfer operation may occur duringassociation status changed.
execution of either the data transfer statement or the corresponding wait operation. If an ID= specifier does not8 If execution of the program is terminated during execution of an output statement, the contents of the file becomeappear in the initiating data transfer statement, the conditions may occur during the execution of any subsequent
data transfer or wait operation for the same unit. When a condition occurs for a previously executed asynchronous
data transfer statement, a wait operation is performed for all pending data transfer operations on that unit. When
a condition occurs during a subsequent statement, any actions specified by IOSTAT=, IOMSG=, ERR=, END=,
and EOR= specifiers for that statement are taken.
undefined.1 Execution of a READ statement causes values to be transferred from a file to the entities specified by the inputNOTE 12.36
Because end-of-file and error conditions for asynchronous data transfer statements without an ID= specifier
can be reported by the processor during the execution of a subsequent data transfer statement, it might be
impossible for the user to determine which data transfer statement caused the condition. Reliably detecting
which input statement caused an end-of-file condition requires that all asynchronous input statements for
the unit include an ID= specifier.
12.6.4.2 Direction of data transfer
list, if any, or specified within the file itself for namelist input. Execution of a WRITE or PRINT statement1 A data transfer statement that contains an input/output control list includes a UNIT= specifier that identifiescauses values to be transferred to a file from the entities specified by the output list and format specification, if
any, or by the namelist-group-name for namelist output.
12.6.4.3 Identifying a unit
an external or internal unit. A READ statement that does not contain an input/output control list specifies a2 The unit identified by an unformatted data transfer statement shall be an external unit.particular processor-dependent unit, which is the same as the unit identified by * in a READ statement that
contains an input/output control list (12.5.1) and is the same as the unit identified by the value of the named
constant INPUT_UNIT of the intrinsic module ISO_FORTRAN_ENV (16.10.2.13). The PRINT statement
specifies some other processor-dependent unit, which is the same as the unit identified by * in a WRITE statement
and is the same as the unit identified by the value of the named constant OUTPUT_UNIT of the intrinsic module
ISO_FORTRAN_ENV (16.10.2.22). Thus, each data transfer statement identifies an external or internal unit.
3 The unit identified by a data transfer statement shall be connected to a file when execution of the statement begins.1 If the input/output control list contains * as a format, list-directed formatting is established. If namelist-group-NOTE 12.37
The unit could be preconnected.
240 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
12.6.4.4 Establishing a format
name appears, namelist formatting is established. If no format or namelist-group-name is specified, unformatted2 For output to an internal file, a format specification that is in the file or is associated with the file shall not bedata transfer is established. Otherwise, the format specified by format is established.
specified.3 An input list item, or an entity associated with it, shall not contain any portion of an established format spe-
cification.1 Data are transferred between the file and the entities specified by the input/output list or namelist. The list items12.6.4.5 Data transfer
12.6.4.5.1 General
are processed in the order of the input/output list for all data transfer statements except namelist data transfer2 All values needed to determine which entities are specified by an input/output list item are determined at thestatements. The list items for a namelist input statement are processed in the order of the entities specified
within the input records. The list items for a namelist output statement are processed in the order in which the
variables are specified in the namelist-group-object-list. Effective items are derived from the input/output list
items as described in 12.6.3.
beginning of the processing of that item.3 All values are transmitted to or from the entities specified by a list item prior to the processing of any succeeding
list item for all data transfer statements.4 All values following the name= part of the namelist entity (13.11) within the input records are transmitted toNOTE 12.38
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.
the matching entity specified in the namelist-group-object-list prior to processing any succeeding entity within5 If the input/output item is a pointer, data are transferred between the file and the associated target.the input record for namelist input statements. If an entity is specified more than once within the input record
during a namelist input statement, the last occurrence of the entity specifies the value or values to be used for
that entity.
6 If an internal file has been specified, an input/output list item shall not be in the file or associated with the file.
7 During the execution of an output statement that specifies an internal file, no part of that internal file shall be
referenced, defined, or become undefined as the result of evaluating any output list item.8 During the execution of an input statement that specifies an internal file, no part of that internal file shall be
defined or become undefined as the result of transferring a value to any input list item.9 A DO variable becomes defined and its iteration count established at the beginning of processing of the io-implied-
do-object-list an io-implied-do.10 On output, every entity whose value is to be transferred shall be defined.
⃝c ISO/IEC 2017 – All rights reserved 241ISO/IEC DIS 1539-1:2017 (E)
12.6.4.5.2 Unformatted data transfer 1 If the file is not connected for unformatted input/output, unformatted data transfer is prohibited. 2 During unformatted data transfer, data are transferred without editing between the file and the entities specified by the input/output list. If the file is connected for sequential or direct access, exactly one record is read or3 A value in the file is stored in a contiguous sequence of file storage units, beginning with the file storage unitwritten.
immediately following the current file position.4 After each value is transferred, the current file position is moved to a point immediately after the last file storage
unit of the value.5 On input from a file connected for sequential or direct access, the number of file storage units required by the
input list shall be less than or equal to the number of file storage units in the record.6 On input, if the file storage units transferred do not contain a value with the same type and type parameters as
the input list entity, then the resulting value of the entity is processor dependent except in the following cases.7 On output to a file connected for unformatted direct access, the output list shall not specify more values than• A complex entity may correspond to two real values with the same kind type parameter as the complex
entity.
• A default character list entity of length n may correspond to n default characters stored in the file, regardless
of the length parameters of the entities that were written to these storage units of the file. If the file is
connected for stream input, the characters may have been written by formatted stream output.
can fit into the record. If the file is connected for direct access and the values specified by the output list do not8 If the file is connected for unformatted sequential access, the record is created with a length sufficient to holdfill the record, the remainder of the record is undefined.
the values from the output list. This length shall be one of the set of allowed record lengths for the file and1 If the file is not connected for formatted input/output, formatted data transfer is prohibited.shall not exceed the value specified in the RECL= specifier, if any, of the OPEN statement that established the
connection.
12.6.4.5.3 Formatted data transfer
2 During formatted data transfer, data are transferred with editing between the file and the entities specified by the input/output list or by the namelist-group-name. Format control is initiated and editing is performed as3 The current record and possibly additional records are read or written.described in Clause 13.
4 During advancing input when the pad mode has the value NO, the input list and format specification shall not require more characters from the record than the record contains.5 During advancing input when the pad mode has the value YES, blank characters are supplied by the processor
if the input list and format specification require more characters from the record than the record contains.6 During nonadvancing input when the pad mode has the value NO, an end-of-record condition (12.11) occurs if
the input list and format specification require more characters from the record than the record contains, and the7 During nonadvancing input when the pad mode has the value YES, blank characters are supplied by the processorrecord is complete (12.3.3.4). If the record is incomplete, an end-of-file condition occurs instead of an end-of-record
condition.
if an effective item and its corresponding data edit descriptors require more characters from the record than the8 If the file is connected for direct access, the record number is increased by one as each succeeding record is readrecord contains. If the record is incomplete, an end-of-file condition occurs; otherwise, an end-of-record condition
occurs.
242 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
or written.9 On output, if the file is connected for direct access or is an internal file and the characters specified by the output
list and format do not fill a record, blank characters are added to fill the record.10 On output, the output list and format specification shall not specify more characters for a record than have been
specified by a RECL= specifier in the OPEN statement or the record length of an internal file.1 If list-directed formatting has been established, editing is performed as described in 13.10.12.6.4.6 List-directed formatting
12.6.4.7 Namelist formatting1 If namelist formatting has been established, editing is performed as described in 13.11.
2 Every allocatable namelist-group-object in the namelist group shall be allocated and every namelist-group-object
that is a pointer shall be associated with a target. If a namelist-group-object is polymorphic or has an ultimate1 Defined input/output allows a program to override the default handling of derived-type objects and values incomponent that is allocatable or a pointer, that object shall be processed by a defined input/output procedure
(12.6.4.8).
12.6.4.8 Defined input/output
12.6.4.8.1 General
data transfer statements described in 12.6.3.2 A defined input/output procedure is a procedure accessible by a defined-io-generic-spec (15.4.3.2). A particular
defined input/output procedure is selected as described in 12.6.4.8.4.1 For a particular derived type and a particular set of kind type parameter values, there are four possible sets of12.6.4.8.2 Defined input/output procedures
characteristics for defined input/output procedures; one each for formatted input, formatted output, unformatted2 In the four interfaces, which specify the characteristics of defined input/output procedures, the following syntaxinput, and unformatted output. The program need not supply all four procedures. The procedures are specified
to be used for derived-type input/output by interface blocks (15.4.3.2) or by generic bindings (7.5.5), with a
defined-io-generic-spec (R1509). The defined-io-generic-specs for these procedures are READ (FORMATTED),
READ (UNFORMATTED), WRITE (FORMATTED), and WRITE (UNFORMATTED), for formatted input,
unformatted input, formatted output, and unformatted output respectively.
term is used:3 If the defined-io-generic-spec is READ (FORMATTED), the characteristics shall be the same as those specifiedR1221 dtv-type-spec is TYPE( derived-type-spec )
or CLASS( derived-type-spec )
C1234 (R1221) If derived-type-spec specifies an extensible type, the CLASS keyword shall be used; otherwise,
the TYPE keyword shall be used.
C1235 (R1221) All length type parameters of derived-type-spec shall be assumed.
by the following interface:ISO/IEC DIS 1539-1:2017 (E)SUBROUTINE my_read_routine_formatted (dtv, &
unit, &
iotype, v_list, &
⃝c ISO/IEC 2017 – All rights reserved 243
iostat, iomsg)! the derived-type variable
dtv-type-spec , INTENT(INOUT) :: dtv
INTEGER, INTENT(IN) :: unit ! unit number
! the edit descriptor string
CHARACTER (LEN=*), INTENT(IN) :: iotype
INTEGER, INTENT(IN) :: v_list(:)
INTEGER, INTENT(OUT) :: iostat
CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
4 If the defined-io-generic-spec is READ (UNFORMATTED), the characteristics shall be the same as those specified
by the following interface:SUBROUTINE my_read_routine_unformatted (dtv, &
unit, &
iostat, iomsg)
! the derived-type variable
dtv-type-spec , INTENT(INOUT) :: dtv
INTEGER, INTENT(IN) :: unit
INTEGER, INTENT(OUT) :: iostat
CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
5 If the defined-io-generic-spec is WRITE (FORMATTED), the characteristics shall be the same as those specified
by the following interface:SUBROUTINE my_write_routine_formatted (dtv, &
unit, &
iotype, v_list, &
iostat, iomsg)
! the derived-type value/variable
dtv-type-spec , INTENT(IN) :: dtv
INTEGER, INTENT(IN) :: unit
! the edit descriptor string
CHARACTER (LEN=*), INTENT(IN) :: iotype
INTEGER, INTENT(IN) :: v_list(:)
INTEGER, INTENT(OUT) :: iostat
CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
6 If the defined-io-generic-spec is WRITE (UNFORMATTED), the characteristics shall be the same as those
specified by the following interface:SUBROUTINE my_write_routine_unformatted (dtv, &
unit, &
iostat, iomsg)
! the derived-type value/variable
dtv-type-spec , INTENT(IN) :: dtv
INTEGER, INTENT(IN) :: unit
INTEGER, INTENT(OUT) :: iostat
CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
244 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)7 The actual specific procedure names (the my_..._routine_... procedure names above) are not significant. In
the discussion here and elsewhere, the dummy arguments in these interfaces are referred to by the names given1 If a defined input/output procedure is selected for an effective item as specified in 12.6.4.8.4, the processor shallabove; the names are, however, arbitrary.
12.6.4.8.3 Executing defined input/output data transfers
call the selected defined input/output procedure for that item. The defined input/output procedure controls the2 A data transfer statement that includes a derived-type list item and that causes a defined input/output procedureactual data transfer operations for the derived-type list item.
to be invoked is called a parent data transfer statement. A data transfer statement that is executed while a parent3 A child data transfer statement is processed differently from a nonchild data transfer statement in the followingdata transfer statement is being processed and that specifies the unit passed into a defined input/output procedure
is called a child data transfer statement.
NOTE 12.39
A defined input/output procedure will usually contain child data transfer statements that read values
from or write values to the current record or at the current file position. The effect of executing the
defined 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 12.40
A particular execution of a READ, WRITE or PRINT statement can be both a parent and a child data
transfer statement. A defined input/output procedure can indirectly call itself or another defined in-
put/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 defined input/output procedure calls
itself indirectly in this manner, it cannot be declared NON_RECURSIVE.
ways.4 When a defined input/output procedure is invoked, the processor shall pass a unit argument that has a value as• Executing a child data transfer statement does not position the file prior to data transfer.
• An unformatted child data transfer statement does not position the file after data transfer is complete.
• Any ADVANCE= specifier in a child input/output statement is ignored.
follows.5 For formatted data transfer, the processor shall pass an iotype argument that has the value• If the parent data transfer statement uses a file-unit-number, the value of the unit argument shall be that
of the file-unit-number.
• If the parent data transfer statement is a WRITE statement with an asterisk unit or a PRINT statement,
the unit argument shall have the same value as the named constant OUTPUT_UNIT of the intrinsic
module ISO_FORTRAN_ENV (16.10.2).
• If the parent data transfer statement is a READ statement with an asterisk unit or a READ statement
without an io-control-spec-list, the unit argument shall have the same value as the INPUT_UNIT named
constant of the intrinsic module ISO_FORTRAN_ENV (16.10.2).
• Otherwise the parent data transfer statement accesses an internal file, in which case the unit argument
shall have a processor-dependent negative value.
NOTE 12.41
The unit argument passed to a defined input/output procedure will be negative when the parent data
transfer statement specified an internal unit, or specified an external unit that is a NEWUNIT value.
⃝c ISO/IEC 2017 – All rights reserved 245
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.41 (cont.)
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 intrinsic module ISO_FORTRAN_ENV (16.10.2).
• “LISTDIRECTED” if the parent data transfer statement specified list directed formatting,6 If the parent data transfer statement is an input statement, the dtv dummy argument is argument associated• “NAMELIST” if the parent data transfer statement specified namelist formatting, or
• “DT” concatenated with the char-literal-constant, if any, of the DT edit descriptor in the format specification
of the parent data transfer statement.
with the effective item that caused the defined input procedure to be invoked, as if the effective item were an7 If the parent data transfer statement is an output statement, the processor shall provide the value of the effectiveactual argument in this procedure reference (5.4.5).
item in the dtv dummy argument.8 If the v-list of the edit descriptor appears in the parent data transfer statement, the processor shall provide the
values from it in the v_list dummy argument, with the same number of elements in the same order as v-list.9 The iostat argument is used to report whether an error, end-of-record, or end-of-file condition (12.11) occurs.If there is no v-list in the edit descriptor or if the data transfer statement specifies list-directed or namelist
formatting, the processor shall provide v_list as a zero-sized array.
NOTE 12.42
The user’s procedure might 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.
If an error condition occurs, the defined input/output procedure shall assign a positive value to the iostat10 If the defined input/output procedure returns a nonzero value for the iostat argument, the procedure shall alsoargument. Otherwise, if an end-of-file condition occurs, the defined input procedure shall assign the value of the
named constant IOSTAT_END (16.10.2.16) to the iostat argument. Otherwise, if an end-of-record condition
occurs, the defined input procedure shall assign the value of the named constant IOSTAT_EOR (16.10.2.17) to
iostat. Otherwise, the defined input/output procedure shall assign the value zero to the iostat argument.
return an explanatory message in the iomsg argument. Otherwise, the procedure shall not change the value of11 If the iostat argument of the defined input/output procedure has a nonzero value when that procedure returns,the iomsg argument.
NOTE 12.43
The values of the iostat and iomsg arguments set in a defined input/output procedure need not be passed
to all of the parent data transfer statements.
and the processor therefore terminates execution of the program as described in 12.11, the processor shall make12 While a parent READ statement is active, an input/output statement shall not read from any external unit otherthe value of the iomsg argument available in a processor-dependent manner.
than the one specified by the unit dummy argument and shall not perform output to any external unit.13 While a parent WRITE or PRINT statement is active, an input/output statement shall not perform output to
any external unit other than the one specified by the unit dummy argument and shall not read from any external14 While a parent data transfer statement is active, a data transfer statement that specifies an internal file isunit.
246 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
permitted.15 OPEN, CLOSE, BACKSPACE, ENDFILE, and REWIND statements shall not be executed while a parent data
transfer statement is active.16 A defined input/output procedure may use a format specification with a DT edit descriptor for handling a
component of the derived type that is itself of a derived type. A child data transfer statement that is a list17 Because a child data transfer statement does not position the file prior to data transfer, the child data transferdirected or namelist input/output statement may contain a list item of derived type.
statement starts transferring data from where the file was positioned by the parent data transfer statement’s18 The edit descriptors T and TL used on unit by a child data transfer statement shall not cause the file to bemost recently processed effective item or edit descriptor. This is not necessarily at the beginning of a record.
positioned before the file position at the time the defined input/output procedure was invoked.19 Neither a parent nor child data transfer statement shall be asynchronous.NOTE 12.44
A defined input/output procedure could use INQUIRE to determine the settings of BLANK=, PAD=,
ROUND=, DECIMAL=, and DELIM= for an external unit. The INQUIRE statement provides values as
specified in 12.10.
20 A defined input/output procedure, and any procedures invoked therefrom, shall not define, nor cause to become
undefined, any storage unit referenced by any input/output list item, the corresponding format, or any specifierin any active parent data transfer statement, except through the dtv argument.
NOTE 12.45
A data transfer statement with an ID=, POS=, or REC= specifier cannot be a child data transfer statement
in a standard-conforming program.
NOTE 12.46
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
PROCEDURE,PRIVATE :: pwf
GENERIC :: WRITE(FORMATTED) => pwf END TYPE person
SUBROUTINE pwf (dtv,unit,iotype,vlist,iostat,iomsg)
! argument definitions
CLASS(person), INTENT(IN) :: dtvINTEGER, INTENT(IN) :: unit
CHARACTER (LEN=*), INTENT(IN) :: iotype
⃝c ISO/IEC 2017 – All rights reserved 247
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.46 (cont.)INTEGER, INTENT(IN) :: vlist(:)
INTEGER, INTENT(OUT) :: iostat
CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
! local variable
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 committee
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 12.47
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 nodeINTEGER :: value = 0
TYPE (NODE), POINTER :: next_node => NULL ( )
CONTAINS
PROCEDURE,PRIVATE :: pwf
GENERIC :: WRITE(FORMATTED) => pwf END TYPE node
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) :: dtvINTEGER, INTENT(IN) :: unit
CHARACTER (LEN=*), INTENT(IN) :: iotype
INTEGER, INTENT(IN) :: vlist(:)
INTEGER, INTENT(OUT) :: iostat
CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
248 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 12.47 (cont.)
WRITE(unit,’(i9 /)’, IOSTAT = iostat) dtv%valueEND SUBROUTINE pwfIF(iostat/=0) RETURN
IF(ASSOCIATED(dtv%next_node)) WRITE(unit,’(dt)’, IOSTAT=iostat) dtv%next_node
END MODULE p
12.6.4.8.4 Resolving defined input/output procedure references 1 A suitable generic interface for defined input/output of an effective item is one that has a defined-io-generic-spec
that is appropriate to the direction (read or write) and form (formatted or unformatted) of the data transfer2 When an effective item (12.6.3) that is of derived type is encountered during a data transfer, defined input/outputas specified in 12.6.4.8.2, and has a specific interface whose dtv argument is compatible with the effective item
according to the rules for argument association in 15.5.2.4.
occurs if both of the following conditions are true.3 If (2a) is true, the procedure referenced is determined as for explicit type-bound procedure references (15.5); that(1) The circumstances of the input/output are such that defined input/output is permitted; that is,
either
(a) the transfer was initiated by a list-directed, namelist, or unformatted input/output statement,
or
(b) a format specification is supplied for the data transfer statement, and the edit descriptor
corresponding to the effective item is a DT edit descriptor.
(2) A suitable defined input/output procedure is available; that is, either
(a) the declared type of the effective item has a suitable generic type-bound procedure, or
(b) a suitable generic interface is accessible.
is, the binding with the appropriate specific interface is located in the declared type of the effective item, and the4 If (2a) is false and (2b) is true, the reference is to the procedure identified by the appropriate specific interfacecorresponding binding in the dynamic type of the effective item is selected.
in the interface block.1 Termination of a data transfer statement occurs when12.6.5 Termination of data transfer statements
• format processing encounters a colon or data edit descriptor and there are no remaining elements in theinput-item-list or output-item-list,
• unformatted or list-directed data transfer exhausts the input-item-list or output-item-list,
• namelist output exhausts the namelist-group-object-list,
• an error condition occurs,
• an end-of-file condition occurs,
• a slash (/) is encountered as a value separator (13.10, 13.11) in the record being read during list-directed
or namelist input, or
• an end-of-record condition occurs during execution of a nonadvancing input statement (12.11).
⃝c ISO/IEC 2017 – All rights reserved 249
ISO/IEC DIS 1539-1:2017 (E)
12.7 Waiting on pending data transfer 12.7.1 Wait operation 1 Execution of an asynchronous data transfer statement in which neither an error, end-of-record, nor end-of-file
condition occurs initiates a pending data transfer operation. There may be multiple pending data transfer2 A wait operation completes the processing of a pending data transfer operation. Each wait operation completesoperations for the same or multiple units simultaneously. A pending data transfer operation remains pending
until a corresponding wait operation is performed. A wait operation may be performed by a BACKSPACE,
CLOSE, ENDFILE, FLUSH, INQUIRE, PRINT, READ, REWIND, WAIT, or WRITE statement.
only a single data transfer operation, although a single statement may perform multiple wait operations.3 If the actual data transfer is not yet complete, the wait operation first waits for its completion. If the data
transfer operation is an input operation that completed without error, the storage units of the input/output4 If any error, end-of-file, or end-of-record conditions occur, the applicable actions specified by the IOSTAT=,storage sequence then become defined with the values as described in 12.6.2.15 and 12.6.4.5.
IOMSG=, ERR=, END=, and EOR= specifiers of the statement that performs the wait operation are taken.5 If an error or end-of-file condition occurs during a wait operation for a unit, the processor performs a wait
operation for all pending data transfer operations for that unit.6 After completion of the wait operation, the data transfer operation and its input/output storage sequence are noNOTE 12.48
Error, end-of-file, and end-of-record conditions can be raised either during the data transfer statement 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.
longer considered to be pending.1 A WAIT statement performs a wait operation for specified pending asynchronous data transfer operations.12.7.2 WAIT statement
R1222 wait-stmt is WAIT (wait-spec-list)2 The IOSTAT=, ERR=, EOR=, END=, and IOMSG= specifiers are described in 12.11.R1223 wait-spec is [ UNIT = ] file-unit-number
or END = label
or EOR = label
or ERR = label
or ID = scalar-int-expr
or IOMSG = iomsg-variable
or IOSTAT = stat-variable
C1236 No specifier shall appear more than once in a given wait-spec-list.
C1237 A file-unit-number shall be specified in a wait-spec-list; if the optional characters UNIT= are omitted,
the file-unit-number shall be the first item in the wait-spec-list.
C1238 (R1223) The label in the ERR=, EOR=, or END= specifier shall be the statement label of a branch
target statement that appears in the same inclusive scope as the WAIT statement.
250 ⃝c ISO/IEC 2017 – All rights reserved3 The value of the expression specified in the ID= specifier shall be zero or the identifier of a pending data transfer
ISO/IEC DIS 1539-1:2017 (E)
operation for the specified unit. If the ID= specifier appears, a wait operation for the specified data transfer4 Execution of a WAIT statement specifying a unit that does not exist, has no file connected to it, or is not openoperation, if any, is performed. If the ID= specifier is omitted, wait operations for all pending data transfers for
the specified unit are performed.
for asynchronous input/output is permitted, provided that the WAIT statement has no ID= specifier; such a1 A unit that is connected for direct access shall not be referred to by a BACKSPACE, ENDFILE, or REWINDWAIT statement does not cause an error or end-of-file condition to occur.
NOTE 12.49
An EOR= specifier has no effect if the pending data transfer operation is not a nonadvancing read. An
END= specifier has no effect if the pending data transfer operation is not a READ.
12.8 File positioning statements
12.8.1 Syntax
R1224 backspace-stmt is BACKSPACE file-unit-number
or BACKSPACE ( position-spec-list )
R1225 endfile-stmt is ENDFILE file-unit-number
or ENDFILE ( position-spec-list )
R1226 rewind-stmt is REWIND file-unit-number
or REWIND ( position-spec-list )
statement. A unit that is connected for unformatted stream access shall not be referred to by a BACKSPACE2 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.statement. A unit that is connected with an ACTION= specifier having the value READ shall not be referred
to by an ENDFILE statement.
R1227 position-spec is [ UNIT = ] file-unit-number
or IOMSG = iomsg-variable
or IOSTAT = stat-variable
or ERR = label
C1239 No specifier shall appear more than once in a given position-spec-list.
C1240 A file-unit-number shall be specified in a position-spec-list; if the optional characters UNIT= are omitted,
the file-unit-number shall be the first item in the position-spec-list.
C1241 (R1227) The label in the ERR= specifier shall be the statement label of a branch target statement that
appears in the same inclusive scope as the file positioning statement.
3 Execution of a file positioning statement performs a wait operation for all pending asynchronous data transfer
operations for the specified unit.1 Execution of a BACKSPACE statement causes the file connected to the specified unit to be positioned before12.8.2 BACKSPACE statement
the current record if there is a current record, or before the preceding record if there is no current record. If the2 If a BACKSPACE statement causes the implicit writing of an endfile record, the file is positioned before thefile is at its initial point, the position of the file is not changed.
⃝c ISO/IEC 2017 – All rights reserved 251
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.50
If the preceding record is an endfile record, the file is positioned before the endfile record.
record that precedes the endfile record.3 Backspacing a file that is connected but does not exist is prohibited.
4 Backspacing over records written using list-directed or namelist formatting is prohibited.
NOTE 12.51An example of a BACKSPACE statement is:
BACKSPACE (10, IOSTAT = N)
12.8.3 ENDFILE statement 1 Execution of an ENDFILE statement for a file connected for sequential access writes an endfile record as the next
record of the file. The file is then positioned after the endfile record, which becomes the last record of the file.2 After execution of an ENDFILE statement for a file connected for sequential access, a BACKSPACE or REWINDIf the file also may be connected for direct access, only those records before the endfile record are considered to
have been written. Thus, only those records may be read during subsequent direct access connections to the file.
statement shall be used to reposition the file prior to execution of any data transfer input/output statement or3 Execution of an ENDFILE statement for a file connected for stream access causes the terminal point of the fileENDFILE statement.
to become equal to the current file position. Only file storage units before the current position are considered4 Execution of an ENDFILE statement for a file that is connected but does not exist creates the file; if the file isto have been written; thus only those file storage units may be subsequently read. Subsequent stream output
statements may be used to write further data to the file.
connected for sequential access, it is created prior to writing the endfile record.NOTE 12.52
An example of an ENDFILE statement is:
ENDFILE K
12.8.4 REWIND statement 1 Execution of a REWIND statement causes the specified file to be positioned at its initial point.
NOTE 12.532 Execution of a REWIND statement for a file that is connected but does not exist is permitted and has no effectIf the file is already positioned at its initial point, execution of this statement has no effect on the position
of the file.
on any file.1 The IOSTAT=, IOMSG= and ERR= specifiers are described in 12.11.NOTE 12.54
An example of a REWIND statement is:
REWIND 10
252 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
12.9 FLUSH statement
R1228 flush-stmt is FLUSH file-unit-number
or FLUSH ( flush-spec-list )
R1229 flush-spec is [UNIT =] file-unit-number
or IOSTAT = stat-variable
or IOMSG = iomsg-variable
or ERR = label
C1242 No specifier shall appear more than once in a given flush-spec-list.
C1243 A file-unit-number shall be specified in a flush-spec-list; if the optional characters UNIT= are omitted
from the unit specifier, the file-unit-number shall be the first item in the flush-spec-list.
C1244 (R1229) The label in the ERR= specifier shall be the statement label of a branch target statement that
appears in the same inclusive scope as the FLUSH statement.
2 Execution of a FLUSH statement causes data written to an external file to be available to other processes, or
causes data placed in an external file by means other than Fortran to be available to a READ statement. These3 Execution of a FLUSH statement for a file that is connected but does not exist is permitted and has no effect onactions are processor dependent.
any file. A FLUSH statement has no effect on file position.4 Execution of a FLUSH statement performs a wait operation for all pending asynchronous data transfer operations
for the specified unit.1 The INQUIRE statement can be used to inquire about properties of a particular named file, of the connectionNOTE 12.55
Because this document does not specify the mechanism of file storage, the exact meaning of the flush
operation is not precisely defined. It is expected that the flush operation will 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 input/output
buffers”.
NOTE 12.56
An example of a FLUSH statement is:
FLUSH (10, IOSTAT = N)
12.10 File inquiry statement
12.10.1 Forms of the INQUIRE statement
to a particular unit, or the number of file storage units required for an output list. There are three forms of the2 For inquiry by unit, the unit specified need not exist or be connected to a file. If it is connected to a file, theINQUIRE statement: inquire by file, which uses the FILE= specifier, inquire by unit, which uses the UNIT=
specifier, and inquire by output list, which uses only the IOLENGTH= specifier. Assignments to specifier variables
are converted, truncated, or padded according to the rules of intrinsic assignment.
inquiry is being made about the connection and about the file connected.3 For inquiry by file, the file specified need not exist or be connected to a unit. If it is connected to a unit, the
inquiry is being made about the connection as well as about the file.4 An INQUIRE statement may be executed before, while, or after a file is connected to a unit. All values assigned⃝c ISO/IEC 2017 – All rights reserved 253
ISO/IEC DIS 1539-1:2017 (E)
by an INQUIRE statement are those that are current at the time the statement is executed.1 Unless constrained, the following inquiry specifiers may be used in either of the inquire by file or inquire by unitR1230 inquire-stmt is INQUIRE ( inquire-spec-list )
or INQUIRE ( IOLENGTH = scalar-int-variable )
output-item-list
NOTE 12.57
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)
12.10.2 Inquiry specifiers
12.10.2.1 Syntax
forms of the INQUIRE statement.2 If file-unit-number identifies an internal unit (12.6.4.8.2), an error condition occurs.R1231 inquire-spec is [ UNIT = ] file-unit-number
or FILE = file-name-expr
or ACCESS = scalar-default-char-variable
or ACTION = scalar-default-char-variable
or ASYNCHRONOUS = scalar-default-char-variable
or BLANK = scalar-default-char-variable
or DECIMAL = scalar-default-char-variable
or DELIM = scalar-default-char-variable
or DIRECT = scalar-default-char-variable
or ENCODING = scalar-default-char-variable
or ERR = label
or EXIST = scalar-logical-variable
or FORM = scalar-default-char-variable
or FORMATTED = scalar-default-char-variable
or ID = scalar-int-expr
or IOMSG = iomsg-variable
or IOSTAT = stat-variable
or NAME = scalar-default-char-variable
or NAMED = scalar-logical-variable
or NEXTREC = scalar-int-variable
or NUMBER = scalar-int-variable
or OPENED = scalar-logical-variable
or PAD = scalar-default-char-variable
or PENDING = scalar-logical-variable
or POS = scalar-int-variable
or POSITION = scalar-default-char-variable
or READ = scalar-default-char-variable
or READWRITE = scalar-default-char-variable
or RECL = scalar-int-variable
or ROUND = scalar-default-char-variable
or SEQUENTIAL = scalar-default-char-variable
or SIGN = scalar-default-char-variable
or SIZE = scalar-int-variable
or STREAM = scalar-default-char-variable
or UNFORMATTED = scalar-default-char-variable
or WRITE = scalar-default-char-variable
254 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C1245 No specifier shall appear more than once in a given inquire-spec-list.
C1246 An inquire-spec-list shall contain one FILE= specifier or one file-unit-number, but not both.
C1247 In the inquire by unit form of the INQUIRE statement, if the optional characters UNIT= are omitted,
the file-unit-number shall be the first item in the inquire-spec-list.
C1248 If an ID= specifier appears in an inquire-spec-list, a PENDING= specifier shall also appear.
C1249 (R1229) The label in the ERR= specifier shall be the statement label of a branch target statement that
appears in the same inclusive scope as the INQUIRE statement.
3 When a returned value of a specifier other than the NAME= specifier is of type character, the value returned is
in upper case.4 If an error condition occurs during execution of an INQUIRE statement, all of the inquiry specifier variables
become undefined, except for variables in the IOSTAT= and IOMSG= specifiers (if any).5 The IOSTAT=, ERR=, and IOMSG= specifiers are described in 12.11.
12.10.2.2 FILE= specifier in the INQUIRE statement1 The value of the file-name-expr in the FILE= specifier specifies the name of the file being inquired about. The
named file need not exist or be connected to a unit. The value of the file-name-expr shall be of a form acceptable1 The scalar-default-char-variable in the ACCESS= specifier is assigned the value SEQUENTIAL if the connectionto the processor as a file name. Any trailing blanks are ignored. The interpretation of case is processor dependent.
12.10.2.3 ACCESS= specifier in the INQUIRE statement
is for sequential access, DIRECT if the connection is for direct access, or STREAM if the connection is for stream1 The scalar-default-char-variable in the ACTION= specifier is assigned the value READ if the connection is foraccess. If there is no connection, it is assigned the value UNDEFINED.
12.10.2.4 ACTION= specifier in the INQUIRE statement
input only, WRITE if the connection is for output only, and READWRITE if the connection is for both input1 The scalar-default-char-variable in the ASYNCHRONOUS= specifier is assigned the value YES if the connectionand output. If there is no connection, the scalar-default-char-variable is assigned the value UNDEFINED.
12.10.2.5 ASYNCHRONOUS= specifier in the INQUIRE statement
allows asynchronous input/output; it is assigned the value NO if the connection does not allow asynchronous1 The scalar-default-char-variable in the BLANK= specifier is assigned the value ZERO or NULL, correspondinginput/output. If there is no connection, the scalar-default-char-variable is assigned the value UNDEFINED.
12.10.2.6 BLANK= specifier in the INQUIRE statement
to the blank interpretation mode in effect for a connection for formatted input/output. If there is no connection,1 The scalar-default-char-variable in the DECIMAL= specifier is assigned the value COMMA or POINT, corres-or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value
UNDEFINED.
12.10.2.7 DECIMAL= specifier in the INQUIRE statement
ponding to the decimal edit mode in effect for a connection for formatted input/output. If there is no connection,1 The scalar-default-char-variable in the DELIM= specifier is assigned the value APOSTROPHE, QUOTE, oror if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the value
UNDEFINED.
⃝c ISO/IEC 2017 – All rights reserved 255
ISO/IEC DIS 1539-1:2017 (E)
12.10.2.8 DELIM= specifier in the INQUIRE statement
NONE, corresponding to the delimiter mode in effect for a connection for formatted input/output. If there is no1 The scalar-default-char-variable in the DIRECT= specifier is assigned the value YES if DIRECT is included inconnection or if the connection is not for formatted input/output, the scalar-default-char-variable is assigned the
value UNDEFINED.
12.10.2.9 DIRECT= specifier in the INQUIRE statement
the set of allowed access methods for the file, NO if DIRECT is not included in the set of allowed access methods1 The scalar-default-char-variable in the ENCODING= specifier is assigned the value UTF-8 if the connection isfor the file, and UNKNOWN if the processor is unable to determine whether DIRECT is included in the set of
allowed access methods for the file or if the unit identified by file-unit-number is not connected to a file.
12.10.2.10 ENCODING= specifier in the INQUIRE statement
for formatted input/output with an encoding form of UTF-8, and is assigned the value UNDEFINED if the1 Execution of an INQUIRE by file statement causes the scalar-logical-variable in the EXIST= specifier to beconnection is for unformatted input/output. If there is no connection, it is assigned the value UTF-8 if the
processor is able to determine that the encoding form of the file is UTF-8; if the processor is unable to determine
the encoding form of the file or if the unit identified by file-unit-number is not connected to a file, the variable is
assigned the value UNKNOWN.
NOTE 12.58
The value assigned could be something other than UTF-8, UNDEFINED, or UNKNOWN if the processor
supports other specific encoding forms (e.g. UTF-16BE).
12.10.2.11 EXIST= specifier in the INQUIRE statement
assigned the value true if there exists a file with the specified name; otherwise, false is assigned. Execution of an1 The scalar-default-char-variable in the FORM= specifier is assigned the value FORMATTED if the connectionINQUIRE by unit statement causes true to be assigned if the specified unit exists; otherwise, false is assigned.
12.10.2.12 FORM= specifier in the INQUIRE statement
is for formatted input/output, and is assigned the value UNFORMATTED if the connection is for unformatted1 The scalar-default-char-variable in the FORMATTED= specifier is assigned the value YES if FORMATTED isinput/output. If there is no connection, it is assigned the value UNDEFINED.
12.10.2.13 FORMATTED= specifier in the INQUIRE statement
included in the set of allowed forms for the file, NO if FORMATTED is not included in the set of allowed forms1 The value of the expression specified in the ID= specifier shall be the identifier of a pending data transfer operationfor the file, and UNKNOWN if the processor is unable to determine whether FORMATTED is included in the
set of allowed forms for the file or if the unit identified by file-unit-number is not connected to a file.
12.10.2.14 ID= specifier in the INQUIRE statement
for the specified unit. This specifier interacts with the PENDING= specifier (12.10.2.21).1 The scalar-default-char-variable in the NAME= specifier is assigned the value of the name of the file if the file12.10.2.15 NAME= specifier in the INQUIRE statement
has a name; otherwise, it becomes undefined. The value assigned shall be suitable for use as the value of the2 The case of the characters assigned to scalar-default-char-variable is processor dependent.file-name-expr in the FILE= specifier in an OPEN statement.
256 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 12.59
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.
The processor could assign a file name qualified by a user identification, device, directory, or other relevant
information.
12.10.2.16 NAMED= specifier in the INQUIRE statement1 The scalar-logical-variable in the NAMED= specifier is assigned the value true if the file has a name; otherwise,
it is assigned the value false.1 The scalar-int-variable in the NEXTREC= specifier is assigned the value n + 1, where n is the record number of12.10.2.17 NEXTREC= specifier in the INQUIRE statement
the last record read from or written to the connection for direct access. If there is a connection but no records have1 Execution of an INQUIRE by file statement causes the scalar-int-variable in the NUMBER= specifier to bebeen read or written since the connection, the scalar-int-variable is assigned the value 1. If there is no connection,
the connection is not for direct access, or the position is indeterminate because of a previous error condition, the
scalar-int-variable becomes undefined. If there are pending data transfer operations for the specified unit, the
value assigned is computed as if all the pending data transfers had already completed.
12.10.2.18 NUMBER= specifier in the INQUIRE statement
assigned the value of the external unit number of the unit that is connected to the file. If more than one unit1 Execution of an INQUIRE by file statement causes the scalar-logical-variable in the OPENED= specifier to beon an image is connected to the file, which of the connected external unit numbers is assigned to the scalar-int-
variable is processor dependent. If there is no unit connected to the file, the value −1 is assigned. Execution of
an INQUIRE by unit statement causes the scalar-int-variable to be assigned the value of file-unit-number.
12.10.2.19 OPENED= specifier in the INQUIRE statement
assigned the value true if the file specified is connected to a unit; otherwise, false is assigned. Execution of an1 The scalar-default-char-variable in the PAD= specifier is assigned the value YES or NO, corresponding to theINQUIRE by unit statement causes the scalar-logical-variable to be assigned the value true if the specified unit
is connected to a file; otherwise, false is assigned.
12.10.2.20 PAD= specifier in the INQUIRE statement
pad mode in effect for a connection for formatted input/output. If there is no connection or if the connection is1 The PENDING= specifier is used to determine whether previously pending asynchronous data transfers arenot for formatted input/output, the scalar-default-char-variable is assigned the value UNDEFINED.
12.10.2.21 PENDING= specifier in the INQUIRE statement
complete. A data transfer operation is previously pending if it is pending at the beginning of execution of the2 If an ID= specifier appears and the specified data transfer operation is complete, then the variable specified inINQUIRE statement.
the PENDING= specifier is assigned the value false and the INQUIRE statement performs the wait operation3 If the ID= specifier is omitted and all previously pending data transfer operations for the specified unit arefor the specified data transfer.
complete, then the variable specified in the PENDING= specifier is assigned the value false and the INQUIRE4 In all other cases, the variable specified in the PENDING= specifier is assigned the value true, no wait operationsstatement performs wait operations for all previously pending data transfers for the specified unit.
⃝c ISO/IEC 2017 – All rights reserved 257
ISO/IEC DIS 1539-1:2017 (E)
are performed, and the previously pending data transfers remain pending after the execution of the INQUIRE1 The scalar-int-variable in the POS= specifier is assigned the number of the file storage unit immediately followingstatement.
NOTE 12.60
The processor has considerable flexibility in defining when it considers a transfer to be complete. Any of
the following approaches could be used:
• The INQUIRE statement could consider an asynchronous data transfer to be incomplete 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.
• The INQUIRE statement could wait for all specified data transfers to complete and then always return
false for PENDING=.
• The INQUIRE statement could actually test the state of the specified data transfer operations.
12.10.2.22 POS= specifier in the INQUIRE statement
the current position of a file connected for stream access. If the file is positioned at its terminal position, the1 The scalar-default-char-variable in the POSITION= specifier is assigned the value REWIND if the connectionvariable is assigned a value one greater than the number of the highest-numbered file storage unit in the file.
If there are pending data transfer operations for the specified unit, the value assigned is computed as if all the
pending data transfers had already completed. If there is no connection, the file is not connected for stream
access, or if the position of the file is indeterminate because of previous error conditions, the variable becomes
undefined.
12.10.2.23 POSITION= specifier in the INQUIRE statement
was opened for positioning at its initial point, APPEND if the connection was opened for positioning before its1 The scalar-default-char-variable in the READ= specifier is assigned the value YES if READ is included in theendfile record or at its terminal point, and ASIS if the connection was opened without changing its position.
If there is no connection or if the file is connected for direct access, the scalar-default-char-variable is assigned
the value UNDEFINED. If the file has been repositioned since the connection, the scalar-default-char-variable
is assigned a processor-dependent value, which shall not be REWIND unless the file is positioned at its initial
point and shall not be APPEND unless the file is positioned so that its endfile record is the next record or at its
terminal point if it has no endfile record.
12.10.2.24 READ= specifier in the INQUIRE statement
set of allowed actions for the file, NO if READ is not included in the set of allowed actions for the file, and1 The scalar-default-char-variable in the READWRITE= specifier is assigned the value YES if READWRITE isUNKNOWN if the processor is unable to determine whether READ is included in the set of allowed actions for
the file or if the unit identified by file-unit-number is not connected to a file.
12.10.2.25 READWRITE= specifier in the INQUIRE statement
included in the set of allowed actions for the file, NO if READWRITE is not included in the set of allowed actions1 The scalar-int-variable in the RECL= specifier is assigned the value of the record length of a connection for directfor the file, and UNKNOWN if the processor is unable to determine whether READWRITE is included in the
set of allowed actions for the file or if the unit identified by file-unit-number is not connected to a file.
12.10.2.26 RECL= specifier in the INQUIRE statement
access, or the value of the maximum record length of a connection for sequential access. If the connection is for1 The scalar-default-char-variable in the ROUND= specifier is assigned the value UP, DOWN, ZERO, NEAREST,formatted input/output, the length is the number of characters for all records that contain only characters of
258 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
default kind. If the connection is for unformatted input/output, the length is measured in file storage units. If
there is no connection, the scalar-int-variable is assigned the value −1, and if the connection is for stream access,
the scalar-int-variable is assigned the value −2.
12.10.2.27 ROUND= specifier in the INQUIRE statement
COMPATIBLE, or PROCESSOR_DEFINED, corresponding to the input/output rounding mode in effect for1 The scalar-default-char-variable in the SEQUENTIAL= specifier is assigned the value YES if SEQUENTIAL isa connection for formatted input/output. If there is no connection or if the connection is not for formatted
input/output, the scalar-default-char-variable is assigned the value UNDEFINED. The processor shall return the
value PROCESSOR_DEFINED only if the behavior of the input/output rounding mode is different from that
of the UP, DOWN, ZERO, NEAREST, and COMPATIBLE modes.
12.10.2.28 SEQUENTIAL= specifier in the INQUIRE statement
included in the set of allowed access methods for the file, NO if SEQUENTIAL is not included in the set of allowed1 The scalar-default-char-variable in the SIGN= specifier is assigned the value PLUS, SUPPRESS, or PRO-access methods for the file, and UNKNOWN if the processor is unable to determine whether SEQUENTIAL is
included in the set of allowed access methods for the file or if the unit identified by file-unit-number is not
connected to a file.
12.10.2.29 SIGN= specifier in the INQUIRE statement
CESSOR_DEFINED, corresponding to the sign mode in effect for a connection for formatted input/output.1 The scalar-int-variable in the SIZE= specifier is assigned the size of the file in file storage units. If the file sizeIf there is no connection, or if the connection is not for formatted input/output, the scalar-default-char-variable
is assigned the value UNDEFINED.
12.10.2.30 SIZE= specifier in the INQUIRE statement
cannot be determined or if the unit identified by file-unit-number is not connected to a file, the variable is assigned2 For a file that may be connected for stream access, the file size is the number of the highest-numbered file storagethe value −1.
unit in the file.3 For a file that may be connected for sequential or direct access, the file size may be different from the number of
storage units implied by the data in the records; the exact relationship is processor dependent.4 If there are pending data transfer operations for the specified unit, the value assigned is computed as if all the
pending data transfers had already completed.1 The scalar-default-char-variable in the STREAM= specifier is assigned the value YES if STREAM is included in12.10.2.31 STREAM= specifier in the INQUIRE statement
the set of allowed access methods for the file, NO if STREAM is not included in the set of allowed access methods1 The scalar-default-char-variable in the UNFORMATTED= specifier is assigned the value YES if UNFORMAT-for the file, and UNKNOWN if the processor is unable to determine whether STREAM is included in the set of
allowed access methods for the file or if the unit identified by file-unit-number is not connected to a file.
12.10.2.32 UNFORMATTED= specifier in the INQUIRE statement
TED is included in the set of allowed forms for the file, NO if UNFORMATTED is not included in the set of1 The scalar-default-char-variable in the WRITE= specifier is assigned the value YES if WRITE is included in theallowed forms for the file, and UNKNOWN if the processor is unable to determine whether UNFORMATTED is
included in the set of allowed forms for the file or if the unit identified by file-unit-number is not connected to a
file.
⃝c ISO/IEC 2017 – All rights reserved 259
ISO/IEC DIS 1539-1:2017 (E)
12.10.2.33 WRITE= specifier in the INQUIRE statement
set of allowed actions for the file, NO if WRITE is not included in the set of allowed actions for the file, and1 The scalar-int-variable in the IOLENGTH= specifier is assigned the processor-dependent number of file storageUNKNOWN if the processor is unable to determine whether WRITE is included in the set of allowed actions for
the file or if the unit identified by file-unit-number is not connected to a file.
12.10.3 Inquire by output list
units that would be required to store the data of the output list in an unformatted file. The value shall be suitable2 The output list in an INQUIRE statement shall not contain any derived-type list items that require a definedas a RECL= specifier in an OPEN statement that connects a file for unformatted direct access if data will be
read from or written to the file using data transfer statements with an input/output list that specifies transfer of
a sequence of objects having the same types, type parameters, and extents, in the same order as the output list
in the INQUIRE statement.
input/output procedure as described in subclause 12.6.3. If a derived-type list item appears in the output list, the1 The set of input/output error conditions is processor dependent. Except as otherwise specified, when an errorvalue returned for the IOLENGTH= specifier assumes that no defined input/output procedure will be invoked.
12.11 Error, end-of-record, and end-of-file conditions
12.11.1 Occurrence of input/output conditions
condition occurs or is detected is processor dependent.2 An end-of-record condition occurs when a nonadvancing input statement attempts to transfer data from a position
beyond the end of the current record, unless the file is a stream file and the current record is at the end of the3 An end-of-file condition occurs whenfile (an end-of-file condition occurs instead).
• an endfile record is encountered during the reading of a file connected for sequential access,4 An end-of-file condition may occur at the beginning of execution of an input statement. An end-of-file condition• an attempt is made to read a record beyond the end of an internal file, or
• an attempt is made to read beyond the end of a stream file.
also may occur during execution of a formatted input statement when more than one record is required by the1 If an error condition occurs during execution of an input/output statement, the position of the file becomesinteraction of the input list and the format. An end-of-file condition also may occur during execution of a stream
input statement.
12.11.2 Error conditions and the ERR= specifier
indeterminate.2 If an error condition occurs during execution of an input/output statement that contains neither an ERR= nor
IOSTAT= specifier, error termination is initiated. If an error condition occurs during execution of an input/output1 If an end-of-file condition occurs during execution of an input/output statement that contains neither an END=statement that contains either an ERR= specifier or an IOSTAT= specifier then:
(1) processing of the input/output list, if any, terminates;
(2) if the statement is a data transfer statement or the error condition occurs during a wait operation,
all do-variables in the statement that initiated the transfer become undefined;
(3) if an IOSTAT= specifier appears, the stat-variable in the IOSTAT= specifier becomes defined as
specified in 12.11.5;
260 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
(4) if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 12.11.6;
(5) if the statement is a READ statement and it contains a SIZE= specifier, the scalar-int-variable in
the SIZE= specifier becomes defined as specified in 12.6.2.15;
(6) if the statement is a READ statement or the error condition occurs in a wait operation for a transfer
initiated by a READ statement, all input items or namelist group objects in the statement that
initiated the transfer become undefined;
(7) if an ERR= specifier appears, a branch to the statement labeled by the label in the ERR= specifier
occurs.
12.11.3 End-of-file condition and the END= specifier
specifier nor an IOSTAT= specifier, error termination is initiated. If an end-of-file condition occurs during1 If an end-of-record condition occurs during execution of an input/output statement that contains neither anexecution of an input/output statement that contains either an END= specifier or an IOSTAT= specifier, and
an error condition does not occur then:
(1) processing of the input list, if any, terminates;
(2) if the statement is a data transfer statement or the end-of-file condition occurs during a wait operation,
all do-variables in the statement that initiated the transfer become undefined;
(3) if the statement is an input statement or the end-of-file condition occurs during a wait operation
for a transfer initiated by an input statement, all input list items or namelist group objects in the
statement that initiated the transfer become undefined;
(4) if the file specified in the input statement is an external record file, it is positioned after the endfile
record;
(5) if an IOSTAT= specifier appears, the stat-variable in the IOSTAT= specifier becomes defined as
specified in 12.11.5;
(6) if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 12.11.6;
(7) if an END= specifier appears, a branch to the statement labeled by the label in the END= specifier
occurs.
12.11.4 End-of-record condition and the EOR= specifier
EOR= specifier nor an IOSTAT= specifier, error termination is initiated. If an end-of-record condition occurs1 Execution of an input/output statement containing the IOSTAT= specifier causes the stat-variable in the IO-during execution of an input/output statement that contains either an EOR= specifier or an IOSTAT= specifier,
and an error condition does not occur then:
(1) if the pad mode has the value
(a) YES, the record is padded with blanks to satisfy the effective item (12.6.4.5.3) and correspond-
ing data edit descriptors that require more characters than the record contains,
(b) NO, the input list item becomes undefined;
(2) processing of the input list, if any, terminates;
(3) if the statement is a data transfer statement or the end-of-record condition occurs during a wait
operation, all do-variables in the statement that initiated the transfer become undefined;
(4) the file specified in the input statement is positioned after the current record;
(5) if an IOSTAT= specifier appears, the stat-variable in the IOSTAT= specifier becomes defined as
specified in 12.11.5;
(6) if an IOMSG= specifier appears, the iomsg-variable becomes defined as specified in 12.11.6;
(7) if a SIZE= specifier appears, the scalar-int-variable in the SIZE= specifier becomes defined as spe-
cified in (12.6.2.15);
(8) if an EOR= specifier appears, a branch to the statement labeled by the label in the EOR= specifier
occurs.
⃝c ISO/IEC 2017 – All rights reserved 261
ISO/IEC DIS 1539-1:2017 (E)
12.11.5 IOSTAT= specifier
STAT= specifier to become defined with• a zero value if neither an error condition, an end-of-file condition, nor an end-of-record condition occurs,
• the processor-dependent positive integer value of the constant IOSTAT_INQUIRE_INTERNAL_UNIT
from the intrinsic module ISO_FORTRAN_ENV (16.10.2) if a unit number in an INQUIRE statement
identifies an internal file,
• a processor-dependent positive integer value different from IOSTAT_INQUIRE_INTERNAL_UNIT if any
other error condition occurs,
• the processor-dependent negative integer value of the constant IOSTAT_END (16.10.2.16) from the intrinsic
module ISO_FORTRAN_ENV if an end-of-file condition occurs and no error condition occurs,
• the processor-dependent negative integer value of the constant IOSTAT_EOR (16.10.2.17) from the intrinsic
module ISO_FORTRAN_ENV if an end-of-record condition occurs and no error condition or end-of-file
condition occurs, or
• a processor-dependent negative integer value different from IOSTAT_EOR and IOSTAT_END, if the IO-
STAT= specifier appears in a FLUSH statement and the processor does not support the flush operation for
the specified unit.
NOTE 12.61
An end-of-file condition can occur only for sequential or stream input and an end-of-record condition can
occur only for nonadvancing input.
For 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
12.11.6 IOMSG= specifier 1 If an error, end-of-file, or end-of-record condition occurs during execution of an input/output statement, iomsg-
variable is assigned an explanatory message, truncated or padded according to the rules of intrinsic assignment.1 If a unit, or a file connected to a unit, does not have all of the properties required for the execution of certainIf no such condition occurs, the definition status and value of iomsg-variable are unchanged.
12.12 Restrictions on input/output statements
input/output statements, those statements shall not refer to the unit.2 An input/output statement that is executed while another input/output statement is being executed is a recursive
input/output statement. A recursive input/output statement shall not identify an external unit that is identified3 An input/output statement shall not cause the value of any established format specification to be modified.by another input/output statement being executed except that a child data transfer statement may identify its
parent data transfer statement external unit.
4 A recursive input/output statement shall not modify the value of any internal unit except that a recursive WRITE
statement may modify the internal unit identified by that recursive WRITE statement.5 The value of a specifier in an input/output statement shall not depend on the definition or evaluation of any other262 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
specifier in the io-control-spec-list or inquire-spec-list in that statement. The value of an internal-file-variable or6 The value of any subscript or substring bound of a variable that appears in a specifier in an input/outputof a FMT=, ID=, IOMSG=, IOSTAT=, or SIZE= specifier shall not depend on the value of any input-item or
io-implied-do do-variable in the same statement.
statement shall not depend on any input-item, io-implied-do do-variable, or on the definition or evaluation of any7 In a data transfer statement, the variable specified in an IOSTAT=, IOMSG=, or SIZE= specifier, if any, shallother specifier in the io-control-spec-list or inquire-spec-list in that statement.
not be associated with any entity in the data transfer input/output list (12.6.3) or namelist-group-object-list, nor8 In a data transfer statement, if a variable specified in an IOSTAT=, IOMSG=, or SIZE= specifier is an arraywith a do-variable of an io-implied-do in the data transfer input/output list.
element reference, its subscript values shall not be affected by the data transfer, the io-implied-do processing, or9 A variable that may become defined or undefined as a result of its use in a specifier in an INQUIRE statement,the definition or evaluation of any other specifier in the io-control-spec-list.
or any associated entity, shall not appear in another specifier in the same INQUIRE statement.ISO/IEC DIS 1539-1:2017 (E)NOTE 12.62
Restrictions on the evaluation of expressions (10.1.4) prohibit certain side effects.
⃝c ISO/IEC 2017 – All rights reserved 263
(Blank page)
264 c ISO/IEC 2017 – All rights reserved13 Input/output editing
ISO/IEC DIS 1539-1:2017 (E)
13.1 Format specifications 1 A format used in conjunction with a data transfer statement provides information that directs the editing between the internal representation of data and the characters of a sequence of formatted records.2 A format (12.6.2.2) in a data transfer statement may refer to a FORMAT statement or to a character expression
that contains a format specification. A format specification provides explicit editing information. The format1 Blank characters may precede the initial left parenthesis of the format specification. Additional blank charactersalternatively may be an asterisk (*), which indicates list-directed formatting (13.10). Namelist formatting (13.11)
may be indicated by specifying a namelist-group-name instead of a format.
13.2 Explicit format specification methods
13.2.1 FORMAT statement
R1301 format-stmt is FORMAT format-specification
R1302 format-specification is ( [ format-items ] )
or ( [ format-items, ] unlimited-format-item )
C1301 (R1301) The format-stmt shall be labeled.
may appear at any point within the format specification, with no effect on the interpretation of the format1 A character expression used as a format in a formatted input/output statement shall evaluate to a characterspecification, except within a character string edit descriptor (13.9).
NOTE 13.1
Examples of FORMAT statements are:
5 FORMAT (1PE12.4, I10)
9 FORMAT (I12, /, ’ Dates: ’, 2 (2I3, I5))
13.2.2 Character format specification
string whose leading part is a valid format specification.2 All character positions up to and including the final right parenthesis of the format specification shall be definedNOTE 13.2
The format specification begins with a left parenthesis and ends with a right parenthesis.
at the time the data transfer statement is executed, and shall not become redefined or undefined during the3 If the format is a character array, it is treated as if all of the elements of the array were specified in array elementexecution of the statement. Character positions, if any, following the right parenthesis that ends the format
specification need not be defined and may contain any character data with no effect on the interpretation of the
format specification.
order and were concatenated. However, if a format is a character array element, the format specification shall be1 The integer literal constant r is called a repeat specification.entirely within that array element.
⃝c ISO/IEC 2017 – All rights reserved 265
ISO/IEC DIS 1539-1:2017 (E)
NOTE 13.3
If a character constant is used as a format in data transfer 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
can 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.
13.3 Form of a format item list
13.3.1 Syntax
R1303 format-items is format-item [ [ , ] format-item ] ...
R1304 format-item is [ r ] data-edit-desc
or control-edit-desc
or char-string-edit-desc
or [ r ] ( format-items )
R1305 unlimited-format-item is * ( format-items )
R1306 r is int-literal-constant
C1302 (R1303) The optional comma shall not be omitted except
• between a P edit descriptor and an immediately following F, E, EN, ES, D, or G edit descriptor
(13.8.5), possibly preceded by a repeat specification,
• before a slash edit descriptor when the optional repeat specification does not appear (13.8.2),
• after a slash edit descriptor, or
• before or after a colon edit descriptor (13.8.3)
C1303 (R1305) An unlimited-format-item shall contain at least one data edit descriptor.
C1304 (R1306) r shall be positive.
C1305 (R1306) A kind parameter shall not be specified for r.
13.3.2 Edit descriptors1 An edit descriptor is a data edit descriptor (data-edit-desc), control edit descriptor (control-edit-desc), or character
string edit descriptor (char-string-edit-desc).2 An I, B, O, Z, F, E, EN, ES, EX, G, L, A, D, or DT edit descriptor indicates the manner of editing.266 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
R1307 data-edit-desc is Iw[. m]
or Bw[. m]
or Ow[. m]
or Zw[. m]
or Fw. d
or Ew. d [Ee]
or EN w . d [ E e ]
or ES w . d [ E e ]
or EX w . d [ E e ]
or Gw[. d [Ee]]
or Lw
or A[w]
or Dw. d
or DT [ char-literal-constant ] [ ( v-list ) ]
R1308 w is int-literal-constant
R1309 m is int-literal-constant
R1310 d is int-literal-constant
R1311 e is int-literal-constant
R1312 v is signed-int-literal-constant
C1306 (R1308) w shall be zero or positive for the I, B, O, Z, D, E, EN, ES, EX, F, and G edit descriptors. w
shall be positive for all other edit descriptors.
C1307 (R1307) For the G edit descriptor, d shall be specified if w is not zero.
C1308 (R1307) For the G edit descriptor, e shall not be specified if w is zero.
C1309 (R1307) A kind parameter shall not be specified for the char-literal-constant in the DT edit descriptor,
or for w, m, d, e, and v.
R1313 control-edit-desc is position-edit-desc3 In k P, k is called the scale factor.or [r ]/
or :
or sign-edit-desc
or k P
or blank-interp-edit-desc
or round-edit-desc
or decimal-edit-desc
R1314 k is signed-int-literal-constant
C1310 (R1314) A kind parameter shall not be specified for k.
R1315 position-edit-desc is Tn4 A T, TL, TR, X, slash, colon, SS, SP, S, P, BN, BZ, RU, RD, RZ, RN, RC, RP, DC, or DP edit descriptoror TL n
or TR n
or nX
R1316 n is int-literal-constant
C1311 (R1316) n shall be positive.
⃝c ISO/IEC 2017 – All rights reserved 267
ISO/IEC DIS 1539-1:2017 (E)
C1312 (R1316) A kind parameter shall not be specified for n.
R1317 sign-edit-desc is SS
or SP
or S
R1318 blank-interp-edit-desc is BN
or BZ
R1319 round-edit-desc is RU
or RD
or RZ
or RN
or RC
or RP
R1320 decimal-edit-desc is DC
or DP
indicates the manner of editing.5 Each rep-char in a character string edit descriptor shall be capable of representation by the processor.R1321 char-string-edit-desc is char-literal-constant
C1313 (R1321) A kind parameter shall not be specified for the char-literal-constant.
6 A character string edit descriptor provides constant data to be output, and is not valid for input. 7 The edit descriptors are without regard to case except within a character string edit descriptor. 13.3.3 Fields1 A field is a part of a record that is read on input or written on output when format control encounters a data
edit descriptor or a character string edit descriptor. The field width is the size in characters of the field.1 The start of formatted data transfer using a format specification initiates format control (12.6.4.5.3). Each action13.4 Interaction between input/output list and format
of format control depends on information jointly provided by the next edit descriptor in the format specification2 If an input/output list specifies at least one effective item, at least one data edit descriptor shall exist in theand the next effective item in the input/output list, if one exists.
format specification.3 A format specification is interpreted from left to right. The exceptions are format items preceded by a repeatNOTE 13.4
An empty format specification of the form ( ) can be used only if the input/output list has no effective item
(12.6.4.5). A zero length character item is an effective item, but a zero sized array and an implied DO list
with an iteration count of zero is not.
specification r, and format reversion (described below).4 A format item preceded by a repeat specification is processed as a list of r items, each identical to the format
item but without the repeat specification and separated by commas.5 To each data edit descriptor interpreted in a format specification, there corresponds one effective item specified by268 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 13.5
An omitted repeat specification is treated in the same way as a repeat specification whose value is one.
the input/output list (12.6.3), except that an input/output list item of type complex requires the interpretation6 Whenever format control encounters a data edit descriptor in a format specification, it determines whetherof two F, E, EN, ES, D, or G edit descriptors. For each control edit descriptor or character edit descriptor,
there is no corresponding item specified by the input/output list, and format control communicates information
directly with the record.
there is a corresponding effective item specified by the input/output list. If there is such an item, it transmits7 If format control encounters a colon edit descriptor in a format specification and another effective item is notappropriately edited information between the item and the record, and then format control proceeds. If there is
no such item, format control terminates.
specified, format control terminates.8 If format control encounters the rightmost parenthesis of an unlimited format item, control reverts to the leftmost
parenthesis of that unlimited format item. This reversion of format control has no effect on the changeable modes9 If format control encounters the rightmost parenthesis of a complete format specification and another effective(12.5.2).
item is not specified, format control terminates. However, if another effective item is specified, format control1 After each data edit descriptor or character string edit descriptor is processed, the file is positioned after the lastthen reverts to the beginning of the format item terminated by the last preceding right parenthesis that is not
part of a DT edit descriptor. If there is no such preceding right parenthesis, format control reverts to the first
left parenthesis of the format specification. If any reversion occurs, the reused portion of the format specification
shall contain at least one data edit descriptor. If format control reverts to a parenthesis that is preceded by a
repeat specification, the repeat specification is reused. Reversion of format control, of itself, has no effect on
the changeable modes. The file is positioned in a manner identical to the way it is positioned when a slash edit
descriptor is processed (13.8.2).
NOTE 13.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 13.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 can 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.
⃝c ISO/IEC 2017 – All rights reserved 269
ISO/IEC DIS 1539-1:2017 (E)
13.5 Positioning by format control
character read or written in the current record.2 After each T, TL, TR, or X edit descriptor is processed, the file is positioned as described in 13.8.1.1. After each
slash edit descriptor is processed, the file is positioned as described in 13.8.2.3 During formatted stream output, processing of an A edit descriptor can cause file positioning to occur (13.7.4).
4 If format control reverts as described in 13.4, the file is positioned in a manner identical to the way it is positioned when a slash edit descriptor is processed (13.8.2).5 During a read operation, any unprocessed characters of the current record are skipped whenever the next record
is read.1 The decimal symbol is the character that separates the whole and fractional parts in the decimal representation13.6 Decimal symbol
of a real number in an internal or external file. When the decimal edit mode is POINT, the decimal symbol is a2 If the decimal edit mode is COMMA during list-directed input/output, the character used as a value separatordecimal point. When the decimal edit mode is COMMA, the decimal symbol is a comma.
is a semicolon in place of a comma.1 Data edit descriptors cause the conversion of data to or from its internal representation; during formatted stream13.7 Data edit descriptors
13.7.1 Purpose of data edit descriptors
output, the A data edit descriptor may also cause file positioning. On input, the specified variable becomes2 During input from a Unicode file,defined unless an error condition, an end-of-file condition, or an end-of-record condition occurs. On output, the
specified expression is evaluated.
• characters in the record that correspond to an ASCII character variable shall have a position in the ISO3 During input from a non-Unicode file,10646 character collating sequence of 127 or less, and
• characters in the record that correspond to a default character variable shall be representable as default
characters.
• characters in the record that correspond to a character variable shall have the kind of the character variable,4 During output to a Unicode file, all characters transmitted to the record are of ISO 10646 character kind. If aand
• characters in the record that correspond to a numeric or logical variable shall be default characters.
character input/output list item or character string edit descriptor contains a character that is not representable5 During output to a non-Unicode file, characters transmitted to the record as a result of processing a characteras an ISO 10646 character, the result is processor dependent.
string edit descriptor or as a result of evaluating a numeric, logical, or default character data entity, are of default1 The I, B, O, Z, F, E, EN, ES, EX, D, and G edit descriptors may be used to specify the input/output of integer,kind.
270 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
13.7.2 Numeric editing
13.7.2.1 General rules
real, and complex data. The following general rules apply.1 The Iw and Iw.m edit descriptors indicate that the field to be edited occupies w positions, except when w is zero.(1) On input, leading blanks are not significant. When the input field is not an IEEE exceptional
specification or hexadecimal-significand number (13.7.2.3.2), the interpretation of blanks, other than
leading blanks, is determined by the blank interpretation mode (13.8.6). Plus signs may be omitted.
A field containing only blanks is considered to be zero.
(2) On input, with F, E, EN, ES, EX, D, and G editing, a decimal symbol appearing in the input field
overrides the portion of an edit descriptor that specifies the decimal symbol location. The input field
may have more digits than the processor uses to approximate the value of the datum.
(3) On output with I, F, E, EN, ES, EX, D, and G editing, the representation of a positive or zero
internal value in the field may be prefixed with a plus sign, as controlled by the S, SP, and SS edit
descriptors or the processor. The representation of a negative internal value in the field shall be
prefixed with a minus sign.
(4) On output, the representation is right justified in the field. If the number of characters produced by
the editing is smaller than the field width, leading blanks are inserted in the field.
(5) On output, if an exponent exceeds its specified or implied width using the E, EN, ES, EX, D, or G
edit descriptor, or the number of characters produced exceeds the field width, the processor shall fill
the entire field of width w with asterisks. However, the processor shall not produce asterisks if the
field width is not exceeded when optional characters are omitted.
NOTE 13.8
When the sign mode is PLUS, a plus sign is not optional.
(6) On output, with I, B, O, Z, D, E, EN, ES, EX, F, and G editing, the specified value of the field width
w may be zero. In such cases, the processor selects the smallest positive actual field width that does
not result in a field filled with asterisks. The specified value of w shall not be zero on input.
(7) On output of a real zero value, the digits in the exponent field shall all be zero.
13.7.2.2 Integer editing
When w is zero, the processor selects the field width. On input, w shall not be zero. The specified input/output2 On input, m has no effect.list item shall be of type integer. The G, B, O, and Z edit descriptor also may be used to edit integer data
(13.7.5.2.1, 13.7.2.4).
3 In the standard form of the input field for the I edit descriptor, the character string is a signed-digit-string (R710), except for the interpretation of blanks. If the input field does not have the standard form and is not acceptable4 The output field for the Iw edit descriptor consists of zero or more leading blanks followed by a minus sign if theto the processor, an error condition occurs.
internal value is negative, or an optional plus sign otherwise, followed by the magnitude of the internal value as5 The output field for the Iw.m edit descriptor is the same as for the Iw edit descriptor, except that the digit-stringa digit-string without leading zeros.
NOTE 13.9
A digit-string always consists of at least one digit.
consists of at least m digits. If necessary, sufficient leading zeros are included to achieve the minimum of m digits.1 The F, E, EN, ES, and D edit descriptors specify the editing of real and complex data. An input/output listThe value of m shall not exceed the value of w, except when w is zero. If m is zero and the internal value is zero,
⃝c ISO/IEC 2017 – All rights reserved 271
ISO/IEC DIS 1539-1:2017 (E)
the output field consists of only blank characters, regardless of the sign control in effect. When m and w are both
zero, and the internal value is zero, one blank character is produced.
13.7.2.3 Real and complex editing
13.7.2.3.1 General
item corresponding to an F, E, EN, ES, or D edit descriptor shall be real or complex. The G, B, O, and Z edit1 The Fw.d edit descriptor indicates that the field occupies w positions, except when w is zero in which case thedescriptors also may be used to edit real and complex data (13.7.5.2.2, 13.7.2.4).
13.7.2.3.2 F editing
processor selects the field width. The fractional part of the field consists of d digits. On input, w shall not be2 A lower-case letter is equivalent to the corresponding upper-case letter in an IEEE exceptional specification orzero.
the exponent in a numeric input field.3 The standard form of the input field is an IEEE exceptional specification, a hexadecimal-significand number, or
consists of a mantissa optionally followed by an exponent. The form of the mantissa is an optional sign, followed4 An exponent containing a D is processed identically to an exponent containing an E.by a string of one or more digits optionally containing a decimal symbol, including any blanks interpreted as
zeros. The d has no effect on input if the input field contains a decimal symbol. If the decimal symbol is omitted,
the rightmost d digits of the string, with leading zeros assumed if necessary, are interpreted as the fractional part
of the value represented. The string of digits may contain more digits than a processor uses to approximate the
value. The form of the exponent is one of the following:
• a sign followed by a digit-string;
• the letter E followed by zero or more blanks, followed by a signed-digit-string;
• the letter D followed by zero or more blanks, followed by a signed-digit-string.
NOTE 13.105 An input field that is an IEEE exceptional specification consists of optional blanks, followed by eitherIf 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 (13.8.5).
• an optional sign, followed by the string ’INF’ or the string ’INFINITY’, oroptionally followed by blanks.• an optional sign, followed by the string ’NAN’, optionally followed by zero or more alphanumeric characters
enclosed in parentheses,
6 The value specified by ’INF’ or ’INFINITY’ is an IEEE infinity; this form shall not be used if the processor does not support IEEE infinities for the input variable. The value specified by ’NAN’ is an IEEE NaN; this form shall7 An input field that is a hexadecimal-significand number consists of an optional sign, followed by the hexadecimalnot be used if the processor does not support IEEE NaNs for the input variable. The NaN value is a quiet NaN if
the only nonblank characters in the field are ’NAN’ or ’NAN()’; otherwise, the NaN value is processor dependent.
The interpretation of a sign in a NaN input field is processor dependent.
indicator which is the digit 0 immediately followed by the letter X, followed by a hexadecimal significand followed8 If the input field does not have one of the standard forms, and is not acceptable to the processor, an errorby a hexadecimal exponent. A hexadecimal significand is a string of one or more hexadecimal characters optionally
containing a decimal symbol. The decimal symbol indicates the position of the hexadecimal point; if no decimal
symbol appears, the hexadecimal point implicitly follows the last hexadecimal symbol. A hexadecimal exponent
272 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
is the letter P followed by a (decimal) signed-digit-string. Embedded blanks are not permitted in a hexadecimal-
significand number. The value is equal to the significand multiplied by two raised to the power of the exponent,
negated if the optional sign is minus.
condition occurs.9 For an internal value that is an IEEE infinity, the output field consists of blanks, if necessary, followed by a minus
sign for negative infinity or an optional plus sign otherwise, followed by the letters ’Inf’ or ’Infinity’, right justified10 For an internal value that is an IEEE NaN, the output field consists of blanks, if necessary, followed by thewithin the field. The minimum field width required for output of the form ’Inf’ is 3 if no sign is produced, and
4 otherwise. The minimum field width required for output of the form ’Infinity’ is 8 if no sign is produced, and
9 otherwise. If w is greater than or equal to the minimum required for the form ’Infinity’, the form ’Infinity’ is
output. If w is zero or w is less than the minimum required for the form ’Infinity’ and greater than or equal to
the minimum required for the form ’Inf’, the form ’Inf’ is output. Otherwise (w is greater than zero but less than
the minimum required for any form), the field is filled with asterisks.
letters ’NaN’ and optionally followed by one to w−5 alphanumeric processor-dependent characters enclosed in11 For an internal value that is neither an IEEE infinity nor a NaN, the output field consists of blanks, if necessary,parentheses, right justified within the field. If w is greater than zero and less than 3, the field is filled with
asterisks. If w is zero, the output field is ’NaN’.
NOTE 13.11
The processor-dependent characters following ’NaN’ might convey additional information about that par-
ticular NaN.
followed by a minus sign if the internal value is negative, or an optional plus sign otherwise, followed by a string1 The Ew.d, Dw.d, and Ew.d Ee edit descriptors indicate that the external field occupies w positions, except whenof digits that contains a decimal symbol and represents the magnitude of the internal value, as modified by the
established scale factor and rounded (13.7.2.3.8) to d fractional digits. Leading zeros are not permitted except
for an optional zero immediately to the left of the decimal symbol if the magnitude of the value in the output
field is less than one. The optional zero shall appear if there would otherwise be no digits in the output field.
13.7.2.3.3 E and D editing
w is zero in which case the processor selects the field width. The fractional part of the field contains d digits,2 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).unless a scale factor greater than one is in effect. If e is positive the exponent part contains e digits, otherwise it
contains the minimum number of digits required to represent the exponent value. The e has no effect on input.
3 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.
4 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field for a scale factor
of zero isISO/IEC DIS 1539-1:2017 (E)[ ± ] [0].x1 x2 . . . xd exp
where:
• ± signifies a plus sign or a minus sign;
• . signifies a decimal symbol (13.6);
• x1 x2 . . . xd are the d most significant digits of the internal value after rounding (13.7.2.3.8);
• exp is a decimal exponent having one of the forms specified in table 13.1.
⃝c ISO/IEC 2017 – All rights reserved 273
Table 13.1: E and D exponent forms
Edit Absolute Value Form of
Descriptor of Exponent Exponent1 Ew.d |exp| ≤ 99 E±z1 z2 or ±0z1 z299 < |exp| ≤ 999 ±z1 z2 z3
e
Ew.d Ee with e > 0 |exp| ≤ 10 − 1 E±z1 z2 . . . ze Ew.d E0 any E±z1 z2 . . . zs(1) where each z is a digit, and s is the minimum number of digitsDw.d |exp| ≤ 99 D±z1 z2 or E±z1 z2
or ±0z1 z2
99 < |exp| ≤ 999 ±z1 z2 z3
required to represent the exponent.
5 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero. 6 The scale factor k controls the decimal normalization (13.3.2, 13.8.5). If −d < k ≤ 0, the output field contains exactly |k| leading zeros and d − |k| significant digits after the decimal symbol. If 0 < k < d + 2, the output field1 The EN edit descriptor produces an output field in the form of a real number in engineering notation such thatcontains exactly k significant digits to the left of the decimal symbol and d − k + 1 significant digits to the right
of the decimal symbol. Other values of k are not permitted.
13.7.2.3.4 EN editing
the decimal exponent is divisible by three and the absolute value of the significand (R715) is greater than or2 The forms of the edit descriptor are ENw.d and ENw.d Ee indicating that the external field occupies w positions,equal to 1 and less than 1000, except when the output value is zero. The scale factor has no effect on output.
except when w is zero in which case the processor selects the field width. The fractional part of the field contains3 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).d digits. If e is positive the exponent part contains e digits, otherwise it contains the minimum number of digits
required to represent the exponent value.
4 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d. 5 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is [ ± ] yyy . x1 x2 . . . xd expwhere:
• ± signifies a plus sign or a minus sign;• yyy are the 1 to 3 decimal digits representative of the most significant digits of the internal value after
rounding (13.7.2.3.8);
• yyy is an integer such that 1 ≤ yyy < 1000 or, if the output value is zero, yyy = 0;
• . signifies a decimal symbol (13.6);
• x1 x2 . . . xd are the d next most significant digits of the internal value after rounding;
• exp is a decimal exponent, divisible by three, having one of the forms specified in table 13.2.
274 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)Table 13.2: EN exponent forms
Edit Absolute Value Form of
Descriptor of Exponent Exponent1 ENw.d |exp| ≤ 99 E±z1 z2 or ±0z1 z299 < |exp| ≤ 999 ±z1 z2 z3
e
ENw.d Ee with e > 0 |exp| ≤ 10 − 1 E±z1 z2 . . . ze ENw.d E0 any E±z1 z2 . . . zs(1) where each z is a digit, and s is the minimum number of digits
required to represent the exponent.
6 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero. NOTE 13.12Examples:
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
13.7.2.3.5 ES editing 1 The ES edit descriptor produces an output field in the form of a real number in scientific notation such that the absolute value of the significand (R715) is greater than or equal to 1 and less than 10, except when the output2 The forms of the edit descriptor are ESw.d and ESw.d Ee indicating that the external field occupies w positions,value is zero. The scale factor has no effect on output.
except when w is zero in which case the processor selects the field width. The fractional part of the field contains3 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).d digits. If e is positive the exponent part contains e digits, otherwise it contains the minimum number of digits
required to represent the exponent value.
4 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.
5 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is
[ ± ] y . x1 x2 . . . xd expwhere:
• ± signifies a plus sign or a minus sign;• y is a decimal digit representative of the most significant digit of the internal value after rounding (13.7.2.3.8);
• . signifies a decimal symbol (13.6);
• x1 x2 . . . xd are the d next most significant digits of the internal value after rounding;
• exp is a decimal exponent having one of the forms specified in table 13.3.
Table 13.3: ES exponent forms
Edit Absolute Value Form of
Descriptor of Exponent Exponent1
ESw.d |exp| ≤ 99 E±z1 z2 or ±0z1 z2
99 < |exp| ≤ 999 ±z1 z2 z3
ESw.d Ee with e > 0 |exp| ≤ 10e − 1 E±z1 z2 . . . ze
ESw.d E0 any E±z1 z2 . . . zs
(1) where each z is a digit, and s is the minimum number of digits
required to represent the exponent.
⃝c ISO/IEC 2017 – All rights reserved 275
ISO/IEC DIS 1539-1:2017 (E) 6 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero. NOTE 13.13Examples:
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
13.7.2.3.6 EX editing 1 The EX edit descriptor produces an output field in the form of a hexadecimal-significand number. 2 The EXw.d and EXw.dEe edit descriptors indicate that the external field occupies w positions, except when w
is zero in which case the processor selects the field width. The fractional part of the field contains d hexadecimal3 The form and interpretation of the input field is the same as for Fw.d editing (13.7.2.3.2).digits, except when d is zero in which case the processor selects the number of hexadecimal digits to be the
minimum required so that the output field is equal to the internal value; d shall not be zero if the radix of the
internal value is not a power of two. The hexadecimal point, represented by a decimal symbol, appears after
the first hexadecimal digit. For the form EXw.d, and for EXw.dE0, the exponent part contains the minimum
number of digits needed to represent the exponent; otherwise the exponent contains e digits. The e has no effect
on input. The scale factor has no effect on output.
4 For an internal value that is an IEEE infinity or NaN, the form of the output field is the same as for Fw.d.
5 For an internal value that is neither an IEEE infinity nor a NaN, the form of the output field is
[ ± ] 0X x0 . x1 x2 . . . expwhere:
• ± signifies a plus sign or a minus sign;6 The sign in the exponent is produced. A plus sign is produced if the exponent value is zero.• . signifies a decimal symbol (13.6);
• x0 x1 x2 . . . are the most significant hexadecimal digits of the internal value, after rounding if d is not zero
(13.7.2.3.8);
• exp is a binary exponent expressed as a decimal integer; for EXw.d and EXw.dE0, the form is P ±z1 . . . zn ,
where n is the minimum number of digits needed to represent exp, and for EXw.dEe with e greater than
zero the form is P ±z1 . . . ze . The choice of binary exponent is processor dependent. If the most significant
binary digits of the internal value are b0 b1 b2 . . ., the binary exponent might make the value of x0 be that of
b0 , b0 b1 , b0 b1 b2 , or b0 b1 b2 b3 .
NOTE 13.14Examples:
Internal value Edit descriptor Possible output with SS in effect
1.375 EX0.1 0X1.6P+0
−15.625 EX14.4E3 -0X1.F400P+003
1048580.0 EX0.0 0X1.00004P+20
2.375 EX0.1 0X2.6P+0
13.7.2.3.7 Complex editing 1 A complex datum consists of a pair of separate real data. The editing of a scalar datum of complex type is
specified by two edit descriptors each of which specifies the editing of real data. The first edit descriptor specifies1 The input/output rounding mode can be specified by an OPEN statement (12.5.2), a data transfer statement276 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
the editing for the real part; the second specifies it for the imaginary part. The two edit descriptors may be
different. Control and character string edit descriptors may be processed between the edit descriptor for the real
part and the edit descriptor for the imaginary part.
13.7.2.3.8 Input/output rounding mode
(12.6.2.13), or an edit descriptor (13.8.7).2 In what follows, the term “decimal value” means the exact decimal number as given by the character string, while
the term “internal value” means the number actually stored in the processor. For example, in dealing with the3 When the input/output rounding mode is UP, the value resulting from conversion shall be the smallest represent-decimal constant 0.1, the decimal value is the mathematical quantity 1/10, which has no exact representation
in binary form. Formatted output of real data involves conversion from an internal value to a decimal value;
formatted input involves conversion from a decimal value to an internal value.
able value that is greater than or equal to the original value. When the input/output rounding mode is DOWN,4 On processors that support IEEE rounding on conversions (17.4), NEAREST shall correspond to round to nearest,the value resulting from conversion shall be the largest representable value that is less than or equal to the original
value. When the input/output rounding mode is ZERO, the value resulting from conversion shall be the value
closest to the original value and no greater in magnitude than the original value. When the input/output rounding
mode is NEAREST, the value resulting from conversion shall be the closer of the two nearest representable values
if one is closer than the other. If the two nearest representable values are equidistant from the original value, it is
processor dependent which one of them is chosen. When the input/output rounding mode is COMPATIBLE, the
value resulting from conversion shall be the closer of the two nearest representable values or the value away from
zero if halfway between them. When the input/output rounding mode is PROCESSOR_DEFINED, rounding
during conversion shall be a processor-dependent default mode, which may correspond to one of the other modes.
as specified in ISO/IEC/IEEE 60559:2011.1 The Bw, Bw.m, Ow, Ow.m, Zw, and Zw.m edit descriptors indicate that the field to be edited occupies wNOTE 13.15
On processors that support IEEE rounding on conversions, the input/output rounding modes COMPAT-
IBLE 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 input/output rounding modes UP, DOWN, and ZERO have the same effect as
those specified in ISO/IEC/IEEE 60559:2011 for round toward +∞, round toward −∞, and round toward
0, respectively.
13.7.2.4 B, O, and Z editing
positions, except when w is zero. When w is zero, the processor selects the field width. On input, w shall not be2 On input, m has no effect.zero. The corresponding input/output list item shall be of type integer, real, or complex.
3 In the standard form of the input field for the B, O, and Z edit descriptors the character string consists of binary,
octal, or hexadecimal digits (as in R765, R766, R767) in the respective input field. The lower-case hexadecimal4 The value is INT (X) if the input list item is of type integer and REAL (X) if the input list item is of type realdigits a through f in a hexadecimal input field are equivalent to the corresponding upper-case hexadecimal digits.
If the input field does not have the standard form, and is not acceptable to the processor, an error condition
occurs.
or complex, where X is a boz-literal-constant that specifies the same bit sequence as the digits of the input field.5 The output field for the Bw, Ow, and Zw descriptors consists of zero or more leading blanks followed by the
internal value in a form identical to the digits of a binary, octal, or hexadecimal constant, respectively, that6 The output field for the Bw.m, Ow.m, and Zw.m edit descriptor is the same as for the Bw, Ow, and Zw editspecifies the same bit sequence but without leading zero bits.
⃝c ISO/IEC 2017 – All rights reserved 277
ISO/IEC DIS 1539-1:2017 (E)
NOTE 13.16
A binary, octal, or hexadecimal constant always consists of at least one digit or hexadecimal digit.
R1322 hex-digit-string is hex-digit [ hex-digit ] ...
descriptor, except that the digit-string or hex-digit-string consists of at least m digits. If necessary, sufficient1 The Lw edit descriptor indicates that the field occupies w positions. The specified input/output list item shallleading zeros are included to achieve the minimum of m digits. The value of m shall not exceed the value of w,
except when w is zero. If m is zero and the internal value consists of all zero bits, the output field consists of
only blank characters. When m and w are both zero, and the internal value consists of all zero bits, one blank
character is produced.
13.7.3 Logical editing
be of type logical. The G edit descriptor also may be used to edit logical data (13.7.5.3).2 The standard form of the input field consists of optional blanks, optionally followed by a period, followed by a T
for true or F for false. The T or F may be followed by additional characters in the field, which are ignored. If the3 A lower-case letter is equivalent to the corresponding upper-case letter in a logical input field.input field does not have the standard form, and is not acceptable to the processor, an error condition occurs.
NOTE 13.174 The output field consists of w−1 blanks followed by a T or F, depending on whether the internal value is true orThe logical constants .TRUE. and .FALSE. are acceptable input forms.
false, respectively.1 The A[w] edit descriptor is used with an input/output list item of type character. The G edit descriptor also may13.7.4 Character editing
be used to edit character data (13.7.5.4). The kind type parameter of all characters transferred and converted2 If a field width w is specified with the A edit descriptor, the field consists of w characters. If a field width w isunder control of one A or G edit descriptor is implied by the kind of the corresponding list item.
not specified with the A edit descriptor, the number of characters in the field is the length of the corresponding3 Let len be the length of the input/output list item. If the specified field width w for an A edit descriptorlist item, regardless of the value of the kind type parameter.
corresponding to an input item is greater than or equal to len, the rightmost len characters will be taken from the4 If the specified field width w for an A edit descriptor corresponding to an output item is greater than len, theinput field. If the specified field width w is less than len, the w characters will appear left justified with len−w
trailing blanks in the internal value.
output field will consist of w−len blanks followed by the len characters from the internal value. If the specified5 If the file is connected for stream access, the output may be split across more than one record if it containsfield width w is less than or equal to len, the output field will consist of the leftmost w characters from the internal
value.
NOTE 13.18
For nondefault character kinds, the blank padding character is processor dependent.
newline characters. A newline character is a nonblank character returned by the intrinsic function NEW_LINE.1 The Gw, Gw.d and Gw.d Ee edit descriptors are used with an input/output list item of any intrinsic type. WhenBeginning with the first character of the output field, each character that is not a newline is written to the current
record in successive positions; each newline character causes file positioning at that point as if by slash editing
278 ⃝ c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
(the current record is terminated at that point, a new empty record is created following the current record, this
new record becomes the last and current record of the file, and the file is positioned at the beginning of this new
record).
NOTE 13.19
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.
13.7.5 Generalized editing
13.7.5.1 Overview
w is nonzero, these edit descriptors indicate that the external field occupies w positions. For real or complex1 When used to specify the input/output of integer, real, and complex data, the Gw, Gw.d and Gw.d Ee editdata the fractional part consists of a maximum of d digits and the exponent part consists of e digits. When these
edit descriptors are used to specify the input/output of integer, logical, or character data, d and e have no effect.
When w is zero the processor selects the field width. On input, w shall not be zero.
13.7.5.2 Generalized numeric editing
descriptors follow the general rules for numeric editing (13.7.2).1 When used to specify the input/output of integer data, the Gw, Gw.d, and Gw.d Ee edit descriptors follow theNOTE 13.20
The Gw.d Ee edit descriptor follows any additional rules for the Ew.d Ee edit descriptor.
13.7.5.2.1 Generalized integer editing
rules for the Iw edit descriptor (13.7.2.2). Note that w cannot be zero for input editing (13.7.5.1).1 The form and interpretation of the input field for Gw.d and Gw.d Ee editing is the same as for Fw.d editing13.7.5.2.2 Generalized real and complex editing
(13.7.2.3.2). The rest of this subclause applies only to output editing.2 If w is nonzero and d is zero, kPEw.0 or kPEw.0Ee editing is used for Gw.0 editing or Gw.0Ee editing respectively.
3 When used to specify the output of real or complex data that is not an IEEE infinity or NaN, the G0 and G0.d
edit descriptors follow the rules for the Gw.dEe edit descriptor, except that any leading or trailing blanks are4 For an internal value that is an IEEE infinity or NaN, the form of the output field for the Gw.d and Gw.d Eeremoved. Reasonable processor-dependent values of w, d (if not specified), and e are used with each output value.
edit descriptors is the same as for Fw.d, and the form of the output field for the G0 and G0.d edit descriptors is5 Otherwise, the method of representation in the output field depends on the magnitude of the internal valuethe same as for F0.0.
being edited. If the internal value is zero, let s be one. If the internal value is a number other than zero, let N6 The value of w−n shall be positive.be the decimal value that is the result of converting the internal value to d significant digits according to the
input/output rounding mode and let s be the integer such that 10s−1 ≤ |N | < 10s . If s < 0 or s > d, kPEw.d or
kPEw.dEe editing is used for Gw.d editing or Gw.dEe editing respectively, where k is the scale factor (13.8.5).
If 0 ≤ s ≤ d, the scale factor has no effect and F(w − n).(d − s),n(’b’) editing is used where b is a blank and n is
4 for Gw.d editing, e + 2 for Gw.dEe editing if e > 0, and 4 for Gw.dE0 editing.
⃝c ISO/IEC 2017 – All rights reserved 2791 When used to specify the input/output of logical data, the Gw.d and Gw.d Ee edit descriptors with nonzero w
ISO/IEC DIS 1539-1:2017 (E)
NOTE 13.21
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.
13.7.5.3 Generalized logical editing
follow the rules for the Lw edit descriptor (13.7.3). When used to specify the output of logical data, the G0 and1 When used to specify the input/output of character data, the Gw.d and Gw.d Ee edit descriptors with nonzeroG0.d edit descriptors follow the rules for the L1 edit descriptor.
13.7.5.4 Generalized character editing
w follow the rules for the Aw edit descriptor (13.7.4). When used to specify the output of character data, the G01 The DT edit descriptor specifies that a user-provided procedure shall be used instead of the processor’s defaultand G0.d edit descriptors follow the rules for the A edit descriptor with no field width.
13.7.6 User-defined derived-type editing
input/output formatting for processing a list item of derived type.2 The DT edit descriptor may include a character literal constant. The character value “DT” concatenated with the
character literal constant is passed to the defined input/output procedure as the iotype argument (12.6.4.8). The3 If a derived-type variable or value corresponds to a DT edit descriptor, there shall be an accessible interface tov values of the edit descriptor are passed to the defined input/output procedure as the v_list array argument.
NOTE 13.22
For the edit descriptor DT’Link List’(10, 4, 2), iotype is "DTLink List" and v_list is [10, 4, 2].
a corresponding defined input/output procedure for that derived type (12.6.4.8). A DT edit descriptor shall not1 The position edit descriptors T, TL, TR, and X, specify the position at which the next character will be transmit-correspond to a list item that is not of a derived type.
13.8 Control edit descriptors
13.8.1 Position edit descriptors
13.8.1.1 Position editing
ted to or from the record. If any character skipped by a position edit descriptor is of type nondefault character,2 On input, if the position specified by a position edit descriptor is before the current position, portions of a recordand the unit is a default character internal file or an external non-Unicode file, the result of that position editing
is processor dependent.
can be processed more than once, possibly with different editing.3 On input, a position beyond the last character of the record may be specified if no characters are transmitted
from such positions.4 On output, a position edit descriptor does not by itself cause characters to be transmitted and therefore does not
by itself affect the length of the record. If characters are transmitted to positions at or after the position specified5 On output, a character in the record can be replaced. A position edit descriptor never directly causes a characterby a position edit descriptor, positions skipped and not previously filled are filled with blanks. The result is as if
the entire record were initially filled with blanks.
280 ⃝1 The left tab limit affects file positioning by the T and TL edit descriptors. Immediately prior to nonchild datac ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
already placed in the record to be replaced, but it might result in positioning such that subsequent editing causes
a replacement.
13.8.1.2 T, TL, and TR editing
transfer (12.6.4.8.3), the left tab limit becomes defined as the character position of the current record or the2 The Tn edit descriptor indicates that the transmission of the next character to or from a record is to occur atcurrent position of the stream file. If, during data transfer, the file is positioned to another record, the left tab
limit becomes defined as character position one of that record.
the nth character position of the record, relative to the left tab limit. This position can be in either direction3 The TLn edit descriptor indicates that the transmission of the next character to or from the record is to occur atfrom the current position.
the character position n characters backward from the current position. However, if n is greater than the difference4 The TRn edit descriptor indicates that the transmission of the next character to or from the record is to occurbetween the current position and the left tab limit, the TLn edit descriptor indicates that the transmission of
the next character to or from the record is to occur at the left tab limit.
at the character position n characters forward from the current position.1 The nX edit descriptor indicates that the transmission of the next character to or from a record is to occur at13.8.1.3 X editing
the character position n characters forward from the current position.1 The slash edit descriptor indicates the end of data transfer to or from the current record.NOTE 13.23
An nX edit descriptor has the same effect as a TRn edit descriptor.
13.8.2 Slash editing
2 On input from a file connected for sequential or stream access, the remaining portion of the current record is
skipped and the file is positioned at the beginning of the next record. This record becomes the current record.3 For a file connected for direct access, the record number is increased by one and the file is positioned at theOn output to a file connected for sequential or stream access, a new empty record is created following the current
record; this new record then becomes the last and current record of the file and the file is positioned at the
beginning of this new record.
beginning of the record that has that record number, if there is such a record, and this record becomes the4 The repeat specification is optional in the slash edit descriptor. If it is not specified, the default value is one.current record.
NOTE 13.24
A record that contains no characters can 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 can be skipped on input.
13.8.3 Colon editing1 The colon edit descriptor terminates format control if there are no more effective items in the input/output list
(12.6.3). The colon edit descriptor has no effect if there are more effective items in the input/output list.1 The SS, SP, and S edit descriptors temporarily change (12.5.2) the sign mode (12.5.6.17, 12.6.2.14) for the⃝c ISO/IEC 2017 – All rights reserved 281
ISO/IEC DIS 1539-1:2017 (E)
13.8.4 SS, SP, and S editing
connection. The edit descriptors SS, SP, and S set the sign mode corresponding to the SIGN= specifier values2 The sign mode controls optional plus characters in numeric output fields. When the sign mode is PLUS, theSUPPRESS, PLUS, and PROCESSOR_DEFINED, respectively.
processor shall produce a plus sign in any position that normally contains an optional plus sign. When the3 The SS, SP, and S edit descriptors affect only I, F, E, EN, ES, D, and G editing during the execution of an outputsign mode is SUPPRESS, the processor shall not produce a plus sign in such positions. When the sign mode is
PROCESSOR_DEFINED, the processor has the option of producing a plus sign or not in such positions, subject
to 13.7.2(5).
statement. The SS, SP, and S edit descriptors have no effect during the execution of an input statement.1 The kP edit descriptor temporarily changes (12.5.2) the scale factor for the connection to k. The scale factor13.8.5 P editing
affects the editing done by the F, E, EN, ES, EX, D, and G edit descriptors for real and complex quantities.2 The scale factor k affects the appropriate editing in the following manner.
• On input, with F, E, EN, ES, EX, D, and G editing (provided that no exponent exists in the field), theeffect is that the externally represented number equals the internally represented number multiplied by 10k ;
the scale factor is applied to the external decimal value and then this is converted using the input/output
rounding mode.
• On input, with F, E, EN, ES, EX, D, and G editing, the scale factor has no effect if there is an exponent
in the field.
• On output, with F output editing, the effect is that the externally represented number equals the internally
represented number multiplied by 10k ; the internal value is converted using the input/output rounding
mode and then the scale factor is applied to the converted decimal value.
• On output, with E and D editing, the effect is that the significand (R715) part of the quantity to be
produced is multiplied by 10k and the exponent is reduced by k.
• On output, with G editing, the effect is suspended unless the magnitude of the datum to be edited is outside
the range that permits the use of F editing. If the use of E editing is required, the scale factor has the same
effect as with E output editing.
• On output, with EN, ES, and EX editing, the scale factor has no effect.
13.8.6 BN and BZ editing 1 The BN and BZ edit descriptors temporarily change (12.5.2) the blank interpretation mode (12.5.6.6, 12.6.2.6)
for the connection. The edit descriptors BN and BZ set the blank interpretation mode corresponding to the2 The blank interpretation mode controls the interpretation of nonleading blanks in numeric input fields. SuchBLANK= specifier values NULL and ZERO, respectively.
blank characters are interpreted as zeros when the blank interpretation mode has the value ZERO; they are3 The blank interpretation mode affects only numeric editing (13.7.2) and generalized numeric editing (13.7.5.2)ignored when the blank interpretation mode has the value NULL. The effect of ignoring blanks is to treat the
input field as if blanks had been removed, the remaining portion of the field right justified, and the blanks replaced
as leading blanks. However, a field containing only blanks has the value zero.
on input. It has no effect on output.1 The round edit descriptors temporarily change (12.5.2) the connection’s input/output rounding mode (12.5.6.16,13.8.7 RU, RD, RZ, RN, RC, and RP editing
12.6.2.13, 13.7.2.3.8). The round edit descriptors RU, RD, RZ, RN, RC, and RP set the input/output rounding1 The decimal edit descriptors temporarily change (12.5.2) the decimal edit mode (12.5.6.7, 12.6.2.7, 13.6) for282 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
mode corresponding to the ROUND= specifier values UP, DOWN, ZERO, NEAREST, COMPATIBLE, and
PROCESSOR_DEFINED, respectively. The input/output rounding mode affects the conversion of real and
complex values in formatted input/output. It affects only D, E, EN, ES, F, and G editing.
13.8.8 DC and DP editing
the connection. The edit descriptors DC and DP set the decimal edit mode corresponding to the DECIMAL=2 The decimal edit mode controls the representation of the decimal symbol (13.6) during conversion of real andspecifier values COMMA and POINT, respectively.
complex values in formatted input/output. The decimal edit mode affects only D, E, EN, ES, F, and G editing.1 A character string edit descriptor shall not be used on input.13.9 Character string edit descriptors
2 The character string edit descriptor causes characters to be written from the enclosed characters of the edit
descriptor itself, including blanks. For a character string edit descriptor, the width of the field is the number of1 List-directed input/output allows data editing according to the type of the list item instead of by a formatcharacters between the delimiting characters. Within the field, two consecutive delimiting characters are counted
as a single character.
NOTE 13.25
A delimiter for a character string edit descriptor is either an apostrophe or quote.
13.10 List-directed formatting
13.10.1 Purpose of list-directed formatting
specification. It also allows data to be free-field, that is, separated by commas (or semicolons) or blanks.1 The characters in one or more list-directed records constitute a sequence of values and value separators. The end13.10.2 Values and value separators
of a record has the same effect as a blank character, unless it is within a character constant. Any sequence of two2 Each value is either a null value, c, r*c, or r*, where c is a literal constant, optionally signed if integer or real,or more consecutive blanks is treated as a single blank, unless it is within a character constant.
or an undelimited character constant and r is an unsigned, nonzero, integer literal constant. Neither c nor r3 A value separator isshall have kind type parameters specified. The constant c is interpreted as though it had the same kind type
parameter as the corresponding list item. The r*c form is equivalent to r successive appearances of the constant
c, and the r* form is equivalent to r successive appearances of the null value. Neither of these forms may contain
embedded blanks, except where permitted within the constant c.
• a comma optionally preceded by one or more contiguous blanks and optionally followed by one or morecontiguous blanks, unless the decimal edit mode is COMMA, in which case a semicolon is used in place of
the comma,
• a slash optionally preceded by one or more contiguous blanks and optionally followed by one or more
contiguous blanks, or
• one or more contiguous blanks between two nonblank values or following the last nonblank value, where a
nonblank value is a constant, an r*c form, or an r* form.
⃝c ISO/IEC 2017 – All rights reserved 283
ISO/IEC DIS 1539-1:2017 (E)
NOTE 13.26Although 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 13.27
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.
13.10.3 List-directed input 13.10.3.1 List-directed input forms 1 Input forms acceptable to edit descriptors for a given type are acceptable for list-directed formatting, except as noted below. If the form of the input value is not acceptable to the processor for the type of the next effective2 For the r*c form of an input value, the constant c is interpreted as an undelimited character constant if the firstitem in the list, an error condition occurs. Blanks are never used as zeros, and embedded blanks are not permitted
in constants, except within character constants and complex constants as specified below.
list item corresponding to this value is default, ASCII, or ISO 10646 character, there is a nonblank character3 When the next effective item is of type integer, the value in the input record is interpreted as if an Iw editimmediately after r*, and that character is not an apostrophe or a quotation mark; otherwise, c is interpreted as
a literal constant.
NOTE 13.28
The end of a record has the effect of a blank, except when it appears within a character constant.
descriptor with a suitable value of w were used.4 When the next effective item is of type real, the input form is that of a numeric input field. A numeric input field
is a field suitable for F editing (13.7.2.3.2) that is assumed to have no fractional digits unless a decimal symbol5 When the next effective item is of type complex, the input form consists of a left parenthesis followed by anappears within the field.
ordered pair of numeric input fields separated by a comma (if the decimal edit mode is POINT) or semicolon6 When the next effective item is of type logical, the input form shall not include value separators among the(if the decimal edit mode is COMMA), and followed by a right parenthesis. The first numeric input field is the
real part of the complex constant and the second is the imaginary part. Each of the numeric input fields may be
preceded or followed by any number of blanks and ends of records. The end of a record may occur after the real
part or before the imaginary part.
optional characters permitted for L editing.7 When the next effective item is of type character, the input form consists of a possibly delimited sequence of zero
or more rep-chars whose kind type parameter is implied by the kind of the effective item. Character sequences8 If the next effective item is default, ASCII, or ISO 10646 character andmay be continued from the end of one record to the beginning of the next record, but the end of record shall
not occur between a doubled apostrophe in an apostrophe-delimited character sequence, nor between a doubled
quote in a quote-delimited character sequence. The end of the record does not cause a blank or any other
character to become part of the character sequence. The character sequence may be continued on as many
records as needed. The characters blank, comma, semicolon, and slash may appear in default, ASCII, or ISO
10646 character sequences.
• the character sequence does not contain value separators,• the character sequence does not cross a record boundary,
• the first nonblank character is not a quotation mark or an apostrophe,
284 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)• the leading characters are not digits followed by an asterisk, and
• the character sequence contains at least one character,
the delimiting apostrophes or quotation marks are not required. If the delimiters are omitted, the character sequence is terminated by the first blank, comma (if the decimal edit mode is POINT), semicolon (if the decimal
edit mode is COMMA), slash, or end of record; in this case apostrophes and quotation marks within the datum
are not to be doubled.
9 Let len be the current length of the next effective item, and let w be the length of the character sequence. If len is less than or equal to w, the leftmost len characters of the sequence are transmitted to the next effective item.1 A null value is specified byIf len is greater than w, the sequence is transmitted to the leftmost w characters of the next effective item and
the remaining len−w characters of the next effective item are filled with blanks.
NOTE 13.29
An allocatable, deferred-length character effective item does not have its allocation status or allocated
length changed as a result of list-directed input.
13.10.3.2 Null values
• the r* form,2 A null value has no effect on the definition status of the next effective item. A null value shall not be used for• no characters between consecutive value separators, or
• no characters before the first value separator in the first record read by each execution of a list-directed
input statement.
NOTE 13.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.
either the real or imaginary part of a complex constant, but a single null value may represent an entire complex3 A slash encountered as a value separator during execution of a list-directed input statement causes terminationconstant.
of execution of that input statement after the transference of the previous value. Any characters remaining in the1 The form of the values produced is the same as that required for input, except as noted otherwise. With thecurrent record are ignored. If there are additional items in the input list, the effect is as if null values had been
supplied for them. Any do-variable in the input list becomes defined as if enough null values had been supplied
for any remaining input list items.
NOTE 13.31
All blanks encountered during list-directed input are considered to be part of some value separator except
for
• blanks embedded in a character sequence,
• embedded blanks surrounding the real or imaginary part of a complex constant, and
• leading blanks in the first record read by each execution of a list-directed input statement, unless
immediately followed by a slash or comma.
NOTE 13.32
List-directed input example:
INTEGER I; REAL X (8); CHARACTER (11) P; COMPLEX Z; LOGICAL G
...
READ *, I, X, P, Z, G
⃝c ISO/IEC 2017 – All rights reserved 285
ISO/IEC DIS 1539-1:2017 (E)
NOTE 13.32 (cont.)
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
P ISN’T_BOB’S
Z (123.0,0.0)
G true
13.10.4 List-directed output
exception of adjacent undelimited character sequences, the values are separated by one or more blanks or by a2 The processor may begin new records as necessary, but the end of record shall not occur within a constant exceptcomma, or a semicolon if the decimal edit mode is COMMA, optionally preceded by one or more blanks and
optionally followed by one or more blanks. Two undelimited character sequences are considered adjacent when
both were written using list-directed input/output, no intervening data transfer or file positioning operations on
that unit occurred, and both were written either by a single data transfer statement, or during the execution of
a parent data transfer statement along with its child data transfer statements. The form of the values produced
by defined output (12.6.4.8) is determined by the defined output procedure; this form need not be compatible
with list-directed input.
as specified for complex constants and character sequences. The processor shall not insert blanks within character3 Logical output values are T for the value true and F for the value false.sequences or within constants, except as specified for complex constants.
4 Integer output constants are produced with the effect of an Iw edit descriptor.
5 Real constants are produced with the effect of either an F edit descriptor or an E edit descriptor, depending on
the magnitude x of the value and a range 10d1 ≤ x < 10d2 , where d1 and d2 are processor-dependent integers. If6 For numeric output, reasonable processor-dependent values of w, d, and e are used for each of the numericthe magnitude x is within this range or is zero, the constant is produced using 0PFw.d; otherwise, 1PEw.d Ee is
used.
constants output.7 Complex constants are enclosed in parentheses with a separator between the real and imaginary parts, each
produced as defined above for real constants. The separator is a comma if the decimal edit mode is POINT; it8 Character sequences produced when the delimiter mode has a value of NONEis a semicolon if the decimal edit mode is COMMA. The end of a record may occur between the separator and
the imaginary part only if the entire constant is as long as, or longer than, an entire record. The only embedded
blanks permitted within a complex constant are between the separator and the end of a record and one blank at
the beginning of the next record.
• are not delimited by apostrophes or quotation marks,
286 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)• are not separated from each other by value separators,
• have each internal apostrophe or quotation mark represented externally by one apostrophe or quotation
mark, and• have a blank character inserted by the processor at the beginning of any record that begins with the
continuation of a character sequence from the preceding record.9 Character sequences produced when the delimiter mode has a value of QUOTE are delimited by quotes, are
preceded and followed by a value separator, and have each internal quote represented on the external medium by10 Character sequences produced when the delimiter mode has a value of APOSTROPHE are delimited by apo-two contiguous quotes.
strophes, are preceded and followed by a value separator, and have each internal apostrophe represented on the11 If two or more successive values in an output record have identical values, the processor has the option of producingexternal medium by two contiguous apostrophes.
a repeated constant of the form r*c instead of the sequence of identical values.12 Slashes, as value separators, and null values are not produced as output by list-directed formatting.
13 Except for new records created by explicit formatting within a defined output procedure or by continuation of delimited character sequences, each output record begins with a blank character.1 Namelist input/output allows data editing with name-value subsequences. This facilitates documentation of inputNOTE 13.33
The length of the output records is not specified and is processor dependent.
13.11 Namelist formatting
13.11.1 Purpose of namelist formatting
and output files and more flexibility on input.1 The characters in one or more namelist records constitute a sequence of name-value subsequences, each of which13.11.2 Name-value subsequences
consists of an object designator followed by an equals and followed by one or more values and value separators.2 Each object designator shall begin with a name from the namelist-group-object-list (8.9) and shall follow theThe equals may optionally be preceded or followed by one or more contiguous blanks. The end of a record has the
same effect as a blank character, unless it is within a character constant. Any sequence of two or more consecutive
blanks is treated as a single blank, unless it is within a character constant.
syntax of designator (R901). It shall not contain a vector subscript or an image-selector and shall not designate a3 A value separator for namelist formatting is the same as for list-directed formatting (13.10.2), or one or morezero-sized array, a zero-sized array section, or a zero-length character string. Each subscript, stride, and substring
range expression shall be an optionally signed integer literal constant with no kind type parameter specified. If
a section subscript list appears, the number of section subscripts shall be equal to the rank of the object. If
the namelist group object is of derived type, the designator in the input record may be either the name of the
variable or the designator of one of its components, indicated by qualifying the variable name with the appropriate
component name. Successive qualifications may be applied as appropriate to the shape and type of the variable
represented. Each designator may be preceded and followed by one or more optional blanks but shall not contain
embedded blanks.
contiguous blanks between a nonblank value and the following object designator or namelist comment (13.11.3.6).ISO/IEC DIS 1539-1:2017 (E)⃝c ISO/IEC 2017 – All rights reserved 287
13.11.3 Namelist input 13.11.3.1 Overall syntax 1 Input for a namelist input statement consists of (1) optional blanks and namelist comments,NOTE 13.34(2) the character & followed immediately by the namelist-group-name as specified in the NAMELIST
statement,
(3) one or more blanks,
(4) a sequence of zero or more name-value subsequences separated by value separators, and
(5) a slash to terminate the namelist input.
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.
2 The order of the name-value subsequences in the input records need not match the order of the namelist-group- object-list. The input records need not specify all objects in the namelist-group-object-list. They may specify a3 A group name or object name is without regard to case.part of an object more than once.
13.11.3.2 Namelist input processing1 The name-value subsequences are evaluated serially, in left-to-right order. A namelist group object designator
may appear in more than one name-value subsequence. The definition status of an object that is not a subobject2 When the designator in the input record represents an array variable or a variable of derived type, the effect isof a designator in any name-value subsequence remains unchanged.
as if the variable represented were expanded into a sequence of scalar list items, in the same way that formatted3 A slash encountered as a value separator during the execution of a namelist input statement causes terminationinput/output list items are expanded (12.6.3). The number of values following the equals shall not exceed the
number of list items in the expanded sequence, but may be less; in the latter case, the effect is as if sufficient
null values had been appended to match any remaining list items in the expanded sequence. Except as noted
elsewhere in this subclause, if an input value is not acceptable to the processor for the type of the list item in the
corresponding position in the expanded sequence, an error condition occurs.
NOTE 13.35
For example, if the designator in the input record designates an integer array of size 100, at most 100
values, each of which is either a digit string or a null value, can follow the equals; these values would then
be assigned to the elements of the array in array element order.
of execution of that input statement after transference of the previous value. If there are additional items in the4 Successive namelist records are read by namelist input until a slash is encountered; the remainder of the recordnamelist group object being transferred, the effect is as if null values had been supplied for them.
is ignored.5 A namelist comment may appear after any value separator except a slash (which terminates namelist input). A
namelist comment is also permitted to start in the first nonblank position of an input record except within a1 Each value is either a null value (13.11.3.4), c, r*c, or r*, where c is a literal constant, optionally signed if integercharacter literal constant.
13.11.3.3 Namelist input values
or real, and r is an unsigned, nonzero, integer literal constant. A kind type parameter shall not be specified for c2 The datum c (13.11) is any input value acceptable to format specifications for a given type, except for a restriction288 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
or r. The constant c is interpreted as though it had the same kind type parameter as the corresponding effective
item. The r*c form is equivalent to r successive appearances of the constant c, and the r* form is equivalent to r
successive null values. Neither of these forms may contain embedded blanks, except where permitted within the
constant c.
on the form of input values corresponding to list items of types logical, integer, and character as specified in this3 When the next effective item is of type real, the input form of the input value is that of a numeric input field. Asubclause. The form of a real or complex value is dependent on the decimal edit mode in effect (13.6). The form
of an input value shall be acceptable for the type of the namelist group object list item. The number and forms
of the input values that may follow the equals in a name-value subsequence depend on the shape and type of
the object represented by the name in the input record. When the name in the input record is that of a scalar
variable of an intrinsic type, the equals shall not be followed by more than one value. Blanks are never used
as zeros, and embedded blanks are not permitted in constants except within character constants and complex
constants as specified in this subclause.
numeric input field is a field suitable for F editing (13.7.2.3.2) that is assumed to have no fractional digits unless4 When the next effective item is of type complex, the input form of the input value consists of a left parenthesisa decimal symbol appears within the field.
followed by an ordered pair of numeric input fields separated by a comma (if the decimal edit mode is POINT) or5 When the next effective item is of type logical, the input form of the input value shall not include equals or valuea semicolon (if the decimal edit mode is COMMA), and followed by a right parenthesis. The first numeric input
field is the real part of the complex constant and the second field is the imaginary part. Each of the numeric
input fields may be preceded or followed by any number of blanks and ends of records. The end of a record may
occur between the real part and the comma or semicolon, or between the comma or semicolon and the imaginary
part.
separators among the optional characters permitted for L editing (13.7.3).6 When the next effective item is of type integer, the value in the input record is interpreted as if an Iw edit
descriptor with a suitable value of w were used.7 When the next effective item is of type character, the input form consists of a sequence of zero or more rep-chars
whose kind type parameter is implied by the kind of the corresponding list item, delimited by apostrophes or8 Let len be the length of the next effective item, and let w be the length of the character sequence. If len is lessquotes. Such a sequence may be continued from the end of one record to the beginning of the next record, but the
end of record shall not occur between a doubled apostrophe in an apostrophe-delimited sequence, nor between a
doubled quote in a quote-delimited sequence. The end of the record does not cause a blank or any other character
to become part of the sequence. The sequence may be continued on as many records as needed. The characters
blank, comma, semicolon, and slash may appear in such character sequences.
NOTE 13.36
The delimiters in the input form for a namelist input item of type character avoid the ambiguity that could
arise between undelimited character sequences and object names. The value of the DELIM= specifier, if
any, in the OPEN statement for an external file is ignored during namelist input (12.5.6.8).
than or equal to w, the leftmost len characters of the sequence are transmitted to the next effective item. If len1 A null value is specified byis greater than w, the constant is transmitted to the leftmost w characters of the next effective item and the
remaining len−w characters of the next effective item are filled with blanks. The effect is as though the sequence
were assigned to the next effective item in an intrinsic assignment statement (10.2.1.3).
13.11.3.4 Null values
• the r* form,
⃝c ISO/IEC 2017 – All rights reserved 289
ISO/IEC DIS 1539-1:2017 (E)
• blanks between two consecutive nonblank value separators following an equals,2 A null value has no effect on the definition status of the corresponding input list item. If the namelist group• a value separator that is the first nonblank character following an equals, or
• two consecutive nonblank value separators.
object list item is defined, it retains its previous value; if it is undefined, it remains undefined. A null value shall1 All blanks in a namelist input record are considered to be part of some value separator except fornot be used as either the real or imaginary part of a complex constant, but a single null value may represent an
entire complex constant.
NOTE 13.37
The end of a record following a value separator, with or without intervening blanks, does not specify a null
value in namelist input.
13.11.3.5 Blanks
• blanks embedded in a character constant,• embedded blanks surrounding the real or imaginary part of a complex constant,
• leading blanks following the equals unless followed immediately by a slash or comma, or a semicolon if the
decimal edit mode is COMMA, and
• blanks between a name and the following equals.
13.11.3.6 Namelist comments 1 Except within a character literal constant, a “!” character after a value separator or in the first nonblank position of a namelist input record initiates a comment. The comment extends to the end of the record and may contain1 The form of the output produced by intrinsic namelist output shall be suitable for input, except for characterany graphic character in the processor-dependent character set. The comment is ignored. A slash within the
namelist comment does not terminate execution of the namelist input statement. Namelist comments are not
allowed in stream input because comments depend on record structure.
NOTE 13.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
P ISN’T_BOB’S
Z (123.0,0.0)
G unchanged
290 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
13.11.4 Namelist output
13.11.4.1 Form of namelist output
output. The names in the output are in upper case. With the exception of adjacent undelimited character2 Namelist output shall not include namelist comments.values, the values are separated by one or more blanks or by a comma, or a semicolon if the decimal edit mode is
COMMA, optionally preceded by one or more blanks and optionally followed by one or more blanks. The form
of the output produced by defined output (12.6.4.8) is determined by the defined output procedure; this form
need not be compatible with namelist input.
3 The processor may begin new records as necessary. However, except for complex constants and character values,
the end of a record shall not occur within a constant, character value, or name, and blanks shall not appear1 Values in namelist output records are edited as for list-directed output (13.10.4).within a constant, character value, or name.
NOTE 13.39
The length of the output records is not specified exactly and is processor dependent.
13.11.4.2 Namelist output editing
NOTE 13.40Namelist 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.
13.11.4.3 Namelist output records 1 If two or more successive values for the same namelist group item in an output record produced have identical
values, the processor has the option of producing a repeated constant of the form r*c instead of the sequence of2 The name of each namelist group object list item is placed in the output record followed by an equals and a listidentical values.
of values of the namelist group object list item.3 An ampersand character followed immediately by a namelist-group-name is placed at the start of the first output
record to indicate which particular group of data objects is being output. A slash is placed in the output record4 A null value is not produced by namelist formatting.to indicate the end of the namelist formatting.
5 Except for new records created by explicit formatting within a defined output procedure or by continuation of
delimited character sequences, each output record begins with a blank character.ISO/IEC DIS 1539-1:2017 (E)⃝c ISO/IEC 2017 – All rights reserved 291
(Blank page)
1 A Fortran main program is a program unit that does not contain a SUBROUTINE, FUNCTION, MODULE,
292 c ISO/IEC 2017 – All rights reserved14 Program units
ISO/IEC DIS 1539-1:2017 (E)
14.1 Main program
SUBMODULE, or BLOCK DATA statement as its first statement.R1401 main-program is [ program-stmt ]
[ specification-part ]
[ execution-part ]
[ internal-subprogram-part ]
end-program-stmt
R1402 program-stmt is PROGRAM program-name
R1403 end-program-stmt is END [ PROGRAM [ program-name ] ]
C1401 (R1401) The program-name may be included in the end-program-stmt only if the optional program-stmt
is used and, if included, shall be identical to the program-name specified in the program-stmt.
NOTE 14.1
The program name is global to the program (19.2). For explanatory information about uses for the program
name, see subclause C.9.1.
NOTE 14.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
2 The main program may be defined by means other than Fortran; in that case, the program shall not contain a
main-program program unit.3 A reference to a Fortran main-program shall not appear in any program unit in the program, including itself.
14.2 Modules1 A module contains declarations, specifications, and definitions. Public identifiers of module entities are accessible14.2.1 Module syntax and semantics
to other program units by use association as specified in 14.2.2. A module that is provided as an inherent part2 Procedures and types defined in an intrinsic module are not themselves intrinsic.of the processor is an intrinsic module. A nonintrinsic module is defined by a module program unit or a means
other than Fortran.
⃝c ISO/IEC 2017 – All rights reserved 2933 If a procedure declared in the scoping unit of a module has an implicit interface, it shall be given the EXTERNAL
ISO/IEC DIS 1539-1:2017 (E)
R1404 module is module-stmt
[ specification-part ]
[ module-subprogram-part ]
end-module-stmt
R1405 module-stmt is MODULE module-name
R1406 end-module-stmt is END [ MODULE [ module-name ] ]
R1407 module-subprogram-part is contains-stmt
[ module-subprogram ] ...
R1408 module-subprogram is function-subprogram
or subroutine-subprogram
or separate-module-subprogram
C1402 (R1404) If the module-name is specified in the end-module-stmt, it shall be identical to the module-name
specified in the module-stmt.
C1403 (R1404) A module specification-part shall not contain a stmt-function-stmt , an entry-stmt, or a format-stmt.
attribute in that scoping unit; if it is a function, its type and type parameters shall be explicitly declared in a4 If an intrinsic procedure is declared in the scoping unit of a module, it shall explicitly be given the INTRINSICtype declaration statement in that scoping unit.
attribute in that scoping unit or be used as an intrinsic procedure in that scoping unit.1 The USE statement specifies use association. A USE statement is a reference to the module it specifies. At theNOTE 14.3
The module name is global to the program (19.2).
NOTE 14.4
Although statement function definitions, ENTRY statements, and FORMAT statements cannot appear in the spe-
cification part of a module, they can appear in the specification part of a module subprogram in the module.
NOTE 14.5
For a discussion of the impact of modules on dependent compilation, see subclause C.9.2.
NOTE 14.6
For examples of the use of modules, see subclause C.9.3.
14.2.2 The USE statement and use association
time a USE statement is processed, the public portions of the specified module shall be available. A module shall2 The USE statement provides the means by which a scoping unit accesses named data objects, derived types,not reference itself, either directly or indirectly.
procedures, abstract interfaces, generic identifiers, and namelist groups in a module. The entities in the scoping3 A use-stmt without a module-nature provides access either to an intrinsic or to a nonintrinsic module. If theunit are use associated with the entities in the module. The accessed entities have the attributes specified
in the module, except that an accessed entity may have a different accessibility attribute, it may have the
ASYNCHRONOUS attribute even if the associated module entity does not, and if it is not a coarray it may have
the VOLATILE attribute even if the associated module entity does not. The entities made accessible are identified
by the names or generic identifiers used to identify them in the module. By default, the accessed entities are
identified by the same identifiers in the scoping unit containing the USE statement, but it is possible to specify
294 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
that different identifiers are used. A use-associated variable is considered to have been previously declared; any
other use-associated entity is considered to have been previously defined.
NOTE 14.7
The accessibility of module entities can be controlled by accessibility attributes (7.5.2.2, 8.5.2), and the
ONLY option of the USE statement. Definability of module entities can be controlled by the PROTECTED
attribute (8.5.15).
R1409 use-stmt is USE [ [ , module-nature ] :: ] module-name [ , rename-list ]
or USE [ [ , module-nature ] :: ] module-name ,
ONLY : [ only-list ]
R1410 module-nature is INTRINSIC
or NON_INTRINSIC
R1411 rename is local-name => use-name
or OPERATOR (local-defined-operator) =>
OPERATOR (use-defined-operator)
R1412 only is generic-spec
or only-use-name
or rename
R1413 only-use-name is use-name
C1404 (R1409) If module-nature is INTRINSIC, module-name shall be the name of an intrinsic module.
C1405 (R1409) If module-nature is NON_INTRINSIC, module-name shall be the name of a nonintrinsic module.
C1406 (R1409) A scoping unit shall not directly reference an intrinsic module and a nonintrinsic module of the
same name.
C1407 (R1411) OPERATOR (use-defined-operator) shall not identify a type-bound generic interface.
C1408 (R1412) The generic-spec shall not identify a type-bound generic interface.
NOTE 14.8
Constraints C1407 and C1408 do not prevent accessing a generic-spec that is declared by an interface block,
even if a type-bound generic interface has the same generic-spec.
C1409 Each generic-spec, use-name, and use-defined-operator in a USE statement shall be a public identifier of
the module.
C1410 An only-use-name shall be a nongeneric name.
R1414 local-defined-operator is defined-unary-op
or defined-binary-op
R1415 use-defined-operator is defined-unary-op
or defined-binary-op
module-name is the name of both an intrinsic and a nonintrinsic module, the nonintrinsic module is accessed.4 The USE statement without the ONLY option provides access to all public entities in the specified module.
5 A USE statement with the ONLY option provides access only to those entities that appear as generic-specs,
use-names, or use-defined-operators in the only-list.6 More than one USE statement for a given module may appear in a specification part. If one of the USE statements⃝c ISO/IEC 2017 – All rights reserved 295
ISO/IEC DIS 1539-1:2017 (E)
is without an ONLY option, all public entities in the module are accessible. If all the USE statements have ONLY7 An accessible entity in the referenced module is associated with one or more accessed entities, each with its ownoptions, only those entities in one or more of the only-lists are accessible.
identifier. These identifiers are8 An ultimate entity is a module entity that is not accessed by use association. An accessed entity shall not be• the identifier of the entity in the referenced module if that identifier appears as an only-use-name or as the
defined-operator of a generic-spec in any only for that module,
• each of the local-names or local-defined-operators that the entity is given in any rename for that module,
and
• the identifier of the entity in the referenced module if that identifier does not appear as a use-name or
use-defined-operator in any rename for that module.
associated with two or more ultimate entities unless its identifier is not used, or the ultimate entities are generic9 The local identifier of an entity made accessible by a USE statement shall not appear in any other nonexecutableinterfaces. Generic interfaces are handled as described in 15.4.3.4.
NOTE 14.9
There is no prohibition against a use-name or use-defined-operator appearing multiple times in one USE
statement or in multiple USE statements involving the same module. As a result, it is possible for one
use-associated entity to be accessible by more than one local identifier.
statement that would cause any attribute (8.5) of the entity to be specified in the scoping unit that contains the10 An entity in a scoping unit that is accessed by use association through more than one use path, has the ASYN-USE statement, except that it may appear in a PUBLIC or PRIVATE statement in the scoping unit of a module
and it may be given the ASYNCHRONOUS or VOLATILE attribute.
CHRONOUS or VOLATILE attribute in any of those use paths, and is not given that attribute in that scopingunit, shall have that attribute in all use paths.
NOTE 14.10
The constraints in subclauses 8.10.1, 8.10.2, and 8.9 prohibit the local-name from appearing as a common-
block-object in a COMMON statement, an equivalence-object in an EQUIVALENCE statement, or a namelist-group-name
in a NAMELIST statement, respectively. There is no prohibition against the local-name appearing as a
common-block-name or a namelist-group-object.
NOTE 14.11
For a discussion of the impact of the ONLY option and renaming on dependent compilation, see subclause
C.9.2.1.
NOTE 14.12
Examples:
USE STATS_LIB
provides access to all public entities in the module STATS_LIB.
USE MATH_LIB; USE STATS_LIB, SPROD => PROD
provides access to all public identifiers in both MATH_LIB and STATS_LIB. If MATH_LIB contains an
entity named PROD, it can be accessed by that name, while the entity PROD of STATS_LIB can be
accessed by the name SPROD.
296 c ISO/IEC 2017 – All rights reservedNOTE 14.12 (cont.)
ISO/IEC DIS 1539-1:2017 (E)
USE STATS_LIB, ONLY: YPROD; USE STATS_LIB, ONLY : PROD
provides access to YPROD and PROD in STAT_LIB.
USE STATS_LIB, ONLY : YPROD; USE STATS_LIB
provides access to all public identifiers in STAT_LIB.
14.2.3 Submodules 1 A submodule is a program unit that extends a module or another submodule. The program unit that it extends
is its host, and is specified by the parent-identifier in the submodule-stmt.2 A module or submodule is an ancestor program unit of all of its descendants, which are its submodules and their
descendants. The submodule identifier is the ordered pair whose first element is the ancestor module name and3 A submodule may provide implementations for separate module procedures (15.6.2.5), each of which is declaredwhose second element is the submodule name; the submodule name by itself is not a local or global identifier.
NOTE 14.13
A module and its submodules stand in a tree-like relationship one to another, with the module at the root.
Therefore, a submodule has exactly one ancestor module and can have one or more ancestor submodules.
(15.4.3.2) within that submodule or one of its ancestors, and declarations and definitions of other entities that1 A block data program unit is used to provide initial values for data objects in named common blocks.are accessible by host association in its descendants.
R1416 submodule is submodule-stmt
[ specification-part ]
[ module-subprogram-part ]
end-submodule-stmt
R1417 submodule-stmt is SUBMODULE ( parent-identifier ) submodule-name
R1418 parent-identifier is ancestor-module-name [ : parent-submodule-name ]
R1419 end-submodule-stmt is END [ SUBMODULE [ submodule-name ] ]
C1411 (R1416) A submodule specification-part shall not contain a format-stmt, entry-stmt, or stmt-function-stmt .
C1412 (R1418) The ancestor-module-name shall be the name of a nonintrinsic module that declares a separate
module procedure; the parent-submodule-name shall be the name of a descendant of that module.
C1413 (R1416) If a submodule-name appears in the end-submodule-stmt, it shall be identical to the one in the
submodule-stmt.
14.3 Block data program units
R1420 block-data is block-data-stmt2 If an object in a named common block is initially defined, all storage units in the common block storage sequence shall be specified[ specification-part ]
end-block-data-stmt
R1421 block-data-stmt is BLOCK DATA [ block-data-name ]
R1422 end-block-data-stmt is END [ BLOCK DATA [ block-data-name ] ]
C1414 (R1420) The block-data-name shall be included in the end-block-data-stmt only if it was provided in the block-data-stmt
and, if included, shall be identical to the block-data-name in the block-data-stmt.
⃝c ISO/IEC 2017 – All rights reserved 297
ISO/IEC DIS 1539-1:2017 (E)
C1415 (R1420) A block-data specification-part shall contain only derived-type definitions and ASYNCHRONOUS, BIND, COM-
MON, DATA, DIMENSION, EQUIVALENCE, IMPLICIT, INTRINSIC, PARAMETER, POINTER, SAVE, TARGET,
USE, VOLATILE, and type declaration statements.
C1416 (R1420) A type declaration statement in a block-data specification-part shall not contain ALLOCATABLE, EXTERNAL,
or BIND attribute specifiers.
even if they are not all initially defined. More than one named common block may have objects initially defined in a single block3 Only an object in a named common block may be initially defined in a block data program unit.data program unit.
4 The same named common block shall not be specified in more than one block data program unit in a program.
5 There shall not be more than one unnamed block data program unit in a program.
298 ⃝c ISO/IEC 2017 – All rights reserved1 The concept of a procedure was introduced in 5.2.3. This clause contains a complete description of procedures.
ISO/IEC DIS 1539-1:2017 (E)
15 Procedures
15.1 Concepts
The actions specified by a procedure are performed when the procedure is invoked by execution of a reference to2 The sequence of actions encapsulated by a procedure has access to entities in the procedure reference by way ofit.
argument association (15.5.2). A name that appears as a dummy-arg-name in the SUBROUTINE, FUNCTION,1 The definition of a procedure specifies it to be a function or a subroutine. A reference to a function either appearsor ENTRY statement in the declaration of a procedure (R1536) is a dummy argument. Dummy arguments are
also specified for intrinsic procedures and procedures in intrinsic modules in Clauses 16, 17, and 18.
15.2 Procedure classifications
15.2.1 Procedure classification by reference
explicitly as a primary within an expression, or is implied by a defined operation (10.1.6) within an expression.2 A procedure is classified as elemental if it is a procedure that may be referenced elementally (15.8).A reference to a subroutine is a CALL statement, a defined assignment statement (10.2.1.4), the appearance of
an object processed by defined input/output (12.6.4.8) in an input/output list, or finalization (7.5.6).
15.2.2 Procedure classification by means of definition1 A procedure that is provided as an inherent part of the processor is an intrinsic procedure.15.2.2.1 Intrinsic procedures
15.2.2.2 External, internal, and module procedures1 An external procedure is a procedure that is defined by an external subprogram or by a means other than Fortran.
2 An internal procedure is a procedure that is defined by an internal subprogram. Internal subprograms may
appear in the main program, in an external subprogram, or in a module subprogram. Internal subprograms shall3 A module procedure is a procedure that is defined by a module subprogram.not appear in other internal subprograms. Internal subprograms are the same as external subprograms except
that the name of the internal procedure is not a global identifier, an internal subprogram shall not contain an ENTRY
statement, and the internal subprogram has access to host entities by host association.
4 A subprogram defines a procedure for the SUBROUTINE or FUNCTION statement. If the subprogram has one or
more ENTRY statements, it also defines a procedure for each of them.1 A dummy argument that is specified to be a procedure or appears as the procedure designator in a procedure15.2.2.3 Dummy procedures
reference is a dummy procedure. A dummy procedure with the POINTER attribute is a dummy procedure1 A procedure pointer is a procedure that has the EXTERNAL and POINTER attributes; it may be pointerpointer.
⃝c ISO/IEC 2017 – All rights reserved 299
ISO/IEC DIS 1539-1:2017 (E)
15.2.2.4 Procedure pointers
associated with an external procedure, an internal procedure, an intrinsic procedure, a module procedure, or a1 A function that is defined by a single statement is a statement function (15.6.4).dummy procedure that is not a procedure pointer.
15.2.2.5 Statement functions
15.3 Characteristics1 The characteristics of a procedure are the classification of the procedure as a function or subroutine, whether it15.3.1 Characteristics of procedures
is pure, whether it is elemental, whether it has the BIND attribute, the characteristics of its dummy arguments,1 Each dummy argument has the characteristic that it is a dummy data object, a dummy procedure, or an asteriskand the characteristics of its function result if it is a function.
15.3.2 Characteristics of dummy arguments
15.3.2.1 General
(alternate return indicator).1 The characteristics of a dummy data object are its declared type, its type parameters, its shape (unless it is15.3.2.2 Characteristics of dummy data objects
assumed-rank), its corank, its codimensions, its intent (8.5.10, 8.6.9), whether it is optional (8.5.12, 8.6.10),1 The characteristics of a dummy procedure are the explicitness of its interface (15.4.2), its characteristics as awhether it is allocatable (8.5.3), whether it has the ASYNCHRONOUS (8.5.4), CONTIGUOUS (8.5.7), VALUE
(8.5.18), or VOLATILE (8.5.19) attributes, whether it is polymorphic, and whether it is a pointer (8.5.14, 8.6.12)
or a target (8.5.17, 8.6.15). If a type parameter of an object or a bound of an array is not a constant expression,
the exact dependence on the entities in the expression is a characteristic. If a rank, shape, size, type, or type
parameter is assumed or deferred, it is a characteristic.
15.3.2.3 Characteristics of dummy procedures
procedure if the interface is explicit, whether it is a pointer, and whether it is optional (8.5.12, 8.6.10).1 A dummy argument that is an asterisk has no other characteristic.15.3.2.4 Characteristics of asterisk dummy arguments
15.3.3 Characteristics of function results1 The characteristics of a function result are its declared type, type parameters, rank, whether it is polymorphic,
whether it is allocatable, whether it is a pointer, whether it has the CONTIGUOUS attribute, and whether it is a1 The interface of a procedure determines the forms of reference through which it may be invoked. The procedure’sprocedure pointer. If a function result is an array that is not allocatable or a pointer, its shape is a characteristic.
If a type parameter of a function result or a bound of a function result array is not a constant expression, the
exact dependence on the entities in the expression is a characteristic. If type parameters of a function result are
deferred, which parameters are deferred is a characteristic. Whether the length of a character function result is assumed
is a characteristic.
300 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
15.4 Procedure interface
15.4.1 Interface and abstract interface
interface consists of its name, binding label, generic identifiers, characteristics, and the names of its dummy2 An abstract interface is a set of procedure characteristics with the dummy argument names.arguments. The characteristics and binding label of a procedure are fixed, but the remainder of the interface may
differ in differing contexts, except that for a separate module procedure body (15.6.2.5), the dummy argument
names and whether it has the NON_RECURSIVE attribute shall be the same as in its corresponding module
procedure interface body (15.4.3.2).
15.4.2 Implicit and explicit interfaces1 The interface of a procedure is either explicit or implicit. It is explicit if it is15.4.2.1 Interfaces and scopes
• an internal procedure, module procedure, or intrinsic procedure,Otherwise, the interface of the identifier is implicit. The interface of a statement function is always implicit.• a subroutine, or a function with a separate result name, within the scoping unit that defines it, or
• a procedure declared by a procedure declaration statement that specifies an explicit interface, or by an
interface body.
NOTE 15.1For example, the subroutine LLS of C.9.3.4 has an explicit interface.
15.4.2.2 Explicit interface 1 Within the scope of a procedure identifier, the procedure shall have an explicit interface if it is not a statement
function and1 The interface for an internal, external, module, or dummy procedure is specified by a FUNCTION, SUB-(1) a reference to the procedure appears with an argument keyword (15.5.2),
(2) the procedure is used in a context that requires it to be pure (15.7),
(3) the procedure has a dummy argument that
(a) has the ALLOCATABLE, ASYNCHRONOUS, OPTIONAL, POINTER, TARGET, VALUE,
or VOLATILE attribute,
(b) is an assumed-shape array,
(c) is assumed-rank,
(d) is a coarray,
(e) is of a parameterized derived type, or
(f) is polymorphic,
(4) the procedure has a result that
(a) is an array,
(b) is a pointer or is allocatable, or
(c) has a nonassumed type parameter value that is not a constant expression,
(5) the procedure is elemental, or
(6) the procedure has the BIND attribute.
⃝c ISO/IEC 2017 – All rights reserved 301
ISO/IEC DIS 1539-1:2017 (E)
15.4.3 Specification of the procedure interface
15.4.3.1 General
ROUTINE, or ENTRY statement and by specification statements for the dummy arguments and the result of1 An external or module subprogram specifies a specific interface for each procedure defined in that subprogram.a function. These statements may appear in the procedure definition, in an interface body, or both, except that
the ENTRY statement shall not appear in an interface body.
NOTE 15.2
An interface body cannot be used to describe the interface of an internal procedure, a module procedure
that is not a separate module procedure, or an intrinsic procedure because the interfaces of such procedures
are already explicit. However, the name of a procedure can appear in a PROCEDURE statement in an
interface block (15.4.3.2).
15.4.3.2 Interface block
R1501 interface-block is interface-stmt
[ interface-specification ] ...
end-interface-stmt
R1502 interface-specification is interface-body
or procedure-stmt
R1503 interface-stmt is INTERFACE [ generic-spec ]
or ABSTRACT INTERFACE
R1504 end-interface-stmt is END INTERFACE [ generic-spec ]
R1505 interface-body is function-stmt
[ specification-part ]
end-function-stmt
or subroutine-stmt
[ specification-part ]
end-subroutine-stmt
R1506 procedure-stmt is [ MODULE ] PROCEDURE [ :: ] specific-procedure-list
R1507 specific-procedure is procedure-name
R1508 generic-spec is generic-name
or OPERATOR ( defined-operator )
or ASSIGNMENT ( = )
or defined-io-generic-spec
R1509 defined-io-generic-spec is READ (FORMATTED)
or READ (UNFORMATTED)
or WRITE (FORMATTED)
or WRITE (UNFORMATTED)
C1501 (R1501) An interface-block in a subprogram shall not contain an interface-body for a procedure defined
by that subprogram.
C1502 (R1501) If the end-interface-stmt includes a generic-spec, the interface-stmt shall specify the same
generic-spec, except that if one generic-spec has a defined-operator that is .LT., .LE., .GT., .GE., .EQ.,
or .NE., the other generic-spec may have a defined-operator that is the corresponding operator <, <=,
>, >=, ==, or /=.
302 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C1503 (R1503) If the interface-stmt is ABSTRACT INTERFACE, then the function-name in the function-stmt
or the subroutine-name in the subroutine-stmt shall not be the same as a keyword that specifies an
intrinsic type.
C1504 (R1502) A procedure-stmt is allowed only in an interface block that has a generic-spec.
C1505 (R1505) An interface-body of a pure procedure shall specify the intents of all dummy arguments except
alternate return indicators, dummy procedures, and arguments with the POINTER or VALUE attribute.
C1506 (R1505) An interface-body shall not contain a data-stmt, format-stmt, entry-stmt, or stmt-function-stmt .
C1507 (R1506) If MODULE appears in a procedure-stmt, each procedure-name in that statement shall denote a
module procedure.
C1508 (R1507) A procedure-name shall denote a nonintrinsic procedure that has an explicit interface.
C1509 (R1501) An interface-specification in a generic interface block shall not specify a procedure that was
specified previously in any accessible interface with the same generic identifier.
2 An interface block introduced by ABSTRACT INTERFACE is an abstract interface block. An interface body
in an abstract interface block specifies an abstract interface. An interface block with a generic specification is3 The name of the entity declared by an interface body is the function-name in the function-stmt or the subroutine-a generic interface block. An interface block with neither ABSTRACT nor a generic specification is a specific
interface block.
name in the subroutine-stmt that begins the interface body.4 A module procedure interface body is an interface body whose initial statement contains the keyword MODULE.
It specifies the interface for a separate module procedure (15.6.2.5). A separate module procedure is accessible5 An interface body in a generic or specific interface block specifies the EXTERNAL attribute and an explicitby use association if and only if its interface body is declared in the specification part of a module and is public.
If a corresponding (15.6.2.5) separate module procedure is not defined, the interface may be used to specify an
explicit specific interface but the procedure shall not be used in any other way.
specific interface for an external procedure, dummy procedure, or procedure pointer. If the name of the declared6 An interface body specifies all of the characteristics of the explicit specific interface or abstract interface. Theprocedure is that of a dummy argument in the subprogram containing the interface body, the procedure is a
dummy procedure. If the procedure has the POINTER attribute, it is a procedure pointer. If it is not a dummy
procedure or procedure pointer, it is an external procedure.
specification part of an interface body may specify attributes or define values for data entities that do not7 If an explicit specific interface for an external procedure is specified by an interface body or a procedure declarationdetermine characteristics of the procedure. Such specifications have no effect.
statement (15.4.3.6), the characteristics shall be consistent with those specified in the procedure definition, exceptthat the interface may specify a procedure that is not pure even if the procedure is defined to be pure. An interface
for a procedure defined by an ENTRY statement may be specified by using the entry name as the procedure name in the interface body.
If an external procedure does not exist in the program, an interface body for it may be used to specify an explicit
specific interface but the procedure shall not be used in any other way. A procedure shall not have more than
one explicit specific interface in a given scoping unit, except that if the interface is accessed by use association,
there may be more than one local name for the procedure. If a procedure is accessed by use association, each
access shall be to the same procedure declaration or definition.
NOTE 15.3
The dummy argument names in an interface body can be different from the corresponding dummy argument
names in the procedure definition because the name of a dummy argument is not a characteristic.
⃝c ISO/IEC 2017 – All rights reserved 303
ISO/IEC DIS 1539-1:2017 (E)
NOTE 15.4
An example of a specific interface block is:
INTERFACE
SUBROUTINE EXT1 (X, Y, Z)
REAL, DIMENSION (100, 100) :: X, Y, ZEND SUBROUTINE EXT1
SUBROUTINE EXT2 (X, Z)
REAL X
COMPLEX (KIND = 4) Z (2000)
END SUBROUTINE EXT2
FUNCTION EXT3 (P, Q)
LOGICAL EXT3END FUNCTION EXT3INTEGER P (1000)
LOGICAL Q (1000)
END INTERFACE
This interface block specifies explicit interfaces for the three external procedures EXT1, EXT2, and EXT3.
Invocations of these procedures can use argument keywords (15.5.2); for example:
PRINT *, EXT3 (Q = P_MASK (N+1 : N+1000), P = ACTUAL_P)
15.4.3.3 GENERIC statement 1 A GENERIC statement specifies a generic identifier for one or more specific procedures, in the same way as a
generic interface block that does not contain interface bodies.2 If access-spec appears, it specifies the accessibility (8.5.2) of generic-spec.R1510 generic-stmt is GENERIC [ , access-spec ] :: generic-spec => specific-procedure-list
C1510 (R1510) A specific-procedure in a GENERIC statement shall not specify a procedure that was specified
previously in any accessible interface with the same generic identifier.
15.4.3.4 Generic interfaces1 A generic interface block specifies a generic interface for each of the procedures in the interface block. The15.4.3.4.1 Generic identifiers
PROCEDURE statement lists procedure pointers, external procedures, dummy procedures, or module procedures2 The generic-spec in an interface-stmt is a generic identifier for all the procedures in the interface block. Thethat have this generic interface. A GENERIC statement specifies a generic interface for each of the procedures
named in its specific-procedure-list. A generic interface is always explicit.
generic-spec in a GENERIC statement is a generic identifier for all of the procedures named in its specific-3 A generic name is a generic identifier that refers to all of the procedure names in the generic interface. A genericprocedure-list. The rules specifying how any two procedures with the same generic identifier shall differ are given
in 15.4.3.4.5. They ensure that any generic invocation applies to at most one specific procedure. If a specific
procedure in a generic interface has a function dummy argument, that argument shall have its type and type
parameters explicitly declared in the specific interface.
name may be the same as any one of the procedure names in the generic interface, or the same as any accessible4 A generic name may be the same as a derived-type name, in which case all of the procedures in the genericgeneric name.
interface shall be functions.5 An interface-stmt having a defined-io-generic-spec is an interface for a defined input/output procedure (12.6.4.8).304 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 15.5An example of a generic procedure interface is:
INTERFACE SWITCH
SUBROUTINE INT_SWITCH (X, Y)
INTEGER, INTENT (INOUT) :: X, Y
END SUBROUTINE INT_SWITCH
SUBROUTINE REAL_SWITCH (X, Y)
REAL, INTENT (INOUT) :: X, Y
END SUBROUTINE REAL_SWITCH
SUBROUTINE COMPLEX_SWITCH (X, Y) COMPLEX, INTENT (INOUT) :: X, Y
END SUBROUTINE COMPLEX_SWITCH
END INTERFACE SWITCH
Any of these three subroutines (INT_SWITCH, REAL_SWITCH, COMPLEX_SWITCH) can be ref-
erenced with the generic name SWITCH, as well as by its specific name. For example, a reference to
INT_SWITCH could take the form:
CALL SWITCH (MAX_VAL, LOC_VAL) ! MAX_VAL and LOC_VAL are of type INTEGER
NOTE 15.6
A type-bound-generic-stmt within a derived-type definition (7.5.5) specifies a generic identifier for a set of
type-bound procedures.
15.4.3.4.2 Defined operations 1 If OPERATOR is specified in a generic specification, all of the procedures specified in the generic interface shall
be functions that may be referenced as defined operations (10.1.6, 15.5). In the case of functions of two arguments,infix binary operator notation is implied. In the case of functions of one argument, prefix operator notation is
implied. OPERATOR shall not be specified for functions with no arguments or for functions with more than two
arguments. The dummy arguments shall be nonoptional dummy data objects and shall have the INTENT (IN)
or VALUE attribute. The function result shall not have assumed character length. If the operator is an intrinsic-operator
(R608), the number of dummy arguments shall be consistent with the intrinsic uses of that operator, and the
types, kind type parameters, or ranks of the dummy arguments shall differ from those required for the intrinsic
operation (10.1.5).
2 A defined operation is treated as a reference to the function. For a unary defined operation, the operand corresponds to the function’s dummy argument; for a binary operation, the left-hand operand corresponds to the3 A given defined operator may, as with generic names, apply to more than one function, in which case it is genericfirst dummy argument of the function and the right-hand operand corresponds to the second dummy argument.
All restrictions and constraints that apply to actual arguments in a reference to the function also apply to the
corresponding operands in the expression as if they were used as actual arguments.
in exact analogy to generic procedure names. For intrinsic operator symbols, the generic properties include theintrinsic operations they represent. Because both forms of each relational operator have the same interpretation
(10.1.6.2), extending one form (such as <=) has the effect of defining both forms (<= and .LE.).
NOTE 15.7
An example of the use of the OPERATOR generic specification is:
INTERFACE OPERATOR ( * )
FUNCTION BOOLEAN_AND (B1, B2)
LOGICAL, INTENT (IN) :: B1 (:), B2 (SIZE (B1))
⃝c ISO/IEC 2017 – All rights reserved 305
ISO/IEC DIS 1539-1:2017 (E)
NOTE 15.7 (cont.)
LOGICAL :: BOOLEAN_AND (SIZE (B1))
END FUNCTION BOOLEAN_AND
END INTERFACE OPERATOR ( * )
This allows, for example
SENSOR (1:N) * ACTION (1:N)as an alternative to the function reference
BOOLEAN_AND (SENSOR (1:N), ACTION (1:N)) ! SENSOR and ACTION are! of type LOGICAL
15.4.3.4.3 Defined assignments 1 If ASSIGNMENT ( = ) is specified in a generic specification, all the procedures in the generic interface shall
be subroutines that may be referenced as defined assignments (10.2.1.4, 10.2.1.5). Defined assignment may, as2 Each of these subroutines shall have exactly two dummy arguments. The dummy arguments shall be nonoptionalwith generic names, apply to more than one subroutine, in which case it is generic in exact analogy to generic
procedure names.
dummy data objects. The first argument shall have INTENT (OUT) or INTENT (INOUT) and the secondargument shall have the INTENT (IN) or VALUE attribute. Either the second argument shall be an array whose
rank differs from that of the first argument, the declared types and kind type parameters of the arguments shall
not conform as specified in Table 10.8, or the first argument shall be of derived type. A defined assignment is
treated as a reference to the subroutine, with the left-hand side as the first argument and the right-hand side
enclosed in parentheses as the second argument. All restrictions and constraints that apply to actual arguments
in a reference to the subroutine also apply to the left-hand-side and to the right-hand-side enclosed in parentheses
as if they were used as actual arguments. The ASSIGNMENT generic specification specifies that assignment is
extended or redefined.
NOTE 15.8
An example of the use of the ASSIGNMENT generic specification is:
INTERFACE ASSIGNMENT ( = )
SUBROUTINE LOGICAL_TO_NUMERIC (N, B)
INTEGER, INTENT (OUT) :: N
LOGICAL, INTENT (IN) :: B
END SUBROUTINE LOGICAL_TO_NUMERIC
SUBROUTINE CHAR_TO_STRING (S, C)
USE STRING_MODULE ! Contains definition of type STRINGTYPE (STRING), INTENT (OUT) :: S ! A variable-length string
CHARACTER (*), INTENT (IN) :: C
END SUBROUTINE CHAR_TO_STRING
END INTERFACE ASSIGNMENT ( = )
Example assignments are:
KOUNT = SENSOR (J) ! CALL LOGICAL_TO_NUMERIC (KOUNT, (SENSOR (J)))NOTE 15.9NOTE = ’89AB’ ! CALL CHAR_TO_STRING (NOTE, (’89AB’))
A procedure which has a generic identifier of ASSIGNMENT ( = ) and whose second dummy argument
has the ALLOCATABLE or POINTER attribute cannot be directly invoked by defined assignment. This
is because the actual argument associated with that dummy argument is the right-hand side of the as-
306 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 15.9 (cont.)
signment enclosed in parentheses, which makes the actual argument an expression that does not have the
ALLOCATABLE, POINTER, or TARGET attribute.
15.4.3.4.4 Defined input/output procedure interfaces 1 All of the procedures specified in an interface block for a defined input/output procedure shall be subroutines
that have interfaces as described in 12.6.4.8.2.1 This subclause contains the rules that shall be satisfied by every pair of specific procedures that have the same15.4.3.4.5 Restrictions on generic declarations
generic identifier within the scope of the identifier. If a generic procedure is accessed from a module, the rules2 A dummy argument is type, kind, and rank compatible, or TKR compatible, with another dummy argument ifapply to all the specific versions even if some of them are inaccessible by their specific names.
NOTE 15.10
In most scoping units, the possible sources of procedures with a particular generic identifier are the accessible
generic identifiers specified by generic interface blocks or GENERIC statements and the generic bindings
other than names for the accessible objects in that scoping unit. In a type definition, they are the generic
bindings, including those from a parent type.
the first is type compatible with the second, the kind type parameters of the first have the same values as the3 Two dummy arguments are distinguishable ifcorresponding kind type parameters of the second, and both have the same rank or either is assumed-rank.
• one is a procedure and the other is a data object,C1511 Within the scope of a generic operator, if two procedures with that identifier have the same number of• they are both data objects or known to be functions, and neither is TKR compatible with the other,
• one has the ALLOCATABLE attribute and the other has the POINTER attribute and not the INTENT
(IN) attribute, or
• one is a function with nonzero rank and the other is not known to be a function.
arguments, one shall have a dummy argument that corresponds by position in the argument list to aC1512 Within the scope of the generic ASSIGNMENT (=) identifier, if two procedures have that identifier, onedummy argument of the other that is distinguishable from it.
shall have a dummy argument that corresponds by position in the argument list to a dummy argumentC1513 Within the scope of a defined-io-generic-spec, if two procedures have that generic identifier, their dtvof the other that is distinguishable from it.
arguments (12.6.4.8.2) shall be distinguishable.C1514 Within the scope of a generic name, each pair of procedures identified by that name shall both be
subroutines or both be functions, and(1) there is a non-passed-object dummy data object in one or the other of them such that
(a) the number of dummy data objects in one that are nonoptional, are not passed-object, and
with which that dummy data object is TKR compatible, possibly including that dummy
data object itself,
exceeds
(b) the number of non-passed-object dummy data objects, both optional and nonoptional, in
the other that are not distinguishable from that dummy data object,
⃝c ISO/IEC 2017 – All rights reserved 307
ISO/IEC DIS 1539-1:2017 (E)
(2) the number of nonoptional dummy procedures in one of them exceeds the number of dummy4 The effective position of a dummy argument is its position in the argument list after any passed-object dummyprocedures in the other,
(3) both have passed-object dummy arguments and the passed-object dummy arguments are distin-
guishable, or
(4) at least one of them shall have both
(a) a nonoptional non-passed-object dummy argument at an effective position such that either
the other procedure has no dummy argument at that effective position or the dummy argu-
ment at that position is distinguishable from it, and
(b) a nonoptional non-passed-object dummy argument whose name is such that either the other
procedure has no dummy argument with that name or the dummy argument with that name
is distinguishable from it,
and the dummy argument that disambiguates by position shall either be the same as or occur
earlier in the argument list than the one that disambiguates by name.
argument has been removed.5 Within the scope of a generic name that is the same as the generic name of an intrinsic procedure, the intrinsic
procedure is not accessible by its generic name if the procedures in the interface and the intrinsic procedure are1 An EXTERNAL statement specifies the EXTERNAL attribute (8.5.9) for a list of names.not all functions or not all subroutines. If a generic invocation is consistent with both a specific procedure from
an interface and an accessible intrinsic procedure, it is the specific procedure from the interface that is referenced.
NOTE 15.11
An extensive explanation of the application of these rules is in C.10.6.
15.4.3.5 EXTERNAL statement
R1511 external-stmt is EXTERNAL [ :: ] external-name-list2 The appearance of the name of a block data program unit in an EXTERNAL statement confirms that the block
data program unit is a part of the program.NOTE 15.12
For explanatory information on potential portability problems with external procedures, see subclause
C.10.1.
NOTE 15.13
An example of an EXTERNAL statement is:
EXTERNAL FOCUS
15.4.3.6 Procedure declaration statement 1 A procedure declaration statement declares procedure pointers, dummy procedures, and external procedures. It
specifies the EXTERNAL attribute (8.5.9) for all entities in the proc-decl-list.2 If proc-interface appears and consists of interface-name, it specifies an explicit specific interface (15.4.3.2) for theR1512 procedure-declaration-stmt is PROCEDURE ( [ proc-interface ] )
[ [ , proc-attr-spec ] ... :: ] proc-decl-list
R1513 proc-interface is interface-name
or declaration-type-spec
R1514 proc-attr-spec is access-spec
or proc-language-binding-spec
308 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
or INTENT ( intent-spec )
or OPTIONAL
or POINTER
or PROTECTED
or SAVE
R1515 proc-decl is procedure-entity-name [ => proc-pointer-init ]
R1516 interface-name is name
R1517 proc-pointer-init is null-init
or initial-proc-target
R1518 initial-proc-target is procedure-name
C1515 (R1516) The name shall be the name of an abstract interface or of a procedure that has an explicit
interface. If name is declared by a procedure-declaration-stmt it shall be previously declared. If name
denotes an intrinsic procedure it shall be one that is listed in Table 16.2.
C1516 (R1516) The name shall not be the same as a keyword that specifies an intrinsic type.
C1517 (R1512) If a proc-interface describes an elemental procedure, each procedure-entity-name shall specify an
external procedure.
C1518 (R1515) If => appears in proc-decl, the procedure entity shall have the POINTER attribute.
C1519 (R1518) The procedure-name shall be the name of a nonelemental external or module procedure, or a
specific intrinsic function listed in Table 16.2.
C1520 (R1512) If proc-language-binding-spec with NAME= is specified, then proc-decl-list shall contain exactly
one proc-decl, which shall neither have the POINTER attribute nor be a dummy procedure.
C1521 (R1512) If proc-language-binding-spec is specified, the proc-interface shall appear, it shall be an interface-
name, and interface-name shall be declared with a proc-language-binding-spec.
declared procedure entities. The abstract interface (15.4) is that specified by the interface named by interface-3 If proc-interface appears and consists of declaration-type-spec, it specifies that the declared procedure entities arename. The interface specified by interface-name shall not depend on any characteristic of a procedure identified
by a procedure-entity-name in the proc-decl-list of the same procedure declaration statement.
functions having implicit interfaces and the specified result type. If a type is specified for an external function,4 If proc-interface does not appear, the procedure declaration statement does not specify whether the declaredits function definition (15.6.2.2) shall specify the same result type and type parameters.
procedure entities are subroutines or functions.5 If a proc-attr-spec other than a proc-language-binding-spec appears, it specifies that the declared procedure entities
have that attribute. These attributes are described in 8.5. If a proc-language-binding-spec with NAME= appears,6 If => appears in a proc-decl in a procedure-declaration-stmt it specifies the initial association status of theit specifies a binding label or its absence, as described in 18.10.2. A proc-language-binding-spec without NAME=
is allowed, but is redundant with the proc-interface required by C1521.
corresponding procedure entity, and implies the SAVE attribute, which may be confirmed by explicit specification.7 If procedure-entity-name has an explicit interface, its characteristics shall be the same as initial-proc-target exceptIf => null-init appears, the procedure entity is initially disassociated. If => initial-proc-target appears, the
procedure entity is initially associated with the target.
that initial-proc-target may be pure even if procedure-entity-name is not pure and initial-proc-target may be an elemental8 If the characteristics of procedure-entity-name or initial-proc-target are such that an explicit interface is required,intrinsic procedure.
⃝c ISO/IEC 2017 – All rights reserved 309
ISO/IEC DIS 1539-1:2017 (E)
both procedure-entity-name and initial-proc-target shall have an explicit interface.9 If procedure-entity-name has an implicit interface and is explicitly typed or referenced as a function, initial-proc-
target shall be a function. If procedure-entity-name has an implicit interface and is referenced as a subroutine,10 If initial-proc-target and procedure-entity-name are functions, their results shall have the same characteristics.initial-proc-target shall be a subroutine.
NOTE 15.14The following code illustrates procedure declaration statements. NOTE 10.47 illustrates the use of the P
and BESSEL defined by this code.
ABSTRACT INTERFACE
FUNCTION REAL_FUNC (X)
REAL, INTENT (IN) :: XREAL :: REAL_FUNC
END FUNCTION REAL_FUNC
END INTERFACE
INTERFACE
SUBROUTINE SUB (X)
REAL, INTENT (IN) :: X
END SUBROUTINE SUB
END INTERFACE
!-- Some external or dummy procedures with explicit interface.
PROCEDURE (REAL_FUNC) :: BESSEL, GFUN
PROCEDURE (SUB) :: PRINT_REAL
!-- Some procedure pointers with explicit interface,
!-- one initialized to NULL().
PROCEDURE (REAL_FUNC), POINTER :: P, R => NULL ()
PROCEDURE (REAL_FUNC), POINTER :: PTR_TO_GFUN
!-- A derived type with a procedure pointer component ...
TYPE STRUCT_TYPE
PROCEDURE (REAL_FUNC), POINTER, NOPASS :: COMPONENT
END TYPE STRUCT_TYPE
!-- ... and a variable of that type.
TYPE(STRUCT_TYPE) :: STRUCT
!-- An external or dummy function with implicit interface
PROCEDURE (REAL) :: PSI
15.4.3.7 INTRINSIC statement 1 An INTRINSIC statement specifies the INTRINSIC attribute (8.5.11) for a list of names.
R1519 intrinsic-stmt is INTRINSIC [ :: ] intrinsic-procedure-name-list1 If the interface of a function is implicit, the type and type parameters of the function result are specified by anC1522 (R1519) Each intrinsic-procedure-name shall be the name of an intrinsic procedure.
15.4.3.8 Implicit interface specification
implicit or explicit type specification of the function name. The type, type parameters, and shape of the dummyarguments of a procedure invoked from where the interface of the procedure is implicit shall be such that each
actual argument is consistent with the characteristics of the corresponding dummy argument.
310 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
15.5 Procedure reference 15.5.1 Syntax of a procedure reference 1 The form of a procedure reference is dependent on the interface of the procedure or procedure pointer, but is independent of the means by which the procedure is defined. The forms of procedure references are as follows.2 The data-ref in a procedure-designator shall not be an unallocated allocatable variable or a pointer that is notR1520 function-reference is procedure-designator ( [ actual-arg-spec-list ] )
C1523 (R1520) The procedure-designator shall designate a function.
C1524 (R1520) The actual-arg-spec-list shall not contain an alt-return-spec.
R1521 call-stmt is CALL procedure-designator [ ( [ actual-arg-spec-list ] ) ]
C1525 (R1521) The procedure-designator shall designate a subroutine.
R1522 procedure-designator is procedure-name
or proc-component-ref
or data-ref % binding-name
C1526 (R1522) A procedure-name shall be a generic name or the name of a procedure.
C1527 (R1522) A binding-name shall be a binding name (7.5.5) of the declared type of data-ref .
C1528 (R1522) A data-ref shall not be a polymorphic subobject of a coindexed object.
C1529 (R1522) If data-ref is an array, the referenced type-bound procedure shall have the PASS attribute.
associated.3 Resolving references to type-bound procedures is described in 15.5.6.
4 A function may also be referenced as a defined operation (10.1.6). A subroutine may also be referenced as a
defined assignment (10.2.1.4, 10.2.1.5), by defined input/output (12.6.4.8), or by finalization (7.5.6).ISO/IEC DIS 1539-1:2017 (E)NOTE 15.15
When resolving type-bound procedure references, constraints on the use of coindexed objects ensure that
the coindexed object (on the remote image) has the same dynamic type as the corresponding object on the
local image. Thus a processor can resolve the type-bound procedure using the coarray variable on its own
image and pass the coindexed object as the actual argument.
R1523 actual-arg-spec is [ keyword = ] actual-arg
R1524 actual-arg is expr
or variable
or procedure-name
or proc-component-ref
or alt-return-spec
R1525 alt-return-spec is * label
C1530 (R1523) The keyword = shall not appear if the interface of the procedure is implicit.
C1531 (R1523) The keyword = shall not be omitted from an actual-arg-spec unless it has been omitted from
each preceding actual-arg-spec in the argument list.
C1532 (R1523) Each keyword shall be the name of a dummy argument in the explicit interface of the procedure.
⃝c ISO/IEC 2017 – All rights reserved 311
C1533 (R1524) A nonintrinsic elemental procedure shall not be used as an actual argument.
C1534 (R1524) A procedure-name shall be the name of an external, internal, module, or dummy procedure, a
specific intrinsic function listed in Table 16.2, or a procedure pointer.C1535 (R1524) expr shall not be a variable.
C1536 (R1525) The label shall be the statement label of a branch target statement that appears in the same inclusive scope as the
call-stmt.C1537 An actual argument that is a coindexed object shall not have a pointer ultimate component.
NOTE 15.16Examples of procedure reference using procedure pointers:
P => BESSEL
WRITE (*, *) P(2.5) !-- BESSEL(2.5)
S => PRINT_REAL
CALL S(3.14)
NOTE 15.17
An internal procedure cannot be invoked using a procedure pointer from either Fortran or C after the host
instance completes execution, because the pointer is then undefined. While the host instance is active,
however, if an internal procedure was passed as an actual argument or is the target of a procedure pointer,
it could be invoked from outside of the host subprogram.
Rb
Assume there is a procedure with the following interface that calculates a f (x) dx.
INTERFACE
FUNCTION INTEGRATE(F, A, B) RESULT(INTEGRAL) BIND(C)
USE ISO_C_BINDING
INTERFACE
FUNCTION F(X) BIND(C) ! Integrand
USE ISO_C_BINDING
REAL(C_FLOAT), VALUE :: X
REAL(C_FLOAT) :: F
END FUNCTION
END INTERFACE
REAL(C_FLOAT), VALUE :: A, B ! Bounds
REAL(C_FLOAT) :: INTEGRAL
END FUNCTION INTEGRATE
END INTERFACE
This procedure can be called from Fortran or C, and could be written in either Fortran or C. The argument F
representing the mathematical function f (x) can be written as an internal procedure; this internal procedure
will have access to any host instance local variables necessary to actually calculate f (x). For example:
REAL FUNCTION MY_INTEGRATION(N, A, B) RESULT(INTEGRAL)! Integrate f(x)=x^n over [a,b]
USE ISO_C_BINDING
INTEGER, INTENT(IN) :: N
REAL, INTENT(IN) :: A, B
INTEGRAL = INTEGRATE(MY_F, REAL (A, C_FLOAT), REAL (B, C_FLOAT))
! This will call the internal function MY_F to calculate f(x).! The above interface of INTEGRATE needs to be explicit and available.
312 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 15.17 (cont.)
CONTAINS
REAL(C_FLOAT) FUNCTION MY_F(X) BIND(C) ! Integrand
REAL(C_FLOAT), VALUE :: XMY_F = X**N ! N is taken from the host instance of MY_INTEGRATION.
END FUNCTION
END FUNCTION MY_INTEGRATION
The function INTEGRATE cannot retain a function pointer to MY_F and use it after INTEGRATE has
finished execution, because the host instance of MY_F might no longer exist, making the pointer undefined.
If such a pointer is retained, then it can only be used to invoke MY_F during the execution of the instance
of MY_INTEGRATION that called INTEGRATE.
1 In either a subroutine reference or a function reference, the actual argument list identifies the correspondence
15.5.2 Actual arguments, dummy arguments, and argument association
15.5.2.1 Argument correspondence
between the actual arguments and the dummy arguments of the procedure. This correspondence may be estab-lished either by keyword or by position. If an argument keyword appears, the actual argument corresponds to
the dummy argument whose name is the same as the argument keyword (using the dummy argument names from
the interface accessible by the procedure reference). In the absence of an argument keyword, an actual argument
corresponds to the dummy argument occupying the corresponding position in the reduced dummy argument list;
that is, the first actual argument corresponds to the first dummy argument in the reduced list, the second actual
argument corresponds to the second dummy argument in the reduced list, etc. The reduced dummy argument
list is either the full dummy argument list or, if there is a passed-object dummy argument (7.5.4.5), the dummy
argument list with the passed-object dummy argument omitted. Exactly one actual argument shall correspond
to each nonoptional dummy argument. At most one actual argument shall correspond to each optional dummy
argument. Each actual argument shall correspond to a dummy argument.
NOTE 15.18
For example, the procedure defined by
SUBROUTINE SOLVE (FUNCT, SOLUTION, METHOD, STRATEGY, PRINT)
INTERFACE
FUNCTION FUNCT (X)
REAL FUNCT, X
END FUNCTION FUNCT
END INTERFACE
REAL SOLUTION
INTEGER, OPTIONAL :: METHOD, STRATEGY, PRINT
...
can be invoked with
CALL SOLVE (FUN, SOL, PRINT = 6)
provided its interface is explicit, and if the interface is specified by an interface body, the name of the last
argument is PRINT.
15.5.2.2 The passed-object dummy argument and argument correspondence 1 In a reference to a type-bound procedure, or a procedure pointer component, that has a passed-object dummy
argument (7.5.4.5), the data-ref of the function-reference or call-stmt corresponds, as an actual argument, with1 Except in references to intrinsic inquiry functions, a pointer actual argument that corresponds to a nonoptionalthe passed-object dummy argument.
⃝c ISO/IEC 2017 – All rights reserved 313
ISO/IEC DIS 1539-1:2017 (E)
15.5.2.3 Argument association
nonpointer dummy argument shall be pointer associated with a target.2 If a nonpointer dummy argument without the VALUE attribute corresponds to a pointer actual argument that
is pointer associated with a target,3 If a present nonpointer dummy argument without the VALUE attribute corresponds to a nonpointer actual• if the dummy argument is polymorphic, it becomes argument associated with that target;
• if the dummy argument is nonpolymorphic, it becomes argument associated with the declared type part of
that target.
argument,4 A present dummy argument with the VALUE attribute becomes argument associated with a definable anonymous• if the dummy argument is polymorphic, it becomes argument associated with that actual argument;
• if the dummy argument is nonpolymorphic, it becomes argument associated with the declared type part of
that actual argument.
data object whose initial value is the value of the actual argument.5 A present pointer dummy argument that corresponds to a pointer actual argument becomes argument associated
with that actual argument. A present pointer dummy argument that does not correspond to a pointer actual6 The entity that is argument associated with a dummy argument is called its effective argument.argument is not argument associated.
7 The ultimate argument is the effective argument if the effective argument is not a dummy argument or a subobject
of a dummy argument. If the effective argument is a dummy argument, the ultimate argument is the ultimate1 The requirements in this subclause apply to actual arguments that correspond to nonallocatable nonpointerargument of that dummy argument. If the effective argument is a subobject of a dummy argument, the ultimate
argument is the corresponding subobject of the ultimate argument of that dummy argument.
NOTE 15.19
For the sequence of subroutine calls
INTEGER :: X(100)
CALL SUBA (X)
...
SUBROUTINE SUBA(A)
INTEGER :: A(:)
CALL SUBB (A(1:5), A(5:1:-1))
...
SUBROUTINE SUBB(B, C)
INTEGER :: B(:), C(:)
the ultimate argument of B is X(1:5). The ultimate argument of C is X(5:1:-1) and this is not the same
object as the ultimate argument of B.
NOTE 15.20
Fortran argument association is usually similar to call by reference and call by value-result. If the VALUE
attribute is specified, the effect is as if the actual argument were assigned to a temporary variable, and
that variable were then argument associated with the dummy argument. Subsequent changes to the value
or definition status of the dummy argument do not affect the actual argument. The actual mechanism by
which this happens is determined by the processor.
314 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
15.5.2.4 Ordinary dummy variables
dummy data objects.2 The dummy argument shall be type compatible with the actual argument. If the actual argument is a polymorphic
coindexed object, the dummy argument shall not be polymorphic. If the actual argument is a polymorphic3 The kind type parameter values of the actual argument shall agree with the corresponding ones of the dummyassumed-size array, the dummy argument shall be polymorphic. If the actual argument is of a derived type that
has type parameters, type-bound procedures, or final subroutines, the dummy argument shall not be assumed-
type.
argument. The length type parameter values of a present actual argument shall agree with the corresponding4 If a present scalar dummy argument is of type character with default kind or C character kind, the length len ofones of the dummy argument that are not assumed, except for the case of the character length parameter of
an actual argument of type character with default kind or C character kind (18.2.2) associated with a dummy
argument that is not assumed-shape or assumed-rank.
the dummy argument shall be less than or equal to the length of the actual argument. The dummy argument5 The values of assumed type parameters of a dummy argument are assumed from the corresponding type para-becomes associated with the leftmost len characters of the actual argument. If a present array dummy argument
is of type character with default kind or C character kind and is not assumed-shape or assumed-rank, it becomes
associated with the leftmost characters of the actual argument element sequence (15.5.2.11).
meters of its effective argument.6 If the actual argument is a coindexed object with an allocatable ultimate component, the dummy argument shall
have the INTENT (IN) or the VALUE attribute.7 Except in references to intrinsic inquiry functions, if the dummy argument is nonoptional and the actual argumentNOTE 15.21
If the actual argument is a coindexed object, a processor that uses distributed memory might create a copy
on the executing image of the actual argument, including copies of any allocated allocatable subobjects,
and associate the dummy argument with that copy. If necessary, on return from the procedure, the value
of the copy would be copied back to the actual argument.
is allocatable, the corresponding actual argument shall be allocated.8 If the dummy argument does not have the TARGET attribute, any pointers associated with the effective argument
do not become associated with the corresponding dummy argument on invocation of the procedure. If such a9 If the dummy argument has the TARGET attribute, does not have the VALUE attribute, and either the effectivedummy argument is used as an actual argument that corresponds to a dummy argument with the TARGET
attribute, whether any pointers associated with the original effective argument become associated with the dummy
argument with the TARGET attribute is processor dependent.
argument is simply contiguous or the dummy argument is scalar, assumed-rank, or assumed-shape, and does not10 If the dummy argument has the TARGET attribute and is an explicit-shape array, an assumed-shape array withhave the CONTIGUOUS attribute, and the effective argument has the TARGET attribute but is not a coindexed
object or an array section with a vector subscript then
• any pointers associated with the effective argument become associated with the corresponding dummy
argument on invocation of the procedure, and
• when execution of the procedure completes, any pointers that do not become undefined (19.5.2.5) and are
associated with the dummy argument remain associated with the effective argument.
the CONTIGUOUS attribute, an assumed-rank object with the CONTIGUOUS attribute, or an assumed-size11 If the dummy argument has the TARGET attribute and the effective argument does not have the TARGETarray, and the effective argument has the TARGET attribute but is not simply contiguous and is not an array
⃝c ISO/IEC 2017 – All rights reserved 315
ISO/IEC DIS 1539-1:2017 (E)
section with a vector subscript then
• on invocation of the procedure, whether any pointers associated with the effective argument become asso-
ciated with the corresponding dummy argument is processor dependent, and
• when execution of the procedure completes, the pointer association status of any pointer that is pointer
associated with the dummy argument is processor dependent.
attribute or is an array section with a vector subscript, any pointers associated with the dummy argument12 If the dummy argument has the TARGET attribute and the VALUE attribute, any pointers associated with thebecome undefined when execution of the procedure completes.
dummy argument become undefined when execution of the procedure completes.13 If the actual argument is a coindexed scalar, the corresponding dummy argument shall be scalar. If the actual
argument is a noncoindexed scalar, the corresponding dummy argument shall be scalar unless the actual argument14 If a dummy argument is an assumed-shape array, the rank of the actual argument shall be the same as the rankis default character, of type character with the C character kind (18.2.2), or is an element or substring of an element
of an array that is not an assumed-shape, pointer, or polymorphic array. If the procedure is nonelemental and is
referenced by a generic name or as a defined operator or defined assignment, the ranks of the actual arguments
and corresponding dummy arguments shall agree.
of the dummy argument, and the actual argument shall not be an assumed-size array.15 An actual argument of any rank may correspond to an assumed-rank dummy argument. The rank and extents of
the dummy argument are the rank and extents of the corresponding actual argument. The lower bound of each16 Except when a procedure reference is elemental (15.8), each element of an array actual argument or of a sequencedimension of the dummy argument is equal to one. The upper bound is equal to the extent, except for the last
dimension when the actual argument is assumed-size.
in a sequence association (15.5.2.11) is associated with the element of the dummy array that has the same position17 A scalar dummy argument of a nonelemental procedure shall correspond only to a scalar actual argument.in array element order (9.5.3.2).
NOTE 15.22
For default character sequence associations, the interpretation of element is provided in 15.5.2.11.
18 If a dummy argument has INTENT (OUT) or INTENT (INOUT), the actual argument shall be definable. If a
dummy argument has INTENT (OUT), the effective argument becomes undefined at the time the association is19 If the procedure is nonelemental, the dummy argument does not have the VALUE attribute, and the actualestablished, except for direct components of an object of derived type for which default initialization has been
specified.
argument is an array section having a vector subscript, the dummy argument is not definable and shall not have20 If the dummy argument has a coarray ultimate component, the corresponding actual argument shall have thethe ASYNCHRONOUS, INTENT (OUT), INTENT (INOUT), or VOLATILE attributes.
VOLATILE attribute if and only if the dummy argument has the VOLATILE attribute.C1538 An actual argument that is a coindexed object with the ASYNCHRONOUS or VOLATILE attribute shallNOTE 15.23
Argument intent specifications serve several purposes. See NOTE 8.18.
NOTE 15.24
For more explanatory information on targets as dummy arguments, see subclause C.10.4.
316 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
not correspond to a dummy argument that has either the ASYNCHRONOUS or VOLATILE attribute,C1539 (R1524) If an actual argument is a nonpointer array that has the ASYNCHRONOUS or VOLATILEunless the dummy argument has the VALUE attribute.
attribute but is not simply contiguous (9.5.4), and the corresponding dummy argument has either theC1540 (R1524) If an actual argument is an array pointer that has the ASYNCHRONOUS or VOLATILEASYNCHRONOUS or VOLATILE attribute, but does not have the VALUE attribute, that dummy
argument shall be assumed-shape or assumed-rank and shall not have the CONTIGUOUS attribute.
attribute but does not have the CONTIGUOUS attribute, and the corresponding dummy argumentNOTE 15.25has either the ASYNCHRONOUS or VOLATILE attribute, but does not have the VALUE attribute,
that dummy argument shall be an array pointer, an assumed-shape array without the CONTIGUOUS
attribute, or an assumed-rank entity without the CONTIGUOUS attribute.
The constraints on an actual argument with the ASYNCHRONOUS or VOLATILE attribute that corres-
ponds to a dummy argument with either the ASYNCHRONOUS or VOLATILE attribute are designed to
avoid forcing a processor to use the so-called copy-in/copy-out argument passing mechanism. Making a
copy of an actual argument whose value is likely to change due to an asynchronous input/output operation
completing or in some unpredictable manner will cause the new value to be lost when a called procedure
returns and the copy-out overwrites the actual argument.
1 The requirements in this subclause apply to an actual argument with the ALLOCATABLE or POINTER attribute
15.5.2.5 Allocatable and pointer dummy variables
that corresponds to a dummy argument with the same attribute.2 The actual argument shall be polymorphic if and only if the associated dummy argument is polymorphic, and
either both the actual and dummy arguments shall be unlimited polymorphic, or the declared type of the actual3 The rank of the actual argument shall be the same as that of the dummy argument, unless the dummy argumentargument shall be the same as the declared type of the dummy argument.
NOTE 15.26
The dynamic type of a polymorphic allocatable or pointer dummy argument can change as a result of
execution of an ALLOCATE statement or pointer assignment in the subprogram. Because of this the
corresponding actual argument needs to be polymorphic and have a declared type that is the same as the
declared type of the dummy argument or an extension of that type. However, type compatibility requires
that the declared type of the dummy argument be the same as, or an extension of, the type of the actual
argument. Therefore, the dummy and actual arguments need to have the same declared type.
Dynamic type information is not maintained for a nonpolymorphic allocatable or pointer dummy argument.
However, allocating or pointer-assigning such a dummy argument would require maintenance of this inform-
ation if the corresponding actual argument is polymorphic. Therefore, the corresponding actual argument
needs to be nonpolymorphic.
is assumed-rank. The type parameter values of the actual argument shall agree with the corresponding ones of4 The actual argument shall have deferred the same type parameters as the dummy argument.the dummy argument that are not assumed or deferred. The values of assumed type parameters of the dummy
argument are assumed from the corresponding type parameters of its effective argument.
15.5.2.6 Allocatable dummy variables1 The requirements in this subclause apply to actual arguments that correspond to allocatable dummy data objects.
2 The actual argument shall be allocatable. It is permissible for the actual argument to have an allocation status
of unallocated.3 The corank of the actual argument shall be the same as that of the dummy argument.⃝c ISO/IEC 2017 – All rights reserved 317
ISO/IEC DIS 1539-1:2017 (E)
4 If the actual argument is a coindexed object, the dummy argument shall have the INTENT (IN) attribute.
5 If the dummy argument does not have the TARGET attribute, any pointers associated with the actual argument
do not become associated with the corresponding dummy argument on invocation of the procedure. If such a6 If the dummy argument has the TARGET attribute, does not have the INTENT (OUT) or VALUE attribute,dummy argument is used as an actual argument that is associated with a dummy argument with the TARGET
attribute, whether any pointers associated with the original actual argument become associated with the dummy
argument with the TARGET attribute is processor dependent.
and the corresponding actual argument has the TARGET attribute then7 If a dummy argument has INTENT (OUT) or INTENT (INOUT), the actual argument shall be definable. If a• any pointers associated with the actual argument become associated with the corresponding dummy argu-
ment on invocation of the procedure, and
• when execution of the procedure completes, any pointers that do not become undefined (19.5.2.5) and are
associated with the dummy argument remain associated with the actual argument.
dummy argument has INTENT (OUT) and its associated actual argument is allocated, the actual argument is1 The requirements in this subclause apply to actual arguments that correspond to dummy data pointers.deallocated on procedure invocation (9.7.3.2).
15.5.2.7 Pointer dummy variables
C1541 The actual argument corresponding to a dummy pointer with the CONTIGUOUS attribute shall be2 If the dummy argument does not have INTENT (IN), the actual argument shall be a pointer. Otherwise, thesimply contiguous (9.5.4).
C1542 The actual argument corresponding to a dummy pointer shall not be a coindexed object.
NOTE 15.27
Constraint C1542 does not apply to any intrinsic procedure because an intrinsic procedure is defined in
terms of its actual arguments.
actual argument shall be a pointer or a valid target for the dummy pointer in a pointer assignment statement. If3 If the dummy argument has INTENT (OUT), the pointer association status of the actual argument becomesthe actual argument is not a pointer, the dummy pointer becomes pointer associated with the actual argument.
undefined on invocation of the procedure.1 If the dummy argument is a coarray, the corresponding actual argument shall be a coarray and shall have theNOTE 15.28
For more explanatory information on pointers as dummy arguments, see subclause C.10.4.
15.5.2.8 Coarray dummy variables
VOLATILE attribute if and only if the dummy argument has the VOLATILE attribute.2 If the dummy argument is an array coarray that has the CONTIGUOUS attribute or is not of assumed shape,
the corresponding actual argument shall be simply contiguous or an element of a simply contiguous array.NOTE 15.29
Consider the invocation of a procedure on a particular image. Each dummy coarray is associated with its
ultimate argument on the image. In addition, during this execution of the procedure, this image can access
the coarray corresponding to the ultimate argument on any other image. For example, consider
318 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 15.29 (cont.)
INTERFACE
SUBROUTINE SUB(X)
REAL :: X[*]
END SUBROUTINE SUB
END INTERFACE
...
REAL :: A(1000)[*]
...
CALL SUB(A(10))
During execution of this invocation of SUB, the executing image has access through the syntax X[P] to
A(10) on image P.
NOTE 15.30
Each invocation of a procedure with a nonallocatable coarray dummy argument establishes a dummy coarray
for the image with its own bounds and cobounds. During this execution of the procedure, this image can
use its own bounds and cobounds to access the coarray corresponding to the ultimate argument on any
other image. For example, consider
INTERFACE
SUBROUTINE SUB(X,N)
INTEGER :: NREAL :: X(N,N)[N,*]
END SUBROUTINE SUB
END INTERFACE
...
REAL :: A(1000)[*]
...
CALL SUB(A,10)
During execution of this invocation of SUB, the executing image has access through the syntax X(1,2)[3,4]
to A(11) on the image with image index 33.
NOTE 15.31
The requirements on an actual argument that corresponds to a dummy coarray that is not of assumed-
shape or has the CONTIGUOUS attribute are designed to avoid forcing a processor to use the so-called
copy-in/copy-out argument passing mechanism.
15.5.2.9 Actual arguments associated with dummy procedure entities 1 If the interface of a dummy procedure is explicit, its characteristics as a procedure (15.3.1) shall be the same as
those of its effective argument, except that a pure effective argument may be associated with a dummy argument2 If the interface of a dummy procedure is implicit and either the dummy argument is explicitly typed or referencedthat is not pure and an elemental intrinsic actual procedure may be associated with a dummy procedure (which cannot be
elemental).
as a function, it shall not be referenced as a subroutine and any corresponding actual argument shall be a function,3 If the interface of a dummy procedure is implicit and a reference to it appears as a subroutine reference, anyfunction procedure pointer, or dummy procedure. If both the actual argument and dummy argument are known
to be functions, they shall have the same type and type parameters. If only the dummy argument is known to
be a function, the function that would be invoked by a reference to the dummy argument shall have the same
type and type parameters, except that an external function with assumed character length may be associated with a dummy
argument with explicit character length.
corresponding actual argument shall be a subroutine, subroutine procedure pointer, or dummy procedure.4 If a dummy argument is a dummy procedure without the POINTER attribute, its effective argument shall be an⃝c ISO/IEC 2017 – All rights reserved 319
ISO/IEC DIS 1539-1:2017 (E)
external, internal, module, or dummy procedure, or a specific intrinsic procedure listed in Table 16.2. If the specific name5 If a dummy argument is a procedure pointer, the corresponding actual argument shall be a procedure pointer, ais also a generic name, only the specific procedure is associated with the dummy argument.
reference to a function that returns a procedure pointer, a reference to the intrinsic function NULL, or a valid6 When the actual argument is a procedure, the host instance of the dummy argument is the host instance of thetarget for the dummy pointer in a pointer assignment statement. If the actual argument is not a pointer, the
dummy argument shall have INTENT (IN) and becomes pointer associated with the actual argument.
actual argument (15.6.2.4).7 If an external procedure or a dummy procedure is used as an actual argument, its interface shall be explicit or it
shall be explicitly declared to have the EXTERNAL attribute.1 If a dummy argument is an asterisk (15.6.2.3), the corresponding actual argument shall be an alternate return specifier (R1525).15.5.2.10 Actual arguments and alternate return indicators
15.5.2.11 Sequence association1 An actual argument represents an element sequence if it is an array expression, an array element designator, a
default character scalar, or a scalar of type character with the C character kind (18.2.2). If the actual argument is2 If the actual argument is default character or of type character with the C character kind, and is an arrayan array expression, the element sequence consists of the elements in array element order. If the actual argument
is an array element designator, the element sequence consists of that array element and each element that follows
it in array element order.
expression, array element, or array element substring designator, the element sequence consists of the storage3 If the actual argument is default character or of type character with the C character kind, and is a scalar that isunits beginning with the first storage unit of the actual argument and continuing to the end of the array. The
storage units of an array element substring designator are viewed as array elements consisting of consecutive
groups of storage units having the character length of the dummy array.
not an array element or array element substring designator, the element sequence consists of the storage units of4 An actual argument that represents an element sequence and corresponds to a dummy argument that is an arraythe actual argument.
NOTE 15.32
Some of the elements in the element sequence might consist of storage units from different elements of the
original array.
is sequence associated with the dummy argument if the dummy argument is an explicit-shape or assumed-size1 A dummy argument or an entity that is host associated with a dummy argument is not present if the dummyarray. The rank and shape of the actual argument need not agree with the rank and shape of the dummy
argument, but the number of elements in the dummy argument shall not exceed the number of elements in the
element sequence of the actual argument. If the dummy argument is assumed-size, the number of elements in the
dummy argument is exactly the number of elements in the element sequence.
15.5.2.12 Argument presence and restrictions on arguments not present
argument2 A nonoptional dummy argument shall be present. If an optional nonpointer dummy argument corresponds to a• does not correspond to an actual argument,
• corresponds to an actual argument that is not present, or
• does not have the ALLOCATABLE or POINTER attribute, and corresponds to an actual argument that
– has the ALLOCATABLE attribute and is not allocated, or
320 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
– has the POINTER attribute and is disassociated;
otherwise, it is present.
present pointer actual argument, the pointer association status of the actual argument shall not be undefined.3 An optional dummy argument that is not present is subject to the following restrictions.
(1) If it is a data object, it shall not be referenced or be defined. If it is of a type that has default4 Except as noted in the list above, it may be supplied as an actual argument corresponding to an optional dummyinitialization, the initialization has no effect.
(2) It shall not be used as the data-target or proc-target of a pointer assignment.
(3) If it is a procedure or procedure pointer, it shall not be invoked.
(4) It shall not be supplied as an actual argument corresponding to a nonoptional dummy argument
other than as the argument of the intrinsic function PRESENT or as an argument of a function
reference that is a constant expression.
(5) A designator with it as the base object and with one or more subobject selectors shall not be supplied
as an actual argument.
(6) If it is an array, it shall not be supplied as an actual argument to an elemental procedure unless an
array of the same rank is supplied as an actual argument corresponding to a nonoptional dummy
argument of that elemental procedure.
(7) If it is a pointer, it shall not be allocated, deallocated, nullified, pointer-assigned, or supplied as an
actual argument corresponding to an optional nonpointer dummy argument.
(8) If it is allocatable, it shall not be allocated, deallocated, or supplied as an actual argument corres-
ponding to an optional nonallocatable dummy argument.
(9) If it has length type parameters, they shall not be the subject of an inquiry.
(10) It shall not be used as the selector in an ASSOCIATE, SELECT RANK, or SELECT TYPE construct.
(11) It shall not be supplied as the data-ref in a procedure-designator.
(12) If shall not be supplied as the scalar-variable in a proc-component-ref .
argument, which is then also considered not to be present.1 While an entity is associated with a dummy argument, the following restrictions hold.15.5.2.13 Restrictions on entities associated with dummy arguments
(1) Action that affects the allocation status of the entity or a subobject thereof shall be taken throughthe dummy argument.
(2) If the allocation status of the entity or a subobject thereof is affected through the dummy argument,
then at any time during the invocation and execution of the procedure, either before or after the
allocation or deallocation, it shall be referenced only through the dummy argument.
(3) Action that affects the value of the entity or any subobject of it shall be taken only through the
dummy argument unless
(a) the dummy argument has the POINTER attribute,
(b) the dummy argument is a scalar, assumed-shape, or assumed-rank object, and has the TAR-
GET attribute but not the INTENT (IN) or CONTIGUOUS attributes, and the actual argu-
ment is a target other than a coindexed object or an array section with a vector subscript,
(c) the dummy argument is an assumed-rank object with the TARGET attribute and not the
INTENT (IN) attribute, and the actual argument is a scalar target, or
(d) the dummy argument is a coarray and the action is a coindexed definition of the corresponding
ultimate argument coarray by a different image.
(4) If the value of the entity or any subobject of it is affected through the dummy argument, then at
any time during the invocation and execution of the procedure, either before or after the definition,
it may be referenced only through that dummy argument unless
⃝c ISO/IEC 2017 – All rights reserved 321
ISO/IEC DIS 1539-1:2017 (E)
(a) the dummy argument has the POINTER attribute,NOTE 15.33(b) the dummy argument is a scalar, assumed-shape, or assumed-rank object, and has the TAR-
GET attribute but not the INTENT (IN) or CONTIGUOUS attributes, and the actual argu-
ment is a target other than a coindexed object or an array section with a vector subscript,
(c) the dummy argument is an assumed-rank object with the TARGET attribute and not the
INTENT (IN) attribute, and the actual argument is a scalar target, or
(d) the dummy argument is a coarray and the reference is a coindexed reference of its corresponding
ultimate argument coarray by a different image.
In
SUBROUTINE OUTER
REAL, POINTER :: A (:)
...
ALLOCATE (A (1:N))
...
CALL INNER (A)
...
CONTAINS
SUBROUTINE INNER (B)
REAL :: B (:)...
END SUBROUTINE INNER
SUBROUTINE SET (C, D)
REAL, INTENT (OUT) :: CREAL, INTENT (IN) :: D
C = D
END SUBROUTINE SET
END SUBROUTINE OUTER
an assignment statement such as
A (1) = 1.0would not be permitted during the execution of INNER because this would be changing A without using
B, but statements such as
B (1) = 1.0or
CALL SET (B (1), 1.0)would be allowed. Similarly,
DEALLOCATE (A)would not be allowed because this affects the allocation of B without using B. In this case,
DEALLOCATE (B)also would not be permitted. If B were declared with the POINTER attribute, either of the statements
DEALLOCATE (A)and
DEALLOCATE (B)would be permitted, but not both.
322 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 15.34
If there is a partial or complete overlap between the effective arguments of two different dummy arguments
of the same procedure and the dummy arguments have neither the POINTER nor TARGET attribute,
the overlapped portions cannot be defined, redefined, or become undefined during the execution of the
procedure. For example, in
CALL SUB (A (1:5), A (3:9))the array section A (3:5) cannot be defined, redefined, or become undefined through the first dummy
argument because it is part of the argument associated with the second dummy argument and cannot be
defined, redefined, or become undefined through the second dummy argument because it is part of the
argument associated with the first dummy argument. The array section A (1:2) remains definable through
the first dummy argument and A (6:9) remains definable through the second dummy argument.
This restriction applies equally to pointer targets. In
REAL, DIMENSION (10), TARGET :: Athe array section B (3:5) cannot be defined because it is part of the argument associated with the secondREAL, DIMENSION (:), POINTER :: B, C
B => A (1:5)
C => A (3:9)
CALL SUB (B, C) ! The dummy arguments of SUB are neither pointers nor targets.
dummy argument. The array section C (1:3) cannot be defined because it is part of the argument associated
with the first dummy argument. The array section A (1:2), which is associated with B (1:2), remains
definable through the first dummy argument and A (6:9), which is associated with C (4:7), remains definable
through the second dummy argument.
NOTE 15.35
In
MODULE DATA
REAL :: W, X, Y, Z
END MODULE DATA
PROGRAM MAIN
USE DATA
...
CALL INIT (X)
...
END PROGRAM MAIN
SUBROUTINE INIT (V)
USE DATA
...
READ (*, *) V
...
END SUBROUTINE INIT
variable X cannot be directly referenced at any time during the execution of INIT because it is being defined
through the dummy argument V. X can be (indirectly) referenced through V. W, Y, and Z can be directly
referenced. X can, of course, be directly referenced once execution of INIT is complete.
NOTE 15.36
The restrictions on entities associated with dummy arguments are intended to facilitate a variety of optim-
izations in the translation of the subprogram, including implementations of argument association in which
the value of an actual argument that is neither a pointer nor a target is maintained in a register or in local
storage.
⃝
c ISO/IEC 2017 – All rights reserved 323
ISO/IEC DIS 1539-1:2017 (E)1 A function is invoked during expression evaluation by a function-reference or by a defined operation (10.1.6).NOTE 15.37
The exception to the aliasing restrictions for dummy coarrays enables cross-image access while the procedure
is executing. Because nonatomic accesses from different images typically need to be separated by an image
control statement, code optimization within segments is not unduly inhibited.
15.5.3 Function reference
When it is invoked, all actual argument expressions are evaluated, then the arguments are associated, and then1 A subroutine is invoked by execution of a CALL statement, execution of a defined assignment statement (10.2.1.4),the function is executed. When execution of the function is complete, the value of the function result is available
for use in the expression that caused the function to be invoked. The characteristics of the function result (15.3.3)
are determined by the interface of the function. If a reference to an elemental function (15.8) is an elemental
reference, all array arguments shall have the same shape.
15.5.4 Subroutine reference
defined input/output (12.6.4.8.3), or finalization(7.5.6). When a subroutine is invoked, all actual argument1 The rules for interpreting a procedure reference depend on whether the procedure name in the reference isexpressions are evaluated, then the arguments are associated, and then the subroutine is executed. When the
actions specified by the subroutine are completed, the execution of the CALL statement, the execution of the
defined assignment statement, the processing of an input or output list item, or finalization of an object is
also completed. If a CALL statement includes one or more alternate return specifiers among its arguments, a branch to one
of the statements indicated might occur, depending on the action specified by the subroutine. If a reference to an elemental
subroutine (15.8) is an elemental reference, at least one actual argument shall correspond to an INTENT (OUT)
or INTENT (INOUT) dummy argument, all such actual arguments shall be arrays, and all actual arguments
shall be conformable.
15.5.5 Resolving named procedure references
15.5.5.1 Establishment of procedure names
established by the available declarations and specifications to be generic in the scoping unit containing the2 A procedure name is established to be generic in a scoping unitreference, is established to be only specific in the scoping unit containing the reference, or is not established.
(1) if that scoping unit contains an interface block with that name;3 A procedure name is established to be only specific in a scoping unit if it is established to be specific and not(2) if that scoping unit contains a GENERIC statement with a generic-spec that is that name;
(3) if that scoping unit contains an INTRINSIC attribute specification for that name and it is the generic
name of an intrinsic procedure;
(4) if that scoping unit contains a USE statement that makes that procedure name accessible and the
corresponding name in the module is established to be generic; or
(5) if that scoping unit contains no declarations of that name, that scoping unit has a host scoping unit,
and that name is established to be generic in the host scoping unit.
established to be generic. It is established to be specific4 A procedure name is not established in a scoping unit if it is neither established to be generic nor established to(1) if that scoping unit contains a module subprogram, internal subprogram, or statement function statement
that defines a procedure with that name;
(2) if that scoping unit is of a subprogram that defines a procedure with that name;
(3) if that scoping unit contains an INTRINSIC attribute specification for that name and it is the name of a specific
intrinsic procedure;
(4) if that scoping unit contains an explicit EXTERNAL attribute specification for that name;
324 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
(5) if that scoping unit contains a USE statement that makes that procedure name accessible and the
corresponding name in the module is established to be specific; or
(6) if that scoping unit contains no declarations of that name, that scoping unit has a host scoping unit,
and that name is established to be specific in the host scoping unit.
be specific.1 If the reference is consistent with a nonelemental reference to one of the specific interfaces of a generic interface15.5.5.2 Resolving procedure references to names established to be generic
that has that name and either is defined in the scoping unit in which the reference appears or is made accessible2 Otherwise, if the reference is consistent with an elemental reference to one of the specific interfaces of a genericby a USE statement in the scoping unit, the reference is to the specific procedure in the interface block that
provides that interface. The rules in 15.4.3.4.5 ensure that there can be at most one such specific procedure.
interface that has that name and either is defined in the scoping unit in which the reference appears or is made3 Otherwise, if the scoping unit contains either an INTRINSIC attribute specification for that name or a USEaccessible by a USE statement in the scoping unit, the reference is to the specific elemental procedure in the
interface block that provides that interface. The rules in 15.4.3.4.5 ensure that there can be at most one such
specific elemental procedure.
statement that makes that name accessible from a module in which the corresponding name is specified to have4 Otherwise, if the scoping unit has a host scoping unit, the name is established to be generic in that host scopingthe INTRINSIC attribute, and if the reference is consistent with the interface of that intrinsic procedure, the
reference is to that intrinsic procedure.
unit, and there is agreement between the scoping unit and the host scoping unit as to whether the name is a5 Otherwise, if the name is that of an intrinsic procedure and the reference is consistent with that intrinsic procedure,function name or a subroutine name, the name is resolved by applying the rules in this subclause to the host
scoping unit as if the reference appeared there.
the reference is to that intrinsic procedure.NOTE 15.38
Because of the renaming facility of the USE statement, the name in the reference can be different from the
usual name of the intrinsic procedure.
NOTE 15.39
These rules allow particular specific procedures with the same generic identifier to be used for particular
array ranks and a general elemental version to be used for other ranks. For example, given an interface
block such as
INTERFACE RANF
ELEMENTAL FUNCTION SCALAR_RANF(X)
REAL, INTENT(IN) :: X
END FUNCTION SCALAR_RANF
FUNCTION VECTOR_RANDOM(X)
REAL X(:)REAL VECTOR_RANDOM(SIZE(X))
END FUNCTION VECTOR_RANDOM
END INTERFACE RANF
and a declaration such as:
REAL A(10,10), AA(10,10)then the statement
⃝c ISO/IEC 2017 – All rights reserved 325
ISO/IEC DIS 1539-1:2017 (E)
NOTE 15.39 (cont.)A = RANF(AA)
is an elemental reference to SCALAR_RANF. The statement
A(6:10,2) = RANF(AA(6:10,2))
is a nonelemental reference to VECTOR_RANDOM.
15.5.5.3 Resolving procedure references to names established to be only specific 1 If the name has the EXTERNAL attribute, • if it is a procedure pointer, the reference is to its target;2 If the name is that of an accessible external procedure, internal procedure, module procedure, intrinsic procedure,• if it is a dummy procedure that is not a procedure pointer, the reference is to the effective argument
corresponding to that name;
• otherwise, the reference is to the external procedure with that name.
or statement function, the reference is to that procedure.1 If the name is the name of a dummy argument of the scoping unit, the dummy argument is a dummy procedureNOTE 15.40
Because of the renaming facility of the USE statement, the name in the reference can be different from the
original name of the procedure.
15.5.5.4 Resolving procedure references to names not established
and the reference is to that dummy procedure. That is, the procedure invoked by executing that reference is the2 Otherwise, if the name is the name of an intrinsic procedure, and if there is agreement between the reference andeffective argument corresponding to that dummy procedure.
the status of the intrinsic procedure as being a function or subroutine, the reference is to that intrinsic procedure.3 Otherwise, the reference is to an external procedure with that name.
15.5.6 Resolving type-bound procedure references1 If the binding-name in a procedure-designator (R1522) is that of a specific type-bound procedure, the procedure
referenced is the one bound to that name in the dynamic type of the data-ref .2 If the binding-name in a procedure-designator is that of a generic type bound procedure, the generic binding with
that name in the declared type of the data-ref is used to select a specific binding using the following criteria.3 The reference is to the procedure bound to the same name as the selected specific binding in the dynamic type• If the reference is consistent with one of the specific bindings of that generic binding, that specific binding
is selected.
• Otherwise, the reference shall be consistent with an elemental reference to one of the specific bindings of
that generic binding; that specific binding is selected.
of the data-ref .1 Intrinsic procedures are defined as an inherent part of the processor. A standard-conforming processor shall326 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
15.6 Procedure definition
15.6.1 Intrinsic procedure definition
include the intrinsic procedures described in Clause 16, but may include others. However, a standard-conforming1 A procedure is defined by the initial SUBROUTINE or FUNCTION statement of a subprogram, and each ENTRYprogram shall not make use of intrinsic procedures other than those described in Clause 16.
15.6.2 Procedures defined by subprograms
15.6.2.1 General
statement defines an additional procedure (15.6.2.6).2 A subprogram is specified to have the NON_RECURSIVE attribute, or to be elemental (15.8), pure (15.7), or a
separate module subprogram (15.6.2.5) by a prefix in its initial SUBROUTINE or FUNCTION statement.3 The NON_RECURSIVE prefix-spec shall not appear if any procedure defined by the subprogram directly orR1526 prefix is prefix-spec [ prefix-spec ] ...
R1527 prefix-spec is declaration-type-spec
or ELEMENTAL
or IMPURE
or MODULE
or NON_RECURSIVE
or PURE
or RECURSIVE
C1543 (R1526) A prefix shall contain at most one of each prefix-spec.
C1544 (R1526) A prefix shall not specify both PURE and IMPURE.
C1545 (R1526) A prefix shall not specify both NON_RECURSIVE and RECURSIVE.
C1546 An elemental procedure shall not have the BIND attribute.
C1547 (R1526) MODULE shall appear only in the function-stmt or subroutine-stmt of a module subprogram or
of a nonabstract interface body that is declared in the scoping unit of a module or submodule.
C1548 (R1526) If MODULE appears in the prefix of a module subprogram, it shall have been declared to be a
separate module procedure in the containing program unit or an ancestor of that program unit.
C1549 (R1526) If MODULE appears in the prefix of a module subprogram, the subprogram shall specify the
same characteristics and dummy argument names as its corresponding module procedure interface body.
C1550 (R1526) If MODULE appears in the prefix of a module subprogram and a binding label is specified, it
shall be the same as the binding label specified in the corresponding module procedure interface body.
C1551 (R1526) If MODULE appears in the prefix of a module subprogram, NON_RECURSIVE shall appear
if and only if NON_RECURSIVE appears in the prefix in the corresponding module procedure interface
body.
indirectly invokes itself or any other procedure defined by the subprogram. If a subprogram defines a function whose name is4 If the prefix-spec PURE appears, or the prefix-spec ELEMENTAL appears and IMPURE does not appear, thedeclared with an asterisk type-param-value, no procedure defined by the subprogram shall directly or indirectly invoke itself or any
other procedure defined by the subprogram.
subprogram is a pure subprogram and shall meet the additional constraints of 15.7.5 If the prefix-spec ELEMENTAL appears, the subprogram is an elemental subprogram and shall meet the additional⃝c ISO/IEC 2017 – All rights reserved 327
ISO/IEC DIS 1539-1:2017 (E)
constraints of 15.8.1.6 A proc-language-binding-spec specifies that the procedure defined or declared by the statement is interoperableR1528 proc-language-binding-spec is language-binding-spec
(18.3.7).1 A function subprogram is a subprogram that has a FUNCTION statement as its first statement.C1552 A proc-language-binding-spec with a NAME= specifier shall not be specified in the function-stmt or
subroutine-stmt of an internal procedure, or of an interface body for an abstract interface or a dummy
procedure.
C1553 If proc-language-binding-spec is specified for a function, the function result shall be an interoperable scalar
variable.
C1554 If proc-language-binding-spec is specified for a procedure, each of its dummy arguments shall be an inter-
operable procedure (18.3.7) or a variable that is interoperable (18.3.5, 18.3.6), assumed-shape, assumed-
rank, assumed-type, of type CHARACTER with assumed length, or that has the ALLOCATABLE or
POINTER attribute.
C1555 A variable that is a dummy argument of a procedure that has a proc-language-binding-spec shall be
assumed-type or of interoperable type and kind type parameters.
C1556 If proc-language-binding-spec is specified for a procedure, it shall not have a default-initialized dummy
argument with the ALLOCATABLE or POINTER attribute.
C1557 If proc-language-binding-spec is specified for a procedure, it shall not have a dummy argument that is a
coarray.
C1558 If proc-language-binding-spec is specified for a procedure, it shall not have an array dummy argument
with the VALUE attribute.
15.6.2.2 Function subprogram
R1529 function-subprogram is function-stmt2 The name of the function is function-name.[ specification-part ]
[ execution-part ]
[ internal-subprogram-part ]
end-function-stmt
R1530 function-stmt is [ prefix ] FUNCTION function-name
( [ dummy-arg-name-list ] ) [ suffix ]
C1559 (R1530) If RESULT appears, result-name shall not be the same as function-name and shall not be the same
as the entry-name in any ENTRY statement in the subprogram.
C1560 (R1530) If RESULT appears, the function-name shall not appear in any specification statement in the
scoping unit of the function subprogram.
R1531 dummy-arg-name is name
C1561 (R1531) A dummy-arg-name shall be the name of a dummy argument.
R1532 suffix is proc-language-binding-spec [ RESULT ( result-name ) ]
or RESULT ( result-name ) [ proc-language-binding-spec ]
R1533 end-function-stmt is END [ FUNCTION [ function-name ] ]
328 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C1562 (R1529) An internal function subprogram shall not contain an internal-subprogram-part.
C1563 (R1533) If a function-name appears in the end-function-stmt, it shall be identical to the function-name
specified in the function-stmt.
3 The type and type parameters (if any) of the result of the function defined by a function subprogram may be
specified by a type specification in the FUNCTION statement or by the name of the function result appearing4 If RESULT appears, the name of the function result of the function is result-name and all occurrences of thein a type declaration statement in the specification part of the function subprogram. They shall not be specified
both ways. If they are not specified either way, they are determined by the implicit typing rules in effect within
the function subprogram. If the function result is an array, allocatable, or a pointer, this shall be specified by
specifications of the name of the function result within the function body. The specifications of the function
result attributes, the specification of dummy argument attributes, and the information in the procedure heading
collectively define the characteristics of the function (15.3.1).
function name in execution-part statements in its scope refer to the function itself. If RESULT does not appear,the name of the function result is function-name and all occurrences of the function name in execution-part
statements in its scope are references to the function result. On completion of execution of the function, the value
returned is that of its function result. If the function result is a data pointer, the shape of the value returned by
the function is determined by the shape of the function result when the execution of the function is completed. If
the function result is not a pointer, its value shall be defined by the function. If the function result is a pointer,
on return the pointer association status of the function result shall not be undefined.
NOTE 15.41
The function result is similar to any other entity (variable or procedure pointer) local to a function sub-
program. Its existence begins when execution of the function is initiated and ends when execution of the
function is terminated. However, because the final value of this entity is used subsequently in the evaluation
of the expression that invoked the function, an implementation might defer releasing the storage occupied
by that entity until after its value has been used in expression evaluation.
NOTE 15.42
The following is an example of the declaration of an interface body with the BIND attribute, and a reference
to the procedure declared.
USE, INTRINSIC :: ISO_C_BINDING
INTERFACE
FUNCTION JOE (I, J, R) BIND(C,NAME="FrEd")
USE, INTRINSIC :: ISO_C_BINDINGINTEGER(C_INT) :: JOE
INTEGER(C_INT), VALUE :: I, J
REAL(C_FLOAT), VALUE :: R
END FUNCTION JOE
END INTERFACE
INT = JOE(1_C_INT, 3_C_INT, 4.0_C_FLOAT)
END PROGRAM
The invocation of the function JOE results in a reference to a function with a binding label "FrEd". FrEd
could be a C function described by the C prototype
int FrEd(int n, int m, float x);
⃝c ISO/IEC 2017 – All rights reserved 329
ISO/IEC DIS 1539-1:2017 (E)
15.6.2.3 Subroutine subprogram 1 A subroutine subprogram is a subprogram that has a SUBROUTINE statement as its first statement. R1534 subroutine-subprogram is subroutine-stmt2 The name of the subroutine is subroutine-name.[ specification-part ]
[ execution-part ]
[ internal-subprogram-part ]
end-subroutine-stmt
R1535 subroutine-stmt is [ prefix ] SUBROUTINE subroutine-name
[ ( [ dummy-arg-list ] ) [ proc-language-binding-spec ] ]
C1564 (R1535) The prefix of a subroutine-stmt shall not contain a declaration-type-spec.
R1536 dummy-arg is dummy-arg-name
or *
R1537 end-subroutine-stmt is END [ SUBROUTINE [ subroutine-name ] ]
C1565 (R1534) An internal subroutine subprogram shall not contain an internal-subprogram-part.
C1566 (R1537) If a subroutine-name appears in the end-subroutine-stmt, it shall be identical to the subroutine-
name specified in the subroutine-stmt.
15.6.2.4 Instances of a subprogram1 When a procedure defined by a subprogram is invoked, an instance of that subprogram is created. Each instance
has an independent sequence of execution and an independent set of dummy arguments, unsaved local variables,2 When a statement function is invoked, an instance of that statement function is created.and unsaved local procedure pointers. Saved local entities are shared by all instances of the subprogram.
3 When execution of an instance completes it ceases to exist.
4 The caller of an instance of a procedure is the instance of the main program, subprogram, or statement function
that invoked it. The call sequence of an instance of a procedure is its caller, followed by the call sequence of its1 A separate module procedure is a module procedure defined by a separate-module-subprogram, by a function-caller. The call sequence of the main program is empty. The host instance of an instance of a statement function
or an internal procedure that is invoked by its name is the first element of the call sequence that is an instance
of the host of the statement function or internal subprogram. The host instance of an internal procedure that is
invoked via a dummy procedure or procedure pointer is the host instance of the associating entity from when the
argument association or pointer association was established (19.5.5). The host instance of a module procedure is
the module or submodule in which it is defined. A main program or external subprogram has no host instance.
15.6.2.5 Separate module procedures
subprogram whose initial statement contains the keyword MODULE, or by a subroutine-subprogram whose initial2 A separate module procedure shall not be defined more than once.statement contains the keyword MODULE.
R1538 separate-module-subprogram is mp-subprogram-stmt
[ specification-part ]
[ execution-part ]
[ internal-subprogram-part ]
end-mp-subprogram-stmt
R1539 mp-subprogram-stmt is MODULE PROCEDURE procedure-name
330 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
R1540 end-mp-subprogram-stmt is END [PROCEDURE [procedure-name]]
C1567 (R1538) The procedure-name shall have been declared to be a separate module procedure in the containing
program unit or an ancestor of that program unit.
C1568 (R1540) If a procedure-name appears in the end-mp-subprogram-stmt, it shall be identical to the procedure-
name in the mp-subprogram-stmt.
3 The interface of a procedure defined by a separate-module-subprogram is explicitly declared by the mp-subprogram-
stmt to be the same as its module procedure interface body. It has the NON_RECURSIVE attribute if and only1 An ENTRY statement permits a procedure reference to begin with a particular executable statement within the function or subroutineif it was declared to have that attribute by the interface body. If it is a function its result name is determined
by the FUNCTION statement in the interface body.
NOTE 15.43
A separate module procedure can be accessed by use association only if its interface body is declared in the
specification part of a module and is public.
15.6.2.6 ENTRY statement
subprogram in which the ENTRY statement appears.2 Optionally, a subprogram may have one or more ENTRY statements.R1541 entry-stmt is ENTRY entry-name [ ( [ dummy-arg-list ] ) [ suffix ] ]
C1569 (R1541) If RESULT appears, the entry-name shall not appear in any specification or type declaration statement in the
scoping unit of the function program.
C1570 (R1541) An entry-stmt shall appear only in an external-subprogram or a module-subprogram that does not define a separate
module procedure. An entry-stmt shall not appear within an executable-construct.
C1571 (R1541) RESULT shall appear only if the entry-stmt is in a function subprogram.
C1572 (R1541) A dummy-arg shall not be an alternate return indicator if the ENTRY statement is in a function subprogram.
C1573 (R1541) If RESULT appears, result-name shall not be the same as the function-name in the FUNCTION statement and
shall not be the same as the entry-name in any ENTRY statement in the subprogram.
3 If the ENTRY statement is in a function subprogram, an additional function is defined by that subprogram. The name of the
function is entry-name and the name of its result is result-name or is entry-name if no result-name is provided. The dummy4 If the ENTRY statement is in a subroutine subprogram, an additional subroutine is defined by that subprogram. The name of thearguments of the function are those specified in the ENTRY statement. If the characteristics of the result of the function named in
the ENTRY statement are the same as the characteristics of the result of the function named in the FUNCTION statement, their
result names identify the same entity, although their names need not be the same. Otherwise, they are storage associated and shall
all be nonpointer, nonallocatable scalar variables that are default integer, default real, double precision real, default complex, or
default logical.
subroutine is entry-name. The dummy arguments of the subroutine are those specified in the ENTRY statement.5 The order, number, types, kind type parameters, and names of the dummy arguments in an ENTRY statement may differ from the
order, number, types, kind type parameters, and names of the dummy arguments in the FUNCTION or SUBROUTINE statement6 Because an ENTRY statement defines an additional function or an additional subroutine, it is referenced in the same manner as anyin the containing subprogram.
other function or subroutine (15.5).7 In a subprogram, a dummy argument specified in an ENTRY statement shall not appear in an executable statement preceding that
ENTRY statement, unless it also appears in a FUNCTION, SUBROUTINE, or ENTRY statement that precedes the executable8 In a subprogram, a dummy argument specified in an ENTRY statement shall not appear in the expression of a statement function⃝c ISO/IEC 2017 – All rights reserved 331
ISO/IEC DIS 1539-1:2017 (E)
statement. A function result specified by a result-name in an ENTRY statement shall not appear in any executable statement that
precedes the first RESULT clause with that name.
that precedes the first dummy-arg with that name in the subprogram. A function result specified by a result-name in an ENTRY9 If a dummy argument appears in an executable statement, the execution of the executable statement is permitted during thestatement shall not appear in the expression of a statement function that precedes the first RESULT clause with that name.
execution of a reference to the function or subroutine only if the dummy argument appears in the dummy argument list of the10 If a dummy argument is used in a specification expression to specify an array bound or character length of an object, the appearancereferenced procedure.
of the object in a statement that is executed during a procedure reference is permitted only if the dummy argument appears in the11 The NON_RECURSIVE and RECURSIVE keywords are not used in an ENTRY statement. Instead, the presence or absence ofdummy argument list of the referenced procedure and it is present (15.5.2.12).
NON_RECURSIVE in the initial SUBROUTINE or FUNCTION statement controls whether the procedure defined by an ENTRY12 The keywords PURE and IMPURE are not used in an ENTRY statement. Instead, the procedure defined by an ENTRY statementstatement is permitted to reference itself or another procedure defined by the subprogram.
is pure if and only if the subprogram is a pure subprogram.13 The keyword ELEMENTAL is not used in an ENTRY statement. Instead, the procedure defined by an ENTRY statement is elemental
if and only if ELEMENTAL is specified in the SUBROUTINE or FUNCTION statement.1 Execution of the RETURN statement completes execution of the instance of the subprogram in which it appears.15.6.2.7 RETURN statement
R1542 return-stmt is RETURN [ scalar-int-expr ]
C1574 (R1542) The return-stmt shall be in the inclusive scope of a function or subroutine subprogram.
C1575 (R1542) The scalar-int-expr is allowed only in the inclusive scope of a subroutine subprogram.
If the expression appears and has a value n between 1 and the number of asterisks in the dummy argument list, the CALL statement2 Execution of an end-function-stmt, end-mp-subprogram-stmt, or end-subroutine-stmt is equivalent to executionthat invoked the subroutine branches (11.2) to the branch target statement identified by the nth alternate return specifier in the
actual argument list of the referenced procedure. If the expression is omitted or has a value outside the required range, there is no
transfer of control to an alternate return.
of a RETURN statement with no expression.1 The CONTAINS statement separates the body of a main program, module, submodule, or subprogram from any15.6.2.8 CONTAINS statement
R1543 contains-stmt is CONTAINS
internal or module subprograms it might contain, or it introduces the type-bound procedure part of a derived-type1 A procedure may be defined by means other than Fortran. The interface of a procedure defined by means otherdefinition (7.5.5). The CONTAINS statement is not executable.
15.6.3 Definition and invocation of procedures by means other than Fortran
than Fortran may be specified by an interface body or procedure declaration statement. A reference to such a2 A procedure defined by means other than Fortran that is invoked by a Fortran procedure and does not causeprocedure is made as though it were defined by an external subprogram.
termination of execution shall return to its caller.3 If the interface of a procedure has a proc-language-binding-spec, the procedure is interoperable (18.10).332 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 15.44
Examples of code that might cause a transfer of control that bypasses the normal return mechanism of
a Fortran procedure are setjmp and longjmp in C and exception handling in other languages. No such
behavior is permitted by this document.
4 Interoperation with C functions is described in 18.10.
NOTE 15.45For explanatory information on definition of procedures by means other than Fortran, see subclause C.10.2.
15.6.4 Statement function 1 A statement function is a function defined by a single statement.
R1544 stmt-function-stmt is function-name ( [ dummy-arg-name-list ] ) = scalar-expr2 The definition of a statement function with the same name as an accessible entity from the host shall be preceded by the declarationC1576 (R1544) Each primary in scalar-expr shall be a constant (literal or named), a reference to a variable, a reference to a
function, or an expression in parentheses. Each operation shall be intrinsic. If scalar-expr contains a reference to a
function, the reference shall not require an explicit interface, the function shall not require an explicit interface unless it is
an intrinsic function, the function shall not be a transformational intrinsic, and the result shall be scalar. If an argument to
a function is an array, it shall be an array name. If a reference to a statement function appears in scalar-expr, its definition
shall have been provided earlier in the scoping unit and shall not be the name of the statement function being defined.
C1577 (R1544) Named constants in scalar-expr shall have been declared earlier in the scoping unit or made accessible by use
or host association. If array elements appear in scalar-expr, the array shall have been declared as an array earlier in the
scoping unit or made accessible by use or host association.
C1578 (R1544) If a dummy-arg-name, variable, function reference, or dummy function reference is typed by the implicit typing
rules, its appearance in any subsequent type declaration statement shall confirm this implied type and the values of any
implied type parameters.
C1579 (R1544) The function-name and each dummy-arg-name shall be specified, explicitly or implicitly, to be scalar.
C1580 (R1544) A given dummy-arg-name shall not appear more than once in a given dummy-arg-name-list.
C1581 A statement function shall not be of a parameterized derived type.
of its type in a type declaration statement.3 The dummy arguments have a scope of the statement function statement. Each dummy argument has the same type and type
parameters as the entity of the same name in the scoping unit containing the statement function statement.4 A statement function shall not be supplied as an actual argument.
5 Execution of a statement function consists of evaluating the expression using the values of the actual arguments for the values of the
corresponding dummy arguments and, if necessary, converting the result to the declared type and type parameters of the function.6 A function reference in the scalar expression shall not cause a dummy argument of the statement function to become redefined or
undefined.1 A pure procedure is15.7 Pure procedures
• a pure intrinsic procedure (16.1),• a module procedure in an intrinsic module, if it is specified to be pure,
• defined by a pure subprogram,
⃝c ISO/IEC 2017 – All rights reserved 333
ISO/IEC DIS 1539-1:2017 (E)
• a dummy procedure that has been specified to be PURE, or2 A pure subprogram is a subprogram that has the prefix-spec PURE or that has the prefix-spec ELEMENTAL• a statement function that references only pure functions and does not contain the designator of a variable with the VOLATILE
attribute.
and does not have the prefix-spec IMPURE. The following additional constraints apply to pure subprograms.1 An elemental procedure is an elemental intrinsic procedure or a procedure that is defined by an elemental sub-C1582 The specification-part of a pure function subprogram shall specify that all its nonpointer dummy data
objects have the INTENT (IN) or the VALUE attribute.
C1583 The function result of a pure function shall not be such that finalization of a reference to the function
would reference an impure procedure.
C1584 The function result of a pure function shall not be both polymorphic and allocatable, or have a poly-
morphic allocatable ultimate component.
C1585 The specification-part of a pure subroutine subprogram shall specify the intents of all its nonpointer
dummy data objects that do not have the VALUE attribute.
C1586 An INTENT (OUT) dummy argument of a pure procedure shall not be such that finalization of the
actual argument would reference an impure procedure.
C1587 An INTENT (OUT) dummy argument of a pure procedure shall not be polymorphic or have a poly-
morphic allocatable ultimate component.
C1588 A local variable of a pure subprogram, or of a BLOCK construct within a pure subprogram, shall not
have the SAVE or VOLATILE attribute.
NOTE 15.46
Variable initialization in a type-declaration-stmt or a data-stmt implies the SAVE attribute; therefore, such
initialization is also disallowed.
C1589 The specification-part of a pure subprogram shall specify that all its dummy procedures are pure.
C1590 If a procedure that is neither an intrinsic procedure nor a statement function is used in a context that requires
it to be pure, then its interface shall be explicit in the scope of that use. The interface shall specify that
the procedure is pure.
C1591 All internal subprograms in a pure subprogram shall be pure.
C1592 A designator of a variable with the VOLATILE attribute shall not appear in a pure subprogram.
C1593 In a pure subprogram any designator with a base object that is in common or accessed by host or use
association, is a pointer dummy argument of a pure function, is a dummy argument with the INTENT
(IN) attribute, is a coindexed object, or an object that is storage associated with any such variable, shall
not be used
(1) in a variable definition context (19.6.7),
(2) in a pointer association context (19.6.8),
(3) as the data-target in a pointer-assignment-stmt,
(4) as the expr corresponding to a component in a structure-constructor if the component has the
POINTER attribute or has a pointer component at any level of component selection,
(5) as the expr of an intrinsic assignment statement in which the variable is of a derived type if the
derived type has a pointer component at any level of component selection,
(6) as the source-expr in a SOURCE= specifier if the designator is of a derived type that has a pointer
component at any level of component selection,
(7) as an actual argument corresponding to a dummy argument with the POINTER attribute, or
334 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
(8) as the actual argument to the function C_LOC from the intrinsic module ISO_C_BINDING.
NOTE 15.47
Item 5 requires that processors be able to determine if entities with the PRIVATE attribute or with private
components have a pointer component.
C1594 Any procedure referenced in a pure subprogram, including one referenced via a defined operation, defined
assignment, defined input/output, or finalization, shall be pure.
C1595 A statement that might result in the deallocation of a polymorphic entity is not permitted in a pure
procedure.
NOTE 15.48
This includes intrinsic assignment to a variable that has a potential subobject component that is poly-
morphic and allocatable.
C1596 A pure subprogram shall not contain a print-stmt, open-stmt, close-stmt, backspace-stmt, endfile-stmt,
rewind-stmt, flush-stmt, wait-stmt, or inquire-stmt.
C1597 A pure subprogram shall not contain a read-stmt or write-stmt whose io-unit is a file-unit-number or *.
C1598 A pure subprogram shall not contain an image control statement (11.6.1).
NOTE 15.49
The above constraints are designed to guarantee that a pure procedure is free from side effects (modifications
of data visible outside the procedure), which means that it is safe to reference it in constructs such as DO
CONCURRENT and FORALL, where there is no explicit order of evaluation.
The constraints on pure subprograms appear to be complicated, but it is not necessary for a programmer
to be intimately familiar with them. From the programmer’s point of view, these constraints can be
summarized as follows: a pure subprogram cannot contain any operation that could conceivably result in
an assignment or pointer assignment to a common variable, a variable accessed by use or host association, or an
INTENT (IN) dummy argument; nor can a pure subprogram contain any operation that could conceivably
perform any external file input/output or execute an image control statement (including a STOP statement).
Note the use of the word conceivably; it is not sufficient for a pure subprogram merely to be side-effect
free in practice. For example, a function that contains an assignment to a global variable but in a block
that is not executed in any invocation of the function is nevertheless not a pure function. The exclusion of
functions of this nature is required if strict compile-time checking is to be used.
It is expected that most library procedures will conform to the constraints required of pure procedures, and
so can be declared pure and referenced in DO CONCURRENT constructs, FORALL statements and constructs,
and within user-defined pure procedures.
NOTE 15.50
Pure subroutines are included to allow subroutine calls from pure procedures in a safe way, and to allow
forall-assignment-stmts to be defined assignments. The constraints for pure subroutines are based on the same
principles as for pure functions, except that side effects to INTENT (OUT), INTENT (INOUT), and pointer
dummy arguments are permitted.
15.8 Elemental procedures
15.8.1 Elemental procedure declaration and interface
program. An elemental procedure has only scalar dummy arguments, but may have array actual arguments.2 An elemental subprogram has the prefix-spec ELEMENTAL. An elemental subprogram is a pure subprogram⃝c ISO/IEC 2017 – All rights reserved 335
ISO/IEC DIS 1539-1:2017 (E)
unless it has the prefix-spec IMPURE. The following additional constraints apply to elemental subprograms.3 In a reference to an elemental procedure, if any argument is an array, each actual argument that corresponds toC1599 All dummy arguments of an elemental procedure shall be scalar noncoarray dummy data objects and
shall not have the POINTER or ALLOCATABLE attribute.
C15100 The result of an elemental function shall be scalar, and shall not have the POINTER or ALLOCATABLE
attribute.
C15101 The specification-part of an elemental subprogram shall specify the intents of all of its dummy arguments
that do not have the VALUE attribute.
C15102 In the specification-expr that specifies a type parameter value of the result of an elemental function, an
object designator with a dummy argument of the function as the base object shall appear only as the
subject of a specification inquiry (10.1.11), and that specification inquiry shall not depend on a property
that is deferred.
an INTENT (OUT) or INTENT (INOUT) dummy argument shall be an array. All actual arguments shall be1 If a generic name or a specific name is used to reference an elemental function, the shape of the result is theconformable. An array actual argument is considered to be associated with the scalar dummy arguments of the
procedure throughout the entire execution of the elemental reference; thus, the restrictions on actions specified
in 15.5.2.13 apply to the entirety of the actual array argument.
15.8.2 Elemental function actual arguments and results
same as the shape of the actual argument with the greatest rank. If there are no actual arguments or the actual1 In a reference to an elemental subroutine, if the actual arguments corresponding to INTENT (OUT) and INTENTarguments are all scalar, the result is scalar. In the array case, the values of the elements, if any, of the result are
the same as would have been obtained if the scalar function had been applied separately, in array element order,
to corresponding elements of each array actual argument.
NOTE 15.51
An example of an elemental reference to the intrinsic function MAX:
if X and Y are arrays of shape (M, N),
MAX (X, 0.0, Y)
is an array expression of shape (M, N) whose elements have values
MAX (X(I, J), 0.0, Y(I, J)), I = 1, 2, ..., M, J = 1, 2, ..., N
15.8.3 Elemental subroutine actual arguments
(INOUT) dummy arguments are arrays, the values of the elements, if any, of the results are the same as would1 Intrinsic procedures are divided into eight classes: inquiry functions, elemental functions, transformational func-be obtained if the subroutine had been applied separately, in array element order, to corresponding elements of
each array actual argument.
336 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
16 Intrinsic procedures and modules
16.1 Classes of intrinsic procedures
tions, elemental subroutines, pure subroutines, atomic subroutines, collective subroutines, and (impure) sub-2 An intrinsic inquiry function is one whose result depends on the properties of one or more of its arguments insteadroutines.
of their values; in fact, these argument values may be undefined. Unless the description of an intrinsic inquiry3 An atomic subroutine is an intrinsic subroutine that performs an atomic action. The semantics of atomic actionsfunction states otherwise, these arguments are permitted to be unallocated allocatable variables or pointers that
are undefined or disassociated. An elemental intrinsic function is one that is specified for scalar arguments,
but may be applied to array arguments as described in 15.8. All other intrinsic functions are transformational
functions; they almost all have one or more array arguments or an array result. All standard intrinsic functions
are pure.
are described in 16.5.4 A collective subroutine is an intrinsic subroutine that performs a cooperative calculation on a team of images
without requiring synchronization. The semantics of collective subroutines are described in 16.6.5 The subroutine MOVE_ALLOC with noncoarray argument FROM, and the elemental subroutine MVBITS, are
pure. No other standard intrinsic subroutine is pure.6 Generic names of standard intrinsic procedures are listed in 16.7. In most cases, generic functions accept argu-
ments of more than one type and the type of the result is the same as the type of the arguments. Specific names of7 If an intrinsic procedure is used as an actual argument to a procedure, its specific name shall be used and it may be referenced instandard intrinsic functions with corresponding generic names are listed in 16.8.
the called procedure only with scalar arguments. If an intrinsic procedure does not have a specific name, it shall not be used as an8 Elemental intrinsic procedures behave as described in 15.8.actual argument (15.5.2.9).
16.2 Arguments to intrinsic procedures1 All intrinsic procedures may be invoked with either positional arguments or argument keywords (15.5). The16.2.1 General rules
descriptions in 16.7 through 16.9 give the argument keyword names and positional sequence for standard intrinsicprocedures.
2 Many of the intrinsic procedures have optional arguments. These arguments are identified by the notation “optional” in the argument descriptions. In addition, the names of the optional arguments are enclosed in square3 The dummy arguments of the specific intrinsic procedures in 16.8 have INTENT (IN). The dummy arguments of the intrinsicbrackets in description headings and in lists of procedures. The valid forms of reference for procedures with
optional arguments are described in 15.5.2.
NOTE 16.1
The text CMPLX (X [, Y, KIND]) indicates that Y and KIND are both optional arguments. Valid ref-
erence forms include CMPLX(x), CMPLX(x, y), CMPLX(x, KIND=kind), CMPLX(x, y, kind), and CM-
PLX(KIND=kind, X=x, Y=y).
⃝c ISO/IEC 2017 – All rights reserved 337
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.2
Some intrinsic procedures impose additional requirements on their optional arguments. For example, SE-
LECTED_REAL_KIND requires that at least one of its optional arguments be present, and RANDOM_-
SEED requires that at most one of its optional arguments be present.
procedures in 16.9 have INTENT (IN) if the intent is not stated explicitly.4 The actual argument corresponding to an intrinsic function dummy argument named KIND shall be a scalar
integer constant expression and its value shall specify a representation method for the function result that exists5 Intrinsic subroutines that assign values to arguments of type character do so in accordance with the rules ofon the processor.
intrinsic assignment (10.2.1.3).6 In a reference to the intrinsic subroutine MVBITS, the actual arguments corresponding to the TO and FROM
dummy arguments may be the same variable and may be associated scalar variables or associated array variables7 An argument to an intrinsic procedure other than ASSOCIATED, NULL, or PRESENT shall be a data object.all of whose corresponding elements are associated. Apart from this, the actual arguments in a reference to an
intrinsic subroutine shall be such that the execution of the intrinsic subroutine would satisfy the restrictions of
15.5.2.13.
16.2.2 The shape of array arguments1 Unless otherwise specified, the intrinsic inquiry functions accept array arguments for which the shape need not
be defined. The shape of array arguments to transformational and elemental intrinsic functions shall be defined.1 Some array intrinsic functions have an optional MASK argument of type logical that is used by the function to16.2.3 Mask arguments
select the elements of one or more arguments to be operated on by the function. Any element not selected by the2 The MASK affects only the value of the function, and does not affect the evaluation, prior to invoking themask need not be defined at the time the function is invoked.
function, of arguments that are array expressions.1 Some array intrinsic functions are “reduction” functions; that is, they reduce the rank of an array by collapsing16.2.4 DIM arguments and reduction functions
one dimension (or all dimensions, usually producing a scalar result). These functions have a DIM argument that2 The process of reducing a dimension usually combines the selected elements with a simple operation such ascan specify the dimension to be reduced.
addition or an intrinsic function such as MAX, but more sophisticated reductions are also provided, e.g. by1 The bit manipulation procedures are described in terms of a model for the representation and behavior of bitsCOUNT and MAXLOC.
16.3 Bit model
16.3.1 General
on a processor.2 For the purposes of these procedures, a bit is defined to be a binary digit w located at position k of a nonnegative
integer scalar object based on a model nonnegative integer defined by338 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
z−1
X
j= wk × 2k k=0and for which wk may have the value 0 or 1. This defines a sequence of bits wz−1 . . . w0 , with wz−1 the leftmost
bit and w0 the rightmost bit. The positions of bits in the sequence are numbered from right to left, with the
position of the rightmost bit being zero. The length of a sequence of bits is z. An example of a model number
compatible with the examples used in 16.4 would have z = 32, thereby defining a 32-bit integer.
3 The interpretation of a negative integer as a sequence of bits is processor dependent.
4 The inquiry function BIT_SIZE provides the value of the parameter z of the model.
5 Effectively, this model defines an integer object to consist of z bits in sequence numbered from right to left from
0 to z − 1. This model is valid only in the context of the use of such an object as the argument or result of an
intrinsic procedure that interprets that object as a sequence of bits. In all other contexts, the model defined for
an integer in 16.4 applies. In particular, whereas the models are identical for r = 2 and wz−1 = 0, they do not
correspond for r ̸= 2 or wz−1 = 1 and the interpretation of bits in such objects is processor dependent.
16.3.2 Bit sequence comparisons 1 When bit sequences of unequal length are compared, the shorter sequence is considered to be extended to the
length of the longer sequence by padding with zero bits on the left.2 Bit sequences are compared from left to right, one bit at a time, until unequal bits are found or all bits have been
compared and found to be equal. If unequal bits are found, the sequence with zero in the unequal position is1 When a boz-literal-constant is the argument A of the intrinsic function INT or REAL,considered to be less than the sequence with one in the unequal position. Otherwise the sequences are considered
to be equal.
16.3.3 Bit sequences as arguments to INT and REAL
• if the length of the sequence of bits specified by A is less than the size in bits of a scalar variable of theC1601 If a boz-literal-constant is truncated as an argument to the intrinsic function REAL, the discarded bitssame type and kind type parameter as the result, the boz-literal-constant is treated as if it were extended
to a length equal to the size in bits of the result by padding on the left with zero bits, and
• if the length of the sequence of bits specified by A is greater than the size in bits of a scalar variable of the
same type and kind type parameter as the result, the boz-literal-constant is treated as if it were truncated
from the left to a length equal to the size in bits of the result.
shall all be zero.NOTE 16.3
The result values of the intrinsic functions CMPLX and DBLE are defined by references to the intrinsic
function REAL with the same arguments. Therefore, the padding and truncation of boz-literal-constant
arguments to those intrinsic functions is the same as for the intrinsic function REAL.
1 The numeric manipulation and inquiry functions are described in terms of a model for the representation and
16.4 Numeric models
behavior of numbers on a processor. The model has parameters that are determined so as to make the model2 The model set for integer i is defined bybest fit the machine on which the program is executed.
⃝c ISO/IEC 2017 – All rights reserved 339
ISO/IEC DIS 1539-1:2017 (E)
q−1
X
i=s× wk × rk k=0where r is an integer exceeding one, q is a positive integer, each wk is a nonnegative integer less than r, and s is
+1 or −1. The integer parameters r and q determine the set of model integers.
3 The model set for real x is defined by
0 or
p
x= s×b ×where b and p are integers exceeding one; each fk is a nonnegative integer less than b, with f1 nonzero; s is e
fk × b−k
k=1
+1 or −1; and e is an integer that lies between some integer maximum emax and some integer minimum emin
inclusively. For x = 0, its exponent e and digits fk are defined to be zero. The integer parameters b, p, emin , and
emax determine the set of model floating-point numbers.
4 The parameters of the integer and real models are available for each representation method of the integer and real types. The parameters characterize the set of available numbers in the definition of the model. Intrinsic5 There is also an extended model set for each kind of real x; this extended model is the same as the ordinaryfunctions provide the values of some parameters and other values related to the models.
model except that there are no limits on the range of the exponent e.1 An atomic subroutine is an intrinsic subroutine that performs an action on its ATOM argument, and if it has anNOTE 16.4
Some of the function descriptions use the models
X30
i=s× wk × 2k
k=0
and
24
!
1 X
e
x = 0 or s × 2 × + fk × 2−k , −126 ≤ e ≤ 127
2
k=2
16.5 Atomic subroutines
OLD argument, determination of the value to be assigned to that argument, atomically. Definition or evaluation2 For any two executions in unordered segments of atomic subroutines whose ATOM argument is the same object,of any argument other than ATOM is not performed atomically.
the effect is as if one of the executions is performed completely before the other execution begins. Which executionis performed first is processor dependent. The sequence of atomic actions within ordered segments is specified in
5.3.5. If successive atomic subroutine invocations on image P redefine a variable atomically in segments Pi and
Pj , atomic references to that variable from image Q in a segment Qk that is unordered relative to Pi and Pj may
observe the changes in the value of that variable in any order.
3 Atomic operations shall make asynchronous progress. If a variable X on image P is defined by an atomic subroutine on image Q, image R repeatedly references X [P ] by an atomic subroutine in an unordered segment,4 If the STAT argument is present in an invocation of an atomic subroutine and no error condition occurs, it isand no other image defines X [P ] in an unordered segment, image R shall eventually receive the value assigned
340 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
by image Q, even if none of the images P , Q, or R execute an image control statement until after the definition
of X [P ] by image Q and the reception of that value by image R.
assigned the value zero.5 If the STAT argument is present in an invocation of an atomic subroutine and an error condition occurs, any
other argument that is not INTENT (IN) becomes undefined. If the ATOM argument is on a failed image, an6 If the STAT argument is not present in an invocation of an atomic subroutine and an error condition occurs,error condition occurs and the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_-
ENV is assigned to the STAT argument. If any other error condition occurs, the STAT argument is assigned a
processor-dependent positive value that is different from the value of STAT_FAILED_IMAGE.
error termination is initiated.1 Successful execution of a collective subroutine performs a calculation on all the images of the current team andNOTE 16.5
The properties of atomic subroutines are intended to support custom synchronization mechanisms. The
program will need to handle all possible orderings of sequences of atomic subroutine executions that can
arise as a consequence of the above rules; note that the orderings can appear to be different on different
images even in the same program execution.
16.6 Collective subroutines
assigns a computed value on one or all of them. If it is invoked by one image, it shall be invoked by the same2 Before execution of the first CHANGE TEAM statement on an image, in between executions of CHANGEstatement on all active images of its current team in segments that are not ordered with respect to each other;
corresponding references participate in the same collective computation.
TEAM and/or END TEAM statements, and after the last execution of an END TEAM statement, the sequence3 If the A argument in a reference to a collective subroutine is a coarray, the corresponding ultimate arguments onof invocations of collective subroutines shall be the same on all active images of a team. A collective subroutine
shall not be referenced when an image control statement is not permitted to be executed (for example, in a
procedure invoked from a CRITICAL construct).
C1602 A reference to a collective subroutine shall not appear in a context where an image control statement is
not permitted to appear.
all active images of the current team shall be corresponding coarrays as described in 5.4.7.4 If the STAT argument is present in a reference to a collective subroutine on one image, it shall be present on all
the corresponding references.5 If the STAT argument is present in a reference to a collective subroutine and its execution is successful, it is
assigned the value zero.6 If the STAT argument is present in a reference to a collective subroutine and an error condition occurs, it is
assigned a positive value and the A argument becomes undefined.7 If the STAT argument is present and the current team contains stopped images, an error condition occurs and
the value STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV is assigned to the STAT8 If the STAT argument is not present in a reference to a collective subroutine and an error condition occurs, errorargument. Otherwise, if the current team contained failed images, an error condition occurs and the value
STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV is assigned to the STAT argument.
If any other error condition occurs, the STAT argument is assigned a processor-dependent positive value that is
different from the value of STAT_STOPPED_IMAGE or STAT_FAILED_IMAGE.
termination is initiated.9 If the ERRMSG argument is present in a reference to a collective subroutine and an error condition occurs, it is⃝c ISO/IEC 2017 – All rights reserved 341
ISO/IEC DIS 1539-1:2017 (E)
assigned an explanatory message, truncated or padded with blanks if required. If no error condition occurs, the1 For all of the standard intrinsic procedures, the arguments shown are the names that shall be used for argumentdefinition status and value of ERRMSG are unchanged.
NOTE 16.6
The argument A becomes undefined if an error condition occurs during execution of a collective subroutine
because it is intended to allow the processor to use A for intermediate values during calculation.
NOTE 16.7
Although the calculations performed by a collective subroutine have some internal synchronizations, a
reference to a collective subroutine is not an image control statement.
16.7 Standard generic intrinsic procedures
keywords if the keyword form is used for actual arguments.2 In the Class column of Table 16.1,NOTE 16.8
For example, a reference to CMPLX can be written in the form CMPLX (A, B, M) or in the form CM-
PLX (Y = B, KIND = M, X = A).
NOTE 16.9
Many of the argument keywords have names that are indicative of their usage. For example:
KIND Describes the kind type parameter of the result
STRING, STRING_A An arbitrary character string
BACK Controls the direction of string scan
(forward or backward)
MASK A mask to be applied to the arguments
DIM A selected dimension of an array argument
A indicates that the procedure is an atomic subroutine,C indicates that the procedure is a collective subroutine,
E indicates that the procedure is an elemental function,
ES indicates that the procedure is an elemental subroutine, I indicates that the procedure is an inquiry function,
PS indicates that the procedure is a pure subroutine when the FROM argument is not a coarray, S indicates that the procedure is an impure subroutine, andT indicates that the procedure in a transformational function.
Table 16.1: Standard generic intrinsic procedure summary
Procedure Arguments Class Description
ABS (A) E Absolute value.
ACHAR (I [, KIND]) E Character from ASCII code value.
ACOS (X) E Arccosine (inverse cosine) function.
ACOSH (X) E Inverse hyperbolic cosine function.
ADJUSTL (STRING) E Left-justified string value.
ADJUSTR (STRING) E Right-justified string value.
AIMAG (Z) E Imaginary part of a complex number.
AINT (A [, KIND]) E Truncation toward 0 to a whole number.
342 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Table 16.1: Standard generic intrinsic procedure summary (cont.)
Procedure Arguments Class Description
ALL (MASK) or (MASK, DIM) T Array reduced by .AND. operator. ALLOCATED (ARRAY) or (SCALAR) I Allocation status of allocatable variable. ANINT (A [, KIND]) E Nearest whole number. ANY (MASK) or (MASK, DIM) T Array reduced by .OR. operator. ASIN (X) E Arcsine (inverse sine) function. ASINH (X) E Inverse hyperbolic sine function. ASSOCIATED (POINTER [, TARGET]) I Pointer association status inquiry. ATAN (X) or (Y, X) E Arctangent (inverse tangent) function. ATAN2 (Y, X) E Arctangent (inverse tangent) function. ATANH (X) E Inverse hyperbolic tangent function. ATOMIC_ADD (ATOM, VALUE [, STAT]) A Atomic addition. ATOMIC_AND (ATOM, VALUE [, STAT]) A Atomic bitwise AND. ATOMIC_CAS (ATOM, OLD, COMPARE, A Atomic compare and swap. VALUE [, STAT])
ATOMIC_DEFINE (ATOM, VALUE [, STAT]) A Define a variable atomically. ATOMIC_FETCH_- (ATOM, VALUE, OLD A Atomic fetch and add. ADD [, STAT]) ATOMIC_FETCH_- (ATOM, VALUE, OLD A Atomic fetch and bitwise AND. AND [, STAT]) ATOMIC_FETCH_- (ATOM, VALUE, OLD A Atomic fetch and bitwise OR. OR [, STAT]) ATOMIC_FETCH_- (ATOM, VALUE, OLD A Atomic fetch and bitwise exclusive OR. XOR [, STAT]) ATOMIC_OR (ATOM, VALUE [, STAT]) A Atomic bitwise OR. ATOMIC_REF (VALUE, ATOM [, STAT]) A Reference a variable atomically. ATOMIC_XOR (ATOM, VALUE [, STAT]) A Atomic bitwise exclusive OR. BESSEL_J0 (X) E Bessel function of the 1st kind, order 0. BESSEL_J1 (X) E Bessel function of the 1st kind, order 1. BESSEL_JN (N, X) E Bessel function of the 1st kind, order N. BESSEL_JN (N1, N2, X) T Bessel functions of the 1st kind. BESSEL_Y0 (X) E Bessel function of the 2nd kind, order 0. BESSEL_Y1 (X) E Bessel function of the 2nd kind, order 1. BESSEL_YN (N, X) E Bessel function of the 2nd kind, order N. BESSEL_YN (N1, N2, X) T Bessel functions of the 2nd kind. BGE (I, J) E Bitwise greater than or equal to. BGT (I, J) E Bitwise greater than. BIT_SIZE (I) I Number of bits in integer model 16.3. BLE (I, J) E Bitwise less than or equal to. BLT (I, J) E Bitwise less than. BTEST (I, POS) E Test single bit in an integer. CEILING (A [, KIND]) E Least integer greater than or equal to A. CHAR (I [, KIND]) E Character from code value. CMPLX (X [, KIND]) or E Conversion to complex type. (X [, Y, KIND])
CO_BROADCAST (A, SOURCE_IMAGE [, C Broadcast value to images. STAT, ERRMSG])
CO_MAX (A [, RESULT_IMAGE, C Compute maximum value across images. STAT, ERRMSG])
CO_MIN (A [, RESULT_IMAGE, C Compute minimum value across images. STAT, ERRMSG])
CO_REDUCE (A, OPERATION [, C Generalized reduction across images. RESULT_IMAGE, STAT,⃝ERRMSG])
c ISO/IEC 2017 – All rights reserved 343
ISO/IEC DIS 1539-1:2017 (E)
Table 16.1: Standard generic intrinsic procedure summary (cont.)
Procedure Arguments Class Description CO_SUM (A [, RESULT_IMAGE, C Compute sum across images. STAT, ERRMSG])
COMMAND_ARGU- ( ) T Number of command arguments. MENT_COUNT
CONJG (Z) E Conjugate of a complex number. COS (X) E Cosine function. COSH (X) E Hyperbolic cosine function. COSHAPE (COARRAY [, KIND]) I Sizes of codimensions of a coarray. COUNT (MASK [, DIM, KIND]) T Logical array reduced by counting true values.
CPU_TIME (TIME) S Processor time used. CSHIFT (ARRAY, SHIFT [, DIM]) T Circular shift of an array. DATE_AND_TIME ([DATE, TIME, ZONE, S Date and time. VALUES])
DBLE (A) E Conversion to double precision real. DIGITS (X) I Significant digits in numeric model. DIM (X, Y) E Maximum of X − Y and zero. DOT_PRODUCT (VECTOR_A, T Dot product of two vectors. VECTOR_B)
DPROD (X, Y) E Double precision real product. DSHIFTL (I, J, SHIFT) E Combined left shift. DSHIFTR (I, J, SHIFT) E Combined right shift. EOSHIFT (ARRAY, SHIFT [, T End-off shift of the elements of an array. BOUNDARY, DIM])
EPSILON (X) I Model number that is small compared to 1.
ERF (X) E Error function. ERFC (X) E Complementary error function. ERFC_SCALED (X) E Scaled complementary error function. EVENT_QUERY (EVENT, COUNT [, STAT]) S Query event count. EXECUTE_COM- (COMMAND [, WAIT, S Execute a command line. MAND_LINE EXITSTAT, CMDSTAT, CMDMSG])
EXP (X) E Exponential function. EXPONENT (X) E Exponent of floating-point number. EXTENDS_TYPE_- (A, MOLD) I Dynamic type extension inquiry. OF
FAILED_IMAGES ([TEAM, KIND]) T Indices of failed images. FINDLOC (ARRAY, VALUE, DIM [, T Location(s) of a specified value. MASK, KIND, BACK]) or(ARRAY, VALUE [, MASK,
KIND, BACK])
FLOOR (A [, KIND]) E Greatest integer less than or equal to A. FRACTION (X) E Fractional part of number. GAMMA (X) E Gamma function. GET_COMMAND ([COMMAND, LENGTH, S Get program invocation command. STATUS, ERRMSG])
GET_COMMAND_- (NUMBER [, VALUE, S Get program invocation argument. ARGUMENT LENGTH, STATUS, ERRMSG])
GET_ENVIRON- (NAME [, VALUE, S Get environment variable. MENT_VARIABLE LENGTH, STATUS, TRIM_NAME, ERRMSG])
344 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Table 16.1: Standard generic intrinsic procedure summary (cont.) Procedure Arguments Class Description
GET_TEAM ([LEVEL]) T Team. HUGE (X) I Largest model number. HYPOT (X, Y) E Euclidean distance function. IACHAR (C [, KIND]) E ASCII code value for character. IALL (ARRAY, DIM [, MASK]) or T Array reduced by IAND function. (ARRAY [, MASK])
IAND (I, J) E Bitwise AND. IANY (ARRAY, DIM [, MASK]) or T Array reduced by IOR function. (ARRAY [, MASK])
IBCLR (I, POS) E I with bit POS replaced by zero. IBITS (I, POS, LEN) E Specified sequence of bits. IBSET (I, POS) E I with bit POS replaced by one. ICHAR (C [, KIND]) E Code value for character. IEOR (I, J) E Bitwise exclusive OR. IMAGE_INDEX (COARRAY, SUB) or I Image index from cosubscripts. (COARRAY, SUB, TEAM)or (COARRAY, SUB,
TEAM_NUMBER)
IMAGE_STATUS (IMAGE [, TEAM]) T Image execution state. INDEX (STRING, SUBSTRING [, E Character string search. BACK, KIND])
INT (A [, KIND]) E Conversion to integer type. IOR (I, J) E Bitwise inclusive OR. IPARITY (ARRAY, DIM [, MASK]) or T Array reduced by IEOR function. (ARRAY [, MASK])
ISHFT (I, SHIFT) E Logical shift. ISHFTC (I, SHIFT [, SIZE]) E Circular shift of the rightmost bits. IS_CONTIGUOUS (ARRAY) I Array contiguity test (8.5.7). IS_IOSTAT_END (I) E IOSTAT value test for end of file. IS_IOSTAT_EOR (I) E IOSTAT value test for end of record. KIND (X) I Value of the kind type parameter of X. LBOUND (ARRAY [, DIM, KIND]) I Lower bound(s). LCOBOUND (COARRAY [, DIM, KIND]) I Lower cobound(s) of a coarray. LEADZ (I) E Number of leading zero bits. LEN (STRING [, KIND]) I Length of a character entity. LEN_TRIM (STRING [, KIND]) E Length without trailing blanks. LGE (STRING_A, STRING_B) E ASCII greater than or equal. LGT (STRING_A, STRING_B) E ASCII greater than. LLE (STRING_A, STRING_B) E ASCII less than or equal. LLT (STRING_A, STRING_B) E ASCII less than. LOG (X) E Natural logarithm. LOG_GAMMA (X) E Logarithm of the absolute value of the gamma function.
LOG10 (X) E Common logarithm. LOGICAL (L [, KIND]) E Conversion between kinds of logical. MASKL (I [, KIND]) E Left justified mask. MASKR (I [, KIND]) E Right justified mask. MATMUL (MATRIX_A, MATRIX_B) T Matrix multiplication. MAX (A1, A2 [, A3, ...]) E Maximum value. MAXEXPONENT (X) I Maximum exponent of a real model. MAXLOC (ARRAY, DIM [, MASK, T Location(s) of maximum value. KIND, BACK]) or (ARRAY⃝[, MASK, KIND, BACK])
c ISO/IEC 2017 – All rights reserved 345
ISO/IEC DIS 1539-1:2017 (E)
Table 16.1: Standard generic intrinsic procedure summary (cont.)
Procedure Arguments Class Description MAXVAL (ARRAY, DIM [, MASK]) or T Maximum value(s) of array. (ARRAY [, MASK])
MERGE (TSOURCE, FSOURCE, E Expression value selection. MASK)
MERGE_BITS (I, J, MASK) E Merge of bits under mask. MIN (A1, A2 [, A3, ...]) E Minimum value. MINEXPONENT (X) I Minimum exponent of a real model. MINLOC (ARRAY, DIM [, MASK, T Location(s) of minimum value. KIND, BACK]) or (ARRAY[, MASK, KIND, BACK])
MINVAL (ARRAY, DIM [, MASK]) or T Minimum value(s) of array. (ARRAY [, MASK])
MOD (A, P) E Remainder function. MODULO (A, P) E Modulo function. MOVE_ALLOC (FROM, TO [, STAT, PS Move an allocation. ERRMSG])
MVBITS (FROM, FROMPOS, LEN, ES Copy a sequence of bits. TO, TOPOS)
NEAREST (X, S) E Adjacent machine number. NEW_LINE (A) I Newline character. NINT (A [, KIND]) E Nearest integer. NORM2 (X) or (X, DIM) T L2 norm of an array. NOT (I) E Bitwise complement. NULL ([MOLD]) T Disassociated pointer or unallocated al- locatable entity.
NUM_IMAGES ( ) or (TEAM) or (TEAM_- T Number of images. NUMBER)
OUT_OF_RANGE (X, MOLD [, ROUND]) E Whether a value cannot be converted safely.
PACK (ARRAY, MASK [, T Array packed into a vector. VECTOR])
PARITY (MASK) or (MASK, DIM) T Array reduced by .NEQV. operator. POPCNT (I) E Number of one bits. POPPAR (I) E Parity expressed as 0 or 1. PRECISION (X) I Decimal precision of a real model. PRESENT (A) I Presence of optional argument. PRODUCT (ARRAY, DIM [, MASK]) or T Array reduced by multiplication. (ARRAY [, MASK])
RADIX (X) I Base of a numeric model. RANDOM_INIT (REPEATABLE, IMAGE_- S Initialise the pseudorandom number DISTINCT) generator.
RANDOM_NUMBER (HARVEST) S Generate pseudorandom number(s). RANDOM_SEED ([SIZE, PUT, GET]) S Restart or query the pseudorandom number generator.
RANGE (X) I Decimal exponent range of a numeric model (16.4).
RANK (A) I Rank of a data object. REAL (A [, KIND]) E Conversion to real type. REDUCE (ARRAY, OPERATION, T General reduction of array DIM [, MASK, IDENTITY,ORDERED]) or (ARRAY,
OPERATION [, MASK,
IDENTITY, ORDERED])
346 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Table 16.1: Standard generic intrinsic procedure summary (cont.) Procedure Arguments Class Description
REPEAT (STRING, NCOPIES) T Repetitive string concatenation. RESHAPE (SOURCE, SHAPE [, PAD, T Arbitrary shape array construction. ORDER])
RRSPACING (X) E Reciprocal of relative spacing of model numbers.
SAME_TYPE_AS (A, B) I Dynamic type equality test. SCALE (X, I) E Real number scaled by radix power. SCAN (STRING, SET [, BACK, E Character set membership search. KIND])
SELECTED_CHAR_- (NAME) T Character kind selection. KIND
SELECTED_INT_- (R) T Integer kind selection. KIND
SELECTED_REAL_- ([P, R, RADIX]) T Real kind selection. KIND
SET_EXPONENT (X, I) E Real value with specified exponent. SHAPE (SOURCE [, KIND]) I Shape of an array or a scalar. SHIFTA (I, SHIFT) E Right shift with fill. SHIFTL (I, SHIFT) E Left shift. SHIFTR (I, SHIFT) E Right shift. SIGN (A, B) E Magnitude of A with the sign of B. SIN (X) E Sine function. SINH (X) E Hyperbolic sine function. SIZE (ARRAY [, DIM, KIND]) I Size of an array or one extent. SPACING (X) E Spacing of model numbers. SPREAD (SOURCE, DIM, NCOPIES) T Value replicated in a new dimension. SQRT (X) E Square root. STOPPED_IMAGES ([TEAM, KIND]) T Indices of stopped images. STORAGE_SIZE (A [, KIND]) I Storage size in bits. SUM (ARRAY, DIM [, MASK]) or T Array reduced by addition. (ARRAY [, MASK])
SYSTEM_CLOCK ([COUNT, COUNT_RATE, S Query system clock. COUNT_MAX])
TAN (X) E Tangent function. TANH (X) E Hyperbolic tangent function. TEAM_NUMBER ([TEAM]) T Team number. THIS_IMAGE ([TEAM]) T Index of the invoking image. THIS_IMAGE (COARRAY [, TEAM]) or T Cosubscript(s) for this image. (COARRAY, DIM [,TEAM])
TINY (X) I Smallest positive model number. TRAILZ (I) E Number of trailing zero bits. TRANSFER (SOURCE, MOLD [, SIZE]) T Transfer physical representation. TRANSPOSE (MATRIX) T Transpose of an array of rank two. TRIM (STRING) T String without trailing blanks. UBOUND (ARRAY [, DIM, KIND]) I Upper bound(s). UCOBOUND (COARRAY [, DIM, KIND]) I Upper cobound(s) of a coarray. UNPACK (VECTOR, MASK, FIELD) T Vector unpacked into an array. VERIFY (STRING, SET [, BACK, E Character set non-membership search. KIND])3 The effect of calling EXECUTE_COMMAND_LINE on any image other than image 1 in the initial team is
processor dependent.4 If RANDOM_INIT or RANDOM_SEED is called in a segment A, and RANDOM_INIT, RANDOM_SEED, or⃝c ISO/IEC 2017 – All rights reserved 347
ISO/IEC DIS 1539-1:2017 (E)
RANDOM_NUMBER is called in segment B, then segments A and B shall be ordered. It is processor dependent5 The use of all other standard intrinsic procedures in unordered segments is subject only to their argument usewhether each image uses a separate random number generator, or if some or all images use common random
number generators.
following the rules in 11.6.2.1 Except for AMAX0, AMIN0, MAX1, and MIN1, the result type of the specific function is the same that the result type of the16.8 Specific names for standard intrinsic functions
corresponding generic function reference would be if it were invoked with the same arguments as the specific function.2 A function listed in Table 16.3 is not permitted to be used as an actual argument (15.5.1, C1534), as a target in a procedure
pointer assignment statement (10.2.2.2, C1030), as an initial target in a procedure declaration statement (15.4.3.6, C1519), or to1 Detailed specifications of the standard generic intrinsic procedures are provided in 16.9 in alphabetical order.specify an interface (15.4.3.6, C1515).
Table 16.2: Unrestricted specific intrinsic functions
Specific name Generic name Argument type and kind
ABS ABS default real
ACOS ACOS default real
AIMAG AIMAG default complex
AINT AINT default real
ALOG LOG default real
ALOG10 LOG10 default real
AMOD MOD default real
ANINT ANINT default real
ASIN ASIN default real
ATAN ATAN (X) default real
ATAN2 ATAN2 default real
CABS ABS default complex
CCOS COS default complex
CEXP EXP default complex
CLOG LOG default complex
CONJG CONJG default complex
COS COS default real
COSH COSH default real
CSIN SIN default complex
CSQRT SQRT default complex
DABS ABS double precision real
DACOS ACOS double precision real
DASIN ASIN double precision real
DATAN ATAN double precision real
DATAN2 ATAN2 double precision real
DCOS COS double precision real
DCOSH COSH double precision real
DDIM DIM double precision real
DEXP EXP double precision real
DIM DIM default real
DINT AINT double precision real
DLOG LOG double precision real
DLOG10 LOG10 double precision real
DMOD MOD double precision real
DNINT ANINT double precision real
DPROD DPROD default real
DSIGN SIGN double precision real
DSIN SIN double precision real
DSINH SINH double precision real
DSQRT SQRT double precision real
DTAN TAN double precision real
DTANH TANH double precision real
EXP EXP default real
IABS ABS default integer
IDIM DIM default integer
IDNINT NINT double precision real
INDEX INDEX default character
348 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Unrestricted specific intrinsic functions (cont.)
Specific name Generic name Argument type and kind
ISIGN SIGN default integer
LEN LEN default character
MOD MOD default integer
NINT NINT default real
SIGN SIGN default real
SIN SIN default real
SINH SINH default real
SQRT SQRT default real
TAN TAN default real
TANH TANH default real
Table 16.3: Restricted specific intrinsic functions
Specific name Generic name Argument type and kind
AMAX0 (. . . ) REAL (MAX (. . . )) default integer
AMAX1 MAX default real
AMIN0 (. . . ) REAL (MIN (. . . )) default integer
AMIN1 MIN default real
CHAR CHAR default integer
DMAX1 MAX double precision real
DMIN1 MIN double precision real
FLOAT REAL default integer
ICHAR ICHAR default character
IDINT INT double precision real
IFIX INT default real
INT INT default real
LGE LGE default character
LGT LGT default character
LLE LLE default character
LLT LLT default character
MAX0 MAX default integer
MAX1 (. . . ) INT (MAX (. . . )) default real
MIN0 MIN default integer
MIN1 (. . . ) INT (MIN (. . . )) default real
REAL REAL default integer
SNGL REAL double precision real
16.9 Specifications of the standard intrinsic procedures
16.9.1 General
2 The types and type parameters of standard intrinsic procedure arguments and function results are determined
by these specifications. The “Argument(s)” paragraphs specify requirements on the actual arguments of the3 If an IEEE infinity is assigned or returned by an intrinsic procedure, the intrinsic module IEEE_ARITHMETICprocedures. The result characteristics are sometimes specified in terms of the characteristics of the arguments. A
program shall not invoke an intrinsic procedure under circumstances where a value to be assigned to a subroutine
argument or returned as a function result is not representable by objects of the specified type and type parameters.
is accessible, and the actual arguments were finite numbers, the flag IEEE_OVERFLOW or IEEE_DIVIDE_-1 Description. Absolute value.BY_ZERO shall signal. If an IEEE NaN is assigned or returned, the actual arguments were finite numbers, the
intrinsic module IEEE_ARITHMETIC is accessible, and the exception IEEE_INVALID is supported, the flag
IEEE_INVALID shall signal. If no IEEE infinity or NaN is assigned or returned, these flags shall have the same
status as when the intrinsic procedure was invoked.
⃝c ISO/IEC 2017 – All rights reserved 349
ISO/IEC DIS 1539-1:2017 (E)
16.9.2 ABS (A)
2 Class. Elemental function.
3 Argument. A shall be of type integer, real, or complex.
4 Result Characteristics. The same as A except that if A is complex, the result is real.
5 Result Value. If A is of type integer or real, the value of thep result is |A|; if A is complex with value (x, y), the result is equal to a processor-dependent approximation to x2 + y 2 computed without undue overflow or6 Example. ABS ((3.0, 4.0)) has the value 5.0 (approximately).underflow.
16.9.3 ACHAR (I [, KIND])1 Description. Character from ASCII code value.
2 Class. Elemental function. 3 Arguments. I shall be of type integer.4 Result Characteristics. Character of length one. If KIND is present, the kind type parameter is that specifiedKIND (optional) shall be a scalar integer constant expression.
by the value of KIND; otherwise, the kind type parameter is that of default character.5 Result Value. If I has a value in the range 0 ≤ I ≤ 127, the result is the character in position I of the ASCII
collating sequence, provided the processor is capable of representing that character in the character kind of the6 Example. ACHAR (88) has the value ’X’.result; otherwise, the result is processor dependent. ACHAR (IACHAR (C)) shall have the value C for any
character C capable of representation as a default character.
16.9.4 ACOS (X)1 Description. Arccosine (inverse cosine) function.
2 Class. Elemental function. 3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1, or of type complex. 4 Result Characteristics. Same as X. 5 Result Value. The result has a value equal to a processor-dependent approximation to arccos(X). If it is real it is expressed in radians and lies in the range 0 ≤ ACOS (X) ≤ π. If it is complex the real part is expressed in6 Example. ACOS (0.54030231) has the value 1.0 (approximately).radians and lies in the range 0 ≤ REAL (ACOS (X)) ≤ π.
16.9.5 ACOSH (X)1 Description. Inverse hyperbolic cosine function.
2 Class. Elemental function. 3 Argument. X shall be of type real or complex. 350 ⃝4 Result Characteristics. Same as X.c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic cosine function of X. If the result is complex the imaginary part is expressed in radians and lies in the range6 Example. ACOSH (1.5430806) has the value 1.0 (approximately).0 ≤ AIMAG (ACOSH (X)) ≤ π
16.9.6 ADJUSTL (STRING)1 Description. Left-justified string value.
2 Class. Elemental function. 3 Argument. STRING shall be of type character. 4 Result Characteristics. Character of the same length and kind type parameter as STRING. 5 Result Value. The value of the result is the same as STRING except that any leading blanks have been deleted and the same number of trailing blanks have been inserted.6 Example. ADJUSTL (’ WORD’) has the value ’WORD ’.
16.9.7 ADJUSTR (STRING)1 Description. Right-justified string value.
2 Class. Elemental function. 3 Argument. STRING shall be of type character. 4 Result Characteristics. Character of the same length and kind type parameter as STRING. 5 Result Value. The value of the result is the same as STRING except that any trailing blanks have been deleted and the same number of leading blanks have been inserted.6 Example. ADJUSTR (’WORD ’) has the value ’ WORD’.
16.9.8 AIMAG (Z)1 Description. Imaginary part of a complex number.
2 Class. Elemental function. 3 Argument. Z shall be of type complex. 4 Result Characteristics. Real with the same kind type parameter as Z. 5 Result Value. If Z has the value (x, y), the result has the value y. 6 Example. AIMAG ((2.0, 3.0)) has the value 3.0. 16.9.9 AINT (A [, KIND])1 Description. Truncation toward 0 to a whole number.
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Result Characteristics. The result is of type real. If KIND is present, the kind type parameter is that specifiedKIND (optional) shall be a scalar integer constant expression.
⃝c ISO/IEC 2017 – All rights reserved 351
ISO/IEC DIS 1539-1:2017 (E)
by the value of KIND; otherwise, the kind type parameter is that of A.5 Result Value. If |A| < 1, AINT (A) has the value 0; if |A| ≥ 1, AINT (A) has a value equal to the integer
whose magnitude is the largest integer that does not exceed the magnitude of A and whose sign is the same as6 Examples. AINT (2.783) has the value 2.0. AINT (−2.783) has the value −2.0.the sign of A.
16.9.10 ALL (MASK) or ALL (MASK, DIM)1 Description. Array reduced by .AND. operator.
2 Class. Transformational function. 3 Arguments. MASK shall be a logical array.4 Result Characteristics. The result is of type logical with the same kind type parameter as MASK. It is scalarDIM shall be an integer scalar with value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.
if DIM does not appear or n = 1; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 ,5 Result Value.. . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of MASK.
Case (i): The result of ALL (MASK) has the value true if all elements of MASK are true or if MASK has6 Examples.size zero, and the result has value false if any element of MASK is false.
Case (ii): If MASK has rank one, ALL (MASK, DIM) is equal to ALL (MASK). Otherwise, the value of
element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of ALL (MASK, DIM) is equal to ALL (MASK (s1 ,
s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )).
Case (i): The value of ALL ([.TRUE., .FALSE., .TRUE.]) is false.1 Description. Allocation status of allocatable variable.
1 3 5 0 3 5
Case (ii): If B is the array and C is the array then ALL (B /= C, DIM = 1) is
2 4 6 7 4 8
[true, false, false] and ALL (B /= C, DIM = 2) is [false, false].
16.9.11 ALLOCATED (ARRAY) or ALLOCATED (SCALAR)
2 Class. Inquiry function. 3 Arguments. ARRAY shall be an allocatable array.4 Result Characteristics. Default logical scalar.SCALAR shall be an allocatable scalar.
5 Result Value. The result has the value true if the argument (ARRAY or SCALAR) is allocated and has the value false if the argument is unallocated.1 Description. Nearest whole number.16.9.12 ANINT (A [, KIND])
2 Class. Elemental function. 352 ⃝3 Arguments.c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
A shall be of type real.4 Result Characteristics. The result is of type real. If KIND is present, the kind type parameter is that specifiedKIND (optional) shall be a scalar integer constant expression.
by the value of KIND; otherwise, the kind type parameter is that of A.5 Result Value. The result is the integer nearest A, or if there are two integers equally near A, the result is
whichever such integer has the greater magnitude.6 Examples. ANINT (2.783) has the value 3.0. ANINT (−2.783) has the value −3.0.
16.9.13 ANY (MASK) or ANY (MASK, DIM)1 Description. Array reduced by .OR. operator.
2 Class. Transformational function. 3 Arguments. MASK shall be a logical array.4 Result Characteristics. The result is of type logical with the same kind type parameter as MASK. It is scalarDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.
if DIM does not appear or n = 1; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 ,5 Result Value.. . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of MASK.
Case (i): The result of ANY (MASK) has the value true if any element of MASK is true and has the value6 Examples.false if no elements are true or if MASK has size zero.
Case (ii): If MASK has rank one, ANY (MASK, DIM) is equal to ANY (MASK). Otherwise, the value of
element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of ANY (MASK, DIM) is equal to ANY (MASK (s1 ,
s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )).
Case (i): The value of ANY ([.TRUE., .FALSE., .TRUE.]) is true.1 Description. Arcsine (inverse sine) function.
1 3 5 0 3 5
Case (ii): If B is the array and C is the array then ANY (B /= C, DIM = 1) is
2 4 6 7 4 8
[true, false, true] and ANY (B /= C, DIM = 2) is [true, true].
16.9.14 ASIN (X)
2 Class. Elemental function. 3 Argument. X shall be of type real with a value that satisfies the inequality |X| ≤ 1, or of type complex. 4 Result Characteristics. Same as X. 5 Result Value. The result has a value equal to a processor-dependent approximation to arcsin(X). If it is real it is expressed in radians and lies in the range −π/2 ≤ ASIN (X) ≤ π/2. If it is complex the real part is expressed6 Example. ASIN (0.84147098) has the value 1.0 (approximately).in radians and lies in the range −π/2 ≤ REAL (ASIN (X)) ≤ π/2.
⃝c ISO/IEC 2017 – All rights reserved 3531 Description. Inverse hyperbolic sine function.
ISO/IEC DIS 1539-1:2017 (E)
16.9.15 ASINH (X)
2 Class. Elemental function. 3 Argument. X shall be of type real or complex. 4 Result Characteristics. Same as X. 5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic sine function of X. If the result is complex the imaginary part is expressed in radians and lies in the range6 Example. ASINH (1.1752012) has the value 1.0 (approximately).−π/2 ≤ AIMAG (ASINH (X)) ≤ π/2.
16.9.16 ASSOCIATED (POINTER [, TARGET])1 Description. Pointer association status inquiry.
2 Class. Inquiry function. 3 Arguments. POINTER shall be a pointer. It may be of any type or may be a procedure pointer. Its pointer association4 Result Characteristics. Default logical scalar.status shall not be undefined.
TARGET (optional) shall be allowable as the data-target or proc-target in a pointer assignment statement (10.2.2)
in which POINTER is data-pointer-object or proc-pointer-object. If TARGET is a pointer then its
pointer association status shall not be undefined.
5 Result Value. Case (i): If TARGET is absent, the result is true if and only if POINTER is associated with a target.6 Examples. ASSOCIATED (CURRENT, HEAD) is true if CURRENT is associated with the target HEAD.Case (ii): If TARGET is present and is a procedure, the result is true if and only if POINTER is associated
with TARGET and, if TARGET is an internal procedure, they have the same host instance.
Case (iii): If TARGET is present and is a procedure pointer, the result is true if and only if POINTER and
TARGET are associated with the same procedure and, if the procedure is an internal procedure,
they have the same host instance.
Case (iv): If TARGET is present and is a scalar target, the result is true if and only if TARGET is not a zero-
sized storage sequence and POINTER is associated with a target that occupies the same storage
units as TARGET.
Case (v): If TARGET is present and is an array target, the result is true if and only if POINTER is associated
with a target that has the same shape as TARGET, is neither of size zero nor an array whose elements
are zero-sized storage sequences, and occupies the same storage units as TARGET in array element
order.
Case (vi): If TARGET is present and is a scalar pointer, the result is true if and only if POINTER and
TARGET are associated, the targets are not zero-sized storage sequences, and they occupy the
same storage units.
Case (vii): If TARGET is present and is an array pointer, the result is true if and only if POINTER and
TARGET are both associated, have the same shape, are neither of size zero nor arrays whose
elements are zero-sized storage sequences, and occupy the same storage units in array element
order.
354 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.10
The references to TARGET in the above cases are referring to properties that might be possessed by the
actual argument, so the case of TARGET being a disassociated pointer will be covered by case (iii), (vi),
or (vii).
After the execution of1 Description. Arctangent (inverse tangent) function.A_PART => A (:N)
ASSOCIATED (A_PART, A) is true if N is equal to UBOUND (A, DIM = 1). After the execution of
NULLIFY (CUR); NULLIFY (TOP)
ASSOCIATED (CUR, TOP) is false.
16.9.17 ATAN (X) or ATAN (Y, X)
2 Class. Elemental function. 3 Arguments. Y shall be of type real.4 Result Characteristics. Same as X.X If Y appears, X shall be of type real with the same kind type parameter as Y. If Y has the value
zero, X shall not have the value zero. If Y does not appear, X shall be of type real or complex.
5 Result Value. If Y appears, the result is the same as the result of ATAN2 (Y,X). If Y does not appear, the result has a value equal to a processor-dependent approximation to arctan(X) whose real part is expressed in6 Example. ATAN (1.5574077) has the value 1.0 (approximately).radians and lies in the range −π/2 ≤ ATAN (X) ≤ π/2.
16.9.18 ATAN2 (Y, X)1 Description. Arctangent (inverse tangent) function.
2 Class. Elemental function. 3 Arguments. Y shall be of type real.4 Result Characteristics. Same as X.X shall be of the same type and kind type parameter as Y. If Y has the value zero, X shall not have
the value zero.
5 Result Value. The result has a value equal to a processor-dependent approximation to the principal value of the argument of the complex number (X, Y), expressed in radians. It lies in the range −π ≤ ATAN2 (Y,X)≤ π and is equal to a processor-dependent approximation to a value of arctan(Y/X) if X ̸= 0. If Y > 0, the
result is positive. If Y = 0 and X > 0, the result is Y. If Y = 0 and X < 0, then the result is approximately
π if Y is positive real zero or the processor does not distinguish between positive and negative real zero, and
approximately −π if Y is negative real zero. If Y < 0, the result is negative. If X = 0, the absolute value of the
result is approximately π/2.
1 1
6 Examples. ATAN2 (1.5574077, 1.0) has the value 1.0 (approximately). If Y has the value and X −1 −1
−1 1 3π/4 π/4
has the value , the value of ATAN2 (Y, X) is approximately . −1 1 −3π/4 −π/4
⃝c ISO/IEC 2017 – All rights reserved 355
ISO/IEC DIS 1539-1:2017 (E)
16.9.19 ATANH (X) 1 Description. Inverse hyperbolic tangent function.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the inverse hyperbolic
tangent function of X. If the result is complex the imaginary part is expressed in radians and lies in the range6 Example. ATANH (0.76159416) has the value 1.0 (approximately).−π/2 ≤ AIMAG (ATANH (X)) ≤ π/2.
16.9.20 ATOMIC_ADD (ATOM, VALUE [, STAT])1 Description. Atomic addition.
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_ADD (I [3], 42) will cause I on image 3 to become defined with the value 46 if theKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of ATOM + VALUE.
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The values of VALUE and ATOM +
VALUE shall be representable in kind ATOMIC_INT_KIND.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
value of I [3] is 4 when the atomic operation is executed.1 Description. Atomic bitwise AND.16.9.21 ATOMIC_AND (ATOM, VALUE [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_AND (I [3], 6) will cause I on image 3 to become defined with the value 4 if theKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of IAND (ATOM, INT (VALUE, ATOMIC_INT_KIND)).
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be repres-
entable in kind ATOMIC_INT_KIND.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
value of I [3] is 5 when the atomic operation is executed.1 Description. Atomic compare and swap.356 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
16.9.22 ATOMIC_CAS (ATOM, OLD, COMPARE, NEW [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. If the value of I on image 3 is equal to 13 at the beginning of the atomic operation performed byKIND from the intrinsic module ISO_FORTRAN_ENV, or of type logical with kind ATOMIC_-
LOGICAL_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT)
argument. If an error condition occurs, ATOM becomes undefined; otherwise, if ATOM is of type
integer and equal to COMPARE, or of type logical and equivalent to COMPARE, it becomes defined
with the value of NEW.
OLD shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If
an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that
ATOM had at the start of the atomic operation.
COMPARE shall be scalar and of the same type and kind as ATOM. It is an INTENT (IN) argument.
NEW shall be scalar and of the same type and kind as ATOM. It is an INTENT (IN) argument.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
CALL ATOMIC_CAS (I [3], OLD, 0, 1), the value of I on image 3 will be unchanged, and OLD will become1 Description. Define a variable atomically.defined with the value 13. If the value of I on image 3 is equal to 0 at the beginning of the atomic operation
performed by CALL ATOMIC_CAS (I [3], OLD, 0, 1), I on image 3 will become defined with the value 1, and
OLD will become defined with the value 0.
16.9.23 ATOMIC_DEFINE (ATOM, VALUE [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_DEFINE (I [3], 4) causes I on image 3 to become defined with the value 4.KIND from the intrinsic module ISO_FORTRAN_ENV, or of type logical with kind ATOMIC_-
LOGICAL_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (OUT)
argument. On successful execution, it becomes defined with the value of VALUE. If an error
condition occurs, it becomes undefined.
VALUE shall be scalar and of the same type as ATOM. It is an INTENT (IN) argument.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
16.9.24 ATOMIC_FETCH_ADD (ATOM, VALUE, OLD [, STAT])1 Description. Atomic fetch and add.
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_FETCH_ADD (I [3], 7, J) will cause I on image 3 to become defined with the value⃝c ISO/IEC 2017 – All rights reserved 357
ISO/IEC DIS 1539-1:2017 (E)
KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of ATOM + VALUE.
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The values of VALUE and ATOM +
VALUE shall be representable in kind ATOMIC_INT_KIND.
OLD shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If
an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that
ATOM had at the start of the atomic operation.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
12, and J to become defined with the value 5, if the value of I [3] is 5 when the atomic operation is executed.1 Description. Atomic fetch and bitwise AND.16.9.25 ATOMIC_FETCH_AND (ATOM, VALUE, OLD [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_FETCH_AND (I [3], 6, J) will cause I on image 3 to become defined with the valueKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of IAND (ATOM, INT (VALUE, ATOMIC_INT_KIND)).
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be repres-
entable in kind ATOMIC_INT_KIND.
OLD shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If
an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that
ATOM had at the start of the atomic operation.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
4, and J to become defined with the value 5, if the value of I [3] is 5 when the atomic operation is executed.1 Description. Atomic fetch and bitwise OR.16.9.26 ATOMIC_FETCH_OR (ATOM, VALUE, OLD [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_FETCH_OR (I [3], 1, J) will cause I on image 3 to become defined with the valueKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of IOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be repres-
entable in kind ATOMIC_INT_KIND.
OLD shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If
an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that
ATOM had at the start of the atomic operation.
358 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
3, and J to become defined with the value 2, if the value of I [3] is 2 when the atomic operation is executed.1 Description. Atomic fetch and bitwise exclusive OR.16.9.27 ATOMIC_FETCH_XOR (ATOM, VALUE, OLD [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_FETCH_XOR (I [3], 1, J) will cause I on image 3 to become defined with the valueKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of IEOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be repres-
entable in kind ATOMIC_INT_KIND.
OLD shall be scalar and of the same type and kind as ATOM. It is an INTENT (OUT) argument. If
an error condition occurs, it becomes undefined; otherwise, it becomes defined with the value that
ATOM had at the start of the atomic operation.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
2, and J to become defined with the value 3, if the value of I [3] is 3 when the atomic operation is executed.1 Description. Atomic bitwise OR.16.9.28 ATOMIC_OR (ATOM, VALUE [, STAT])
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_OR (I [3], 1) will cause I on image 3 to become defined with the value 3 if the valueKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of IOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be repres-
entable in kind ATOMIC_INT_KIND.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
of I [3] is 2 when the atomic operation is executed.1 Description. Reference a variable atomically.16.9.29 ATOMIC_REF (VALUE, ATOM [, STAT])
2 Class. Atomic subroutine.
⃝c ISO/IEC 2017 – All rights reserved 3593 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
VALUE shall be scalar and of the same type as ATOM. It is an INTENT (OUT) argument. On successful4 Example. CALL ATOMIC_REF (VAL, I [3]) causes VAL to become defined with the value of I on image 3.execution, it becomes defined with the value of ATOM. If an error condition occurs, it becomes
undefined.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-
KIND from the intrinsic module ISO_FORTRAN_ENV, or of type logical with kind ATOMIC_LO-
GICAL_KIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (IN) argument.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
16.9.30 ATOMIC_XOR (ATOM, VALUE [, STAT])1 Description. Atomic bitwise exclusive OR.
2 Class. Atomic subroutine.
3 Arguments.
ATOM shall be a scalar coarray or coindexed object. It shall be of type integer with kind ATOMIC_INT_-4 Example. CALL ATOMIC_XOR (I [3], 1) will cause I on image 3 to become defined with the value 2 if theKIND from the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If
an error condition occurs, ATOM becomes undefined; otherwise, it becomes defined with the value
of IEOR (ATOM, INT (VALUE, ATOMIC_INT_KIND)).
VALUE shall be an integer scalar. It is an INTENT (IN) argument. The value of VALUE shall be repres-
entable in kind ATOMIC_INT_KIND.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned a value as specified in 16.5. If an error condition occurs
and STAT is not present, error termination is initiated.
value of I [3] is 3 when the atomic operation is executed.1 Description. Bessel function of the 1st kind, order 0.16.9.31 BESSEL_J0 (X)
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of
the first kind and order zero of X.6 Example. BESSEL_J0 (1.0) has the value 0.765 (approximately).
16.9.32 BESSEL_J1 (X)1 Description. Bessel function of the 1st kind, order 1.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Result Characteristics. Same as X.
360 ⃝c ISO/IEC 2017 – All rights reserved5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of
ISO/IEC DIS 1539-1:2017 (E)
the first kind and order one of X.6 Example. BESSEL_J1 (1.0) has the value 0.440 (approximately).
16.9.33 BESSEL_JN (N, X) or BESSEL_JN (N1, N2, X)1 Description. Bessel functions of the 1st kind.
2 Class.
Case (i): BESSEL_JN (N,X) is an elemental function.3 Arguments.Case (ii): BESSEL_JN (N1,N2,X) is a transformational function.
N shall be of type integer and nonnegative.4 Result Characteristics. Same type and kind as X. The result of BESSEL_JN (N1, N2, X) is a rank-one arrayN1 shall be an integer scalar with a nonnegative value.
N2 shall be an integer scalar with a nonnegative value.
X shall be of type real; if the function is transformational, X shall be scalar.
with extent MAX (N2−N1+1, 0).5 Result Value.
Case (i): The result value of BESSEL_JN (N, X) is a processor-dependent approximation to the Bessel6 Example. BESSEL_JN (2, 1.0) has the value 0.115 (approximately).function of the first kind and order N of X.
Case (ii): Element i of the result value of BESSEL_JN (N1, N2, X) is a processor-dependent approximation
to the Bessel function of the first kind and order N1+i − 1 of X.
16.9.34 BESSEL_Y0 (X)1 Description. Bessel function of the 2nd kind, order 0.
2 Class. Elemental function.
3 Argument. X shall be of type real. Its value shall be greater than zero.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of
the second kind and order zero of X.6 Example. BESSEL_Y0 (1.0) has the value 0.088 (approximately).
16.9.35 BESSEL_Y1 (X)1 Description. Bessel function of the 2nd kind, order 1.
2 Class. Elemental function.
3 Argument. X shall be of type real. Its value shall be greater than zero.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the Bessel function of
the second kind and order one of X.6 Example. BESSEL_Y1 (1.0) has the value −0.781 (approximately).⃝c ISO/IEC 2017 – All rights reserved 361
ISO/IEC DIS 1539-1:2017 (E)
16.9.36 BESSEL_YN (N, X) or BESSEL_YN (N1, N2, X)1 Description. Bessel functions of the 2nd kind.
2 Class.
Case (i): BESSEL_YN (N, X) is an elemental function.3 Arguments.Case (ii): BESSEL_YN (N1, N2, X) is a transformational function.
N shall be of type integer and nonnegative.4 Result Characteristics. Same type and kind as X. The result of BESSEL_YN (N1, N2, X) is a rank-one arrayN1 shall be an integer scalar with a nonnegative value.
N2 shall be an integer scalar with a nonnegative value.
X shall be of type real; if the function is transformational, X shall be scalar. Its value shall be greater
than zero.
with extent MAX (N2−N1+1, 0).5 Result Value.
Case (i): The result value of BESSEL_YN (N, X) is a processor-dependent approximation to the Bessel6 Example. BESSEL_YN (2, 1.0) has the value −1.651 (approximately).function of the second kind and order N of X.
Case (ii): Element i of the result value of BESSEL_YN (N1, N2, X) is a processor-dependent approximation
to the Bessel function of the second kind and order N1+i − 1 of X.
16.9.37 BGE (I, J)1 Description. Bitwise greater than or equal to.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Default logical.J shall be of type integer or a boz-literal-constant.
5 Result Value. The result is true if the sequence of bits represented by I is greater than or equal to the sequence
of bits represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of anfalse.
integer value as a sequence of bits is described in 16.3.7 Example. If BIT_SIZE (J) has the value 8, BGE (Z’FF’, J) has the value true for any value of J. BGE (0, −1)
has the value false.1 Description. Bitwise greater than.16.9.38 BGT (I, J)
2 Class. Elemental function.
362 ⃝c ISO/IEC 2017 – All rights reserved3 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Default logical.J shall be of type integer or a boz-literal-constant.
5 Result Value. The result is true if the sequence of bits represented by I is greater than the sequence of bits
represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false.6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an
integer value as a sequence of bits is described in 16.3.7 Example. BGT (Z’FF’, Z’FC’) has the value true. BGT (0, −1) has the value false.
16.9.39 BIT_SIZE (I)1 Description. Number of bits in integer model 16.3.
2 Class. Inquiry function.
3 Argument. I shall be of type integer. It may be a scalar or an array.
4 Result Characteristics. Scalar integer with the same kind type parameter as I.
5 Result Value. The result has the value of the number of bits z of the model integer defined for bit manipulation
contexts in 16.3.6 Example. BIT_SIZE (1) has the value 32 if z of the model is 32.
16.9.40 BLE (I, J)1 Description. Bitwise less than or equal to.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Default logical.J shall be of type integer or a boz-literal-constant.
5 Result Value. The result is true if the sequence of bits represented by I is less than or equal to the sequence of
bits represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false.6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an
integer value as a sequence of bits is described in 16.3.7 Example. BLE (0, J) has the value true for any value of J. BLE (−1, 0) has the value false.
16.9.41 BLT (I, J)1 Description. Bitwise less than.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Default logical.J shall be of type integer or a boz-literal-constant.
⃝c ISO/IEC 2017 – All rights reserved 363
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value. The result is true if the sequence of bits represented by I is less than the sequence of bits
represented by J, according to the method of bit sequence comparison in 16.3.2; otherwise the result is false.6 The interpretation of a boz-literal-constant as a sequence of bits is described in 7.7. The interpretation of an
integer value as a sequence of bits is described in 16.3.7 Example. BLT (0, −1) has the value true. BLT (Z’FF’, Z’FC’) has the value false.
16.9.42 BTEST (I, POS)1 Description. Test single bit in an integer.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Default logical.POS shall be of type integer. It shall be nonnegative and be less than BIT_SIZE (I).
5 Result Value. The result has the value true if bit POS of I has the value 1 and has the value false if bit POS
of I has the value 0. The model for the interpretation of an integer value as a sequence of bits is in 16.3.
1 2
1 Description. Compute maximum value across images.
6 Examples. BTEST (8, 3) has the value true. If A has the value , the value of BTEST (A, 2) is 3 41 Description. Least integer greater than or equal to A.false false true false
and the value of BTEST (2, A) is .
false true false false
16.9.43 CEILING (A [, KIND])
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result has a value equal to the least integer greater than or equal to A.
6 Examples. CEILING (3.7) has the value 4. CEILING (−3.7) has the value −3. 16.9.44 CHAR (I [, KIND])1 Description. Character from code value.
2 Class. Elemental function. 3 Arguments. I shall be of type integer with a value in the range 0 ≤ I ≤ n − 1, where n is the number of characters4 Result Characteristics. Character of length one. If KIND is present, the kind type parameter is that specifiedin the collating sequence associated with the specified kind type parameter.
KIND (optional) shall be a scalar integer constant expression.
364 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
by the value of KIND; otherwise, the kind type parameter is that of default character.5 Result Value. The result is the character in position I of the collating sequence associated with the spe-
cified kind type parameter. ICHAR (CHAR (I, KIND (C))) shall have the value I for 0 ≤ I ≤ n − 1 and6 Example. CHAR (88) has the value ’X’ on a processor using the ASCII collating sequence for default characters.CHAR (ICHAR (C), KIND (C)) shall have the value C for any character C capable of representation in the
processor.
16.9.45 CMPLX (X [, KIND]) or CMPLX (X [, Y, KIND])1 Description. Conversion to complex type.
2 Class. Elemental function. 3 Arguments for CMPLX(X [, KIND]). X shall be of type complex.4 Arguments for CMPLX(X [, Y, KIND]).KIND (optional) shall be a scalar integer constant expression.
X shall be of type integer or real, or a boz-literal-constant.5 Result Characteristics. The result is of type complex. If KIND is present, the kind type parameter is thatY (optional) shall be of type integer or real, or a boz-literal-constant.
KIND (optional) shall be a scalar integer constant expression.
specified by the value of KIND; otherwise, the kind type parameter is that of default real kind.6 Result Value. If Y is absent and X is not complex, it is as if Y were present with the value zero. If KIND is
absent, it is as if KIND were present with the value KIND (0.0). If X is complex, the result is the same as that7 Example. CMPLX (−3) has the value (−3.0, 0.0).of CMPLX (REAL (X), AIMAG (X), KIND). The result of CMPLX (X, Y, KIND) has the complex value whose
real part is REAL (X, KIND) and whose imaginary part is REAL (Y, KIND).
16.9.46 CO_BROADCAST (A, SOURCE_IMAGE [, STAT, ERRMSG])1 Description. Broadcast value to images.
2 Class. Collective subroutine. 3 Arguments. A shall have the same shape, dynamic type, and type parameter values, in corresponding references.4 The semantics of STAT and ERRMSG are described in 16.6.It shall not be a coindexed object. It is an INTENT (INOUT) argument. If no error condition
occurs, A becomes defined, as if by intrinsic assignment, on all images in the current team with the
value of A on image SOURCE_IMAGE.
SOURCE_IMAGE shall be an integer scalar. It is an INTENT (IN) argument. Its value shall be that of an
image index of an image in the current team. The value shall be the same in all corresponding
references.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument.
ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.
⃝c ISO/IEC 2017 – All rights reserved 3655 Example. If A is the array [1, 5, 3] on image one, after execution of
ISO/IEC DIS 1539-1:2017 (E)
CALL CO_BROADCAST (A, 1)the value of A on all images of the current team is [1, 5, 3].
16.9.47 CO_MAX (A [, RESULT_IMAGE, STAT, ERRMSG]) 2 Class. Collective subroutine.
3 Arguments.
A shall be of type integer, real, or character. It shall have the same shape, type, and type parameter4 The semantics of STAT and ERRMSG are described in 16.6.values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT)
argument. If it is scalar, the computed value is equal to the maximum value of A in all corresponding
references. If it is an array each element of the computed value is equal to the maximum value of
all corresponding elements of A in all corresponding references.
The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is
absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes
undefined.
RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value
if present, shall be the same in all corresponding references. If it is present, its value shall be that
of an image index in the current team.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument.
ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.
5 Example. If the number of images in the current team is two and A is the array [1, 5, 3] on one image and [4,
1, 6] on the other image, the value of A after executing the statement CALL CO_MAX (A) is [4, 5, 6] on both1 Description. Compute minimum value across images.images.
16.9.48 CO_MIN (A [, RESULT_IMAGE, STAT, ERRMSG])
2 Class. Collective subroutine.
3 Arguments.
A shall be of type integer, real, or character. It shall have the same shape, type, and type parameter4 The semantics of STAT and ERRMSG are described in 16.6.values, in corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT)
argument. If it is scalar, the computed value is equal to the minimum value of A in all corresponding
references. If it is an array each element of the computed value is equal to the minimum value of
all corresponding elements of A in all corresponding references.
The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is
absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes
undefined.
RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value
if present, shall be the same in all corresponding references. If it is present, its value shall be that
of an image index in the current team.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument.
ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.
366 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
5 Example. If the number of images in the current team is two and A is the array [1, 5, 3] on one image and [4,
1, 6] on the other image, the value of A after executing the statement CALL CO_MIN (A) is [1, 1, 3] on both1 Description. Generalized reduction across images.images.
16.9.49 CO_REDUCE (A, OPERATION [, RESULT_IMAGE, STAT, ERRMSG])
2 Class. Collective subroutine.
3 Arguments.
A shall not be polymorphic. It shall have the same shape, type, and type parameter values, in4 The semantics of STAT and ERRMSG are described in 16.6.corresponding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument.
If A is scalar, the computed value is the result of the reduction operation of applying OPERATION
to the values of A in all corresponding references. If A is an array, each element of the computed
value is equal to the result of the reduction operation of applying OPERATION to corresponding
elements of A in all corresponding references.
The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is
absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes
undefined.
OPERATION shall be a pure function with exactly two arguments; the result and each argument shall be
a scalar, nonallocatable, nonpointer, nonpolymorphic data object with the same type and type
parameters as A. The arguments shall not be optional. If one argument has the ASYNCHRONOUS,
TARGET, or VALUE attribute, the other shall have that attribute. OPERATION shall implement
a mathematically associative operation. OPERATION shall be the same function on all images in
corresponding references.
The computed value of a reduction operation over a set of values is the result of an iterative process.
Each iteration involves the evaluation of OPERATION (x, y) for x and y in the set, the removal of
x and y from the set, and the addition of the value of OPERATION (x, y) to the set. The process
terminates when the set has only one element; this is the computed value.
RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value
if present, shall be the same in all corresponding references. If it is present, its value shall be that
of an image index in the current team.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument.
ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.
5 Example. The subroutine below demonstrates how to use CO_REDUCE to create a collective counterpart to
the intrinsic function ALL:SUBROUTINE co_all(boolean)
LOGICAL, INTENT(INOUT) :: boolean
CALL CO_REDUCE(boolean,both)
CONTAINS
PURE FUNCTION both(lhs,rhs) RESULT(lhs_and_rhs)
LOGICAL, INTENT(IN) :: lhs,rhsEND FUNCTION bothLOGICAL :: lhs_and_rhs
lhs_and_rhs = lhs .AND. rhs
END SUBROUTINE co_all
⃝c ISO/IEC 2017 – All rights reserved 367
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.11If the OPERATION function is not mathematically commutative, the result of calling CO_REDUCE can
depend on the order of evaluations.
16.9.50 CO_SUM (A [, RESULT_IMAGE, STAT, ERRMSG]) 1 Description. Compute sum across images.
2 Class. Collective subroutine.
3 Arguments.
A shall be of numeric type. It shall have the same shape, type, and type parameter values, in cor-4 The semantics of STAT and ERRMSG are described in 16.6.responding references. It shall not be a coindexed object. It is an INTENT (INOUT) argument.
If it is scalar, the computed value is equal to a processor-dependent approximation to the sum of
the values of A in corresponding references. If it is an array, each element of the computed value
is equal to a processor-dependent approximation to the sum of all corresponding elements of A in
corresponding references.
The computed value is assigned to A if no error condition occurs, and either RESULT_IMAGE is
absent, or the executing image is the one identified by RESULT_IMAGE. Otherwise, A becomes
undefined.
RESULT_IMAGE (optional) shall be an integer scalar. It is an INTENT (IN) argument. Its presence, and value
if present, shall be the same in all corresponding references. If it is present, its value shall be that
of an image index in the current team.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument.
ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.
5 Example. If the number of images in the current team is two and A is the array [1, 5, 3] on one image and [4,
1, 6] on the other image, the value of A after executing the statement CALL CO_SUM(A) is [5, 6, 9] on both1 Description. Number of command arguments.images.
16.9.51 COMMAND_ARGUMENT_COUNT ( )
2 Class. Transformational function.
3 Argument. None.
4 Result Characteristics. Default integer scalar.
5 Result Value. The result value is equal to the number of command arguments available. If there are no
command arguments available or if the processor does not support command arguments, then the result has the6 Example. See 16.9.83.value zero. If the processor has a concept of a command name, the command name does not count as one of the
command arguments.
16.9.52 CONJG (Z)1 Description. Conjugate of a complex number.
2 Class. Elemental function.
368 ⃝c ISO/IEC 2017 – All rights reserved3 Argument. Z shall be of type complex.
ISO/IEC DIS 1539-1:2017 (E)
4 Result Characteristics. Same as Z.
5 Result Value. If Z has the value (x, y), the result has the value (x, −y).
6 Example. CONJG ((2.0, 3.0)) has the value (2.0, −3.0).
16.9.53 COS (X)1 Description. Cosine function.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to cos(X). If X is of type
real, it is regarded as a value in radians. If X is of type complex, its real part is regarded as a value in radians.6 Example. COS (1.0) has the value 0.54030231 (approximately).
16.9.54 COSH (X)1 Description. Hyperbolic cosine function.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to cosh(X). If X is of type
complex its imaginary part is regarded as a value in radians.6 Example. COSH (1.0) has the value 1.5430806 (approximately).
16.9.55 COSHAPE (COARRAY [, KIND])1 Description. Sizes of codimensions of a coarray.
2 Class. Inquiry function.
3 Arguments.
COARRAY shall be a coarray of any type. It shall not be an unallocated allocatable coarray. If its designator4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the valuehas more than one part-ref , the rightmost part-ref shall have nonzero corank.
KIND (optional) shall be a scalar integer constant expression.
of KIND; otherwise the kind type parameter is that of default integer type. The result is an array of rank one5 Result Value. The result has a value whose ith element is equal to the size of the ith codimension of COARRAY,whose size is equal to the corank of COARRAY.
as given by UCOBOUND (COARRAY, i) − LCOBOUND (COARRAY, i) +1.6 Example.
The following code allocates the coarray D with the same size in each codimension as that of the coarray C, with1 Description. Logical array reduced by counting true values.the lower cobound 1.
⃝c ISO/IEC 2017 – All rights reserved 369
ISO/IEC DIS 1539-1:2017 (E)
REAL, ALLOCATABLE :: C[:,:], D[:,:]
INTEGER, ALLOCATABLE :: COSHAPE_C(:)
...
COSHAPE_C = COSHAPE(C)
ALLOCATE ( D[COSHAPE_C(1),*] )
16.9.56 COUNT (MASK [, DIM, KIND])
2 Class. Transformational function.
3 Arguments.
MASK shall be a logical array.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofDIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.
The corresponding actual argument shall not be an optional dummy argument, a disassociated
pointer, or an unallocated allocatable.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type. The result is scalar if DIM is absent or5 Result Value.n = 1; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ]
is the shape of MASK.
Case (i): If DIM is absent or MASK has rank one, the result has a value equal to the number of true elements6 Examples.of MASK or has the value zero if MASK has size zero.
Case (ii): If DIM is present and MASK has rank n > 1, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . ,
sn ) of the result is equal to the number of true elements of MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 ,
. . . , sn ).
Case (i): The value of COUNT ([.TRUE., .FALSE., .TRUE.]) is 2.1 Description. Processor time used.
1 3 5 0 3 5
Case (ii): If B is the array and C is the array , COUNT (B /= C, DIM = 1) is
2 4 6 7 4 8
[2, 0, 1] and COUNT (B /= C, DIM = 2) is [1, 2].
16.9.57 CPU_TIME (TIME)
2 Class. Subroutine.
3 Argument. TIME shall be a real scalar. It is an INTENT (OUT) argument. If the processor cannot provide
a meaningful value for the time, it is assigned a processor-dependent negative value; otherwise, it is assigned a4 Example.processor-dependent approximation to the processor time in seconds. Whether the value assigned is an approx-
imation to the amount of time used by the invoking image, or the amount of time used by the whole program, is
processor dependent.
REAL T1, T2...
CALL CPU_TIME(T1)
370 ⃝ c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
CALL CPU_TIME(T2)
... ! Code to be timed. WRITE (*,*) ’Time taken by code was ’, T2-T1, ’ seconds’
writes the processor time taken by a piece of code.
NOTE 16.12A processor for which a single result is inadequate (for example, a parallel processor) might choose to
provide an additional version for which time is an array.
The exact definition of time is left imprecise because of the variability in what different processors are able
to provide. The primary purpose is to compare different algorithms on the same processor or discover which
parts of a calculation are the most expensive.
The start time is left imprecise because the purpose is to time sections of code, as in the example.
Most computer systems have multiple concepts of time. One common concept is that of time expended by
the processor for a given program. This might or might not include system overhead, and has no obvious
connection to elapsed “wall clock” time.
16.9.58 CSHIFT (ARRAY, SHIFT [, DIM]) 1 Description. Circular shift of an array.
2 Class. Transformational function.
3 Arguments.
ARRAY may be of any type. It shall be an array.4 Result Characteristics. The result is of the type and type parameters of ARRAY, and has the shape ofSHIFT shall be of type integer and shall be scalar if ARRAY has rank one; otherwise, it shall be scalar or
of rank n − 1 and of shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape
of ARRAY.
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
If DIM is absent, it is as if it were present with the value 1.
ARRAY.5 Result Value.
Case (i): If ARRAY has rank one, element i of the result is ARRAY (1 + MODULO (i + SHIFT − 1, SIZE6 Examples.(ARRAY))).
Case (ii): If ARRAY has rank greater than one, section (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . ., sn ) of the result
has a value equal to CSHIFT (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . ., sn ), sh, 1), where sh is
SHIFT or SHIFT (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ).
Case (i): If V is the array [1, 2, 3, 4, 5, 6], the effect of shifting V circularly to the left by two positions is1 Description. Date and time.achieved by CSHIFT (V, SHIFT = 2) which has the value [3, 4, 5, 6, 1, 2]; CSHIFT (V, SHIFT =
−2) achieves a circular shift to the right by two positions and has the value [5, 6, 1, 2, 3, 4].
Case (ii): The rows of an array
of ranktwo may all be shifted by the same amount or by different amounts.
1 2 3
If M is the array 4 5 6 , the value of
7 8 9
3 1 2
CSHIFT (M, SHIFT = −1, DIM = 2) is 6 4 5 , and the value of
9 7 8
⃝c ISO/IEC 2017 – All rights reserved 371
ISO/IEC DIS 1539-1:2017 (E)
3 1 2
CSHIFT (M, SHIFT = [−1, 1, 0], DIM = 2) is 5 6 4 .
7 8 9
16.9.59 DATE_AND_TIME ([DATE, TIME, ZONE, VALUES])
2 Class. Subroutine.
3 Arguments.
DATE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned a value4 The date, clock, and time zone information might be available on some images and not others. If the date, clock,of the form YYYYMMDD, where YYYY is the year in the Gregorian calendar, MM is the month
within the year, and DD is the day within the month. The characters of this value shall all be
decimal digits. If there is no date available, DATE is assigned all blanks.
TIME (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned a value
of the form hhmmss.sss, where hh is the hour of the day, mm is the minutes of the hour, and ss.sss
is the seconds and milliseconds of the minute. Except for the decimal point, the characters of this
value shall all be decimal digits. If there is no clock available, TIME is assigned all blanks.
ZONE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned a value of
the form +hhmm or -hhmm, where hh and mm are the time difference with respect to Coordinated
Universal Time (UTC) in hours and minutes, respectively. The characters of this value following
the sign character shall all be decimal digits. If this information is not available, ZONE is assigned
all blanks.
VALUES (optional) shall be a rank-one array of type integer with a decimal exponent range of at least four. It
is an INTENT (OUT) argument. Its size shall be at least 8. The values assigned to VALUES are
as follows:
VALUES (1) the year, including the century (for example, 2008), or −HUGE (VALUES) if there is no date
available;
VALUES (2) the month of the year, or −HUGE (VALUES) if there is no date available;
VALUES (3) the day of the month, or −HUGE (VALUES) if there is no date available;
VALUES (4) the time difference from Coordinated Universal Time (UTC) in minutes, or −HUGE (VALUES)
if this information is not available;
VALUES (5) the hour of the day, in the range of 0 to 23, or −HUGE (VALUES) if there is no clock;
VALUES (6) the minutes of the hour, in the range 0 to 59, or −HUGE (VALUES) if there is no clock;
VALUES (7) the seconds of the minute, in the range 0 to 60, or −HUGE (VALUES) if there is no clock;
VALUES (8) the milliseconds of the second, in the range 0 to 999, or −HUGE (VALUES) if there is no clock.
or time zone information is available on more than one image, it is processor dependent whether or not those5 Example. If run in Geneva, Switzerland on April 12, 2008 at 15:27:35.5 with a system configured for theimages share the same information.
local time zone, this example would have assigned the value 20080412 to BIG_BEN (1), the value 152735.500 to1 Description. Conversion to double precision real.BIG_BEN (2), the value +0100 to BIG_BEN (3), and the value [2008, 4, 12, 60, 15, 27, 35, 500] to DATE_TIME.
INTEGER DATE_TIME (8)
CHARACTER (LEN = 10) BIG_BEN (3)
CALL DATE_AND_TIME (BIG_BEN (1), BIG_BEN (2), BIG_BEN (3), DATE_TIME)
372 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.13
These forms are compatible with the representations defined in ISO 8601:2004. UTC is established by the
International Bureau of Weights and Measures (BIPM, i.e. Bureau International des Poids et Mesures) and
the International Earth Rotation Service (IERS).
16.9.60 DBLE (A)
2 Class. Elemental function.
3 Argument. A shall be of type integer, real, complex, or a boz-literal-constant.
4 Result Characteristics. Double precision real.
5 Result Value. The result has the value REAL (A, KIND (0.0D0)).
6 Example. DBLE (−3) has the value −3.0D0.
16.9.61 DIGITS (X)1 Description. Significant digits in numeric model.
2 Class. Inquiry function.
3 Argument. X shall be of type integer or real. It may be a scalar or an array.
4 Result Characteristics. Default integer scalar.
5 Result Value. The result has the value q if X is of type integer and p if X is of type real, where q and p are as
defined in 16.4 for the model representing numbers of the same type and kind type parameter as X.6 Example. DIGITS (X) has the value 24 for real X whose model is as in NOTE 16.4.
16.9.62 DIM (X, Y)1 Description. Maximum of X − Y and zero.
2 Class. Elemental function.
3 Arguments.
X shall be of type integer or real.4 Result Characteristics. Same as X.Y shall be of the same type and kind type parameter as X.
5 Result Value. The value of the result is the maximum of X − Y and zero.
6 Example. DIM (−3.0, 2.0) has the value 0.0.
16.9.63 DOT_PRODUCT (VECTOR_A, VECTOR_B)1 Description. Dot product of two vectors.
2 Class. Transformational function.
3 Arguments.
VECTOR_A shall be of numeric type (integer, real, or complex) or of logical type. It shall be a rank-one array.4 Result Characteristics. If the arguments are of numeric type, the type and kind type parameter of the result⃝c ISO/IEC 2017 – All rights reserved 373
ISO/IEC DIS 1539-1:2017 (E)
VECTOR_B shall be of numeric type if VECTOR_A is of numeric type or of type logical if VECTOR_A is of
type logical. It shall be a rank-one array. It shall be of the same size as VECTOR_A.
are those of the expression VECTOR_A * VECTOR_B determined by the types and kinds of the arguments5 Result Value.according to 10.1.9.3. If the arguments are of type logical, the result is of type logical with the kind type parameter
of the expression VECTOR_A .AND. VECTOR_B according to 10.1.9.3. The result is scalar.
Case (i): If VECTOR_A is of type integer or real, the result has the value SUM (VECTOR_A*VECTOR_-6 Example. DOT_PRODUCT ([1, 2, 3], [2, 3, 4]) has the value 20.B). If the vectors have size zero, the result has the value zero.
Case (ii): If VECTOR_A is of type complex, the result has the value SUM (CONJG (VECTOR_A)*VECT-
OR_B). If the vectors have size zero, the result has the value zero.
Case (iii): If VECTOR_A is of type logical, the result has the value ANY (VECTOR_A .AND. VECTOR_B).
If the vectors have size zero, the result has the value false.
16.9.64 DPROD (X, Y)1 Description. Double precision real product.
2 Class. Elemental function.
3 Arguments.
X shall be default real.4 Result Characteristics. Double precision real.Y shall be default real.
5 Result Value. The result has a value equal to a processor-dependent approximation to the product of X and
Y. DPROD (X, Y) should have the same value as DBLE (X) * DBLE (Y).6 Example. DPROD (−3.0, 2.0) has the value −6.0D0.
16.9.65 DSHIFTL (I, J, SHIFT)1 Description. Combined left shift.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.J shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have
the same kind type parameter. I and J shall not both be boz-literal-constants.
SHIFT shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I) if I is of
type integer; otherwise, it shall be less than or equal to BIT_SIZE (J).
5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to
type integer with the kind type parameter of the other. The rightmost SHIFT bits of the result value are the same6 Examples. DSHIFTL (1, 2**30, 2) has the value 5 if default integer has 32 bits. DSHIFTL (I, I, SHIFT) hasas the leftmost bits of J, and the remaining bits of the result value are the same as the rightmost bits of I. This
is equal to IOR (SHIFTL (I, SHIFT), SHIFTR (J, BIT_SIZE (J)−SHIFT)). The model for the interpretation of
an integer value as a sequence of bits is in 16.3.
374 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
the same result value as ISHFTC (I, SHIFT).1 Description. Combined right shift.16.9.66 DSHIFTR (I, J, SHIFT)
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.J shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have
the same kind type parameter. I and J shall not both be boz-literal-constants.
SHIFT shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I) if I is of
type integer; otherwise, it shall be less than or equal to BIT_SIZE (J).
5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to
type integer with the kind type parameter of the other. The leftmost SHIFT bits of the result value are the same6 Examples. DSHIFTR (1, 16, 3) has the value 229 + 2 if default integer has 32 bits. DSHIFTR (I, I, SHIFT) hasas the rightmost bits of I, and the remaining bits of the result value are the same as the leftmost bits of J. This
is equal to IOR (SHIFTL (I, BIT_SIZE (I)−SHIFT), SHIFTR (J, SHIFT)). The model for the interpretation of
an integer value as a sequence of bits is in 16.3.
the same result value as ISHFTC (I,−SHIFT).1 Description. End-off shift of the elements of an array.16.9.67 EOSHIFT (ARRAY, SHIFT [, BOUNDARY, DIM])
2 Class. Transformational function.
3 Arguments.
ARRAY shall be an array be of any type.4 Result Characteristics. The result has the type, type parameters, and shape of ARRAY.SHIFT shall be of type integer and shall be scalar if ARRAY has rank one; otherwise, it shall be scalar or
of rank n − 1 and of shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape
of ARRAY.
BOUNDARY (optional) shall be of the same type and type parameters as ARRAY and shall be scalar if ARRAY
has rank one; otherwise, it shall be either scalar or of rank n − 1 and of shape [d1 , d2 , . . . , dDIM−1 ,
dDIM+1 , . . . , dn ]. BOUNDARY is permitted to be absent only for the types in Table 16.4, and in
this case it is as if it were present with the scalar value shown, converted if necessary to the kind
type parameter value of ARRAY.
Table 16.4: Default BOUNDARY values for EOSHIFT
Type of ARRAY Value of BOUNDARY
Integer 0
Real 0.0
Complex (0.0, 0.0)
Logical .FALSE.
Character (len) len blanks
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
If DIM is absent, it is as if it were present with the value 1.
⃝c ISO/IEC 2017 – All rights reserved 375
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value. Element (s1 , s2 , . . . , sn ) of the result has the value ARRAY (s1 , s2 , . . . , sDIM−1 , sDIM + sh,
sDIM+1 , . . . , sn ) where sh is SHIFT or SHIFT (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) provided the inequality6 Examples.LBOUND (ARRAY, DIM) ≤ sDIM + sh ≤ UBOUND (ARRAY, DIM) holds and is otherwise BOUNDARY or
BOUNDARY (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ).
Case (i): If V is the array [1, 2, 3, 4, 5, 6], the effect of shifting V end-off to the left by 3 positions is achievedby EOSHIFT (V, SHIFT = 3), which has the value [4, 5, 6, 0, 0, 0]; EOSHIFT (V, SHIFT = −2,
BOUNDARY = 99) achieves an end-off shift to the right by 2 positions with the boundary value of
99 and has the value [99, 99, 1, 2, 3, 4].
Case (ii): The rows of an array of rank two may all be shifted by the same amountor by different amounts
A B C
and the boundary elements can be the same or different. If M is the array D E F , then the
G H Ivalue of EOSHIFT (M, SHIFT = −1, BOUNDARY = ’*’, DIM = 2) is * D E , and the value* A B
∗ G Hof EOSHIFT (M, SHIFT = [−1, 1, 0], BOUNDARY = [’*’, ’/’, ’?’], DIM = 2) is E F / .
* A B
G H I
16.9.68 EPSILON (X) 1 Description. Model number that is small compared to 1.
2 Class. Inquiry function.
3 Argument. X shall be of type real. It may be a scalar or an array.
4 Result Characteristics. Scalar of the same type and kind type parameter as X.
5 Result Value. The result has the value b1−p where b and p are as defined in 16.4 for the model representing
numbers of the same type and kind type parameter as X.6 Example. EPSILON (X) has the value 2−23 for real X whose model is as in NOTE 16.4.
16.9.69 ERF (X)1 Description. Error function.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the error function of X,
RX
√2 exp(−t2 ) dt. π 06 Example. ERF (1.0) has the value 0.843 (approximately).
16.9.70 ERFC (X)1 Description. Complementary error function.
2 Class. Elemental function.
376 ⃝c ISO/IEC 2017 – All rights reserved3 Argument. X shall be of type real.
ISO/IEC DIS 1539-1:2017 (E)
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the complementary error ∞√2
R
function of X, 1 − ERF (X); this is equivalent to π X exp(−t2 )dt.6 Example. ERFC (1.0) has the value 0.157 (approximately).
16.9.71 ERFC_SCALED (X)1 Description. Scaled complementary error function.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to aR processor-dependent approximation to the exponentially-scaled
2 2 ∞ 2 1 Description. Query event count.
complementary error function of X, exp(X ) √π exp(−t ) dt.6 Example. ERFC_SCALED (20.0) has the value 0.02817434874 (approximately).
NOTE 16.14√
The complementary error function is asymptotic to exp(−X 2 )/(X π). As such it underflows for X >≈ 9
when using ISO/IEC/IEEE 60559:2011 single √ precision arithmetic. The exponentially-scaled complement-
√
ary error function is asymptotic to 1/(X π). As such it does not underflow until X > HUGE (X)/ π.
16.9.72 EVENT_QUERY (EVENT, COUNT [, STAT]) 2 Class. Subroutine.
3 Arguments.
EVENT shall be an event variable (16.10.2.10). It shall not be coindexed. It is an INTENT (IN) argument.4 Example. If EVENT is an event variable for which there have been no successful posts or waits in precedingThe EVENT argument is accessed atomically with respect to the execution of EVENT POST
statements in unordered segments, in exact analogy to atomic subroutines.
COUNT shall be an integer scalar with a decimal exponent range no smaller than that of default integer. It
is an INTENT (OUT) argument. If no error condition occurs, COUNT is assigned the value of the
count of EVENT; otherwise, it is assigned the value −1.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. If the STAT argument is present, it is assigned a processor-dependent
positive value if an error condition occurs; otherwise it is assigned the value zero. If the STAT
argument is not present and an error condition occurs, error termination is initiated.
segments, and for which there are no posts or waits in an unordered segment, after execution of1 Description. Execute a command line.CALL EVENT_QUERY (EVENT, COUNT)
the integer variable COUNT will have the value zero. If there have been ten successful posts to EVENT and two
successful waits without an UNTIL_COUNT= specifier in preceding segments, and for which there are no posts
or waits in an unordered segment, after execution of
CALL EVENT_QUERY (EVENT, COUNT)
the variable COUNT will have the value eight.
⃝c ISO/IEC 2017 – All rights reserved 377
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.15
Execution of EVENT_QUERY does not imply any synchronization.
16.9.73 EXECUTE_COMMAND_LINE (COMMAND [, WAIT, EXITSTAT,
CMDSTAT, CMDMSG ])
2 Class. Subroutine.
3 Arguments.
COMMAND shall be a default character scalar. It is an INTENT (IN) argument. Its value is the command line4 If the processor supports command line execution, it shall support synchronous and may support asynchronousto be executed. The interpretation is processor dependent.
WAIT (optional) shall be a logical scalar. It is an INTENT (IN) argument. If WAIT is present with the value
false, and the processor supports asynchronous execution of the command, the command is executed
asynchronously; otherwise it is executed synchronously.
EXITSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least nine. It is an
INTENT (INOUT) argument. If the command is executed synchronously, it is assigned the value
of the processor-dependent exit status. Otherwise, the value of EXITSTAT is unchanged.
CMDSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned the value −1 if the processor does not support command
line execution, a processor-dependent positive value if an error condition occurs, or the value −2
if no error condition occurs but WAIT is present with the value false and the processor does not
support asynchronous execution. Otherwise it is assigned the value 0.
CMDMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. If an error condi-
tion occurs, it is assigned a processor-dependent explanatory message. Otherwise, it is unchanged.
execution of the command line.5 When the command is executed synchronously, EXECUTE_COMMAND_LINE returns after the command line
has completed execution. Otherwise, EXECUTE_COMMAND_LINE returns without waiting.6 If a condition occurs that would assign a nonzero value to CMDSTAT but the CMDSTAT variable is not present,
error termination is initiated.1 Description. Exponential function.16.9.74 EXP (X)
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to eX . If X is of type
complex, its imaginary part is regarded as a value in radians.6 Example. EXP (1.0) has the value 2.7182818 (approximately).
16.9.75 EXPONENT (X)1 Description. Exponent of floating-point number.
2 Class. Elemental function.
378 ⃝3 Argument. X shall be of type real.c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
4 Result Characteristics. Default integer.
5 Result Value. The result has a value equal to the exponent e of the representation for the value of X in the
extended real model for the kind of X (16.4), provided X is nonzero and e is within the range for default integers.6 Examples. EXPONENT (1.0) has the value 1 and EXPONENT (4.1) has the value 3 for reals whose model isIf X has the value zero, the result has the value zero. If X is an IEEE infinity or NaN, the result has the value
HUGE (0).
as in NOTE 16.4.1 Description. Dynamic type extension inquiry.16.9.76 EXTENDS_TYPE_OF (A, MOLD)
2 Class. Inquiry function.
3 Arguments.
A shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic4 Result Characteristics. Default logical scalar.pointer, it shall not have an undefined association status.
MOLD shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic
pointer, it shall not have an undefined association status.
5 Result Value. If MOLD is unlimited polymorphic and is either a disassociated pointer or unallocated allocatable
variable, the result is true; otherwise if A is unlimited polymorphic and is either a disassociated pointer or6 Example. Given the declarations and assignmentsunallocated allocatable variable, the result is false; otherwise if the dynamic type of A or MOLD is extensible, the
result is true if and only if the dynamic type of A is an extension type of the dynamic type of MOLD; otherwise
the result is processor dependent.
NOTE 16.16
The dynamic type of a disassociated pointer or unallocated allocatable variable is its declared type.
NOTE 16.17
The test performed by EXTENDS_TYPE_OF is not the same as the test performed by the type guard
CLASS IS. The test performed by EXTENDS_TYPE_OF does not consider kind type parameters.
TYPE T1
REAL C
END TYPE
TYPE, EXTENDS(T1) :: T2
END TYPE
CLASS(T1), POINTER :: P, Q
ALLOCATE (P)
ALLOCATE (T2 :: Q)
the result of EXTENDS_TYPE_OF (P, Q) will be false, and the result of EXTENDS_TYPE_OF (Q, P) will
be true.
⃝c ISO/IEC 2017 – All rights reserved 379
ISO/IEC DIS 1539-1:2017 (E)
16.9.77 FAILED_IMAGES ([TEAM, KIND]) 1 Description. Indices of failed images.
2 Class. Transformational function.
3 Arguments.
TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV. Its4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the valuevalue shall be that of the current or an ancestor team. If TEAM is absent, the team specified is the
current team.
KIND (optional) shall be a scalar integer constant expression.
of KIND; otherwise, the kind type parameter is that of default integer type. The result is an array of rank one5 Result Value. The elements of the result are the values of the image indices of the known failed images in thewhose size is equal to the number of images in the specified team that are known by the invoking image to have
failed.
specified team, in numerically increasing order. If the executing image has previously executed an image control6 Examples. If image 3 is the only image in the current team that is known by the invoking image to have failed,statement whose STAT= specifier assigned the value STAT_FAILED_IMAGE from the intrinsic module ISO_-
FORTRAN_ENV, or referenced a collective subroutine whose STAT argument was set to STAT_FAILED_-
IMAGE, at least one image in the set of images participating in that image control statement or collective
subroutine reference shall be known to have failed.
FAILED_IMAGES() will have the value [3]. If there are no images in the current team that are known by the1 Description. Location(s) of a specified value.invoking image to have failed, the value of FAILED_IMAGES() will be a zero-sized array.
16.9.78 FINDLOC (ARRAY, VALUE, DIM [, MASK, KIND, BACK]) or
FINDLOC (ARRAY, VALUE [, MASK, KIND, BACK])
2 Class. Transformational function.
3 Arguments.
ARRAY shall be an array of intrinsic type.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofVALUE shall be scalar and in type conformance with ARRAY, as specified in Table 10.2 for the operator
== or the operator .EQV..
DIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
KIND (optional) shall be a scalar integer constant expression.
BACK (optional) shall be a logical scalar.
KIND; otherwise the kind type parameter is that of default integer type. If DIM does not appear, the result is5 Result Value.an array of rank one and of size equal to the rank of ARRAY; otherwise, the result is of rank n − 1 and shape
[d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where [d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of FINDLOC (ARRAY, VALUE) is a rank-one array whose element values are the values6 If both ARRAY and VALUE are of type logical, the comparison is performed with the .EQV. operator; otherwise,of the subscripts of an element of ARRAY whose value matches VALUE. If there is such a value,
the ith element value is in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY.
If no elements match VALUE or ARRAY has size zero, all elements of the result are zero.
380 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Case (ii): The result of FINDLOC (ARRAY, VALUE, MASK = MASK) is a rank-one array whose element
values are the values of the subscripts of an element of ARRAY, corresponding to a true element
of MASK, whose value matches VALUE. If there is such a value, the ith element value is in the
range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If no elements match VALUE,
ARRAY has size zero, or every element of MASK has the value false, all elements of the result are
zero.
Case (iii): If ARRAY has rank one, the result of
FINDLOC (ARRAY, VALUE, DIM=DIM [, MASK = MASK]) is a scalar whose value is equal to
that of the first element of FINDLOC (ARRAY, VALUE [, MASK = MASK]). Otherwise, the value
of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to FINDLOC (ARRAY (s1 ,
s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ), VALUE, DIM=1 [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :,
sDIM+1 , . . . , sn )]).
the comparison is performed with the == operator. If the value of the comparison is true, that element of ARRAY7 If DIM is not present, more than one element matches VALUE, and BACK is absent or present with the valuematches VALUE.
false, the value returned indicates the first such element, taken in array element order. If DIM is not present and8 Examples.BACK is present with the value true, the value returned indicates the last such element, taken in array element
order.
Case (i): The value of FINDLOC ([2, 6, 4, 6], VALUE = 6) is [2], and the value of FINDLOC ([2, 6, 4, 6],1 Description. Greatest integer less than or equal to A.VALUE = 6, BACK = .TRUE.) is [4].
0 −5 7 7 T T F T
Case (ii): If A has the value 3 4 −1 2 , and M has the value T T F T , FINDLOC (A, 7,
1 5 6 7 T T F T
MASK = M) has the value [1, 4] and FINDLOC (A, 7, MASK = M, BACK = .TRUE.) has the
value [3, 4]. This is independent of the declared lower bounds for A.
Case (iii): The
value of FINDLOC
([2, 6, 4], VALUE = 6, DIM = 1) is 2. If B has the value
1 2 −9
, FINDLOC (B, VALUE = 2, DIM = 1) has the value [2, 1, 0] and FINDLOC (B,
2 2 6
VALUE = 2, DIM = 2) has the value [2, 1]. This is independent of the declared lower bounds for B.
16.9.79 FLOOR (A [, KIND])
2 Class. Elemental function.
3 Arguments.
A shall be of type real.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result has a value equal to the greatest integer less than or equal to A.
6 Examples. FLOOR (3.7) has the value 3. FLOOR (−3.7) has the value −4.
16.9.80 FRACTION (X)1 Description. Fractional part of number.
2 Class. Elemental function.
⃝c ISO/IEC 2017 – All rights reserved 3813 Argument. X shall be of type real.
ISO/IEC DIS 1539-1:2017 (E)
4 Result Characteristics. Same as X.
5 Result Value. The result has the value X × b−e , where b and e are as defined in 16.4 for the representation of
X in the extended real model for the kind of X. If X has the value zero, the result is zero. If X is an IEEE NaN,6 Example. FRACTION (3.0) has the value 0.75 for reals whose model is as in NOTE 16.4.the result is that NaN. If X is an IEEE infinity, the result is an IEEE NaN.
16.9.81 GAMMA (X)1 Description. Gamma function.
2 Class. Elemental function.
3 Argument. X shall be of type real. Its value shall not be a negative integer or zero.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the gamma function of
X,6 Example. GAMMA (1.0) has the value 1.000 (approximately). R ∞ X−1
0 t
exp(−t) dt X>0
Γ(X) =
∞ tX−1 exp(−t) − Pn
R (−t)k
dt −n − 1 < X < −n, n an integer ≥ 0
0 k=0 k!
16.9.82 GET_COMMAND ([COMMAND, LENGTH, STATUS, ERRMSG])1 Description. Get program invocation command.
2 Class. Subroutine.
3 Arguments.
COMMAND (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned4 Example. If the program below is invoked with the command “example” on a processor that supports commandthe entire command by which the program was invoked. If the command cannot be determined,
COMMAND is assigned all blanks.
LENGTH (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned the significant length of the command by which the
program was invoked. The significant length may include trailing blanks if the processor allows
commands with significant trailing blanks. This length does not consider any possible truncation or
padding in assigning the command to the COMMAND argument; in fact the COMMAND argument
need not even be present. If the command length cannot be determined, a length of 0 is assigned.
STATUS (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. It is assigned the value −1 if the COMMAND argument is present and
has a length less than the significant length of the command. It is assigned a processor-dependent
positive value if the command retrieval fails. Otherwise it is assigned the value 0.
ERRMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. It is assigned a
processor-dependent explanatory message if the command retrieval fails. Otherwise, it is unchanged.
retrieval, it will display “Hello example”.382 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
PROGRAM hello
CHARACTER(:), ALLOCATABLE :: cmd
INTEGER :: cmdlen
CALL GET_COMMAND(LENGTH=cmdlen)
IF (cmdlen>0) THEN
ALLOCATE(CHARACTER(cmdlen) :: cmd)
CALL GET_COMMAND(cmd)
PRINT *, ’Hello ’, cmd
END IF
END PROGRAM
16.9.83 GET_COMMAND_ARGUMENT (NUMBER [, VALUE, LENGTH, STATUS, ERRMSG])1 Description. Get program invocation argument.
2 Class. Subroutine.
3 Arguments.
NUMBER shall be an integer scalar. It is an INTENT (IN) argument that specifies the number of the command4 Example. On a processor that supports command arguments, the following program displays the arguments ofargument that the other arguments give information about.
Command argument 0 always exists, and is the command name by which the program was invoked
if the processor has such a concept; otherwise, the value of command argument 0 is processor
dependent. The remaining command arguments are numbered consecutively from 1 to the argument
count in an order determined by the processor.
VALUE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. If the command
argument specified by NUMBER exists, its value is assigned to VALUE; otherwise, VALUE is
assigned all blanks.
LENGTH (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. If the command argument specified by NUMBER exists, its significant
length is assigned to LENGTH; otherwise, LENGTH is assigned the value zero. It is processor
dependent whether the significant length includes trailing blanks. This length does not consider any
possible truncation or padding in assigning the command argument value to the VALUE argument;
in fact the VALUE argument need not even be present.
STATUS (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. If NUMBER is less than zero or greater than the argument count that
would be returned by the intrinsic function COMMAND_ARGUMENT_COUNT, or command
retrieval fails, STATUS is assigned a processor-dependent positive value. Otherwise, if VALUE is
present and has a length less than the significant length of the specified command argument, it is
assigned the value −1. Otherwise it is assigned the value 0.
ERRMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. It is assigned
a processor-dependent explanatory message if the optional argument STATUS is, or would be if
present, assigned a positive value. Otherwise, it is unchanged.
the command by which it was invoked.PROGRAM show_arguments
INTEGER :: i
CHARACTER :: command*32, arg*128
CALL get_command_argument(0, command)
⃝c ISO/IEC 2017 – All rights reserved 383
ISO/IEC DIS 1539-1:2017 (E)
WRITE (*,*) "Command name is: ", command
DO i = 1, command_argument_count()
CALL get_command_argument(i, arg)
WRITE (*,*) "Argument ", i, " is ", arg
END DO
END PROGRAM show_arguments
16.9.84 GET_ENVIRONMENT_VARIABLE (NAME [, VALUE, LENGTH, STATUS, TRIM_NAME, ERRMSG])1 Description. Get environment variable.
2 Class. Subroutine.
3 Arguments.
NAME shall be a default character scalar. It is an INTENT (IN) argument. The interpretation of case is4 It is processor dependent whether an environment variable that exists on an image also exists on another image,processor dependent.
VALUE (optional) shall be a default character scalar. It is an INTENT (OUT) argument. It is assigned the value
of the environment variable specified by NAME. VALUE is assigned all blanks if the environment
variable does not exist or does not have a value or if the processor does not support environment
variables.
LENGTH (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. If the specified environment variable exists and has a value, LENGTH
is assigned the value of its length. Otherwise LENGTH is assigned the value zero.
STATUS (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an
INTENT (OUT) argument. If the environment variable exists and either has no value, its value is
successfully assigned to VALUE, or the VALUE argument is not present, STATUS is assigned the
value zero. STATUS is assigned the value −1 if the VALUE argument is present and has a length
less than the significant length of the environment variable. It is assigned the value 1 if the specified
environment variable does not exist, or 2 if the processor does not support environment variables.
Processor-dependent values greater than 2 may be assigned for other error conditions.
TRIM_NAME (optional) shall be a logical scalar. It is an INTENT (IN) argument. If TRIM_NAME is present
with the value false then trailing blanks in NAME are considered significant if the processor sup-
ports trailing blanks in environment variable names. Otherwise trailing blanks in NAME are not
considered part of the environment variable’s name.
ERRMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. It is assigned
a processor-dependent explanatory message if the optional argument STATUS is, or would be if
present, assigned a positive value. Otherwise, it is unchanged.
and if it does exist on both images, whether the values are the same or different.5 Example. If the value of the environment variable DATAFILE is datafile.dat, executing the statement sequence
below will assign the value ’datafile.dat’ to FILENAME.CHARACTER(:),ALLOCATABLE :: FILENAME
INTEGER :: NAMELEN
CALL GET_ENVIRONMENT_VARIABLE ("DATAFILE", LENGTH=NAMELEN)
IF (LENGTH>0) THEN
ALLOCATE(CHARACTER(LENGTH) :: FILENAME)
CALL GET_ENVIRONMENT_VARIABLE("DATAFILE", FILENAME)
END IF
384 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
16.9.85 GET_TEAM ([LEVEL]) 1 Description. Team.
2 Class. Transformational function.
3 Argument. LEVEL (optional) shall be a scalar integer whose value is equal to one of the named constants
INITIAL_TEAM, PARENT_TEAM, or CURRENT_TEAM from the intrinsic module ISO_FORTRAN_ENV.4 Result Characteristics. Scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.
5 Result Value. The result is a TEAM_TYPE value that identifies the current team if LEVEL is not present,
present with the value CURRENT_TEAM, or if the current team is the initial team. Otherwise, the result6 Examples.identifies the parent team if LEVEL is present with the value PARENT_TEAM, and identifies the initial team
if LEVEL is present with the value INITIAL_TEAM.
PROGRAM EXAMPLE1USE,INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE
TYPE(TEAM_TYPE) :: WORLD_TEAM, TEAM2
! Define a team variable representing the initial team
WORLD_TEAM = GET_TEAM()
END PROGRAM
SUBROUTINE EXAMPLE2 (A)
USE,INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPEREAL A[*]
TYPE(TEAM_TYPE) :: NEW_TEAM, PARENT_TEAM
... ! Form NEW_TEAM
PARENT_TEAM = GET_TEAM ()
CHANGE TEAM (NEW_TEAM)
! Reference image 1 in parent’s team
A [1,TEAM=PARENT_TEAM] = 4.2
! Reference image 1 in current team
A [1] = 9.0
END TEAM
END SUBROUTINE EXAMPLE2
NOTE 16.18
Because the result of GET_TEAM is of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_-
ENV, a program unit that assigns the result of a reference to GET_TEAM to a local variable will also
need access to the definition of TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV.
⃝c ISO/IEC 2017 – All rights reserved 385
ISO/IEC DIS 1539-1:2017 (E)
16.9.86 HUGE (X) 1 Description. Largest model number. 2 Class. Inquiry function.
3 Argument. X shall be of type integer or real. It may be a scalar or an array.
4 Result Characteristics. Scalar of the same type and kind type parameter as X.
5 Result Value. The result has the value r q − 1 if X is of type integer and (1 − b−p )bemax if X is of type real,
where r, q, b, p, and emax are as defined in 16.4 for the model representing numbers of the same type and kind6 Example. HUGE (X) has the value (1 − 2−24 ) × 2127 for real X whose model is as in NOTE 16.4.type parameter as X.
16.9.87 HYPOT (X, Y)1 Description. Euclidean distance function.
2 Class. Elemental function.
3 Arguments.
X shall be of type real.4 Result Characteristics. Same as X.Y shall be of type real with the same kind type parameter as X.
5 Result
p Value. The result has a value equal to a processor-dependent approximation to the Euclidean distance,6 Example. HYPOT (3.0, 4.0) has the value 5.0 (approximately).X2 + Y2 , without undue overflow or underflow.
16.9.88 IACHAR (C [, KIND])1 Description. ASCII code value for character.
2 Class. Elemental function.
3 Arguments.
C shall be of type character and of length one.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. If C is in the collating sequence defined by the codes specified in ISO/IEC 646:1991 (International
Reference Version), the result is the position of C in that sequence; it is nonnegative and less than or equal to6 Example. IACHAR (’X’) has the value 88.127. The value of the result is processor dependent if C is not in the ASCII collating sequence. The results
are consistent with the LGE, LGT, LLE, and LLT comparison functions. For example, if LLE (C, D) is true,
IACHAR (C) <= IACHAR (D) is true where C and D are any two characters representable by the processor.
16.9.89 IALL (ARRAY, DIM [, MASK]) or IALL (ARRAY [, MASK])1 Description. Array reduced by IAND function.
2 Class. Transformational function.
386 ⃝c ISO/IEC 2017 – All rights reserved3 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
ARRAY shall be an array of type integer.4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar ifDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
DIM does not appear or if ARRAY has rank one; otherwise, the result is an array of rank n − 1 and shape [d1 ,5 Result Value.d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): If ARRAY has size zero the result value is equal to NOT (INT (0, KIND (ARRAY))). Otherwise,6 Examples. IALL ([14, 13, 11]) has the value 8. IALL ([14, 13, 11], MASK=[.true., .false., .true]) has the valuethe result of IALL (ARRAY) has a value equal to the bitwise AND of all the elements of ARRAY.
Case (ii): The result of IALL (ARRAY, MASK=MASK) has a value equal to
IALL (PACK (ARRAY, MASK)).
Case (iii): The result of IALL (ARRAY, DIM=DIM [ , MASK=MASK]) has a value equal to that of IALL (AR-
RAY [ , MASK=MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . ,
sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to IALL (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 ,
. . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).
10.1 Description. Bitwise AND.16.9.90 IAND (I, J)
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.J shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have
the same kind type parameter. I and J shall not both be boz-literal-constants.
5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to
type integer with the kind type parameter of the other. The result has the value obtained by combining I and J6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.bit-by-bit according to the following table:
I J IAND (I, J)
1 1 1
1 0 0
0 1 0
0 0 0
7 Example. IAND (1, 3) has the value 1.
16.9.91 IANY (ARRAY, DIM [, MASK]) or IANY (ARRAY [, MASK])1 Description. Reduce array with bitwise OR operation.
2 Class. Transformational function.
⃝c ISO/IEC 2017 – All rights reserved 3873 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
ARRAY shall be of type integer. It shall be an array.4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar ifDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
DIM does not appear or if ARRAY has rank one; otherwise, the result is an array of rank n − 1 and shape [d1 ,5 Result Value.d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where [d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of IANY (ARRAY) is the bitwise OR of all the elements of ARRAY. If ARRAY has size6 Examples. IANY ([14, 13, 8]) has the value 15. IANY ([14, 13, 8], MASK=[.true., .false., .true]) has the valuezero the result value is equal to zero.
Case (ii): The result of IANY (ARRAY, MASK=MASK) has a value equal to
IANY (PACK (ARRAY, MASK)).
Case (iii): The result of IANY (ARRAY, DIM=DIM [, MASK=MASK]) has a value equal to that of IANY (AR-
RAY [, MASK=MASK]) if ARRAY has rank one. Otherwise, the value of element (s1 , s2 , . . . ,
sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to IANY (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 ,
. . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).
14.1 Description. I with bit POS replaced by zero.16.9.92 IBCLR (I, POS)
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.POS shall be of type integer. It shall be nonnegative and less than BIT_SIZE (I).
5 Result Value. The result has the value of the sequence of bits of I, except that bit POS is zero. The model for
the interpretation of an integer value as a sequence of bits is in 16.3.6 Examples. IBCLR (14, 1) has the value 12. If V has the value [1, 2, 3, 4], the value of IBCLR (POS = V, I = 31)
is [29, 27, 23, 15].1 Description. Specified sequence of bits.16.9.93 IBITS (I, POS, LEN)
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.POS shall be of type integer. It shall be nonnegative and POS + LEN shall be less than or equal to
BIT_SIZE (I).
LEN shall be of type integer and nonnegative.
5 Result Value. The result has the value of the sequence of LEN bits in I beginning at bit POS, right-adjusted
and with all other bits zero. The model for the interpretation of an integer value as a sequence of bits is in 16.3.6 Example. IBITS (14, 1, 3) has the value 7.388 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
16.9.94 IBSET (I, POS)1 Description. I with bit POS replaced by one.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.POS shall be of type integer. It shall be nonnegative and less than BIT_SIZE (I).
5 Result Value. The result has the value of the sequence of bits of I, except that bit POS is one. The model for
the interpretation of an integer value as a sequence of bits is in 16.3.6 Examples. IBSET (12, 1) has the value 14. If V has the value [1, 2, 3, 4], the value of IBSET (POS = V, I = 0)
is [2, 4, 8, 16].1 Description. Code value for character.16.9.95 ICHAR (C [, KIND])
2 Class. Elemental function.
3 Arguments.
C shall be of type character and of length one. Its value shall be that of a character capable of4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofrepresentation in the processor.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result is the position of C in the processor collating sequence associated with the kind type
parameter of C; it is nonnegative and less than n, where n is the number of characters in the collating sequence.6 Example. ICHAR (’X’) has the value 88 on a processor using the ASCII collating sequence for default characters.The kind type parameter of the result shall specify an integer kind that is capable of representing n. For any char-
acters C and D capable of representation in the processor, C <= D is true if and only if ICHAR (C) <= ICHAR (D)
is true and C == D is true if and only if ICHAR (C) == ICHAR (D) is true.
16.9.96 IEOR (I, J)1 Description. Bitwise exclusive OR.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.J shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have
the same kind type parameter. I and J shall not both be boz-literal-constants.
5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to
type integer with the kind type parameter of the other. The result has the value obtained by combining I and J6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.⃝c ISO/IEC 2017 – All rights reserved 389
ISO/IEC DIS 1539-1:2017 (E)
bit-by-bit according to the following table:
I J IEOR (I, J)
1 1 0
1 0 1
0 1 1
0 0 0
7 Example. IEOR (1, 3) has the value 2.
16.9.97 IMAGE_INDEX (COARRAY, SUB) or (COARRAY, SUB, TEAM) or1 Description. Image index from cosubscripts.(COARRAY, SUB, TEAM_NUMBER)
2 Class. Inquiry function.
3 Arguments.
COARRAY shall be a coarray of any type. If its designator has more than one part-ref , the rightmost part-ref4 Result Characteristics. Default integer scalar.shall have nonzero corank. If TEAM_NUMBER appears and the current team is not the initial
team, it shall be established in an ancestor of the current team. Otherwise, if TEAM appears, it
shall be established in that team. Otherwise, it shall be established in the current team.
SUB shall be a rank-one integer array of size equal to the corank of COARRAY.
TEAM shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, with a
value that identifies the current or an ancestor team.
TEAM_NUMBER shall be an integer scalar. It shall identify the initial team or a team whose parent is the
same as that of the current team.
5 Result Value. If the value of SUB is a valid sequence of cosubscripts for COARRAY in the team specified by
TEAM or TEAM_NUMBER, or the current team if neither TEAM nor TEAM_NUMBER appears, the result6 Examples. If A and B are declared as A [0:*] and B (10, 20) [10, 0:9, 0:*] respectively, IMAGE_INDEX (A, [0])is the index of the corresponding image in that team. Otherwise, the result is zero.
has the value 1 and IMAGE_INDEX (B, [3, 1, 2]) has the value 213 (on any image).1 Description. Image execution state.16.9.98 IMAGE_STATUS (IMAGE [, TEAM])
2 Class. Elemental function.
3 Arguments.
IMAGE shall be of type integer. Its value shall be positive and less than or equal to the number of images4 Result Characteristics. Default integer.in the specified team.
TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV. Its
value shall represent the current or an ancestor team. If TEAM is absent, the team specified is the
current team.
390 ⃝c ISO/IEC 2017 – All rights reserved5 Result Value. The result value is STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV
ISO/IEC DIS 1539-1:2017 (E)
if the specified image has failed, STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV6 Example. If image 3 of the current team has failed, IMAGE_STATUS (3) has the value STAT_FAILED_-if that image has initiated normal termination, and zero otherwise.
IMAGE.1 Description. Character string search.16.9.99 INDEX (STRING, SUBSTRING [, BACK, KIND])
2 Class. Elemental function.
3 Arguments.
STRING shall be of type character.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofSUBSTRING shall be of type character with the same kind type parameter as STRING.
BACK (optional) shall be of type logical.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type.5 Result Value.
Case (i): If STRING % LEN < SUBSTRING % LEN, the result has the value zero.6 Examples. INDEX (’FORTRAN’, ’R’) has the value 3.Case (ii): Otherwise, if there is an integer I in the range 1 ≤ I ≤ STRING % LEN − SUBSTRING % LEN
+ 1, such that STRING(I : I + SUBSTRING % LEN − 1) is equal to SUBSTRING, the result has
the value of the smallest such I if BACK is absent or present with the value false, and the greatest
such I if BACK is present with the value true.
Case (iii): Otherwise, the result has the value zero.
INDEX (’FORTRAN’, ’R’, BACK = .TRUE.) has the value 5.1 Description. Conversion to integer type.16.9.100 INT (A [, KIND])
2 Class. Elemental function.
3 Arguments.
A shall be of type integer, real, or complex, or a boz-literal-constant.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value.
Case (i): If A is of type integer, INT (A) = A.6 Example. INT (−3.7) has the value −3.Case (ii): If A is of type real, there are two cases: if |A| < 1, INT (A) has the value 0; if |A| ≥ 1, INT (A)
is the integer whose magnitude is the largest integer that does not exceed the magnitude of A and
whose sign is the same as the sign of A.
Case (iii): If A is of type complex, INT (A) = INT (REAL (A, KIND (A))).
Case (iv): If A is a boz-literal-constant, the value of the result is the value whose bit sequence according to the
model in 16.3 is the same as that of A as modified by padding or truncation according to 16.3.3.
The interpretation of a bit sequence whose most significant bit is 1 is processor dependent.
⃝c ISO/IEC 2017 – All rights reserved 391
ISO/IEC DIS 1539-1:2017 (E)
16.9.101 IOR (I, J)1 Description. Bitwise inclusive OR.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.J shall be of type integer or a boz-literal-constant. If both I and J are of type integer, they shall have
the same kind type parameter. I and J shall not both be boz-literal-constants.
5 Result Value. If either I or J is a boz-literal-constant, it is first converted as if by the intrinsic function INT to
type integer with the kind type parameter of the other. The result has the value obtained by combining I and J6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.bit-by-bit according to the following table:
I J IOR (I, J)
1 1 1
1 0 1
0 1 1
0 0 0
7 Example. IOR (5, 3) has the value 7.
16.9.102 IPARITY (ARRAY, DIM [, MASK]) or IPARITY (ARRAY [, MASK])1 Description. Array reduced by IEOR function.
2 Class. Transformational function.
3 Arguments.
ARRAY shall be of type integer. It shall be an array.4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar ifDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where5 Result Value.[d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of IPARITY (ARRAY) has a value equal to the bitwise exclusive OR of all the elements6 Examples. IPARITY ([14, 13, 8]) has the value 11. IPARITY ([14, 13, 8], MASK=[.true., .false., .true]) has theof ARRAY. If ARRAY has size zero the result has the value zero.
Case (ii): The result of IPARITY (ARRAY, MASK=MASK) has a value equal to that of IPARITY (PACK
(ARRAY, MASK)).
Case (iii): The result of IPARITY (ARRAY, DIM=DIM [, MASK=MASK]) has a value equal to that of
IPARITY (ARRAY [, MASK=MASK]) if ARRAY has rank one. Otherwise, the value of element
(s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to IPARITY (ARRAY (s1 , s2 , . . . ,
sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )]).
392 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
value 6.1 Description. Logical shift.16.9.103 ISHFT (I, SHIFT)
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.SHIFT shall be of type integer. The absolute value of SHIFT shall be less than or equal to BIT_SIZE (I).
5 Result Value. The result has the value obtained by shifting the bits of I by SHIFT positions. If SHIFT is
positive, the shift is to the left; if SHIFT is negative, the shift is to the right; if SHIFT is zero, no shift is6 Example. ISHFT (3, 1) has the value 6.performed. Bits shifted out from the left or from the right, as appropriate, are lost. Zeros are shifted in from the
opposite end. The model for the interpretation of an integer value as a sequence of bits is in 16.3.
16.9.104 ISHFTC (I, SHIFT [, SIZE])1 Description. Circular shift of the rightmost bits.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.SHIFT shall be of type integer. The absolute value of SHIFT shall be less than or equal to SIZE.
SIZE (optional) shall be of type integer. The value of SIZE shall be positive and shall not exceed BIT_SIZE (I).
If SIZE is absent, it is as if it were present with the value of BIT_SIZE (I).
5 Result Value. The result has the value obtained by shifting the SIZE rightmost bits of I circularly by SHIFT
positions. If SHIFT is positive, the shift is to the left; if SHIFT is negative, the shift is to the right; and if SHIFT6 Example. ISHFTC (3, 2, 3) has the value 5.is zero, no shift is performed. No bits are lost. The unshifted bits are unaltered. The model for the interpretation
of an integer value as a sequence of bits is in 16.3.
16.9.105 IS_CONTIGUOUS (ARRAY)1 Description. Array contiguity test (8.5.7).
2 Class. Inquiry function.
3 Argument. ARRAY may be of any type. It shall be assumed-rank or an array. If it is a pointer it shall be
associated.4 Result Characteristics. Default logical scalar.
5 Result Value. The result has the value true if ARRAY has rank zero or is contiguous, and false otherwise.
6 Example. After the pointer assignment AP => TARGET (1:10:2), IS_CONTIGUOUS (AP) has the value
false.1 Description. IOSTAT value test for end of file.⃝c ISO/IEC 2017 – All rights reserved 393
ISO/IEC DIS 1539-1:2017 (E)
16.9.106 IS_IOSTAT_END (I)
2 Class. Elemental function.
3 Argument. I shall be of type integer.
4 Result Characteristics. Default logical.
5 Result Value. The result has the value true if and only if I is a value for the stat-variable in an IOSTAT=
specifier (12.11.5) that would indicate an end-of-file condition.1 Description. IOSTAT value test for end of record.16.9.107 IS_IOSTAT_EOR (I)
2 Class. Elemental function.
3 Argument. I shall be of type integer.
4 Result Characteristics. Default logical.
5 Result Value. The result has the value true if and only if I is a value for the stat-variable in an IOSTAT=
specifier (12.11.5) that would indicate an end-of-record condition.1 Description. Value of the kind type parameter of X.16.9.108 KIND (X)
2 Class. Inquiry function.
3 Argument. X may be of any intrinsic type. It may be a scalar or an array.
4 Result Characteristics. Default integer scalar.
5 Result Value. The result has a value equal to the kind type parameter value of X.
6 Example. KIND (0.0) has the kind type parameter value of default real.
16.9.109 LBOUND (ARRAY [, DIM, KIND])1 Description. Lower bound(s).
2 Class. Inquiry function.
3 Arguments.
ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofthat is not associated.
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
The corresponding actual argument shall not be an optional dummy argument, a disassociated
pointer, or an unallocated allocatable.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type. The result is scalar if DIM is present;5 Result Value.otherwise, the result is an array of rank one and size n, where n is the rank of ARRAY.
394 ⃝6 Examples. If A is declared by the statementc ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Case (i): If DIM is present, ARRAY is a whole array, and either ARRAY is an assumed-size array of rank
DIM or dimension DIM of ARRAY has nonzero extent, the result has a value equal to the lower
bound for subscript DIM of ARRAY. Otherwise, if DIM is present, the result value is 1.
Case (ii): LBOUND (ARRAY) has a value whose ith element is equal to LBOUND (ARRAY, i), for i = 1, 2,
. . . , n, where n is the rank of ARRAY. LBOUND (ARRAY, KIND=KIND) has a value whose ith
element is equal to LBOUND (ARRAY, i, KIND), for i = 1, 2, . . . , n, where n is the rank of
ARRAY.
NOTE 16.19
If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement
1 ≤ DIM ≤ 0.
7 REAL A (2:3, 7:10) 8 then LBOUND (A) is [2, 7] and LBOUND (A, DIM=2) is 7. 16.9.110 LCOBOUND (COARRAY [, DIM, KIND])1 Description. Lower cobound(s) of a coarray.
2 Class. Inquiry function. 3 Arguments. COARRAY shall be a coarray and may be of any type. It may be a scalar or an array. If it is allocatable it4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofshall be allocated. If its designator has more than one part-ref , the rightmost part-ref shall have
nonzero corank.
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the corank
of COARRAY. The corresponding actual argument shall not be an optional dummy argument, a
disassociated pointer, or an unallocated allocatable.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type. The result is scalar if DIM is present;5 Result Value.otherwise, the result is an array of rank one and size n, where n is the corank of COARRAY.
Case (i): If DIM is present, the result has a value equal to the lower cobound for codimension DIM of6 Examples. If A is allocated by the statement ALLOCATE (A [2:3, 7:*]) then LCOBOUND (A) is [2, 7] andCOARRAY.
Case (ii): If DIM is absent, the result has a value whose ith element is equal to the lower cobound for codi-
mension i of COARRAY, for i = 1, 2,. . . , n, where n is the corank of COARRAY.
LCOBOUND (A, DIM=2) is 7.1 Description. Number of leading zero bits.16.9.111 LEADZ (I)
2 Class. Elemental function. 3 Argument. I shall be of type integer. 4 Result Characteristics. Default integer. ⃝c ISO/IEC 2017 – All rights reserved 3955 Result Value. If all of the bits of I are zero, the result has the value BIT_SIZE (I). Otherwise, the result has
ISO/IEC DIS 1539-1:2017 (E)
the value BIT_SIZE (I) − 1 − k, where k is the position of the leftmost 1 bit in I. The model for the interpretation6 Examples. LEADZ (1) has the value 31 if BIT_SIZE (1) has the value 32.of an integer value as a sequence of bits is in 16.3.
16.9.112 LEN (STRING [, KIND])1 Description. Length of a character entity.
2 Class. Inquiry function. 3 Arguments. STRING shall be of type character. If it is an unallocated allocatable variable or a pointer that is not4 Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by theassociated, its length type parameter shall not be deferred.
KIND (optional) shall be a scalar integer constant expression.
value of KIND; otherwise the kind type parameter is that of default integer type.5 Result Value. The result has a value equal to the number of characters in STRING if it is scalar or in an
element of STRING if it is an array.6 Example. If C is declared by the statement
7 CHARACTER (11) C (100) 8 LEN (C) has the value 11. 16.9.113 LEN_TRIM (STRING [, KIND])1 Description. Length without trailing blanks.
2 Class. Elemental function. 3 Arguments. STRING shall be of type character.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type.5 Result Value. The result has a value equal to the number of characters remaining after any trailing blanks in
STRING are removed. If the argument contains no nonblank characters, the result is zero.
6 Examples. LEN_TRIM (’ A B ’) has the value 4 and LEN_TRIM (’ ’) has the value 0. 16.9.114 LGE (STRING_A, STRING_B)1 Description. ASCII greater than or equal.
2 Class. Elemental function. 3 Arguments. STRING_A shall be default character or ASCII character.4 Result Characteristics. Default logical.STRING_B shall be of type character with the same kind type parameter as STRING_A.
396 ⃝5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extendedc ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII6 Example. LGE (’ONE’, ’TWO’) has the value false.character set, the result is processor dependent. The result is true if the strings are equal or if STRING_A follows
STRING_B in the ASCII collating sequence; otherwise, the result is false.
NOTE 16.20
The result is true if both STRING_A and STRING_B are of zero length.
16.9.115 LGT (STRING_A, STRING_B)1 Description. ASCII greater than.
2 Class. Elemental function. 3 Arguments. STRING_A shall be default character or ASCII character.4 Result Characteristics. Default logical.STRING_B shall be of type character with the same kind type parameter as STRING_A.
5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII6 Example. LGT (’ONE’, ’TWO’) has the value false.character set, the result is processor dependent. The result is true if STRING_A follows STRING_B in the
ASCII collating sequence; otherwise, the result is false.
NOTE 16.21
The result is false if both STRING_A and STRING_B are of zero length.
16.9.116 LLE (STRING_A, STRING_B)1 Description. ASCII less than or equal.
2 Class. Elemental function. 3 Arguments. STRING_A shall be default character or ASCII character.4 Result Characteristics. Default logical.STRING_B shall be of type character with the same kind type parameter as STRING_A.
5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII6 Example. LLE (’ONE’, ’TWO’) has the value true.character set, the result is processor dependent. The result is true if the strings are equal or if STRING_A
precedes STRING_B in the ASCII collating sequence; otherwise, the result is false.
NOTE 16.22
The result is true if both STRING_A and STRING_B are of zero length.
⃝c ISO/IEC 2017 – All rights reserved 3971 Description. ASCII less than.
ISO/IEC DIS 1539-1:2017 (E)
16.9.117 LLT (STRING_A, STRING_B)
2 Class. Elemental function. 3 Arguments. STRING_A shall be default character or ASCII character.4 Result Characteristics. Default logical.STRING_B shall be of type character with the same kind type parameter as STRING_A.
5 Result Value. If the strings are of unequal length, the comparison is made as if the shorter string were extended on the right with blanks to the length of the longer string. If either string contains a character not in the ASCII6 Example. LLT (’ONE’, ’TWO’) has the value true.character set, the result is processor dependent. The result is true if STRING_A precedes STRING_B in the
ASCII collating sequence; otherwise, the result is false.
NOTE 16.23
The result is false if both STRING_A and STRING_B are of zero length.
16.9.118 LOG (X)1 Description. Natural logarithm.
2 Class. Elemental function. 3 Argument. X shall be of type real or complex. If X is real, its value shall be greater than zero. If X is complex, its value shall not be zero.4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to loge X. A result of type complex is the principal value with imaginary part ω in the range −π ≤ ω ≤ π. If the real part of X is less6 Example. LOG (10.0) has the value 2.3025851 (approximately).than zero and the imaginary part of X is zero, then the imaginary part of the result is approximately π if the
imaginary part of X is positive real zero or the processor does not distinguish between positive and negative real
zero, and approximately −π if the imaginary part of X is negative real zero.
16.9.119 LOG_GAMMA (X)1 Description. Logarithm of the absolute value of the gamma function.
2 Class. Elemental function. 3 Argument. X shall be of type real. Its value shall not be a negative integer or zero. 4 Result Characteristics. Same as X. 5 Result Value. The result has a value equal to a processor-dependent approximation to the natural logarithm of the absolute value of the gamma function of X.6 Example. LOG_GAMMA (3.0) has the value 0.693 (approximately).
398 ⃝c ISO/IEC 2017 – All rights reserved1 Description. Common logarithm.
ISO/IEC DIS 1539-1:2017 (E)
16.9.120 LOG10 (X)
2 Class. Elemental function. 3 Argument. X shall be of type real. The value of X shall be greater than zero. 4 Result Characteristics. Same as X. 5 Result Value. The result has a value equal to a processor-dependent approximation to log10 X. 6 Example. LOG10 (10.0) has the value 1.0 (approximately). 16.9.121 LOGICAL (L [, KIND])1 Description. Conversion between kinds of logical.
2 Class. Elemental function. 3 Arguments. L shall be of type logical.4 Result Characteristics. Logical. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default logical.5 Result Value. The value is that of L.
6 Example. LOGICAL (L .OR. .NOT. L) has the value true and is default logical, regardless of the kind type parameter of the logical variable L.1 Description. Left justified mask.16.9.122 MASKL (I [, KIND])
2 Class. Elemental function. 3 Arguments. I shall be of type integer. It shall be nonnegative and less than or equal to the number of bits z of4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofthe model integer defined for bit manipulation contexts in 16.3 for the kind of the result.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result value has its leftmost I bits set to 1 and the remaining bits set to 0. The model for
the interpretation of an integer value as a sequence of bits is in 16.3.6 Example. MASKL (3) has the value SHIFTL (7, BIT_SIZE (0) − 3).
16.9.123 MASKR (I [, KIND])1 Description. Right justified mask.
2 Class. Elemental function. ⃝c ISO/IEC 2017 – All rights reserved 3993 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
I shall be of type integer. It shall be nonnegative and less than or equal to the number of bits z of4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofthe model integer defined for bit manipulation contexts in 16.3 for the kind of the result.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result value has its rightmost I bits set to 1 and the remaining bits set to 0. The model for
the interpretation of an integer value as a sequence of bits is in 16.3.6 Example. MASKR (3) has the value 7.
16.9.124 MATMUL (MATRIX_A, MATRIX_B)1 Description. Matrix multiplication.
2 Class. Transformational function. 3 Arguments. MATRIX_A shall be a rank-one or rank-two array of numeric type or logical type.4 Result Characteristics. If the arguments are of numeric type, the type and kind type parameter of the resultMATRIX_B shall be of numeric type if MATRIX_A is of numeric type and of logical type if MATRIX_A is of
logical type. It shall be an array of rank one or two. MATRIX_A and MATRIX_B shall not both
have rank one. The size of the first (or only) dimension of MATRIX_B shall equal the size of the
last (or only) dimension of MATRIX_A.
are determined by the types of the arguments as specified in 10.1.9.3 for the * operator. If the arguments are of5 Result Value.type logical, the result is of type logical with the kind type parameter of the arguments as specified in 10.1.9.3
for the .AND. operator. The shape of the result depends on the shapes of the arguments as follows:
Case (i): If MATRIX_A has shape [n, m] and MATRIX_B has shape [m, k], the result has shape [n, k].
Case (ii): If MATRIX_A has shape [m] and MATRIX_B has shape [m, k], the result has shape [k].
Case (iii): If MATRIX_A has shape [n, m] and MATRIX_B has shape [m], the result has shape [n].
Case (i): Element (i, j) of the result has the value SUM (MATRIX_A (i, :) * MATRIX_B (:, j)) if thearguments are of numeric type and has the value ANY (MATRIX_A (i, :) .AND. MATRIX_B (:,
j)) if the arguments are of logical type.
Case (ii): Element (j) of the result has the value SUM (MATRIX_A (:) * MATRIX_B (:, j)) if the arguments
are of numeric type and has the value ANY (MATRIX_A (:) .AND. MATRIX_B (:, j)) if the
arguments are of logical type.
Case (iii): Element (i) of the result has the value SUM (MATRIX_A (i, :) * MATRIX_B (:)) if the arguments
are of numeric type and has the value ANY (MATRIX_A (i, :) .AND. MATRIX_B (:)) if the
arguments are of logical type.
1 2
1 2 3
6 Examples. Let A and B be the matrices and 2 3 ; let X and Y be the vectors [1, 2] and 2 3 4
3 4
[1, 2, 3]. 14 20
Case (i): The result of MATMUL (A, B) is the matrix-matrix product AB with the value . 20 29
Case (ii): The result of MATMUL (X, A) is the vector-matrix product XA with the value [5, 8, 11]. Case (iii): The result of MATMUL (A, Y) is the matrix-vector product AY with the value [14, 20]. 400 c ISO/IEC 2017 – All rights reserved16.9.125 MAX (A1, A2 [, A3, ...])
ISO/IEC DIS 1539-1:2017 (E)
1 Description. Maximum value. 2 Class. Elemental function. 3 Arguments. The arguments shall all have the same type which shall be integer, real, or character and they shall all have the same kind type parameter.4 Result Characteristics. The type and kind type parameter of the result are the same as those of the arguments.
For arguments of character type, the length of the result is the length of the longest argument.5 Result Value. The value of the result is that of the largest argument. For arguments of character type, the
result is the value that would be selected by application of intrinsic relational operators; that is, the collating6 Examples. MAX (−9.0, 7.0, 2.0) has the value 7.0, MAX (’Z’, ’BB’) has the value ’Z ’, and MAX ([’A’, ’Z’],sequence for characters with the kind type parameter of the arguments is applied. If the selected argument is
shorter than the longest argument, the result is extended with blanks on the right to the length of the longest
argument.
[’BB’, ’Y ’]) has the value [’BB’, ’Z ’].1 Description. Maximum exponent of a real model.16.9.126 MAXEXPONENT (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default integer scalar. 5 Result Value. The result has the value emax , as defined in 16.4 for the model representing numbers of the same type and kind type parameter as X.6 Example. MAXEXPONENT (X) has the value 127 for real X whose model is as in NOTE 16.4.
16.9.127 MAXLOC (ARRAY, DIM [, MASK, KIND, BACK]) or1 Description. Location(s) of maximum value.MAXLOC (ARRAY [, MASK, KIND, BACK])
2 Class. Transformational function. 3 Arguments. ARRAY shall be an array of type integer, real, or character.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
KIND (optional) shall be a scalar integer constant expression.
BACK (optional) shall be a logical scalar.
KIND; otherwise the kind type parameter is that of default integer type. If DIM does not appear, the result is5 Result Value.an array of rank one and of size equal to the rank of ARRAY; otherwise, the result is of rank n − 1 and shape
[d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where [d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): If DIM does not appear and MASK is absent, the result is a rank-one array whose element values6 If only one element has the maximum value, that element’s subscripts are returned. Otherwise, if more thanare the values of the subscripts of an element of ARRAY whose value equals the maximum value of
⃝c ISO/IEC 2017 – All rights reserved 401
ISO/IEC DIS 1539-1:2017 (E)
all of the elements of ARRAY. The ith subscript returned lies in the range 1 to ei , where ei is the
extent of the ith dimension of ARRAY. If ARRAY has size zero, all elements of the result are zero.
Case (ii): If DIM does not appear and MASK is present, the result is a rank-one array whose element values
are the values of the subscripts of an element of ARRAY, corresponding to a true element of MASK,
whose value equals the maximum value of all such elements of ARRAY. The ith subscript returned
lies in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If ARRAY has size
zero or every element of MASK has the value false, all elements of the result are zero.
Case (iii): If ARRAY has rank one and DIM is specified, the result has a value equal to that of the first element
of MAXLOC (ARRAY [, MASK = MASK, KIND = KIND, BACK = BACK]). Otherwise, if DIM
is specified, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to
MAXLOC (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ),
DIM = 1
[, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ),
KIND = KIND,
BACK = BACK] ).
one element has the maximum value and BACK is absent or present with the value false, the element whose7 If ARRAY has type character, the result is the value that would be selected by application of intrinsic relationalsubscripts are returned is the first such element, taken in array element order. If BACK is present with the value
true, the element whose subscripts are returned is the last such element, taken in array element order.
operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.8 Examples.
Case (i): The value of MAXLOC ([2, 6, 4, 6]) is [2] and the value of MAXLOC ([2, 6, 4, 6], BACK=.TRUE.)1 Description. Maximum value(s) of array.is [4].
0 −5 8 −3
Case (ii): If A has the value 3 4 −1 2 , MAXLOC (A, MASK = A < 6) has the value [3, 2]. This
1 5 6 −4
is independent of the declared lower bounds for A.
1 3 −9
Case (iii): The value of MAXLOC ([5, −9, 3], DIM = 1) is 1. If B has the value , MAXLOC
2 2 6
(B, DIM = 1) is [2, 1, 2] and MAXLOC (B, DIM = 2) is [2, 3]. This is independent of the declared
lower bounds for B.
16.9.128 MAXVAL (ARRAY, DIM [, MASK]) or MAXVAL (ARRAY [, MASK])
2 Class. Transformational function. 3 Arguments. ARRAY shall be an array of type integer, real, or character.4 Result Characteristics. The result is of the same type and type parameters as ARRAY. It is scalar if DIMDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where5 Result Value.[d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of MAXVAL (ARRAY) has a value equal to the maximum value of all the elements of6 If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relationalARRAY if the size of ARRAY is not zero. If ARRAY has size zero and type integer or real, the
result has the value of the negative number of the largest magnitude supported by the processor
for numbers of the type and kind type parameter of ARRAY. If ARRAY has size zero and type
402 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
character, the result has the value of a string of characters of length LEN (ARRAY), with each
character equal to CHAR (0, KIND (ARRAY)).
Case (ii): The result of MAXVAL (ARRAY, MASK = MASK) has a value equal to that of MAXVAL (PACK
(ARRAY, MASK)).
Case (iii): The result of MAXVAL (ARRAY, DIM = DIM [,MASK = MASK]) has a value equal to that of
MAXVAL (ARRAY [,MASK = MASK]) if ARRAY has rank one. Otherwise, the value of element
(s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to
MAXVAL (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )
[, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).
operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.7 Examples.
Case (i): The value of MAXVAL ([1, 2, 3]) is 3.1 Description. Expression value selection.Case (ii): MAXVAL (C, MASK = C < 0.0) is the maximum of the negative elements of C.
1 3 5
Case (iii): If B is the array , MAXVAL (B, DIM = 1) is [2, 7, 6] and MAXVAL (B, DIM = 2) is
2 7 6
[5, 7].
16.9.129 MERGE (TSOURCE, FSOURCE, MASK)
2 Class. Elemental function. 3 Arguments. TSOURCE may be of any type.4 Result Characteristics. Same type and type parameters as TSOURCE. Because TSOURCE and FSOURCEFSOURCE shall be of the same type and type parameters as TSOURCE.
MASK shall be of type logical.
are required to have the same type and type parameters (for both the declared and dynamic types), the result is5 Result Value. The result is TSOURCE if MASK is true and FSOURCE otherwise.polymorphic if and only if both TSOURCE and FSOURCE are polymorphic.
1 6 5 0 3 2
6 Examples. If TSOURCE is the array , FSOURCE is the array and MASK is the
2 4 6 7 4 8 T . T
16.9.130 MERGE_BITS (I, J, MASK)
array , where “T” represents true and “.” represents false, then MERGE (TSOURCE, FSOURCE, . . T
1 3 5
MASK) is
.The value of MERGE (1.0, 0.0, K > 0) is 1.0 for K = 5 and 0.0 for K = −2.7 4 6
1 Description. Merge of bits under mask. 2 Class. Elemental function. 3 Arguments. I shall be of type integer or a boz-literal-constant.4 Result Characteristics. Same as I if I is of type integer; otherwise, same as J.J shall be of type integer or a boz-literal-constant. If both I and J are of type integer they shall have
the same kind type parameter. I and J shall not both be boz-literal-constants.
⃝c ISO/IEC 2017 – All rights reserved 403
ISO/IEC DIS 1539-1:2017 (E)
MASK shall be of type integer or a boz-literal-constant. If MASK is of type integer, it shall have the same
kind type parameter as each other argument of type integer.
5 Result Value. If any argument is a boz-literal-constant, it is first converted as if by the intrinsic function INT to the type and kind type parameter of the result. The result has the value of IOR (IAND (I, MASK),6 Example. MERGE_BITS (13, 18, 22) has the value 4.IAND (J, NOT (MASK))).
16.9.131 MIN (A1, A2 [, A3, ...])1 Description. Minimum value.
2 Class. Elemental function. 3 Arguments. The arguments shall all be of the same type which shall be integer, real, or character and they shall all have the same kind type parameter.4 Result Characteristics. The type and kind type parameter of the result are the same as those of the arguments.
For arguments of character type, the length of the result is the length of the longest argument.5 Result Value. The value of the result is that of the smallest argument. For arguments of character type, the
result is the value that would be selected by application of intrinsic relational operators; that is, the collating6 Examples. MIN (−9.0, 7.0, 2.0) has the value −9.0, MIN (’A’, ’YY’) has the value ’A ’, andsequence for characters with the kind type parameter of the arguments is applied. If the selected argument is
shorter than the longest argument, the result is extended with blanks on the right to the length of the longest
argument.
MIN ([’Z’, ’A’], [’YY’, ’B ’]) has the value [’YY’, ’A ’].1 Description. Minimum exponent of a real model.16.9.132 MINEXPONENT (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default integer scalar. 5 Result Value. The result has the value emin , as defined in 16.4 for the model representing numbers of the same type and kind type parameter as X.6 Example. MINEXPONENT (X) has the value −126 for real X whose model is as in NOTE 16.4.
16.9.133 MINLOC (ARRAY, DIM [, MASK, KIND, BACK]) or1 Description. Location(s) of minimum value.MINLOC (ARRAY [, MASK, KIND, BACK])
2 Class. Transformational function. 3 Arguments. ARRAY shall be an array of type integer, real, or character.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
404 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
KIND (optional) shall be a scalar integer constant expression.
BACK (optional) shall be a logical scalar.
KIND; otherwise the kind type parameter is that of default integer type. If DIM does not appear, the result is5 Result Value.an array of rank one and of size equal to the rank of ARRAY; otherwise, the result is of rank n − 1 and shape
[d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where [d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): If DIM does not appear and MASK is absent the result is a rank-one array whose element values6 If only one element has the minimum value, that element’s subscripts are returned. Otherwise, if more than oneare the values of the subscripts of an element of ARRAY whose value equals the minimum value
of all the elements of ARRAY. The ith subscript returned lies in the range 1 to ei , where ei is the
extent of the ith dimension of ARRAY. If ARRAY has size zero, all elements of the result are zero.
Case (ii): If DIM does not appear and MASK is present, the result is a rank-one array whose element values
are the values of the subscripts of an element of ARRAY, corresponding to a true element of MASK,
whose value equals the minimum value of all such elements of ARRAY. The ith subscript returned
lies in the range 1 to ei , where ei is the extent of the ith dimension of ARRAY. If ARRAY has size
zero or every element of MASK has the value false, all elements of the result are zero.
Case (iii): If ARRAY has rank one and DIM is specified, the result has a value equal to that of the first element
of MINLOC (ARRAY [, MASK = MASK, KIND = KIND, BACK = BACK]). Otherwise, if DIM
is specified, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to
MINLOC (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ),
DIM = 1
[, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ),
KIND = KIND,
BACK = BACK] ).
element has the minimum value and BACK is absent or present with the value false, the element whose subscripts7 If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relationalare returned is the first such element, taken in array element order. If BACK is present with the value true, the
element whose subscripts are returned is the last such element, taken in array element order.
operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.8 Examples.
Case (i): The value of MINLOC ([4, 3, 6, 3]) is [2] and the value of MINLOC ([4, 3, 6, 3], BACK = .TRUE.)1 Description. Minimum value(s) of array.is [4].
0 −5 8 −3
Case (ii): If A has the value 3 4 −1 2 , MINLOC (A, MASK = A > −4) has the value [1, 4].
1 5 6 −4
This is independent of the declared lower bounds for A.
1 3 −9
Case (iii): The value of MINLOC ([5, −9, 3], DIM = 1) is 2. If B has the value , MIN-
2 2 6
LOC (B, DIM = 1) is [1, 2, 1] and MINLOC (B, DIM = 2) is [3, 1]. This is independent of
the declared lower bounds for B.
16.9.134 MINVAL (ARRAY, DIM [, MASK]) or MINVAL (ARRAY [, MASK])
2 Class. Transformational function. 3 Arguments. ARRAY shall be an array of type integer, real, or character.4 Result Characteristics. The result is of the same type and type parameters as ARRAY. It is scalar if DIMDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
⃝c ISO/IEC 2017 – All rights reserved 405
ISO/IEC DIS 1539-1:2017 (E)
does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where5 Result Value.[d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of MINVAL (ARRAY) has a value equal to the minimum value of all the elements of6 If ARRAY is of type character, the result is the value that would be selected by application of intrinsic relationalARRAY if the size of ARRAY is not zero. If ARRAY has size zero and type integer or real, the
result has the value of the positive number of the largest magnitude supported by the processor
for numbers of the type and kind type parameter of ARRAY. If ARRAY has size zero and type
character, the result has the value of a string of characters of length LEN (ARRAY), with each
character equal to CHAR (n − 1, KIND (ARRAY)), where n is the number of characters in the
collating sequence for characters with the kind type parameter of ARRAY.
Case (ii): The result of MINVAL (ARRAY, MASK = MASK) has a value equal to that of MINVAL (PACK
(ARRAY, MASK)).
Case (iii): The result of MINVAL (ARRAY, DIM = DIM [, MASK = MASK]) has a value equal to that of
MINVAL (ARRAY [, MASK = MASK]) if ARRAY has rank one. Otherwise, the value of element
(s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of the result is equal to
MINVAL (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )
[, MASK= MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).
operators; that is, the collating sequence for characters with the kind type parameter of the arguments is applied.7 Examples.
Case (i): The value of MINVAL ([1, 2, 3]) is 1.1 Description. Remainder function.Case (ii): MINVAL (C, MASK = C > 0.0) is the minimum of the positive elements of C.
1 3 5
Case (iii): If B is the array , MINVAL (B, DIM = 1) is [1, 3, 5] and MINVAL (B, DIM = 2) is
2 4 6
[1, 2].
16.9.135 MOD (A, P)
2 Class. Elemental function. 3 Arguments. A shall be of type integer or real.4 Result Characteristics. Same as A.P shall be of the same type and kind type parameter as A. P shall not be zero.
5 Result Value. The value of the result is A − INT (A/P) * P. 6 Examples. MOD (3.0, 2.0) has the value 1.0 (approximately). MOD (8, 5) has the value 3. MOD (−8, 5) has the value −3. MOD (8, −5) has the value 3. MOD (−8, −5) has the value −3.1 Description. Modulo function.16.9.136 MODULO (A, P)
2 Class. Elemental function. 3 Arguments. A shall be of type integer or real.4 Result Characteristics. Same as A.P shall be of the same type and kind type parameter as A. P shall not be zero.
406 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value. Case (i): A is of type integer. MODULO (A, P) has the value R such that A = Q × P + R, where Q is an6 Examples. MODULO (8, 5) has the value 3. MODULO (−8, 5) has the value 2. MODULO (8, −5) has theinteger, the inequalities 0 ≤ R < P hold if P > 0, and P < R ≤ 0 hold if P < 0.
Case (ii): A is of type real. The value of the result is A − FLOOR (A / P) * P.
value −2. MODULO (−8, −5) has the value −3.1 Description. Move an allocation.16.9.137 MOVE_ALLOC (FROM, TO [, STAT, ERRMSG])
2 Class. Subroutine, pure if and only if FROM is not a coarray. 3 Arguments. FROM may be of any type, rank, and corank. It shall be allocatable and shall not be a coindexed object.4 If execution of MOVE_ALLOC is successful, or if STAT_FAILED_IMAGE is assigned to STAT,It is an INTENT (INOUT) argument.
TO shall be type compatible (7.3.2.3) with FROM and have the same rank and corank. It shall be
allocatable and shall not be a coindexed object. It shall be polymorphic if FROM is polymorphic.
It is an INTENT (OUT) argument. Each nondeferred parameter of the declared type of TO shall
have the same value as the corresponding parameter of the declared type of FROM.
STAT (optional) shall be a noncoindexed integer scalar with a decimal exponent range of at least four. It is an
INTENT (OUT) argument.
ERRMSG (optional) shall be a noncoindexed default character scalar. It is an INTENT (INOUT) argument.
• On invocation of MOVE_ALLOC, if the allocation status of TO is allocated, it is deallocated. Then,5 When a reference to MOVE_ALLOC is executed for which the FROM argument is a coarray, there is an implicitif FROM has an allocation status of allocated on entry to MOVE_ALLOC, TO becomes allocated with
dynamic type, type parameters, bounds, cobounds, and value identical to those that FROM had on entry
to MOVE_ALLOC. Note that if FROM and TO are the same variable, it shall be unallocated when
MOVE_ALLOC is invoked.
• If TO has the TARGET attribute, any pointer associated with FROM on entry to MOVE_ALLOC becomes
correspondingly associated with TO. If TO does not have the TARGET attribute, the pointer association
status of any pointer associated with FROM on entry becomes undefined.
• The allocation status of FROM becomes unallocated.
synchronization of all active images of the current team. On those images, execution of the segment (11.6.2)6 If STAT is present and execution is successful, it is assigned the value zero.following the CALL statement is delayed until all other active images of the current team have executed the same
statement the same number of times. When such a reference is executed, if any image of the current team has
stopped or failed, an error condition occurs.
7 If an error condition occurs, • if STAT is absent, error termination is initiated;• otherwise, if FROM is a coarray and the current team contains a stopped image, STAT is assigned the value
STAT_STOPPED_IMAGE from the intrinsic module ISO_FORTRAN_ENV;
• otherwise, if FROM is a coarray and the current team contains a failed image, and no other error condition
occurs, STAT is assigned the value STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_-
ENV;
⃝c ISO/IEC 2017 – All rights reserved 407
ISO/IEC DIS 1539-1:2017 (E)
• otherwise, STAT is assigned a processor-dependent positive value that differs from that of STAT_STOP-8 If the ERRMSG argument is present and an error condition occurs, it is assigned an explanatory message. If noPED_IMAGE or STAT_FAILED_IMAGE.
error condition occurs, the definition status and value of ERRMSG are unchanged.9 Example. The example below demonstrates reallocation of GRID to twice its previous size, with its previous
contents evenly distributed over the new elements so that intermediate points can be inserted.1 Description. Copy a sequence of bits.REAL,ALLOCATABLE :: GRID(:),TEMPGRID(:)
...
ALLOCATE(GRID(-N:N)) ! initial allocation of GRID
...
ALLOCATE(TEMPGRID(-2*N:2*N)) ! allocate bigger grid
TEMPGRID(::2)=GRID ! distribute values to new locations
CALL MOVE_ALLOC(TO=GRID,FROM=TEMPGRID)
The old grid is deallocated because TO is INTENT (OUT), and GRID then takes over the new grid allocation.
NOTE 16.24
It is expected that the implementation of allocatable objects will typically involve descriptors to locate the
allocated storage; MOVE_ALLOC could then be implemented by transferring the contents of the descriptor
for FROM to the descriptor for TO and clearing the descriptor for FROM.
16.9.138 MVBITS (FROM, FROMPOS, LEN, TO, TOPOS)
2 Class. Elemental subroutine. 3 Arguments.
FROM shall be of type integer. It is an INTENT (IN) argument.4 Example. If TO has the initial value 6, its value after the statement CALL MVBITS (7, 2, 2, TO, 0) is 5.FROMPOS shall be of type integer and nonnegative. It is an INTENT (IN) argument. FROMPOS + LEN
shall be less than or equal to BIT_SIZE (FROM). The model for the interpretation of an integer
value as a sequence of bits is in 16.3.
LEN shall be of type integer and nonnegative. It is an INTENT (IN) argument.
TO shall be a variable of the same type and kind type parameter value as FROM and may be associated
with FROM (15.8.3). It is an INTENT (INOUT) argument. TO is defined by copying the sequence
of bits of length LEN, starting at position FROMPOS of FROM to position TOPOS of TO. No
other bits of TO are altered. On return, the LEN bits of TO starting at TOPOS are equal to
the value that the LEN bits of FROM starting at FROMPOS had on entry. The model for the
interpretation of an integer value as a sequence of bits is in 16.3.
TOPOS shall be of type integer and nonnegative. It is an INTENT (IN) argument. TOPOS + LEN shall
be less than or equal to BIT_SIZE (TO).
16.9.139 NEAREST (X, S)1 Description. Adjacent machine number.
2 Class. Elemental function.
408 ⃝c ISO/IEC 2017 – All rights reserved3 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
X shall be of type real.4 Result Characteristics. Same as X.S shall be of type real and not equal to zero.
5 Result Value. The result has a value equal to the machine-representable number distinct from X and nearest
to it in the direction of the ∞ with the same sign as S.6 Example. NEAREST (3.0, 2.0) has the value 3 + 2−22 on a machine whose representation is that of the model
in NOTE 16.4.1 Description. Newline character.NOTE 16.25
Unlike other floating-point manipulation functions, NEAREST operates on machine-representable numbers
rather than model numbers. On many systems there are machine-representable numbers that lie between
adjacent model numbers.
16.9.140 NEW_LINE (A)
2 Class. Inquiry function.
3 Argument. A shall be of type character. It may be a scalar or an array.
4 Result Characteristics. Character scalar of length one with the same kind type parameter as A.
5 Result Value.
Case (i): If A is default character and the character in position 10 of the ASCII collating sequence is repres-6 Example. If there is a suitable newline character, and unit 10 is connected for formatted stream output, theentable in the default character set, then the result is ACHAR (10).
Case (ii): If A is ASCII character or ISO 10646 character, then the result is CHAR (10, KIND (A)).
Case (iii): Otherwise, the result is a processor-dependent character that represents a newline in output to files
connected for formatted stream output if there is such a character.
Case (iv): Otherwise, the result is the blank character.
statement1 Description. Nearest integer.WRITE (10, ’(A)’) ’New’//NEW_LINE(’a’)//’Line’
will write a record containing “New” and then a record containing “Line”.
16.9.141 NINT (A [, KIND])
2 Class. Elemental function.
3 Arguments.
A shall be of type real.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofKIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result is the integer nearest A, or if there are two integers equally near A, the result is
whichever such integer has the greater magnitude.6 Example. NINT (2.783) has the value 3.⃝c ISO/IEC 2017 – All rights reserved 409
ISO/IEC DIS 1539-1:2017 (E)
16.9.142 NORM2 (X) or NORM2 (X, DIM)1 Description. L2 norm of an array.
2 Class. Transformational function.
3 Arguments.
X shall be a real array.4 Result Characteristics. The result is of the same type and type parameters as X. It is scalar if DIM does notDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of X.
appear; otherwise the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ], where n is the rank5 Result Value.of X and [d1 , d2 , . . . , dn ] is the shape of X.
Case (i): The result of NORM2 (X) has a value equal to a processor-dependent approximation to the gener-6 It is recommended that the processor compute the result without undue overflow or underflow.alized L2 norm of X, which is the square root of the sum of the squares of the elements of X. If X
has size zero, the result has the value zero.
Case (ii): The result of NORM2 (X, DIM=DIM) has a value equal to that of NORM2 (X) if X has rank
one. Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . sn ) of the result is equal to
NORM2 (X(s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . sn )).
1.0 2.0
1 Description. Bitwise complement.
7 Example. The value of NORM2 ([3.0, 4.0]) is 5.0 (approximately). If X has the value then the 3.0 4.0value of NORM2 (X, DIM=1) is [3.162, 4.472] (approximately) and the value of NORM2 (X, DIM=2) is [2.236,
5.0] (approximately).
16.9.143 NOT (I)
2 Class. Elemental function.
3 Argument. I shall be of type integer.
4 Result Characteristics. Same as I.
5 Result Value. The result has the value obtained by complementing I bit-by-bit according to the following table:
I NOT (I)6 The model for the interpretation of an integer value as a sequence of bits is in 16.3.1 0
0 1
7 Example. If I is represented by the string of bits 01010101, NOT (I) has the binary value 10101010.
16.9.144 NULL ([MOLD])1 Description. Disassociated pointer or unallocated allocatable entity.
2 Class. Transformational function.
410 ⃝c ISO/IEC 2017 – All rights reserved3 Argument. MOLD shall be a pointer or allocatable. It may be of any type or may be a procedure pointer.
ISO/IEC DIS 1539-1:2017 (E)
If MOLD is a pointer its pointer association status may be undefined, disassociated, or associated. If MOLD is4 Result Characteristics. If MOLD is present, the characteristics are the same as MOLD. If MOLD has deferredallocatable its allocation status may be allocated or unallocated. It need not be defined with a value.
type parameters, those type parameters of the result are deferred.5 If MOLD is absent, the characteristics of the result are determined by the entity with which the reference is
associated. See Table 16.5. MOLD shall not be absent in any other context. If any type parameters of the6 If the context of the reference to NULL is an actual argument in a generic procedure reference, MOLD shall becontextual entity are deferred, those type parameters of the result are deferred. If any type parameters of the
contextual entity are assumed, MOLD shall be present.
present if the type, type parameters, or rank are required to resolve the generic reference.7 Result. The result is a disassociated pointer or an unallocated allocatable entity.Table 16.5: Characteristics of the result of NULL ( )
Appearance of NULL ( ) Type, type parameters, and rank of result:
right side of a pointer assignment pointer on the left side
initialization for an object in a declaration the object
default initialization for a component the component
in a structure constructor the corresponding component
as an actual argument the corresponding dummy argument
in a DATA statement the corresponding pointer object
8 Examples.
Case (i): REAL, POINTER, DIMENSION (:) :: VEC => NULL ( ) defines the initial association status ofVEC to be disassociated.
Case (ii): The MOLD argument is required in the following:
INTERFACE GEN
SUBROUTINE S1 (J, PI)
INTEGER J
INTEGER, POINTER :: PI
END SUBROUTINE S1
SUBROUTINE S2 (K, PR)
INTEGER K
REAL, POINTER :: PR
END SUBROUTINE S2
END INTERFACE
REAL, POINTER :: REAL_PTR
CALL GEN (7, NULL (REAL_PTR) ) ! Invokes S2 16.9.145 NUM_IMAGES ( ) or NUM_IMAGES (TEAM) or
NUM_IMAGES (TEAM_NUMBER)1 Description. Number of images.
2 Class. Transformational function.
⃝c ISO/IEC 2017 – All rights reserved 4113 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
TEAM shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV, with a4 Result Characteristics. Default integer scalar.value that identifies the current or an ancestor team.
TEAM_NUMBER shall be an integer scalar. It shall identify the initial team or a team whose parent is the
same as that of the current team.
5 Result Value. The number of images in the specified team, or in the current team if no team is specified.
6 Example. The following code uses image 1 to read data and broadcast it to other images.
REAL :: P[*]IF (THIS_IMAGE()==1) THEN
READ (6,*) P
DO I = 2, NUM_IMAGES()
P[I] = P
END DO
END IF
SYNC ALL
16.9.146 OUT_OF_RANGE (X, MOLD [, ROUND])
1 Description. Whether a value cannot be converted safely.
2 Class. Elemental function.
3 Arguments.
X shall be of type integer or real.4 Result Characteristics. Default logical.MOLD shall be an integer or real scalar. If it is a variable, it need not be defined.
ROUND (optional) shall be a logical scalar. ROUND shall be present only if X is of type real and MOLD is of
type integer.
5 Result Value.
Case (i): If MOLD is of type integer, and ROUND is absent or present with the value false, the result is true6 Examples. If INT8 is the kind value for an 8-bit binary integer type, OUT_OF_RANGE (−128.5, 0_INT8)if and only if the value of X is an IEEE infinity or NaN, or if the integer with largest magnitude
that lies between zero and X inclusive is not representable by objects with the type and kind of
MOLD.
Case (ii): If MOLD is of type integer, and ROUND is present with the value true, the result is true if and only
if the value of X is an IEEE infinity or NaN, or if the integer nearest X, or the integer of greater
magnitude if two integers are equally near to X, is not representable by objects with the type and
kind of MOLD.
Case (iii): Otherwise, the result is true if and only if the value of X is an IEEE infinity or NaN that is not
supported by objects of the type and kind of MOLD, or if X is a finite number and the result of
rounding the value of X (according to the IEEE rounding mode if appropriate) to the extended
model for the kind of MOLD has magnitude larger than that of the largest finite number with the
same sign as X that is representable by objects with the type and kind of MOLD.
will have the value false and OUT_OF_RANGE (−128.5, 0_INT8, .TRUE.) will have the value true.1 Description. Array packed into a vector.412 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.26
MOLD is required to be a scalar because the only information taken from it is its type and kind. Allowing
an array MOLD would require that it be conformable with X. ROUND is scalar because allowing an array
rounding mode would have severe performance difficulties on many processors.
16.9.147 PACK (ARRAY, MASK [, VECTOR])
2 Class. Transformational function.
3 Arguments.
ARRAY shall be an array of any type.MASK shall be of type logical and shall be conformable with ARRAY.
VECTOR (optional) shall be of the same type and type parameters as ARRAY and shall have rank one. VEC-
TOR shall have at least as many elements as there are true elements in MASK. If MASK is scalar
with the value true, VECTOR shall have at least as many elements as there are in ARRAY.
1 Description. Array reduced by .NEQV. operation.
4 Result Characteristics. The result is an array of rank one with the same type and type parameters as ARRAY. If VECTOR is present, the result size is that of VECTOR; otherwise, the result size is the number t5 Result Value. Element i of the result is the element of ARRAY that corresponds to the ith true element ofof true elements in MASK unless MASK is scalar with the value true, in which case the result size is the size of
ARRAY.
MASK, taking elements in array element order, for i = 1, 2, . . . , t. If VECTOR is present and has size n > t,6 Examples. The nonzero elements of an array M with the value 9 0 0 can be “gathered” by the func-element i of the result has the value VECTOR (i), for i = t + 1, . . . , n.
0 0 0
0 0 7
tion PACK. The result of PACK (M, MASK = M /= 0) is [9, 7] and the result of PACK (M, M /= 0, VEC- TOR = [2, 4, 6, 8, 10, 12]) is [9, 7, 6, 8, 10, 12].
16.9.148 PARITY (MASK) or PARITY (MASK, DIM)
2 Class. Transformational function.
3 Arguments.
MASK shall be a logical array.4 Result Characteristics. The result is of type logical with the same kind type parameter as MASK. It is scalarDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of MASK.
if DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ]5 Result Value.where [d1 , d2 , . . . , dn ] is the shape of MASK.
Case (i): The result of PARITY (MASK) has the value true if an odd number of the elements of MASK are6 Examples.true, and false otherwise.
Case (ii): If MASK has rank one, PARITY (MASK, DIM) is equal to PARITY (MASK). Otherwise, the
value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of PARITY (MASK, DIM) is equal to
PARITY (MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn )).
⃝c ISO/IEC 2017 – All rights reserved 413
ISO/IEC DIS 1539-1:2017 (E)
Case (i): The value of PARITY ([T, T, T, F]) is true if T has the value true and F has the value false.
T T F
Case (ii): If B is the array , where T has the value true and F has the value false, then T T T
PARITY (B, DIM=1) has the value [F, F, T] and PARITY (B, DIM=2) has the value [F, T].
16.9.149 POPCNT (I)
1 Description. Number of one bits.
2 Class. Elemental function.
3 Argument. I shall be of type integer.
4 Result Characteristics. Default integer.
5 Result Value. The result value is equal to the number of one bits in the sequence of bits of I. The model for
the interpretation of an integer value as a sequence of bits is in 16.3.6 Examples. POPCNT ([1, 2, 3, 4, 5, 6]) has the value [1, 1, 2, 1, 2, 2].
16.9.150 POPPAR (I)1 Description. Parity expressed as 0 or 1.
2 Class. Elemental function.
3 Argument. I shall be of type integer.
4 Result Characteristics. Default integer.
5 Result Value. POPPAR (I) has the value 1 if POPCNT (I) is odd, and 0 if POPCNT (I) is even.
6 Examples. POPPAR ([1, 2, 3, 4, 5, 6]) has the value [1, 1, 0, 1, 0, 0].
16.9.151 PRECISION (X)1 Description. Decimal precision of a real model.
2 Class. Inquiry function.
3 Argument. X shall be of type real or complex. It may be a scalar or an array.
4 Result Characteristics. Default integer scalar.
5 Result Value. The result has the value INT ((p − 1) * LOG10 (b)) + k, where b and p are as defined in 16.4
for the model representing real numbers with the same value for the kind type parameter as X, and where k is 16 Example. PRECISION (X) has the value INT (23 * LOG10 (2.)) = INT (6.92. . . ) = 6 for real X whose modelif b is an integral power of 10 and 0 otherwise.
is as in NOTE 16.4.1 Description. Presence of optional argument.16.9.152 PRESENT (A)
2 Class. Inquiry function.
3 Argument. A shall be the name of an optional dummy argument that is accessible in the subprogram in which
the PRESENT function reference appears. There are no other requirements on A.4 Result Characteristics. Default logical scalar.414 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value. The result has the value true if A is present (15.5.2.12) and otherwise has the value false.
16.9.153 PRODUCT (ARRAY, DIM [, MASK]) or1 Description. Array reduced by multiplication.PRODUCT (ARRAY [, MASK])
2 Class. Transformational function.
3 Arguments.
ARRAY shall be an array of numeric type.4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar ifDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where5 Result Value.[d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of PRODUCT (ARRAY) has a value equal to a processor-dependent approximation to6 Examples.the product of all the elements of ARRAY or has the value one if ARRAY has size zero.
Case (ii): The result of PRODUCT (ARRAY, MASK = MASK) has a value equal to a processor-dependent
approximation to the product of the elements of ARRAY corresponding to the true elements of
MASK or has the value one if there are no true elements.
Case (iii): If ARRAY has rank one, PRODUCT (ARRAY, DIM = DIM [, MASK = MASK]) has a value equal
to that of PRODUCT (ARRAY [, MASK = MASK ]). Otherwise, the value of element (s1 , s2 , . . . ,
sDIM−1 , sDIM+1 , . . . , sn ) of PRODUCT (ARRAY, DIM = DIM [, MASK = MASK]) is equal to
PRODUCT (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK = MASK (s1 , s2 , . . . ,
sDIM−1 , :, sDIM+1 , . . . , sn ) ] ).
Case (i): The value of PRODUCT ([1, 2, 3]) is 6.1 Description. Base of a numeric model.Case (ii): PRODUCT (C, MASK = C > 0.0) forms the product of the positive elements of C.
1 3 5
Case (iii): If B is the array , PRODUCT (B, DIM = 1) is [2, 12, 30] and PRODUCT (B, DIM = 2)
2 4 6
is [15, 48].
16.9.154 RADIX (X)
2 Class. Inquiry function.
3 Argument. X shall be of type integer or real. It may be a scalar or an array.
4 Result Characteristics. Default integer scalar.
5 Result Value. The result has the value r if X is of type integer and the value b if X is of type real, where r and
b are as defined in 16.4 for the model representing numbers of the same type and kind type parameter as X.6 Example. RADIX (X) has the value 2 for real X whose model is as in NOTE 16.4.
⃝c ISO/IEC 2017 – All rights reserved 4151 Description. Initialize the pseudorandom number generator.
ISO/IEC DIS 1539-1:2017 (E)
16.9.155 RANDOM_INIT (REPEATABLE, IMAGE_DISTINCT)
2 Class. Subroutine.
3 Arguments.
REPEATABLE shall be a logical scalar. It is an INTENT (IN) argument. If it has the value true, the seed4 Example. The following statement initializes the pseudorandom number generator so that the seed is differentaccessed by the pseudorandom number generator is set to a processor-dependent value that is the
same each time RANDOM_INIT is called from the same image. If it has the value false, the seed
is set to a processor-dependent, unpredictably different value on each call.
IMAGE_DISTINCT shall be a logical scalar. It is an INTENT (IN) argument. If it has the value true, the
seed accessed by the pseudorandom number generator is set to a processor-dependent value that
is distinct from the value that would be set by a call to RANDOM_INIT by another image. If
it has the value false, the value to which the seed is set does not depend on which image calls
RANDOM_INIT.
on each call and that the sequence generated will differ from that of another image:1 Description. Generate pseudorandom number(s).CALL RANDOM_INIT (REPEATABLE=.FALSE., IMAGE_DISTINCT=.TRUE.)
16.9.156 RANDOM_NUMBER (HARVEST)
2 Class. Subroutine.
3 Argument. HARVEST shall be of type real. It is an INTENT (OUT) argument. It may be a scalar or an array.
It is assigned pseudorandom numbers from the uniform distribution in the interval 0 ≤ x < 1. If images use a4 Example.common generator, the interleaving of values assigned in unordered segments is processor dependent.
REAL X, Y (10, 10)1 Description. Restart or query the pseudorandom number generator.! Initialize X with a pseudorandom number
CALL RANDOM_NUMBER (HARVEST = X)
CALL RANDOM_NUMBER (Y)
! X and Y contain uniformly distributed random numbers
16.9.157 RANDOM_SEED ([SIZE, PUT, GET])
2 Class. Subroutine.
3 Arguments. There shall either be exactly one or no arguments present.
SIZE (optional) shall be a default integer scalar. It is an INTENT (OUT) argument. It is assigned the number4 If no argument is present, the processor assigns a processor-dependent value to the seed.N of integers that the processor uses to hold the value of the seed.
PUT (optional) shall be a default integer array of rank one and size ≥ N . It is an INTENT (IN) argument. It
is used in a processor-dependent manner to compute the seed value accessed by the pseudorandom
number generator.
GET (optional) shall be a default integer array of rank one and size ≥ N . It is an INTENT (OUT) argument.
It is assigned the value of the seed.
416 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
5 The pseudorandom number generator used by RANDOM_NUMBER maintains a seed that is updated during the
execution of RANDOM_NUMBER and that can be retrieved or changed by RANDOM_SEED. Computation6 Examples.of the seed from the argument PUT is performed in a processor-dependent manner. The value assigned to GET
need not be the same as the value of PUT in an immediately preceding reference to RANDOM_SEED. For
example, following execution of the statements
CALL RANDOM_SEED (PUT=SEED1)
CALL RANDOM_SEED (GET=SEED2)
SEED2 need not equal SEED1. When the values differ, the use of either value as the PUT argument in a
subsequent call to RANDOM_SEED shall result in the same sequence of pseudorandom numbers being generated.
For example, after execution of the statements
CALL RANDOM_SEED (PUT=SEED1)
CALL RANDOM_SEED (GET=SEED2)
CALL RANDOM_NUMBER (X1)
CALL RANDOM_SEED (PUT=SEED2)
CALL RANDOM_NUMBER (X2)
X2 equals X1.
CALL RANDOM_SEED ! Processor initialization1 Description. Decimal exponent range of a numeric model (16.4).CALL RANDOM_SEED (SIZE = K) ! Puts size of seed in K
CALL RANDOM_SEED (PUT = SEED (1 : K)) ! Define seed
CALL RANDOM_SEED (GET = OLD (1 : K)) ! Read current seed
16.9.158 RANGE (X)
2 Class. Inquiry function.
3 Argument. X shall be of type integer, real, or complex. It may be a scalar or an array.
4 Result Characteristics. Default integer scalar.
5 Result Value.
Case (i): If X is of type integer, the result has the value INT (LOG10 (HUGE (X))).6 Examples. RANGE (X) has the value 38 for real X whose model is as in NOTE 16.4, because in this caseCase (ii): If X is of type real, the result has the value INT (MIN (LOG10 (HUGE (X)), −LOG10 (TINY (X)))).
Case (iii): If X is of type complex, the result has the value RANGE (REAL (X)).
HUGE (X) = (1 − 2−24 ) × 2127 and TINY (X) = 2−127 .1 Description. Rank of a data object.16.9.159 RANK (A)
2 Class. Inquiry function.
3 Argument. A shall be a data object of any type.
⃝c ISO/IEC 2017 – All rights reserved 4174 Result Characteristics. Default integer scalar.
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value. The value of the result is the rank of A.
6 Example. If X is an assumed-rank dummy argument and its associated effective argument is an array of rank
3, RANK(X) has the value 3.1 Description. Conversion to real type.16.9.160 REAL (A [, KIND])
2 Class. Elemental function.
3 Arguments.
A shall be of type integer, real, or complex, or a boz-literal-constant.4 Result Characteristics. Real.KIND (optional) shall be a scalar integer constant expression.
Case (i): If A is of type integer or real and KIND is present, the kind type parameter is that specified by the5 Result Value.value of KIND. If A is of type integer or real and KIND is not present, the kind type parameter is
that of default real kind.
Case (ii): If A is of type complex and KIND is present, the kind type parameter is that specified by the value
of KIND. If A is of type complex and KIND is not present, the kind type parameter is the kind
type parameter of A.
Case (iii): If A is a boz-literal-constant and KIND is present, the kind type parameter is that specified by the
value of KIND. If A is a boz-literal-constant and KIND is not present, the kind type parameter is
that of default real kind.
Case (i): If A is of type integer or real, the result is equal to a processor-dependent approximation to A.6 Examples. REAL (−3) has the value −3.0. REAL (Z) has the same kind type parameter and the same valueCase (ii): If A is of type complex, the result is equal to a processor-dependent approximation to the real part
of A.
Case (iii): If A is a boz-literal-constant, the value of the result is the value whose internal representation as a
bit sequence is the same as that of A as modified by padding or truncation according to 16.3.3. The
interpretation of the bit sequence is processor dependent.
as the real part of the complex variable Z.1 Description. General reduction of array.16.9.161 REDUCE (ARRAY, OPERATION [, MASK, IDENTITY, ORDERED])
or REDUCE (ARRAY, OPERATION, DIM [, MASK, IDENTITY,
ORDERED])
2 Class. Transformational function.
3 Arguments.
ARRAY shall be an array of any type.4 Result Characteristics. The result is of the same type and type parameters as ARRAY. It is scalar if DIMOPERATION shall be a pure function with exactly two arguments; each argument shall be a scalar, nonal-
locatable, nonpointer, nonpolymorphic, nonoptional dummy data object with the same type and
type parameters as ARRAY. If one argument has the ASYNCHRONOUS, TARGET, or VALUE
attribute, the other shall have that attribute. Its result shall be a nonpolymorphic scalar and have
the same type and type parameters as ARRAY. OPERATION should implement a mathematically
associative operation. It need not be commutative.
418 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
DIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
IDENTITY (optional) shall be scalar with the same type and type parameters as ARRAY.
ORDERED (optional) shall be a logical scalar.
does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where5 Result Value.[d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of REDUCE (ARRAY, OPERATION [, IDENTITY = IDENTITY, ORDERED =6 Examples. The following examples all use the function MY_MULT, which returns the product of its two integerORDERED]) over the sequence of values in ARRAY is the result of an iterative process. The
initial order of the sequence is array element order. While the sequence has more than one element,
each iteration involves the execution of r = OPERATION(x, y) for adjacent x and y in the sequence,
with x immediately preceding y, and the subsequent replacement of x and y with r; if ORDERED
is present with the value true, x and y shall be the first two elements of the sequence. The process
continues until the sequence has only one element which is the value of the reduction. If the initial
sequence is empty, the result has the value IDENTITY if IDENTITY is present, and otherwise,
error termination is initiated.
Case (ii): The result of REDUCE (ARRAY, OPERATION, MASK = MASK [, IDENTITY = IDENTITY,
ORDERED = ORDERED]) is as for Case (i) except that the initial sequence is only those elements
of ARRAY for which the corresponding elements of MASK are true.
Case (iii): If ARRAY has rank one, REDUCE (ARRAY, OPERATION, DIM = DIM [, MASK = MASK,
IDENTITY = IDENTITY, ORDERED = ORDERED]) has a value equal to that of REDUCE (AR-
RAY, OPERATION [, MASK = MASK, IDENTITY = IDENTITY, ORDERED = ORDERED]).
Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 , . . . , sn ) of REDUCE (ARRAY,
DIM = DIM [, MASK = MASK, IDENTITY = IDENTITY]) is equal to
REDUCE (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ),
OPERATION = OPERATION,
DIM=1
[, MASK = MASK (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ),
IDENTITY = IDENTITY,
ORDERED = ORDERED] ).
arguments.1 Description. Repetitive string concatenation.Case (i): The value of REDUCE ([1, 2, 3], MY_MULT) is 6.
Case (ii): REDUCE (C, MY_MULT, MASK= C > 0, IDENTITY=1) forms the product of the positive
elements of C.
1 3 5
Case (iii): If B is the array , REDUCE (B, MY_MULT, DIM = 1) is [2, 12, 30] and REDUCE (B,
2 4 6
MY_MULT, DIM = 2) is [15, 48].
NOTE 16.27
If OPERATION is not computationally associative, REDUCE without ORDERED=.TRUE. with the same
argument values might not always produce the same result, as the processor can apply the associative law
to the evaluation.
16.9.162 REPEAT (STRING, NCOPIES)
2 Class. Transformational function.
⃝c ISO/IEC 2017 – All rights reserved 4193 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
STRING shall be a character scalar.4 Result Characteristics. Character scalar of length NCOPIES times that of STRING, with the same kind typeNCOPIES shall be an integer scalar. Its value shall not be negative.
parameter as STRING.5 Result Value. The value of the result is the concatenation of NCOPIES copies of STRING.
6 Examples. REPEAT (’H’, 2) has the value HH. REPEAT (’XYZ’, 0) has the value of a zero-length string.
16.9.163 RESHAPE (SOURCE, SHAPE [, PAD, ORDER])1 Description. Arbitrary shape array construction.
2 Class. Transformational function.
3 Arguments.
SOURCE shall be an array of any type. If PAD is absent or of size zero, the size of SOURCE shall be greater4 Result Characteristics. The result is an array of shape SHAPE (that is, SHAPE (RESHAPE (SOURCE,than or equal to PRODUCT (SHAPE). The size of the result is the product of the values of the
elements of SHAPE.
SHAPE shall be a rank-one integer array. SIZE (x), where x is the actual argument corresponding to
SHAPE, shall be a constant expression whose value is positive and less than 16. It shall not have
an element whose value is negative.
PAD (optional) shall be an array of the same type and type parameters as SOURCE.
ORDER (optional) shall be of type integer, shall have the same shape as SHAPE, and its value shall be a
permutation of (1, 2, . . . , n), where n is the size of SHAPE. If absent, it is as if it were present with
value (1, 2, . . . , n).
SHAPE, PAD, ORDER)) is equal to SHAPE) with the same type and type parameters as SOURCE.5 Result Value. The elements of the result, taken in permuted subscript order ORDER (1), . . . , ORDER (n), are
those of SOURCE in normal array element order followed if necessary by those of PAD in array element order,followed if necessary by additional copies of PAD in array element order.
1 3 5
1 Description. Reciprocal of relative spacing of model numbers.
6 Examples. RESHAPE ([1, 2, 3, 4, 5, 6], [2, 3]) has the value 2 4 61 2 3 4
16.9.164 RRSPACING (X)
RESHAPE ([1, 2, 3, 4, 5, 6], [2, 4], [0, 0], [2, 1]) has the value 5 6 0 0
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Result Characteristics. Same as X.
5 Result Value. The result has the value |Y × b−e | × bp = ABS (FRACTION (Y)) * RADIX (X) / EPSILON (X),
where b, e, and p are as defined in 16.4 for Y, the value nearest to X in the model for real values whose kind type6 Example. RRSPACING (−3.0) has the value 0.75 × 224 for reals whose model is as in NOTE 16.4.parameter is that of X; if there are two such values, the value of greater absolute value is taken. If X is an IEEE
infinity, the result is an IEEE NaN. If X is an IEEE NaN, the result is that NaN.
420 ⃝c ISO/IEC 2017 – All rights reserved1 Description. Dynamic type equality test.
ISO/IEC DIS 1539-1:2017 (E)
16.9.165 SAME_TYPE_AS (A, B)
2 Class. Inquiry function.
3 Arguments.
A shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic4 Result Characteristics. Default logical scalar.pointer, it shall not have an undefined association status.
B shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic
pointer, it shall not have an undefined association status.
5 Result Value. If the dynamic type of A or B is extensible, the result is true if and only if the dynamic type of
A is the same as the dynamic type of B. If neither A nor B has extensible dynamic type, the result is processor6 Example. Given the declarations and assignmentsdependent.
NOTE 16.28
The dynamic type of a disassociated pointer or unallocated allocatable variable is its declared type. An
unlimited polymorphic entity has no declared type.
NOTE 16.29
The test performed by SAME_TYPE_AS is not the same as the test performed by the type guard TYPE
IS. The test performed by SAME_TYPE_AS does not consider kind type parameters.
TYPE T1
REAL C
END TYPE
TYPE, EXTENDS(T1) :: T2
END TYPE
CLASS(T1), POINTER :: P, Q, R
ALLOCATE(P, Q)
ALLOCATE(T2 :: R)
the value of SAME_TYPE_AS (P, Q) will be true, and the value of SAME_TYPE_AS (P, R) will be false.
16.9.166 SCALE (X, I)
1 Description. Real number scaled by radix power.
2 Class. Elemental function.
3 Arguments.
X shall be of type real.4 Result Characteristics. Same as X.I shall be of type integer.
5 Result Value. The result has the value X × bI , where b is defined in 16.4 for model numbers representing values
of X, provided this result is representable; if not, the result is processor dependent.6 Example. SCALE (3.0, 2) has the value 12.0 for reals whose model is as in NOTE 16.4.
⃝c ISO/IEC 2017 – All rights reserved 4211 Description. Character set membership search.
ISO/IEC DIS 1539-1:2017 (E)
16.9.167 SCAN (STRING, SET [, BACK, KIND])
2 Class. Elemental function.
3 Arguments.
STRING shall be of type character.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofSET shall be of type character with the same kind type parameter as STRING.
BACK (optional) shall be of type logical.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type.5 Result Value.
Case (i): If BACK is absent or is present with the value false and if STRING contains at least one character6 Examples.that is in SET, the value of the result is the position of the leftmost character of STRING that is
in SET.
Case (ii): If BACK is present with the value true and if STRING contains at least one character that is in
SET, the value of the result is the position of the rightmost character of STRING that is in SET.
Case (iii): The value of the result is zero if no character of STRING is in SET or if the length of STRING or
SET is zero.
Case (i): SCAN (’FORTRAN’, ’TR’) has the value 3.1 Description. Character kind selection.Case (ii): SCAN (’FORTRAN’, ’TR’, BACK = .TRUE.) has the value 5.
Case (iii): SCAN (’FORTRAN’, ’BCD’) has the value 0.
16.9.168 SELECTED_CHAR_KIND (NAME)
2 Class. Transformational function.
3 Argument. NAME shall be default character scalar.
4 Result Characteristics. Default integer scalar.
5 Result Value. If NAME has the value DEFAULT, then the result has a value equal to that of the kind type
parameter of default character. If NAME has the value ASCII, then the result has a value equal to that of the6 Examples. SELECTED_CHAR_KIND (’ASCII’) has the value 1 on a processor that uses 1 as the kind typekind type parameter of ASCII character if the processor supports such a kind; otherwise the result has the value
−1. If NAME has the value ISO_10646, then the result has a value equal to that of the kind type parameter of
the ISO 10646 character kind (corresponding to UCS-4 as specified in ISO/IEC 10646) if the processor supports
such a kind; otherwise the result has the value −1. If NAME is a processor-defined name of some other character
kind supported by the processor, then the result has a value equal to that kind type parameter value. If NAME is
not the name of a supported character type, then the result has the value −1. The NAME is interpreted without
respect to case or trailing blanks.
parameter for the ASCII character set. The following subroutine produces a Japanese date stamp.SUBROUTINE create_date_string(string)
INTRINSIC date_and_time,selected_char_kind
INTEGER,PARAMETER :: ucs4 = selected_char_kind("ISO_10646")
422 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
CHARACTER(1,UCS4),PARAMETER :: nen=CHAR(INT(Z’5e74’),UCS4), & !year
gatsu=CHAR(INT(Z’6708’),UCS4), & !month
nichi=CHAR(INT(Z’65e5’),UCS4) !day
CHARACTER(len= *, kind= ucs4) string
INTEGER values(8)
CALL date_and_time(values=values)
WRITE(string,1) values(1),nen,values(2),gatsu,values(3),nichi
1 FORMAT(I0,A,I0,A,I0,A)
END SUBROUTINE
16.9.169 SELECTED_INT_KIND (R)
1 Description. Integer kind selection.
2 Class. Transformational function.
3 Argument. R shall be an integer scalar.
4 Result Characteristics. Default integer scalar.
5 Result Value. The result has a value equal to the value of the kind type parameter of an integer type that
represents all values n in the range −10R < n < 10R , or if no such kind type parameter is available on the6 Example. Assume a processor supports two integer kinds, 32 with representation method r = 2 and q = 31,processor, the result is −1. If more than one kind type parameter meets the criterion, the value returned is the
one with the smallest decimal exponent range, unless there are several such values, in which case the smallest of
these kind values is returned.
and 64 with representation method r = 2 and q = 63. On this processor SELECTED_INT_KIND (9) has the1 Description. Real kind selection.value 32 and SELECTED_INT_KIND (10) has the value 64.
16.9.170 SELECTED_REAL_KIND ([P, R, RADIX])
2 Class. Transformational function.
3 Arguments. At least one argument shall be present.
P (optional) shall be an integer scalar.4 Result Characteristics. Default integer scalar.R (optional) shall be an integer scalar.
RADIX (optional) shall be an integer scalar.
5 Result Value. If P or R is absent, the result value is the same as if it were present with the value zero. If
RADIX is absent, there is no requirement on the radix of the selected kind.6 The result has a value equal to a value of the kind type parameter of a real type with decimal precision, as
returned by the function PRECISION, of at least P digits, a decimal exponent range, as returned by the function7 Otherwise, the result is −1 if the processor supports a real type with radix RADIX and exponent range of at leastRANGE, of at least R, and a radix, as returned by the function RADIX, of RADIX, if such a kind type parameter
is available on the processor.
R but not with precision of at least P, −2 if the processor supports a real type with radix RADIX and precision of8 If more than one kind type parameter value meets the criteria, the value returned is the one with the smallestat least P but not with exponent range of at least R, −3 if the processor supports a real type with radix RADIX
but with neither precision of at least P nor exponent range of at least R, −4 if the processor supports a real type
⃝c ISO/IEC 2017 – All rights reserved 423
ISO/IEC DIS 1539-1:2017 (E)
with radix RADIX and either precision of at least P or exponent range of at least R but not both together, and
−5 if the processor supports no real type with radix RADIX.
decimal precision, unless there are several such values, in which case the smallest of these kind values is returned.9 Example. SELECTED_REAL_KIND (6, 70) has the value KIND (0.0) on a machine that supports a default
real approximation method with b = 16, p = 6, emin = −64, and emax = 63 and does not have a less precise1 Description. Real value with specified exponent.approximation method.
16.9.171 SET_EXPONENT (X, I)
2 Class. Elemental function.
3 Arguments.
X shall be of type real.4 Result Characteristics. Same as X.I shall be of type integer.
5 Result Value. If X has the value zero, the result has the same value as X. If X is an IEEE infinity, the result is
an IEEE NaN. If X is an IEEE NaN, the result is the same NaN. Otherwise, the result has the value X × bI−e ,6 Example. SET_EXPONENT (3.0, 1) has the value 1.5 for reals whose model is as in NOTE 16.4.where b and e are as defined in 16.4 for the representation for the value of X in the extended real model for the
kind of X.
16.9.172 SHAPE (SOURCE [, KIND])1 Description. Shape of an array or a scalar.
2 Class. Inquiry function.
3 Arguments.
SOURCE shall be a scalar or array of any type. It shall not be an unallocated allocatable variable or a pointer4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the valuethat is not associated. It shall not be an assumed-size array.
KIND (optional) shall be a scalar integer constant expression.
of KIND; otherwise the kind type parameter is that of default integer type. The result is an array of rank one5 Result Value. The result has a value whose ith element is equal to the extent of dimension i of SOURCE,whose size is equal to the rank of SOURCE.
except that if SOURCE is assumed-rank, and associated with an assumed-size array, the last element is equal to6 Examples. The value of SHAPE (A (2:5, −1:1) ) is [4, 3]. The value of SHAPE (3) is the rank-one array of size−1.
zero.1 Description. Right shift with fill.16.9.173 SHIFTA (I, SHIFT)
2 Class. Elemental function.
424 ⃝c ISO/IEC 2017 – All rights reserved3 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
I shall be of type integer.4 Result Characteristics. Same as I.SHIFT shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I).
5 Result Value. The result has the value obtained by shifting the bits of I to the right SHIFT bits and replicating
the leftmost bit of I in the left SHIFT bits.6 If SHIFT is zero the result is I. Bits shifted out from the right are lost. The model for the interpretation of an
integer value as a sequence of bits is in 16.3.7 Example. SHIFTA (IBSET (0, BIT_SIZE (0) − 1), 2) is equal to SHIFTL (7, BIT_SIZE (0) − 3).
16.9.174 SHIFTL (I, SHIFT)1 Description. Left shift.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.SHIFT shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I).
5 Result Value. The value of the result is ISHFT (I, SHIFT).
6 Examples. SHIFTL (3, 1) has the value 6.
16.9.175 SHIFTR (I, SHIFT)1 Description. Right shift.
2 Class. Elemental function.
3 Arguments.
I shall be of type integer.4 Result Characteristics. Same as I.SHIFT shall be of type integer. It shall be nonnegative and less than or equal to BIT_SIZE (I).
5 Result Value. The value of the result is ISHFT (I, −SHIFT).
6 Examples. SHIFTR (3, 1) has the value 1.
16.9.176 SIGN (A, B)1 Description. Magnitude of A with the sign of B.
2 Class. Elemental function.
3 Arguments.
A shall be of type integer or real.4 Result Characteristics. Same as A.B shall be of the same type as A.
⃝c ISO/IEC 2017 – All rights reserved 4255 Result Value.
ISO/IEC DIS 1539-1:2017 (E)
Case (i): If B > 0, the value of the result is |A|.6 Example. SIGN (−3.0, 2.0) has the value 3.0.Case (ii): If B < 0, the value of the result is -|A|.
Case (iii): If B is of type integer and B=0, the value of the result is |A|.
Case (iv): If B is of type real and is zero, then:
• if the processor does not distinguish between positive and negative real zero, or if B is positive
real zero, the value of the result is |A|;
• if the processor distinguishes between positive and negative real zero, and B is negative real
zero, the value of the result is -|A|.
16.9.177 SIN (X)1 Description. Sine function.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to sin(X). If X is of type
real, it is regarded as a value in radians. If X is of type complex, its real part is regarded as a value in radians.6 Example. SIN (1.0) has the value 0.84147098 (approximately).
16.9.178 SINH (X)1 Description. Hyperbolic sine function.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to sinh(X). If X is of type
complex its imaginary part is regarded as a value in radians.6 Example. SINH (1.0) has the value 1.1752012 (approximately).
16.9.179 SIZE (ARRAY [, DIM, KIND])1 Description. Size of an array or one extent.
2 Class. Inquiry function.
3 Arguments.
ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable variable or a pointer4 Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by thethat is not associated. If ARRAY is an assumed-size array, DIM shall be present with a value less
than the rank of ARRAY.
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
KIND (optional) shall be a scalar integer constant expression.
value of KIND; otherwise the kind type parameter is that of default integer type.5 Result Value. If DIM is present, the result has a value equal to the extent of dimension DIM of ARRAY, except426 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
that if ARRAY is assumed-rank and associated with an assumed-size array and DIM is present with a value equal6 If DIM is absent and ARRAY is assumed-rank, the result has a value equal to PRODUCT(SHAPE(ARRAY,to the rank of ARRAY, the value is −1.
KIND)). Otherwise, the result has a value equal to the total number of elements of ARRAY.7 Examples. The value of SIZE (A (2:5, −1:1), DIM=2) is 3. The value of SIZE (A (2:5, −1:1)) is 12.
NOTE 16.3016.9.180 SPACING (X)If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement
1 ≤ DIM ≤ 0.
1 Description. Spacing of model numbers.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Result Characteristics. Same as X.
5 Result Value. If X does not have the value zero and is not an IEEE infinity or NaN, the result has the value
be−p , where b, e, and p are as defined in 16.4 for the value nearest to X in the model for real values whose kind6 Example. SPACING (3.0) has the value 2−22 for reals whose model is as in NOTE 16.4.type parameter is that of X, provided this result is representable; otherwise, the result is the same as that of
TINY (X). If there are two extended model values equally near to X, the value of greater absolute value is taken.
If X has the value zero, the result is the same as that of TINY (X). If X is an IEEE infinity, the result is an IEEE
NaN. If X is an IEEE NaN, the result is that NaN.
16.9.181 SPREAD (SOURCE, DIM, NCOPIES)1 Description. Value replicated in a new dimension.
2 Class. Transformational function.
3 Arguments.
SOURCE shall be a scalar or array of any type. The rank of SOURCE shall be less than 15.4 Result Characteristics. The result is an array of the same type and type parameters as SOURCE and of rankDIM shall be an integer scalar with value in the range 1 ≤ DIM ≤ n + 1, where n is the rank of SOURCE.
NCOPIES shall be an integer scalar.
n + 1, where n is the rank of SOURCE.5 Result Value.Case (i): If SOURCE is scalar, the shape of the result is (MAX (NCOPIES, 0)).
Case (ii): If SOURCE is an array with shape [d1 , d2 , . . . , dn ], the shape of the result is [d1 , d2 , . . . , dDIM−1 ,
MAX (NCOPIES, 0), dDIM , . . . , dn ].
Case (i): If SOURCE is scalar, each element of the result has a value equal to SOURCE.6 Examples. If A is the array [2, 3, 4], SPREAD (A, DIM=1, NCOPIES=NC) is the array 2 3 4 if NCCase (ii): If SOURCE is an array, the element of the result with subscripts (r1 , r2 , . . . , rn+1 ) has the value
SOURCE (r1 , r2 , . . . , rDIM−1 , rDIM+1 , . . . , rn+1 ).
2 3 4
2 3 4
has the value 3 and is a zero-sized array if NC has the value 0.
⃝c ISO/IEC 2017 – All rights reserved 427
ISO/IEC DIS 1539-1:2017 (E)16.9.182 SQRT (X)
1 Description. Square root.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex. If X is real, its value shall be greater than or equal to zero.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to the square root of X. A
result of type complex is the principal value with the real part greater than or equal to zero. When the real part6 Example. SQRT (4.0) has the value 2.0 (approximately).of the result is zero, the imaginary part has the same sign as the imaginary part of X.
16.9.183 STOPPED_IMAGES ([TEAM, KIND])1 Description. Indices of stopped images.
2 Class. Transformational function.
3 Arguments.
TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV,4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the valuewhose value identifies the current or an ancestor team. If TEAM is absent the team specified is the
current team.
KIND (optional) shall be a scalar integer constant expression.
of KIND; otherwise, the kind type parameter is that of default integer type. The result is an array of rank one5 Result Value. The elements of the result are the values of the indices of the images that are known to havewhose size is equal to the number of images in the specified team that have initiated normal termination.
initiated normal termination in the specified team, in numerically increasing order. If the executing image has6 Examples. If image 3 is the only image in the current team that is known to have initiated normal termination,previously executed an image control statement whose STAT= specifier assigned the value STAT_STOPPED_-
IMAGE from the intrinsic module ISO_FORTRAN_ENV or invoked a collective subroutine whose STAT argu-
ment was assigned STAT_STOPPED_IMAGE, at least one of the images participating in that image control
statement or collective invocation shall be known to have initiated normal termination.
STOPPED_IMAGES() will have the value [3]. If there are no images in the current team that have initiated1 Description. Storage size in bits.normal termination, the value of STOPPED_IMAGES() will be a zero-sized array.
16.9.184 STORAGE_SIZE (A [, KIND])
2 Class. Inquiry function.
3 Arguments.
A shall be a data object of any type. If it is polymorphic it shall not be an undefined pointer. If4 Result Characteristics. Integer scalar. If KIND is present, the kind type parameter is that specified by theit is unlimited polymorphic or has any deferred type parameters, it shall not be an unallocated
allocatable variable or a disassociated or undefined pointer.
KIND (optional) shall be a scalar integer constant expression.
value of KIND; otherwise, the kind type parameter is that of default integer type.5 Result Value. The result value is the size expressed in bits for an element of an array that has the dynamic428 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
type and type parameters of A. If the type and type parameters are such that storage association (19.5.3) applies,6 Example. STORAGE_SIZE (1.0) has the same value as the named constant NUMERIC_STORAGE_SIZE inthe result is consistent with the named constants defined in the intrinsic module ISO_FORTRAN_ENV.
NOTE 16.31
An array element might take more bits to store than an isolated scalar, since any hardware-imposed align-
ment requirements for array elements might not apply to a simple scalar variable.
NOTE 16.32
This is intended to be the size in memory that an object takes when it is stored; this might differ from the
size it takes during expression handling (which might be the native register size) or when stored in a file.
If an object is never stored in memory but only in a register, this function nonetheless returns the size it
would take if it were stored in memory.
the intrinsic module ISO_FORTRAN_ENV.1 Description. Array reduced by addition.16.9.185 SUM (ARRAY, DIM [, MASK]) or SUM (ARRAY [, MASK])
2 Class. Transformational function.
3 Arguments.
ARRAY shall be an array of numeric type.4 Result Characteristics. The result is of the same type and kind type parameter as ARRAY. It is scalar ifDIM shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
MASK (optional) shall be of type logical and shall be conformable with ARRAY.
DIM does not appear; otherwise, the result has rank n − 1 and shape [d1 , d2 , . . . , dDIM−1 , dDIM+1 , . . . , dn ] where5 Result Value.[d1 , d2 , . . . , dn ] is the shape of ARRAY.
Case (i): The result of SUM (ARRAY) has a value equal to a processor-dependent approximation to the sum6 Examples.of all the elements of ARRAY or has the value zero if ARRAY has size zero.
Case (ii): The result of SUM (ARRAY, MASK = MASK) has a value equal to a processor-dependent approx-
imation to the sum of the elements of ARRAY corresponding to the true elements of MASK or has
the value zero if there are no true elements.
Case (iii): If ARRAY has rank one, SUM (ARRAY, DIM = DIM [, MASK = MASK]) has a value equal to that
of SUM (ARRAY [,MASK = MASK ]). Otherwise, the value of element (s1 , s2 , . . . , sDIM−1 , sDIM+1 ,
. . . , sn ) of SUM (ARRAY, DIM = DIM [ , MASK = MASK]) is equal to
SUM (ARRAY (s1 , s2 , . . . , sDIM−1 , :, sDIM+1 , . . . , sn ) [, MASK= MASK (s1 , s2 , . . . , sDIM−1 ,
:, sDIM+1 , . . . , sn ) ] ).
Case (i): The value of SUM ([1, 2, 3]) is 6.1 Description. Query system clock.Case (ii): SUM (C, MASK= C > 0.0) forms the sum of the positive elements of C.
1 3 5
Case (iii): If B is the array , SUM (B, DIM = 1) is [3, 7, 11] and SUM (B, DIM = 2) is [9, 12].
2 4 6
⃝c ISO/IEC 2017 – All rights reserved 429
ISO/IEC DIS 1539-1:2017 (E)
16.9.186 SYSTEM_CLOCK ([COUNT, COUNT_RATE, COUNT_MAX])
2 Class. Subroutine.
3 Arguments.
COUNT (optional) shall be an integer scalar. It is an INTENT (OUT) argument. It is assigned a processor-4 Whether an image has no clock, has a single clock of its own, or shares a clock with another image, is processordependent value based on the value of a processor clock, or −HUGE (COUNT) if there is no clock
for the invoking image. The processor-dependent value is incremented by one for each clock count
until the value COUNT_MAX is reached and is reset to zero at the next count. It lies in the range
0 to COUNT_MAX if there is a clock.
COUNT_RATE (optional) shall be an integer or real scalar. It is an INTENT (OUT) argument. It is assigned
a processor-dependent approximation to the number of processor clock counts per second, or zero
if there is no clock for the invoking image.
COUNT_MAX (optional) shall be an integer scalar. It is an INTENT (OUT) argument. It is assigned the
maximum value that COUNT can have, or zero if there is no clock for the invoking image.
dependent.5 Example. If the processor clock is a 24-hour clock that registers time at approximately 18.20648193 ticks per
second, at 11:30 A.M. the reference1 Description. Tangent function.CALL SYSTEM_CLOCK (COUNT = C, COUNT_RATE = R, COUNT_MAX = M)
defines C = (11×3600+30×60)×18.20648193 = 753748, R = 18.20648193, and M = 24×3600×18.20648193−1 =
1573039.
16.9.187 TAN (X)
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to tan(X). If X is of type
real, it is regarded as a value in radians. If X is of type complex, its real part is regarded as a value in radians.6 Example. TAN (1.0) has the value 1.5574077 (approximately).
16.9.188 TANH (X)1 Description. Hyperbolic tangent function.
2 Class. Elemental function.
3 Argument. X shall be of type real or complex.
4 Result Characteristics. Same as X.
5 Result Value. The result has a value equal to a processor-dependent approximation to tanh(X). If X is of type
complex its imaginary part is regarded as a value in radians.6 Example. TANH (1.0) has the value 0.76159416 (approximately).
430 ⃝c ISO/IEC 2017 – All rights reserved1 Description. Team number.
ISO/IEC DIS 1539-1:2017 (E)
16.9.189 TEAM_NUMBER ([TEAM])
2 Class. Transformational function.
3 Argument. TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FOR-
TRAN_ENV, whose value identifies the current or an ancestor team. If TEAM is absent, the team specified is4 Result Characteristics. Default integer scalar.the current team.
5 Result Value. The result has the value −1 if the specified team is the initial team; otherwise, the result value
is equal to the positive integer that identifies the specified team within its parent team.6 Example. The team number can be used to control which statements get executed, for example:
TYPE(TEAM_TYPE) :: ODD_EVEN...
FORM TEAM (2-MOD(ME,2), ODD_EVEN)
...
CHANGE TEAM (ODD_EVEN)
SELECT CASE (TEAM_NUMBER())
CASE (1)
! Case for images with odd image indices in the parent team.
CASE (2)
! Case for images with even image indices in the parent team.
END SELECT
END TEAM
16.9.190 THIS_IMAGE ([TEAM]) or THIS_IMAGE (COARRAY [, TEAM]) or
THIS_IMAGE (COARRAY, DIM [, TEAM])1 Description. Cosubscript(s) for this image.
2 Class. Transformational function.
3 Arguments.
COARRAY shall be a coarray of any type. If it is allocatable it shall be allocated. If its designator has more4 Result Characteristics. Default integer. It is scalar if COARRAY does not appear or DIM appears; otherwise,than one part-ref , the rightmost part-ref shall have nonzero corank. If it is of type TEAM_TYPE
from the intrinsic module ISO_FORTRAN_ENV, the TEAM argument shall appear.
DIM shall be an integer scalar. Its value shall be in the range 1 ≤ DIM ≤ n, where n is the corank of
COARRAY.
TEAM (optional) shall be a scalar of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV,
whose value identifies the current or an ancestor team. If COARRAY appears, it shall be established
in that team.
the result has rank one and its size is equal to the corank of COARRAY.5 Result Value.
Case (i): The result of THIS_IMAGE ([TEAM]) is a scalar with a value equal to the index of the invoking6 Examples. If A is declared by the statementimage in the team specified by TEAM, if present, or in the current team if absent.
⃝c ISO/IEC 2017 – All rights reserved 431
ISO/IEC DIS 1539-1:2017 (E)
Case (ii): The result of THIS_IMAGE (COARRAY [, TEAM = TEAM]) is the sequence of cosubscript values
for COARRAY that would specify the invoking image in the team specified by TEAM, if present,
or in the current team if absent.
Case (iii): The result of THIS_IMAGE (COARRAY, DIM [, TEAM = TEAM]) is the value of cosubscript
DIM in the sequence of cosubscript values for COARRAY that would specify the invoking image in
the team specified by TEAM, if present, or in the current team if absent.
REAL A (10, 20) [10, 0:9, 0:*]then on image 5, THIS_IMAGE ( ) has the value 5 and THIS_IMAGE (A) has the value [5, 0, 0]. For the same
coarray on image 213, THIS_IMAGE (A) has the value [3, 1, 2].
7 The following code uses image 1 to read data. The other images then copy the data.
IF (THIS_IMAGE()==1) READ (*,*) P
SYNC ALL
P = P[1]
16.9.191 TINY (X)
1 Description. Smallest positive model number.
2 Class. Inquiry function.
3 Argument. X shall be a real scalar or array.
4 Result Characteristics. Scalar with the same type and kind type parameter as X.
5 Result Value. The result has the value bemin −1 where b and emin are as defined in 16.4 for the model representing
numbers of the same type and kind type parameter as X.6 Example. TINY (X) has the value 2−127 for real X whose model is as in NOTE 16.4.
16.9.192 TRAILZ (I)1 Description. Number of trailing zero bits.
2 Class. Elemental function.
3 Argument. I shall be of type integer.
4 Result Characteristics. Default integer.
5 Result Value. If all of the bits of I are zero, the result value is BIT_SIZE (I). Otherwise, the result value is the
position of the rightmost 1 bit in I. The model for the interpretation of an integer value as a sequence of bits is6 Examples. TRAILZ (8) has the value 3.in 16.3.
16.9.193 TRANSFER (SOURCE, MOLD [, SIZE])1 Description. Transfer physical representation.
2 Class. Transformational function.
3 Arguments.
SOURCE shall be a scalar or array of any type.4 Result Characteristics. The result is of the same type and type parameters as MOLD.432 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
MOLD shall be a scalar or array of any type. If it is a variable, it need not be defined. If the storage size of
SOURCE is greater than zero and MOLD is an array, a scalar with the type and type parameters
of MOLD shall not have a storage size equal to zero.
SIZE (optional) shall be an integer scalar. The corresponding actual argument shall not be an optional dummy
argument.
Case (i): If MOLD is a scalar and SIZE is absent, the result is a scalar.5 Result Value. If the physical representation of the result has the same length as that of SOURCE, the physicalCase (ii): If MOLD is an array and SIZE is absent, the result is an array and of rank one. Its size is as small
as possible such that its physical representation is not shorter than that of SOURCE.
Case (iii): If SIZE is present, the result is an array of rank one and size SIZE.
representation of the result is that of SOURCE. If the physical representation of the result is longer than that6 Examples.of SOURCE, the physical representation of the leading part is that of SOURCE and the remainder is processor
dependent. If the physical representation of the result is shorter than that of SOURCE, the physical representation
of the result is the leading part of SOURCE. If D and E are scalar variables such that the physical representation
of D is as long as or longer than that of E, the value of TRANSFER (TRANSFER (E, D), E) shall be the value
of E. IF D is an array and E is an array of rank one, the value of TRANSFER (TRANSFER (E, D), E, SIZE (E))
shall be the value of E.
Case (i): TRANSFER (1082130432, 0.0) has the value 4.0 on a processor that represents the values 4.0 and1 Description. Transpose of an array of rank two.1082130432 as the string of binary digits 0100 0000 1000 0000 0000 0000 0000 0000.
Case (ii): TRANSFER ([1.1, 2.2, 3.3], [(0.0, 0.0)])) is a complex rank-one array of length two whose first
element has the value (1.1, 2.2) and whose second element has a real part with the value 3.3. The
imaginary part of the second element is processor dependent.
Case (iii): TRANSFER ([1.1, 2.2, 3.3], [(0.0, 0.0)], 1) is a complex rank-one array of length one whose only
element has the value (1.1, 2.2).
16.9.194 TRANSPOSE (MATRIX)
2 Class. Transformational function.
3 Argument. MATRIX shall be a rank-two array of any type.
4 Result Characteristics. The result is an array of the same type and type parameters as MATRIX and with
rank two and shape [n, m] where [m, n] is the shape of MATRIX.5 Result Value. Element (i, j) of the result has the value MATRIX (j + LBOUND (MATRIX, 1) − 1, i +
LBOUND (MATRIX, 2) − 1).
1 2 3 1 4 7
6 Example. If A is the array 4 5 6 , then TRANSPOSE (A) has the value 2 5 8 .
7 8 9 3 6 9 16.9.195 TRIM (STRING) 1 Description. String without trailing blanks. 2 Class. Transformational function. 3 Argument. STRING shall be a character scalar. ⃝c ISO/IEC 2017 – All rights reserved 4334 Result Characteristics. Character with the same kind type parameter value as STRING and with a length
ISO/IEC DIS 1539-1:2017 (E)
that is the length of STRING less the number of trailing blanks in STRING. If STRING contains no nonblank5 Result Value. The value of the result is the same as STRING except any trailing blanks are removed.characters, the result has zero length.
6 Example. TRIM (’ A B ’) has the value ’ A B’. 16.9.196 UBOUND (ARRAY [, DIM, KIND])1 Description. Upper bound(s).
2 Class. Inquiry function. 3 Arguments. ARRAY shall be assumed-rank or an array. It shall not be an unallocated allocatable array or a pointer that4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofis not associated. If ARRAY is an assumed-size array, DIM shall be present with a value less than
the rank of ARRAY.
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the rank of ARRAY.
The corresponding actual argument shall not be an optional dummy argument, a disassociated
pointer, or an unallocated allocatable.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type. The result is scalar if DIM is present;5 Result Value.otherwise, the result is an array of rank one and size n, where n is the rank of ARRAY.
Case (i): If DIM is present, ARRAY is a whole array, and dimension DIM of ARRAY has nonzero extent,6 Examples. If A is declared by the statementthe result has a value equal to the upper bound for subscript DIM of ARRAY. Otherwise, if DIM
is present and ARRAY is assumed-rank, the value of the result is as if ARRAY were a whole array,
with the extent of the final dimension of ARRAY when ARRAY is associated with an assumed-size
array being considered to be −1. Otherwise, if DIM is present, the result has a value equal to the
number of elements in dimension DIM of ARRAY.
Case (ii): If ARRAY has rank zero, UBOUND (ARRAY) has a value that is a zero-sized array. Otherwise,
UBOUND (ARRAY) has a value whose ith element is equal to UBOUND (ARRAY, i), for i = 1, 2,
. . . , n, where n is the rank of ARRAY. UBOUND (ARRAY, KIND=KIND) has a value whose ith
element is equal to UBOUND (ARRAY, i, KIND=KIND), for i = 1, 2, . . . , n, where n is the
rank of ARRAY.
REAL A (2:3, 7:10)then UBOUND (A) is [3, 10] and UBOUND (A, DIM = 2) is 10.
NOTE 16.3316.9.197 UCOBOUND (COARRAY [, DIM, KIND])If ARRAY is assumed-rank and has rank zero, DIM cannot be present since it cannot satisfy the requirement
1 ≤ DIM ≤ 0.
1 Description. Upper cobound(s) of a coarray. 2 Class. Inquiry function. 434 ⃝3 Arguments.c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
COARRAY shall be a coarray of any type. It may be a scalar or an array. If it is allocatable it shall be allocated.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofIf its designator has more than one part-ref , the rightmost part-ref shall have nonzero corank.
DIM (optional) shall be an integer scalar with a value in the range 1 ≤ DIM ≤ n, where n is the corank
of COARRAY. The corresponding actual argument shall not be an optional dummy argument, a
disassociated pointer, or an unallocated allocatable.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise, the kind type parameter is that of default integer type. The result is scalar if DIM is present;5 Result Value. The final upper cobound is the final cosubscript in the cosubscript list for the coarray that selectsotherwise, the result is an array of rank one and size n, where n is the corank of COARRAY.
the image whose index is equal to the number of images in the team current when COARRAY was established.6 Examples. If NUM_IMAGES( ) has the value 30 and A is allocated by the statementCase (i): If DIM is present, the result has a value equal to the upper cobound for codimension DIM of
COARRAY.
Case (ii): If DIM is absent, the result has a value whose ith element is equal to the upper cobound for
codimension i of COARRAY, for i = 1, 2,. . . , n, where n is the corank of COARRAY.
ALLOCATE (A [2:3, 0:7, *])then UCOBOUND (A) is [3, 7, 2] and UCOBOUND (A, DIM=2) is 7. Note that the cosubscripts [3, 7, 2] do
not correspond to an actual image.
16.9.198 UNPACK (VECTOR, MASK, FIELD)
1 Description. Vector unpacked into an array. 2 Class. Transformational function. 3 Arguments. VECTOR shall be a rank-one array of any type. Its size shall be at least t where t is the number of true4 Result Characteristics. The result is an array of the same type and type parameters as VECTOR and theelements in MASK.
MASK shall be a logical array.
FIELD shall be of the same type and type parameters as VECTOR and shall be conformable with MASK.
same shape as MASK.5 Result Value. The element of the result that corresponds to the ith true element of MASK, in array element
order, has the value VECTOR (i) for i = 1, 2, . . . , t, where t is the number of true values in MASK. Each other6 Examples.element has a value equal to FIELD if FIELD is scalar or to the corresponding element of FIELD if it is an array.
Particular values can be “scattered” to particular positionsin an array by
using UNPACK. If M is the
1 0 0 . T .
array 0 1 0 , V is the array [1, 2, 3], and Q is the logical mask T . . , where “T” represents true
0 0 1 . . T 1 2 0
and “.” represents false, then the result of UNPACK (V, MASK = Q, FIELD = M) has the value 1 1 0
0 0 0 2 0
and the result of UNPACK (V, MASK = Q, FIELD = 0) has the value 1 0 0 . 0 0 3
⃝c ISO/IEC 2017 – All rights reserved 435
ISO/IEC DIS 1539-1:2017 (E)16.9.199 VERIFY (STRING, SET [, BACK, KIND])
1 Description. Character set non-membership search.
2 Class. Elemental function.
3 Arguments.
STRING shall be of type character.4 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value ofSET shall be of type character with the same kind type parameter as STRING.
BACK (optional) shall be of type logical.
KIND (optional) shall be a scalar integer constant expression.
KIND; otherwise the kind type parameter is that of default integer type.5 Result Value.
Case (i): If BACK is absent or has the value false and if STRING contains at least one character that is not6 Examples.in SET, the value of the result is the position of the leftmost character of STRING that is not in
SET.
Case (ii): If BACK is present with the value true and if STRING contains at least one character that is not
in SET, the value of the result is the position of the rightmost character of STRING that is not in
SET.
Case (iii): The value of the result is zero if each character in STRING is in SET or if STRING has zero length.
Case (i): VERIFY (’ABBA’, ’A’) has the value 2.1 This document defines five standard intrinsic modules: a Fortran environment module, a set of three modulesCase (ii): VERIFY (’ABBA’, ’A’, BACK = .TRUE.) has the value 3.
Case (iii): VERIFY (’ABBA’, ’AB’) has the value 0.
16.10 Standard intrinsic modules
16.10.1 General
to support floating-point exceptions and IEEE arithmetic, and a module to support interoperability with the C2 The intrinsic modules IEEE_EXCEPTIONS, IEEE_ARITHMETIC, and IEEE_FEATURES are described inprogramming language.
Clause 17. The intrinsic module ISO_C_BINDING is described in Clause 18. The module procedures described3 A processor may extend the standard intrinsic modules to provide public entities in them in addition to thosein 16.10.2 are pure.
NOTE 16.34
The types and procedures defined in standard intrinsic modules are not themselves intrinsic.
specified in this document.1 The intrinsic module ISO_FORTRAN_ENV provides public entities relating to the Fortran environment.16.10.2 The ISO_FORTRAN_ENV intrinsic module
16.10.2.1 General
436 ⃝2 The processor shall provide the named constants, derived types, and procedures described in subclause 16.10.2.c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
In the detailed descriptions below, procedure names are generic and not specific.1 The value of the default integer scalar constant ATOMIC_INT_KIND is the kind type parameter value of type16.10.2.2 ATOMIC_INT_KIND
integer variables for which the processor supports atomic operations specified by atomic subroutines.1 The value of the default integer scalar constant ATOMIC_LOGICAL_KIND is the kind type parameter value16.10.2.3 ATOMIC_LOGICAL_KIND
of type logical variables for which the processor supports atomic operations specified by atomic subroutines.1 The values of the elements of the default integer array constant CHARACTER_KINDS are the kind values16.10.2.4 CHARACTER_KINDS
supported by the processor for variables of type character. The order of the values is processor dependent. The1 The value of the default integer scalar constant CHARACTER_STORAGE_SIZE is the size expressed in bitsrank of the array is one, its lower bound is one, and its size is the number of character kinds supported.
16.10.2.5 CHARACTER_STORAGE_SIZE
of the character storage unit (19.5.3.2).1 Description. Processor-dependent string describing the options that controlled the program translation phase.16.10.2.6 COMPILER_OPTIONS ( )
2 Class. Transformational function.
3 Argument. None.
4 Result Characteristics. Default character scalar with processor-dependent length.
5 Result Value. A processor-dependent value which describes the options that controlled the translation phase of
program execution. This value should include relevant information that could be useful for diagnosing problems6 Example. COMPILER_OPTIONS ( ) might have the value ’/OPTIMIZE /FLOAT=IEEE’.at a later date.
16.10.2.7 COMPILER_VERSION ( )1 Description. Processor-dependent string identifying the program translation phase.
2 Class. Transformational function.
3 Argument. None.
4 Result Characteristics. Default character scalar with processor-dependent length.
5 Result Value. A processor-dependent value that identifies the name and version of the program translation
phase of the processor. This value should include relevant information that could be useful for diagnosing problems6 Example. COMPILER_VERSION ( ) might have the value ’Fast KL-10 Compiler Version 7’.at a later date.
⃝c ISO/IEC 2017 – All rights reserved 4371 The value of the default integer scalar constant CURRENT_TEAM identifies the current team when it is used
ISO/IEC DIS 1539-1:2017 (E)
NOTE 16.35
Relevant information that could be useful for diagnosing problems at a later date might include compiler
release and patch level, default compiler arguments, environment variable values, and run time library
requirements. A processor might include this information in an object file automatically, without the user
needing to save the result of this function in a variable.
16.10.2.8 CURRENT_TEAM
as the LEVEL argument to GET_TEAM.1 The value of the default integer scalar constant ERROR_UNIT identifies the processor-dependent preconnected16.10.2.9 ERROR_UNIT
external unit used for the purpose of error reporting (12.5). This unit may be the same as OUTPUT_UNIT.1 EVENT_TYPE is a derived type with private components. It is an extensible type with no type parameters.The value shall not be −1.
16.10.2.10 EVENT_TYPE
Each nonallocatable component is fully default-initialized.2 A scalar variable of type EVENT_TYPE is an event variable. The value of an event variable includes its event
count, which is updated by execution of a sequence of EVENT POST or EVENT WAIT statements. The effect1 The value of the default integer scalar constant FILE_STORAGE_SIZE is the size expressed in bits of the fileof each change is as if the intrinsic subroutine ATOMIC_ADD were executed with a variable that stores the
event count as its ATOM argument. A coarray that is of type EVENT_TYPE may be referenced or defined
during execution of a segment that is unordered relative to the execution of another segment in which that
coarray is defined. The event count is of type integer with kind ATOMIC_INT_KIND from the intrinsic module
ISO_FORTRAN_ENV. The initial value of the event count of an event variable is zero.
C1603 A named entity with declared type EVENT_TYPE, or which has a noncoarray potential subobject
component with declared type EVENT_TYPE, shall be a variable. A component that is of such a type
shall be a data component.
C1604 A named variable with declared type EVENT_TYPE shall be a coarray. A named variable with a
noncoarray potential subobject component of type EVENT_TYPE shall be a coarray.
C1605 An event variable shall not appear in a variable definition context except as the event-variable in an
EVENT POST or EVENT WAIT statement, as an allocate-object, or as an actual argument in a reference
to a procedure with an explicit interface if the corresponding dummy argument has INTENT (INOUT).
C1606 A variable with a nonpointer subobject of type EVENT_TYPE shall not appear in a variable definition
context except as an allocate-object in an ALLOCATE statement without a SOURCE= specifier, as an
allocate-object in a DEALLOCATE statement, or as an actual argument in a reference to a procedure
with an explicit interface if the corresponding dummy argument has INTENT (INOUT).
NOTE 16.36
The restrictions against changing an event variable except via EVENT POST and EVENT WAIT state-
ments ensure the integrity of its value and facilitate efficient implementation, particularly when special
synchronization is needed for correct event handling.
NOTE 16.37
Updates to variables via atomic subroutines are coherent but not necessarily consistent, so a processor
might have to use extra synchronization to obtain the consistency required for the segments ordered by
EVENT POST and EVENT WAIT statements.
438 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
16.10.2.11 FILE_STORAGE_SIZE
storage unit (12.3.5).1 The value of the default integer scalar constant INITIAL_TEAM identifies the initial team when it is used as16.10.2.12 INITIAL_TEAM
the LEVEL argument to GET_TEAM.1 The value of the default integer scalar constant INPUT_UNIT identifies the same processor-dependent external16.10.2.13 INPUT_UNIT
unit preconnected for sequential formatted input as the one identified by an asterisk in a READ statement; this1 The values of these default integer scalar constants shall be those of the kind type parameters that specify anunit is the one used for a READ statement that does not contain an input/output control list (12.6.4.3). The
value shall not be −1.
16.10.2.14 INT8, INT16, INT32, and INT64
INTEGER type whose storage size expressed in bits is 8, 16, 32, and 64 respectively. If, for any of these constants,1 The values of the elements of the default integer array constant INTEGER_KINDS are the kind values supportedthe processor supports more than one kind of that size, it is processor dependent which kind value is provided. If
the processor supports no kind of a particular size, that constant shall be equal to −2 if the processor supports
a kind with larger size and −1 otherwise.
16.10.2.15 INTEGER_KINDS
by the processor for variables of type integer. The order of the values is processor dependent. The rank of the1 The value of the default integer scalar constant IOSTAT_END is assigned to the variable specified in an IOSTAT=array is one, its lower bound is one, and its size is the number of integer kinds supported.
16.10.2.16 IOSTAT_END
specifier (12.11.5) if an end-of-file condition occurs during execution of an input statement and no error condition1 The value of the default integer scalar constant IOSTAT_EOR is assigned to the variable specified in an IOSTAT=occurs. This value shall be negative.
16.10.2.17 IOSTAT_EOR
specifier (12.11.5) if an end-of-record condition occurs during execution of an input statement and no end-of-file1 The value of the default integer scalar constant IOSTAT_INQUIRE_INTERNAL_UNIT is assigned to theor error condition occurs. This value shall be negative and different from the value of IOSTAT_END.
16.10.2.18 IOSTAT_INQUIRE_INTERNAL_UNIT
variable specified in an IOSTAT= specifier in an INQUIRE statement (12.10) if a file-unit-number identifies an1 LOCK_TYPE is a derived type with private components; no component is allocatable or a pointer. It is aninternal unit in that statement.
NOTE 16.38
This can only occur when a defined input/output procedure is called by the processor as the result of
executing a parent data transfer statement (12.6.4.8.3) for an internal unit.
⃝c ISO/IEC 2017 – All rights reserved 439
ISO/IEC DIS 1539-1:2017 (E)
16.10.2.19 LOCK_TYPE
extensible type with no type parameters. All components have default initialization.2 A scalar variable of type LOCK_TYPE is a lock variable. A lock variable can have one of two states: locked and
unlocked. The unlocked state is represented by the one value that is the default value of a LOCK_TYPE variable;1 The values of the elements of the default integer array constant LOGICAL_KINDS are the kind values supportedthis is the value specified by the structure constructor LOCK_TYPE ( ). The locked state is represented by all
other values. The value of a lock variable can be changed with the LOCK and UNLOCK statements (11.6.10).
C1607 A named entity with declared type LOCK_TYPE, or which has a noncoarray potential subobject com-
ponent with declared type LOCK_TYPE, shall be a variable. A component that is of such a type shall
be a data component.
C1608 A named variable with declared type LOCK_TYPE shall be a coarray. A named variable with a
noncoarray potential subobject component of type LOCK_TYPE shall be a coarray.
C1609 A lock variable shall not appear in a variable definition context except as the lock-variable in a LOCK or
UNLOCK statement, as an allocate-object, or as an actual argument in a reference to a procedure with
an explicit interface where the corresponding dummy argument has INTENT (INOUT).
C1610 A variable with a subobject of type LOCK_TYPE shall not appear in a variable definition context except
as an allocate-object or as an actual argument in a reference to a procedure with an explicit interface
where the corresponding dummy argument has INTENT (INOUT).
NOTE 16.39
The restrictions against changing a lock variable except via the LOCK and UNLOCK statements ensure
the integrity of its value and facilitate efficient implementation, particularly when special synchronization
is needed for correct lock operation.
16.10.2.20 LOGICAL_KINDS
by the processor for variables of type logical. The order of the values is processor dependent. The rank of the1 The value of the default integer scalar constant NUMERIC_STORAGE_SIZE is the size expressed in bits of thearray is one, its lower bound is one, and its size is the number of logical kinds supported.
16.10.2.21 NUMERIC_STORAGE_SIZE
numeric storage unit (19.5.3.2).1 The value of the default integer scalar constant OUTPUT_UNIT identifies the same processor-dependent external16.10.2.22 OUTPUT_UNIT
unit preconnected for sequential formatted output as the one identified by an asterisk in a WRITE statement1 The value of the default integer scalar constant PARENT_TEAM identifies the parent team when it is used as(12.6.4.3). The value shall not be −1.
16.10.2.23 PARENT_TEAM
the LEVEL argument to GET_TEAM.1 The values of the elements of the default integer array constant REAL_KINDS are the kind values supported by16.10.2.24 REAL_KINDS
the processor for variables of type real. The order of the values is processor dependent. The rank of the array is1 The values of these default integer scalar named constants shall be those of the kind type parameters that specifyone, its lower bound is one, and its size is the number of real kinds supported.
440 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
16.10.2.25 REAL32, REAL64, and REAL128
a REAL type whose storage size expressed in bits is 32, 64, and 128 respectively. If, for any of these constants,1 If the processor has the ability to detect that an image has failed, the value of the default integer scalar constantthe processor supports more than one kind of that size, it is processor dependent which kind value is provided. If
the processor supports no kind of a particular size, that constant shall be equal to −2 if the processor supports
kinds of a larger size and −1 otherwise.
16.10.2.26 STAT_FAILED_IMAGE
STAT_FAILED_IMAGE is positive; otherwise, the value of STAT_FAILED_IMAGE is negative. If an image1 The value of the default integer scalar constant STAT_LOCKED is assigned to the variable specified in a STAT=involved in execution of an image control statement, a reference to a coindexed object, or execution of a collective
or atomic subroutine has failed, and no other error condition occurs, the value of STAT_FAILED_IMAGE is
assigned to the variable specified in a STAT= specifier in the execution of an image control statement or reference
to a coindexed object, or to the STAT argument in an invocation of a collective or atomic subroutine.
16.10.2.27 STAT_LOCKED
specifier (11.6.11) of a LOCK statement if the lock variable is locked by the executing image.1 The value of the default integer scalar constant STAT_LOCKED_OTHER_IMAGE is assigned to the variable16.10.2.28 STAT_LOCKED_OTHER_IMAGE
specified in a STAT= specifier (11.6.11) of an UNLOCK statement if the lock variable is locked by another image.1 The value of the default integer scalar constant STAT_STOPPED_IMAGE is assigned to the variable specified16.10.2.29 STAT_STOPPED_IMAGE
in a STAT= specifier (9.7.4, 11.6.11), if execution of the statement with that specifier requires synchronization1 The value of the default integer scalar constant STAT_UNLOCKED is assigned to the variable specified in awith an image that has initiated normal termination. It is assigned to a STAT argument in a reference to a
collective subroutine if any image of the current team has initiated normal termination. This value shall be
positive.
16.10.2.30 STAT_UNLOCKED
STAT= specifier (11.6.11) of an UNLOCK statement if the lock variable is unlocked.1 The value of the default integer scalar constant STAT_UNLOCKED_FAILED_IMAGE is assigned to the vari-16.10.2.31 STAT_UNLOCKED_FAILED_IMAGE
able specified in a STAT= specifier (11.6.11) of a LOCK statement if the lock variable is unlocked because of the1 TEAM_TYPE is a derived type with private components. It is an extensible type with no type parameters.failure of the image that locked it.
16.10.2.32 TEAM_TYPE
Each nonallocatable component is fully default-initialized.2 A scalar variable of type TEAM_TYPE is a team variable, and can identify a team. The default initial value of
a team variable does not identify any team.1 The values of these named constants shall be distinct:⃝c ISO/IEC 2017 – All rights reserved 441
ISO/IEC DIS 1539-1:2017 (E)
16.10.2.33 Uniqueness of named constant values
IOSTAT_INQUIRE_INTERNAL_UNIT STAT_STOPPED_IMAGE
STAT_FAILED_IMAGE STAT_UNLOCKED
STAT_LOCKED STAT_UNLOCKED_FAILED_IMAGE
STAT_LOCKED_OTHER_IMAGE
442 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)17 Exceptions and IEEE arithmetic
17.1 Overview of IEEE arithmetic support 1 The intrinsic modules IEEE_EXCEPTIONS, IEEE_ARITHMETIC, and IEEE_FEATURES provide support
for the facilities defined by ISO/IEC/IEEE 60559:2011∗ . Whether the modules are provided is processor depend-2 If IEEE_EXCEPTIONS or IEEE_ARITHMETIC is accessible in a scoping unit, the exceptions IEEE_OVER-ent. If the module IEEE_FEATURES is provided, which of the named constants defined in this document are
included is processor dependent. The module IEEE_ARITHMETIC behaves as if it contained a USE statement
for IEEE_EXCEPTIONS; everything that is public in IEEE_EXCEPTIONS is public in IEEE_ARITHMETIC.
NOTE 17.1
The types and procedures defined in these modules are not themselves intrinsic.
FLOW and IEEE_DIVIDE_BY_ZERO are supported in the scoping unit for all kinds of real and complex3 If a scoping unit does not access IEEE_FEATURES, IEEE_EXCEPTIONS, or IEEE_ARITHMETIC, the levelIEEE floating-point data. Which other exceptions are supported can be determined by the inquiry function
IEEE_SUPPORT_FLAG (17.11.51); whether control of halting is supported can be determined by the inquiry
function IEEE_SUPPORT_HALTING. The extent of support of the other exceptions may be influenced by
the accessibility of the named constants IEEE_INEXACT_FLAG, IEEE_INVALID_FLAG, and IEEE_UN-
DERFLOW_FLAG of the module IEEE_FEATURES. If a scoping unit has access to IEEE_UNDERFLOW_-
FLAG of IEEE_FEATURES, within the scoping unit the processor shall support underflow and return true from
IEEE_SUPPORT_FLAG (IEEE_UNDERFLOW, X) for at least one kind of real. Similarly, if IEEE_INEX-
ACT_FLAG or IEEE_INVALID_FLAG is accessible, within the scoping unit the processor shall support the
exception and return true from the corresponding inquiry function for at least one kind of real. If IEEE_HALT-
ING is accessible, within the scoping unit the processor shall support control of halting and return true from
IEEE_SUPPORT_HALTING (FLAG) for the flag.
NOTE 17.2
IEEE_INVALID is not required to be supported whenever IEEE_EXCEPTIONS is accessed. This is to
allow a processor whose arithmetic does not conform to ISO/IEC/IEEE 60559:2011 to provide support for
overflow and divide_by_zero. On a processor which does support ISO/IEC/IEEE 60559:2011, invalid is
an equally serious condition.
of support is processor dependent, and need not include support for any exceptions. If a flag is signaling on entry4 Additional ISO/IEC/IEEE 60559:2011 facilities are available from the module IEEE_ARITHMETIC. The extentto such a scoping unit, the processor ensures that it is signaling on exit. If a flag is quiet on entry to such a
scoping unit, whether it is signaling on exit is processor dependent.
of support may be influenced by the accessibility of the named constants of the module IEEE_FEATURES. If a5 Execution might be slowed on some processors by the support of some features. If IEEE_EXCEPTIONS orscoping unit has access to IEEE_DATATYPE of IEEE_FEATURES, within the scoping unit the processor shall
support IEEE arithmetic and return true from IEEE_SUPPORT_DATATYPE (X) (17.11.48) for at least one
kind of real. Similarly, if IEEE_DENORMAL, IEEE_DIVIDE, IEEE_INF, IEEE_NAN, IEEE_ROUNDING,
IEEE_SQRT, or IEEE_SUBNORMAL is accessible, within the scoping unit the processor shall support the
feature and return true from the corresponding inquiry function for at least one kind of real. In the case of
IEEE_ROUNDING, it shall return true for the rounding modes IEEE_NEAREST, IEEE_TO_ZERO, IEEE_-
UP, and IEEE_DOWN; support for IEEE_AWAY is also required if there is at least one kind of real X for
∗ Because ISO/IEC/IEEE 60559:2011 was originally an IEEE standard, its facilities are widely known as “IEEE arithmetic”,
and this terminology is used by this document.
⃝c ISO/IEC 2017 – All rights reserved 443
ISO/IEC DIS 1539-1:2017 (E)
which IEEE_SUPPORT_DATATYPE (X) is true and RADIX (X) is equal to ten. Note that the effect of
IEEE_DENORMAL is the same as that of IEEE_SUBNORMAL.
IEEE_ARITHMETIC is accessed but IEEE_FEATURES is not accessed, the supported subset of features is1 The modules IEEE_EXCEPTIONS, IEEE_ARITHMETIC, and IEEE_FEATURES define five derived types,processor dependent. The processor’s fullest support is provided when all of IEEE_FEATURES is accessed as in
USE, INTRINSIC :: IEEE_ARITHMETIC; USE, INTRINSIC :: IEEE_FEATURES
but execution might then be slowed by the presence of a feature that is not needed. In all cases, the extent of
support can be determined by the inquiry functions.
17.2 Derived types, constants, and operators defined in the modules
whose components are all private. No direct component of any of these types is allocatable or a pointer.2 The module IEEE_EXCEPTIONS defines the following types.
• IEEE_FLAG_TYPE is for identifying a particular exception flag. Its only possible values are those of3 The module IEEE_ARITHMETIC defines the following types, constants, and operators.named constants defined in the module: IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_-
ZERO, IEEE_UNDERFLOW, and IEEE_INEXACT. The module also defines the array named constants
IEEE_USUAL = [ IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_INVALID ] and IEEE_-
ALL = [ IEEE_USUAL, IEEE_UNDERFLOW, IEEE_INEXACT ].
• IEEE_MODES_TYPE is for representing the floating-point modes.
• IEEE_STATUS_TYPE is for representing the floating-point status.
• The type IEEE_CLASS_TYPE, for identifying a class of floating-point values. Its only possible4 The module IEEE_FEATURES defines the type IEEE_FEATURES_TYPE, for expressing the need for particu-values are those of named constants defined in the module: IEEE_SIGNALING_NAN, IEEE_QUI-
ET_NAN, IEEE_NEGATIVE_INF, IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_DENORMAL,
IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, IEEE_POSITIVE_SUBNORMAL, IEEE_POS-
ITIVE_NORMAL, IEEE_POSITIVE_INF, and IEEE_OTHER_VALUE. The named constants IEEE_-
NEGATIVE_DENORMAL and IEEE_POSITIVE_DENORMAL are defined with the same value as
IEEE_NEGATIVE_SUBNORMAL and IEEE_POSITIVE_SUBNORMAL respectively.
• The type IEEE_ROUND_TYPE, for identifying a particular rounding mode. Its only possible values
are those of named constants defined in the module: IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP,
IEEE_DOWN, IEEE_AWAY and IEEE_OTHER for the rounding modes specified in this document.
• The pure elemental operator == for two values of one of these types to return true if the values are the
same and false otherwise.
• The pure elemental operator /= for two values of one of these types to return true if the values differ and
false otherwise.
lar ISO/IEC/IEEE 60559:2011 features. Its only possible values are those of named constants defined in the mod-1 The exceptions are the following.ule: IEEE_DATATYPE, IEEE_DENORMAL, IEEE_DIVIDE, IEEE_HALTING, IEEE_INEXACT_FLAG,
IEEE_INF, IEEE_INVALID_FLAG, IEEE_NAN, IEEE_ROUNDING, IEEE_SQRT, IEEE_SUBNORMAL,
and IEEE_UNDERFLOW_FLAG.
17.3 The exceptions
444 ⃝2 Each exception has a flag whose value is either quiet or signaling. The value can be determined by the subroutinec ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
• IEEE_OVERFLOW occurs in an intrinsic real addition, subtraction, multiplication, division, or conversion
by the intrinsic function REAL, as specified by ISO/IEC/IEEE 60559:2011 if IEEE_SUPPORT_DATA-
TYPE is true for the operands of the operation or conversion, and as determined by the processor otherwise.
It occurs in an intrinsic real exponentiation as determined by the processor. It occurs in a complex op-
eration, or conversion by the intrinsic function CMPLX, if it is caused by the calculation of the real or
imaginary part of the result.
• IEEE_DIVIDE_BY_ZERO occurs in a real division as specified by ISO/IEC/IEEE 60559:2011 if IEEE_-
SUPPORT_DATATYPE is true for the operands of the division, and as determined by the processor
otherwise. It is processor-dependent whether it occurs in a real exponentiation with a negative exponent.
It occurs in a complex division if it is caused by the calculation of the real or imaginary part of the result.
• IEEE_INVALID occurs when a real or complex operation or assignment is invalid; possible examples are
SQRT (X) when X is real and has a nonzero negative value, and conversion to an integer (by assignment,
an intrinsic procedure, or a procedure defined in an intrinsic module) when the result is too large to be
representable. IEEE_INVALID occurs for numeric relational intrinsic operations as specified below.
• IEEE_UNDERFLOW occurs when the result for an intrinsic real operation or assignment has an absolute
value less than a processor-dependent limit, or the real or imaginary part of the result for an intrinsic
complex operation or assignment has an absolute value less than a processor-dependent limit.
• IEEE_INEXACT occurs when the result of a real or complex operation or assignment is not exact.
IEEE_GET_FLAG. Its initial value is quiet. It is set to signaling when the associated exception occurs, except3 If a flag is signaling on entry to a procedure other than IEEE_GET_FLAG or IEEE_GET_STATUS, thethat the flag for IEEE_UNDERFLOW is not set if the result of the operation that caused the exception was exact
and default ISO/IEC/IEEE 60559:2011 exception handling is in effect for IEEE_UNDERFLOW. Its status can
also be changed by the subroutine IEEE_SET_FLAG or the subroutine IEEE_SET_STATUS. Once signaling
within a procedure, it remains signaling unless set quiet by an invocation of the subroutine IEEE_SET_FLAG
or the subroutine IEEE_SET_STATUS.
processor will set it to quiet on entry and restore it to signaling on return. If a flag signals during execution of a4 Evaluation of a specification expression might cause an exception to signal.procedure, the processor shall not set it to quiet on return.
5 In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC, if an intrinsic procedure
or a procedure defined in an intrinsic module executes normally, the values of the flags IEEE_OVERFLOW,6 In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC, if x1 and x2 are numericIEEE_DIVIDE_BY_ZERO, and IEEE_INVALID shall be as on entry to the procedure, even if one or more of
them signals during the calculation. If a real or complex result is too large for the procedure to handle, IEEE_-
OVERFLOW may signal. If a real or complex result is a NaN because of an invalid operation (for example,
LOG (−1.0)), IEEE_INVALID may signal. Similar rules apply to format processing and to intrinsic operations:
no signaling flag shall be set quiet and no quiet flag shall be set signaling because of an intermediate calculation
that does not affect the result.
entities, the type of x1 + x2 is real, and IEEE_SUPPORT_NAN (x1 + x2 ) is true, the relational intrinsic7 In a scoping unit that has access to IEEE_EXCEPTIONS or IEEE_ARITHMETIC, if x1 or x2 are numericoperation x1 rel-op x2 shall signal IEEE_INVALID as specified for the conditional predicate of ISO/IEC/IEEE
60559:2011 corresponding to rel-op indicated by Table 17.1. If the types or kind type parameters of x1 or x2 differ,
the conversions (10.1.5.5.1) might signal exceptions instead of or in addition to an IEEE_INVALID exception
signaled by the comparison.
NOTE 17.3
Each comparison predicate defined by ISO/IEC/IEEE 60559:2011 is either unordered signaling or unordered
quiet. An unordered signaling predicate signals an invalid operation exception if and only if one of the values
being compared is a NaN. An unordered quiet predicate signals an invalid operation exception if and only
if one of the values being compared is a signaling NaN. The comparison predicates do not signal any other
exceptions.
⃝c ISO/IEC 2017 – All rights reserved 445
ISO/IEC DIS 1539-1:2017 (E)
Table 17.1: IEEE relational operator correspondence
Operator ISO/IEC/IEEE 60559:2011 comparison predicate
.LT. or < compareSignalingLess
.LE. or <= compareSignalingLessEqual
.GT. or > compareSignalingGreater
.GE. or >= compareSignalingGreaterEqual
.EQ. or == compareQuietEqual
.NE. or /= compareQuietNotEqual
entities, the type of x1 + x2 is complex, and IEEE_SUPPORT_NAN (REAL (x1 + x2 )) is true, the intrinsic8 In a sequence of statements that has no invocations of IEEE_GET_FLAG, IEEE_SET_FLAG, IEEE_GET_-equality or inequality operation between x1 and x2 may signal IEEE_INVALID if the value of the real or
imaginary part of either operand is a signaling NaN. If any conversions are done before the values are compared,
those conversions might signal exceptions instead of or in addition to an IEEE_INVALID exception signaled by
the comparison.
STATUS, IEEE_SET_HALTING_MODE, or IEEE_SET_STATUS, if the execution of an operation would9 An exception shall not signal if this could arise only during execution of an operation beyond those required orcause an exception to signal but after execution of the sequence no value of a variable depends on the operation,
whether the exception is signaling is processor dependent. For example, when Y has the value zero, whether the
code
X = 1.0/Y
X = 3.0
signals IEEE_DIVIDE_BY_ZERO is processor dependent. Another example is the following:
REAL, PARAMETER :: X=0.0, Y=6.0
IF (1.0/X == Y) PRINT *,’Hello world’
where the processor is permitted to discard the IF statement because the logical expression can never be true
and no value of a variable depends on it.
permitted by the standard. For example, the statement10 The processor need not support IEEE_INVALID, IEEE_UNDERFLOW, and IEEE_INEXACT. If an exceptionIF (F (X) > 0.0) Y = 1.0/Z
shall not signal IEEE_DIVIDE_BY_ZERO when both F (X) and Z are zero and the statement
WHERE (A > 0.0) A = 1.0/A
shall not signal IEEE_DIVIDE_BY_ZERO. On the other hand, when X has the value 1.0 and Y has the value
0.0, the expression
X>0.00001 .OR. X/Y>0.00001
is permitted to cause the signaling of IEEE_DIVIDE_BY_ZERO.
is not supported, its flag is always quiet. The inquiry function IEEE_SUPPORT_FLAG can be used to inquirewhether a particular flag is supported.
446 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
17.4 The rounding modes 1 This document specifies a binary rounding mode that affects floating-point arithmetic with radix two, and a
decimal rounding mode that affects floating-point arithmetic with radix ten. Unqualified references to the round-2 ISO/IEC/IEEE 60559:2011 specifies five possible rounding-direction attributes: roundTiesToEven, roundTo-ing mode with respect to a particular arithmetic operation or operands refers to the mode for the radix of the
operation or operands, and other unqualified references to the rounding mode refers to both binary and decimal
rounding modes.
wardZero, roundTowardPositive, roundTowardNegative, and roundTiesToAway. These correspond to the round-3 The subroutine IEEE_GET_ROUNDING_MODE can be used to get the rounding modes. The initial roundinging modes IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, and IEEE_AWAY respectively.
The rounding mode IEEE_OTHER does not correspond to any ISO/IEC/IEEE 60559:2011 rounding-direction
attribute; if supported, the effect of this rounding mode is processor dependent.
modes are processor dependent.4 If the processor supports the alteration of the rounding modes during execution, the subroutine IEEE_SET_-
ROUNDING_MODE can be used to alter them. The inquiry function IEEE_SUPPORT_ROUNDING can be5 In a procedure other than IEEE_SET_ROUNDING_MODE or IEEE_SET_STATUS, the processor shall notused to inquire whether this facility is available for a particular mode. The inquiry function IEEE_SUPPORT_-
IO can be used to inquire whether rounding for base conversion in formatted input/output (12.5.6.16, 12.6.2.13,
13.7.2.3.8) is as specified in ISO/IEC/IEEE 60559:2011.
change the rounding modes on entry, and on return shall ensure that the rounding modes are the same as they1 Some processors allow control during program execution of whether underflow produces a subnormal number inwere on entry.
NOTE 17.4
ISO/IEC/IEEE 60559:2011 requires support for roundTiesToAway only for decimal floating-point.
NOTE 17.5
ISO/IEC/IEEE 60559:2011 requires that there is a language-defined means to specify a constant value
for the rounding-direction attribute for all standard operations in a block. The means provided by this
document are a CALL to IEEE_GET_ROUNDING_MODE at the beginning of the block followed by
a CALL to IEEE_SET_ROUNDING_MODE with constant arguments, together with another CALL to
IEEE_SET_ROUNDING_MODE at the end of the block to restore the rounding mode.
NOTE 17.6
Within a program, all literal constants that have the same form have the same value (7.1.4). Therefore, the
value of a literal constant is not affected by the rounding modes.
17.5 Underflow mode
conformance with ISO/IEC/IEEE 60559:2011 (gradual underflow) or produces zero instead (abrupt underflow).2 Control over the underflow mode is exercised by invocation of IEEE_SET_UNDERFLOW_MODE. The sub-On some processors, floating-point performance is typically better in abrupt underflow mode than in gradual
underflow mode.
routine IEEE_GET_UNDERFLOW_MODE can be used to get the underflow mode. The inquiry function3 The underflow mode affects only floating-point calculations whose type is that of an X for which IEEE_SUP-IEEE_SUPPORT_UNDERFLOW_CONTROL can be used to inquire whether this facility is available. The
initial underflow mode is processor dependent. In a procedure other than IEEE_SET_UNDERFLOW_MODE
or IEEE_SET_STATUS, the processor shall not change the underflow mode on entry, and on return shall ensure
that the underflow mode is the same as it was on entry.
⃝c ISO/IEC 2017 – All rights reserved 447
ISO/IEC DIS 1539-1:2017 (E)
PORT_UNDERFLOW_CONTROL returns true.1 Some processors allow control during program execution of whether to abort or continue execution after an17.6 Halting
exception. Such control is exercised by invocation of the subroutine IEEE_SET_HALTING_MODE. Halting1 The values of the rounding modes, underflow mode, and halting mode are collectively called the floating-pointis not precise and may occur any time after the exception has occurred. The inquiry function IEEE_SUP-
PORT_HALTING can be used to inquire whether this facility is available. The initial halting mode is processor
dependent. In a procedure other than IEEE_SET_HALTING_MODE or IEEE_SET_STATUS, the processor
shall not change the halting mode on entry, and on return shall ensure that the halting mode is the same as it
was on entry.
17.7 The floating-point modes and status
modes. The values of all the supported flags for exceptions and the floating-point modes are collectively called the1 ISO/IEC/IEEE 60559:2011 specifies the following exceptional floating-point values.floating-point status. The floating-point modes can be stored in a scalar variable of type IEEE_MODES_TYPE
with the subroutine IEEE_GET_MODES and restored with the subroutine IEEE_SET_MODES. The floating-
point status can be stored in a scalar variable of type IEEE_STATUS_TYPE with the subroutine IEEE_GET_-
STATUS and restored with the subroutine IEEE_SET_STATUS. There are no facilities for finding the values of
particular flags represented by such a variable.
NOTE 17.7
Each image has its own floating-point status (5.3.4).
NOTE 17.8
Some processors hold all these flags and modes in one or two status registers that can be obtained and
set as a whole faster than all individual flags and modes can be obtained and set. These procedures are
provided to exploit this feature.
NOTE 17.9
The processor is required to ensure that a call to a Fortran procedure does not change the floating-point
status other than by setting exception flags to signaling.
17.8 Exceptional values
• Subnormal values have very small absolute values and reduced precision.2 A value that does not fall into the above classes is called a normal number.• Infinite values (+infinity and −infinity) are created by overflow or division by zero.
• Not-a-Number ( NaN) values are undefined values or values created by an invalid operation.
3 The functions IEEE_IS_FINITE, IEEE_IS_NAN, IEEE_IS_NEGATIVE, and IEEE_IS_NORMAL are
provided to test whether a value is finite, NaN, negative, or normal. The function IEEE_VALUE is provided to1 The inquiry function IEEE_SUPPORT_DATATYPE can be used to inquire whether IEEE arithmetic is sup-generate an IEEE number of any class, including an infinity or a NaN. The inquiry functions IEEE_SUPPORT_-
SUBNORMAL, IEEE_SUPPORT_INF, and IEEE_SUPPORT_NAN are provided to determine whether these
facilities are available for a particular kind of real.
448 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
17.9 IEEE arithmetic
ported for a particular kind of real. Complete conformance with ISO/IEC/IEEE 60559:2011 is not required,2 The inquiry function IEEE_SUPPORT_NAN is provided to inquire whether the processor supports IEEE NaNs.but
• the normal numbers shall be exactly those of an ISO/IEC/IEEE 60559:2011 floating-point format,
• for at least one rounding mode, the intrinsic operations of addition, subtraction and multiplication shall
conform whenever the operands and result specified by ISO/IEC/IEEE 60559:2011 are normal numbers,
• the IEEE function abs shall be provided by the intrinsic function ABS,
• the IEEE operation remainder shall be provided by the function IEEE_REM, and
• the IEEE functions copySign, logB, and compareQuietUnordered shall be provided by the functions IEEE_-
COPY_SIGN, IEEE_LOGB, and IEEE_UNORDERED, respectively,
for that kind of real.
Where these are supported, the result of the intrinsic operations +, −, and *, and the functions IEEE_REM3 The inquiry function IEEE_SUPPORT_INF is provided to inquire whether the processor supports IEEE infinit-and IEEE_RINT from the intrinsic module IEEE_ARITHMETIC, shall conform to ISO/IEC/IEEE 60559:2011
when the result is an IEEE NaN.
ies. Where these are supported, the result of the intrinsic operations +, −, and *, and the functions IEEE_REM4 The inquiry function IEEE_SUPPORT_SUBNORMAL is provided to inquire whether the processor supportsand IEEE_RINT from the intrinsic module IEEE_ARITHMETIC, shall conform to ISO/IEC/IEEE 60559:2011
when exactly one operand or the result specified by ISO/IEC/IEEE 60559:2011 is an IEEE infinity.
subnormal numbers. Where these are supported, the result of the intrinsic operations +, −, and *, and the5 The inquiry function IEEE_SUPPORT_DIVIDE is provided to inquire whether, on kinds of real for whichfunctions IEEE_REM and IEEE_RINT from the intrinsic module IEEE_ARITHMETIC, shall conform to
ISO/IEC/IEEE 60559:2011 when the result specified by ISO/IEC/IEEE 60559:2011 is subnormal, or any op-
erand is subnormal and either the result is not an IEEE infinity or IEEE_SUPPORT_INF is true.
IEEE_SUPPORT_DATATYPE returns true, the intrinsic division operation conforms to ISO/IEC/IEEE6 ISO/IEC/IEEE 60559:2011 specifies a square root function that returns negative real zero for the square root of60559:2011 when both operands and the result specified by ISO/IEC/IEEE 60559:2011 are normal numbers.
If IEEE_SUPPORT_NAN is also true for a particular kind of real, the intrinsic division operation on that kind
conforms to ISO/IEC/IEEE 60559:2011 when the result specified by ISO/IEC/IEEE 60559:2011 is a NaN. If
IEEE_SUPPORT_INF is also true for a particular kind of real, the intrinsic division operation on that kind
conforms to ISO/IEC/IEEE 60559:2011 when one operand or the result specified by ISO/IEC/IEEE 60559:2011 is
an IEEE infinity. If IEEE_SUPPORT_SUBNORMAL is also true for a particular kind of real, the intrinsic divi-
sion operation on that kind conforms to ISO/IEC/IEEE 60559:2011 when the result specified by ISO/IEC/IEEE
60559:2011 is subnormal, or when any operand is subnormal and either the result specified by ISO/IEC/IEEE
60559:2011 is not an infinity or IEEE_SUPPORT_INF is true.
negative real zero and has certain accuracy requirements. The inquiry function IEEE_SUPPORT_SQRT can7 The inquiry function IEEE_SUPPORT_STANDARD is provided to inquire whether the processor supports allbe used to inquire whether the intrinsic function SQRT conforms to ISO/IEC/IEEE 60559:2011 for a particular
kind of real. If IEEE_SUPPORT_NAN is also true for a particular kind of real, the intrinsic function SQRT
on that kind conforms to ISO/IEC/IEEE 60559:2011 when the result specified by ISO/IEC/IEEE 60559:2011
is a NaN. If IEEE_SUPPORT_INF is also true for a particular kind of real, the intrinsic function SQRT on
that kind conforms to ISO/IEC/IEEE 60559:2011 when the result specified by ISO/IEC/IEEE 60559:2011 is an
IEEE infinity. If IEEE_SUPPORT_SUBNORMAL is also true for a particular kind of real, the intrinsic function
SQRT on that kind conforms to ISO/IEC/IEEE 60559:2011 when the argument is subnormal.
the ISO/IEC/IEEE 60559:2011 facilities defined in this document for a particular kind of real.1 For all of the procedures defined in the modules, the arguments shown are the names that shall be used for⃝c ISO/IEC 2017 – All rights reserved 449
ISO/IEC DIS 1539-1:2017 (E)
17.10 Summary of the procedures
argument keywords if the keyword form is used for the actual arguments.2 A procedure classified in 17.10 as an inquiry function depends on the properties of one or more of its arguments
instead of their values; in fact, these argument values may be undefined. Unless the description of one of these3 In the Class column of Tables 17.2 and 17.3,inquiry functions states otherwise, these arguments are permitted to be unallocated allocatable variables or
pointers that are undefined or disassociated. A procedure that is classified as a transformational function is
neither an inquiry function nor elemental.
E indicates that the procedure is an elemental function,
ES indicates that the procedure is an elemental subroutine, I indicates that the procedure is an inquiry function,
PS indicates that the procedure is a pure subroutine, S indicates that the procedure is an impure subroutine, and
T indicates that the procedure in a transformational function. Table 17.2: IEEE_ARITHMETIC module procedure summary
Procedure Arguments Class Description IEEE_CLASS (X) E Classify number. IEEE_COPY_SIGN (X, Y) E Copy sign. IEEE_FMA (A, B, C) E Fused multiply-add operation. IEEE_GET_ROUNDING_MODE (ROUND_VALUE S Get rounding mode. [, RADIX])
IEEE_GET_UNDERFLOW_- (GRADUAL) S Get underflow mode. MODE
IEEE_INT (A, ROUND [, KIND]) E Conversion to integer type. IEEE_IS_FINITE (X) E Whether a value is finite. IEEE_IS_NAN (X) E Whether a value is an IEEE NaN. IEEE_IS_NEGATIVE (X) E Whether a value is negative. IEEE_IS_NORMAL (X) E Whether a value is a normal number. IEEE_LOGB (X) E Exponent. IEEE_MAX_NUM (X, Y) E Maximum numeric value. IEEE_MAX_NUM_MAG (X, Y) E Maximum magnitude numeric value. IEEE_MIN_NUM (X, Y) E Minimum numeric value. IEEE_MIN_NUM_MAG (X, Y) E Minimum magnitude numeric value. IEEE_NEXT_AFTER (X, Y) E Adjacent machine number. IEEE_NEXT_DOWN (X) E Adjacent lower machine number. IEEE_NEXT_UP (X) E Adjacent higher machine number. IEEE_QUIET_EQ (A, B) E Quiet compares equal. IEEE_QUIET_GE (A, B) E Quiet compares greater than or equal. IEEE_QUIET_GT (A, B) E Quiet compares greater than. IEEE_QUIET_LE (A, B) E Quiet compares less than or equal. IEEE_QUIET_LT (A, B) E Quiet compares less than. IEEE_QUIET_NE (A, B) E Quiet compares not equal. IEEE_REAL (A [, KIND]) E Conversion to real type. IEEE_REM (X, Y) E Exact remainder. IEEE_RINT (X) E Round to integer. IEEE_SCALB (X, I) E X × 2I . IEEE_SELECTED_REAL_KIND ([P, R, RADIX]) T IEEE kind type parameter value. IEEE_SET_ROUNDING_MODE (ROUND_VALUE S Set rounding mode. [, RADIX])
450 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Table 17.2: IEEE_ARITHMETIC module procedure summary (cont.) Procedure Arguments Class Description
IEEE_SET_UNDERFLOW_- (GRADUAL) S Set underflow mode. MODE
IEEE_SIGNALING_EQ (A, B) E Signaling compares equal. IEEE_SIGNALING_GE (A, B) E Signaling compares greater than or equal.
IEEE_SIGNALING_GT (A, B) E Signaling compares greater than. IEEE_SIGNALING_LE (A, B) E Signaling compares less than or equal. IEEE_SIGNALING_LT (A, B) E Signaling compares less than. IEEE_SIGNALING_NE (A, B) E Signaling compares not equal. IEEE_SIGNBIT (X) E Test sign bit. IEEE_SUPPORT_DATATYPE ([X]) I Query IEEE arithmetic support. IEEE_SUPPORT_DENORMAL ([X]) I Query subnormal number support. IEEE_SUPPORT_DIVIDE ([X]) I Query IEEE division support. IEEE_SUPPORT_INF ([X]) I Query IEEE infinity support. IEEE_SUPPORT_IO ([X]) I Query IEEE formatting support. IEEE_SUPPORT_NAN ([X]) I Query IEEE NaN support. IEEE_SUPPORT_ROUNDING (ROUND_VALUE T Query IEEE rounding support. [, X])
IEEE_SUPPORT_SQRT ([X]) I Query IEEE square root support. IEEE_SUPPORT_SUBNORMAL ([X]) I Query subnormal number support. IEEE_SUPPORT_STANDARD ([X]) I Query IEEE standard support. IEEE_SUPPORT_UNDER- ([X]) I Query underflow control support. FLOW_CONTROL
IEEE_UNORDERED (X, Y) E Whether two values are unordered. IEEE_VALUE (X, CLASS) E Return number in a class. Table 17.3: IEEE_EXCEPTIONS module procedure summary
Procedure Arguments Class Description IEEE_GET_FLAG (FLAG, FLAG_VALUE) ES Get an exception flag. IEEE_GET_HALTING_MODE (FLAG, HALTING) ES Get a halting mode. IEEE_GET_MODES (MODES) S Get floating-point modes. IEEE_GET_STATUS (STATUS_VALUE) S Get floating-point status. IEEE_SET_FLAG (FLAG, FLAG_VALUE) PS Set an exception flag. IEEE_SET_HALTING_MODE (FLAG, HALTING) PS Set a halting mode. IEEE_SET_MODES (MODES) S Set floating-point modes. IEEE_SET_STATUS (STATUS_VALUE) S Restore floating-point status. IEEE_SUPPORT_FLAG (FLAG [, X]) T Query exception support. IEEE_SUPPORT_HALTING (FLAG) T Query halting mode support. 4 In the intrinsic module IEEE_ARITHMETIC, the elemental functions listed are provided for all reals X and Y.
17.11 Specifications of the procedures1 In the detailed descriptions in 17.11, procedure names are generic and are not specific. All the functions are pure17.11.1 General
and all the subroutines are impure unless otherwise stated. All dummy arguments have INTENT (IN) if the2 For the elemental functions of IEEE_ARITHMETIC that return a floating-point result, if X or Y has a valueintent is not stated explicitly. In the examples, it is assumed that the processor supports IEEE arithmetic for
default real.
⃝c ISO/IEC 2017 – All rights reserved 451
ISO/IEC DIS 1539-1:2017 (E)
that is an infinity or a NaN, the result shall be consistent with the general rules in 6.1 and 6.2 of ISO/IEC/IEEE3 A program may contain statements that, if executed, would violate the requirements listed in a Restriction60559:2011. For example, the result for an infinity shall be constructed as the limiting case of the result with a
value of arbitrarily large magnitude, if such a limit exists.
paragraph.NOTE 17.10
A program can avoid violating those requirements by using IF constructs to check whether particular
features are supported. For example,
IF (IEEE_SUPPORT_DATATYPE (X)) THEN
C = IEEE_CLASS (X)
ELSE
...
END IF
avoids invoking IEEE_CLASS except on a processor which supports that facility.
17.11.2 IEEE_CLASS (X) 1 Description. Classify number.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Restriction. IEEE_CLASS (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.
5 Result Characteristics. IEEE_CLASS_TYPE.
6 Result Value. The result value shall be IEEE_SIGNALING_NAN or IEEE_QUIET_NAN if IEEE_SUP-
PORT_NAN (X) has the value true and the value of X is a signaling or quiet NaN, respectively. The result7 Example. IEEE_CLASS (−1.0) has the value IEEE_NEGATIVE_NORMAL.value shall be IEEE_NEGATIVE_INF or IEEE_POSITIVE_INF if IEEE_SUPPORT_INF (X) has the value
true and the value of X is negative or positive infinity, respectively. The result value shall be IEEE_NEG-
ATIVE_SUBNORMAL or IEEE_POSITIVE_SUBNORMAL if IEEE_SUPPORT_SUBNORMAL (X) has the
value true and the value of X is a negative or positive subnormal value, respectively. The result value shall
be IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO, or IEEE_POSIT-
IVE_NORMAL if the value of X is negative normal, negative zero, positive zero, or positive normal, respectively.
Otherwise, the result value shall be IEEE_OTHER_VALUE.
NOTE 17.11The result value IEEE_OTHER_VALUE is useful on systems that are almost IEEE-compatible, but do
not implement all of it. For example, if a subnormal value is encountered on a system that does not support
them.
17.11.3 IEEE_COPY_SIGN (X, Y) 1 Description. Copy sign.
2 Class. Elemental function.
3 Arguments. The arguments shall be of type real.
452 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
4 Restriction. IEEE_COPY_SIGN (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or IEEE_SUPPORT_DATATYPE (Y) has the value false.5 Result Characteristics. Same as X.
6 Result Value. The result has the absolute value of X with the sign of Y. This is true even for IEEE special values, such as a NaN or an infinity (on processors supporting such values).7 Example. The value of IEEE_COPY_SIGN (X, 1.0) is ABS (X) even when X is a NaN.
17.11.4 IEEE_FMA (A, B, C)1 Description. Fused multiply-add operation.
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_FMA (A, B, C) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has the valueB shall be of the same type and kind type parameter as A.
C shall be of the same type and kind type parameter as A.
false.5 Result Characteristics. Same as A.
6 Result Value. The result has the value specified by ISO/IEC/IEEE 60559:2011 for the fusedMultiplyAdd operation; that is, when the result is in range, its value is equal to the mathematical value of (A × B) + C roundedto the representation method of A according to the rounding mode. IEEE_OVERFLOW, IEEE_UNDERFLOW,
and IEEE_INEXACT shall be signaled according to the final step in the calculation and not by any intermediate
calculation.
7 Example. The value of IEEE_FMA (TINY (0.0), TINY (0.0), 1.0), when the rounding mode is IEEE_- NEAREST, is equal to 1.0; only the IEEE_INEXACT exception is signaled.1 Description. Get an exception flag.17.11.5 IEEE_GET_FLAG (FLAG, FLAG_VALUE)
2 Class. Elemental subroutine.
3 Arguments.
FLAG shall be of type IEEE_FLAG_TYPE. It specifies the exception flag to be obtained.4 Example. Following CALL IEEE_GET_FLAG (IEEE_OVERFLOW, FLAG_VALUE), FLAG_VALUE isFLAG_VALUE shall be of type logical. It is an INTENT (OUT) argument. If the value of FLAG is IEEE_-
INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_-
INEXACT, FLAG_VALUE is assigned the value true if the corresponding exception flag is signaling
and is assigned the value false otherwise.
true if the IEEE_OVERFLOW flag is signaling and is false if it is quiet.1 Description. Get a halting mode.17.11.6 IEEE_GET_HALTING_MODE (FLAG, HALTING)
2 Class. Elemental subroutine.
⃝c ISO/IEC 2017 – All rights reserved 4533 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
FLAG shall be of type IEEE_FLAG_TYPE. It specifies the exception flag. It shall have one of the val-4 Example. To store the halting mode for IEEE_OVERFLOW, do a calculation without halting, and restore theues IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW,
or IEEE_INEXACT.
HALTING shall be of type logical. It is an INTENT (OUT) argument. It is assigned the value true if the
exception specified by FLAG will cause halting. Otherwise, it is assigned the value false.
halting mode later:USE, INTRINSIC :: IEEE_ARITHMETIC
LOGICAL HALTING
...
CALL IEEE_GET_HALTING_MODE (IEEE_OVERFLOW, HALTING) ! Store halting mode
CALL IEEE_SET_HALTING_MODE (IEEE_OVERFLOW, .FALSE.) ! No halting
... ! calculation without halting
CALL IEEE_SET_HALTING_MODE (IEEE_OVERFLOW, HALTING) ! Restore halting mode
17.11.7 IEEE_GET_MODES (MODES) 1 Description. Get floating-point modes.
2 Class. Subroutine.
3 Argument. MODES shall be a scalar of type IEEE_MODES_TYPE. It is an INTENT (OUT) argument that
is assigned the value of the floating-point modes.4 Example. To save the floating-point modes, do a calculation with specific rounding and underflow modes, and
restore them later:1 Description. Get rounding mode.USE, INTRINSIC :: IEEE_ARITHMETIC
TYPE (IEEE_MODES_TYPE) SAVE_MODES
...
CALL IEEE_GET_MODES (SAVE_MODES) ! Save all modes.
CALL IEEE_SET_ROUNDING_MODE (IEEE_TO_ZERO))
CALL IEEE_SET_UNDERFLOW_MODE (GRADUAL=.FALSE.)
... ! calculation with abrupt round-to-zero.
CALL IEEE_SET_MODES (SAVE_MODES) ! Restore all modes.
17.11.8 IEEE_GET_ROUNDING_MODE (ROUND_VALUE [, RADIX])
2 Class. Subroutine.
3 Arguments.
ROUND_VALUE shall be a scalar of type IEEE_ROUND_TYPE. It is an INTENT (OUT) argument. It is4 Example. To save the binary rounding mode, do a calculation with round to nearest, and restore the roundingassigned the value IEEE_NEAREST, IEEE_TO_ZERO, IEEE_UP, IEEE_DOWN, or IEEE_-
AWAY if the corresponding rounding mode is in operation and IEEE_OTHER otherwise.
RADIX (optional) shall be an integer scalar with the value two or ten. If RADIX is present with the value ten,
the rounding mode queried is the decimal rounding mode, otherwise it is the binary rounding mode.
mode later:1 Description. Get floating-point status.454 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
USE, INTRINSIC :: IEEE_ARITHMETIC
TYPE (IEEE_ROUND_TYPE) ROUND_VALUE
...
CALL IEEE_GET_ROUNDING_MODE (ROUND_VALUE) ! Store the rounding mode
CALL IEEE_SET_ROUNDING_MODE (IEEE_NEAREST)
... ! calculation with round to nearest
CALL IEEE_SET_ROUNDING_MODE (ROUND_VALUE) ! Restore the rounding mode
17.11.9 IEEE_GET_STATUS (STATUS_VALUE)
2 Class. Subroutine.
3 Argument. STATUS_VALUE shall be a scalar of type IEEE_STATUS_TYPE. It is an INTENT (OUT)
argument. It is assigned the value of the floating-point status.4 Example. To store all the exception flags, do a calculation involving exception handling, and restore them later:
USE, INTRINSIC :: IEEE_ARITHMETIC17.11.10 IEEE_GET_UNDERFLOW_MODE (GRADUAL)TYPE (IEEE_STATUS_TYPE) STATUS_VALUE
...
CALL IEEE_GET_STATUS (STATUS_VALUE) ! Get the flags
CALL IEEE_SET_FLAG (IEEE_ALL, .FALSE.) ! Set the flags quiet.
... ! calculation involving exception handling
CALL IEEE_SET_STATUS (STATUS_VALUE) ! Restore the flags
1 Description. Get underflow mode.
2 Class. Subroutine.
3 Argument. GRADUAL shall be a logical scalar. It is an INTENT (OUT) argument. It is assigned the value
true if the underflow mode is gradual underflow, and false if the underflow mode is abrupt underflow.4 Restriction. IEEE_GET_UNDERFLOW_MODE shall not be invoked unless IEEE_SUPPORT_UNDER-
FLOW_CONTROL (X) is true for some X.5 Example. After CALL IEEE_SET_UNDERFLOW_MODE (.FALSE.), a subsequent CALL IEEE_GET_-
UNDERFLOW_MODE (GRADUAL) will set GRADUAL to false.1 Description. Conversion to integer type.17.11.11 IEEE_INT (A, ROUND [, KIND])
2 Class. Elemental function.
3 Arguments.
A shall be of type real.4 Restriction. IEEE_INT (A, ROUND, KIND) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasROUND shall be of type IEEE_ROUND_TYPE.
KIND (optional) shall be a scalar integer constant expression.
the value false.5 Result Characteristics. Integer. If KIND is present, the kind type parameter is that specified by the value of⃝c ISO/IEC 2017 – All rights reserved 455
ISO/IEC DIS 1539-1:2017 (E)
KIND; otherwise, the kind type parameter is that of default integer.6 Result Value. The result has the value specified by ISO/IEC/IEEE 60559:2011 for the convertToInteger{round}
or the convertToIntegerExact{round} operation; the processor shall consistently choose which operation it7 Example. The value of IEEE_INT (12.5, IEEE_UP) is 13; IEEE_INEXACT will be signaled if the processorprovides. That is, the value of A is converted to an integer according to the rounding mode specified by ROUND;
if this value is representable in the representation method of the result, the result has this value, otherwise IEEE_-
INVALID is signaled and the result is processor dependent. If the processor provides the convertToIntegerExact
operation, IEEE_INVALID did not signal, and the value of the result differs from that of A, IEEE_INEXACT
will be signaled.
provides the convertToIntegerExact operation.1 Description. Whether a value is finite.17.11.12 IEEE_IS_FINITE (X)
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Restriction. IEEE_IS_FINITE (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value
false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value true if the value of X is finite, that is, IEEE_CLASS (X) has one
of the values IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_SUBNORMAL, IEEE_NEGATIVE_ZERO,7 Example. IEEE_IS_FINITE (1.0) has the value true.IEEE_POSITIVE_ZERO, IEEE_POSITIVE_SUBNORMAL, or IEEE_POSITIVE_NORMAL; otherwise, the
result has the value false.
17.11.13 IEEE_IS_NAN (X)1 Description. Whether a value is an IEEE NaN.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Restriction. IEEE_IS_NAN (X) shall not be invoked if IEEE_SUPPORT_NAN (X) has the value false.
5 Result Characteristics. Default logical.
6 Result Value. The result has the value true if the value of X is an IEEE NaN; otherwise, it has the value false.
7 Example. IEEE_IS_NAN (SQRT (−1.0)) has the value true if IEEE_SUPPORT_SQRT (1.0) has the value
true.1 Description. Whether a value is negative.17.11.14 IEEE_IS_NEGATIVE (X)
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Restriction. IEEE_IS_NEGATIVE (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the
value false.5 Result Characteristics. Default logical.456 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
6 Result Value. The result has the value true if IEEE_CLASS (X) has one of the values IEEE_NEGATIVE_-
NORMAL, IEEE_NEGATIVE_SUBNORMAL, IEEE_NEGATIVE_ZERO or IEEE_NEGATIVE_INF; oth-7 Example. IEEE_IS_NEGATIVE (0.0) has the value false.erwise, the result has the value false.
17.11.15 IEEE_IS_NORMAL (X)1 Description. Whether a value is a normal number.
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Restriction. IEEE_IS_NORMAL (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the
value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value true if IEEE_CLASS (X) has one of the values IEEE_NEGATIVE_-
NORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_ZERO or IEEE_POSITIVE_NORMAL; otherwise,7 Example. IEEE_IS_NORMAL (SQRT (−1.0) has the value false if IEEE_SUPPORT_SQRT (1.0) has thethe result has the value false.
value true.1 Description. Exponent.17.11.16 IEEE_LOGB (X)
2 Class. Elemental function.
3 Argument. X shall be of type real.
4 Restriction. IEEE_LOGB (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.
5 Result Characteristics. Same as X.
6 Result Value.
Case (i): If the value of X is neither zero, infinity, nor NaN, the result has the value of the unbiased exponent7 Example. IEEE_LOGB (−1.1) has the value 0.0.of X. Note: this value is equal to EXPONENT (X)− 1.
Case (ii): If X==0, the result is −infinity if IEEE_SUPPORT_INF (X) is true and −HUGE (X) otherwise;
IEEE_DIVIDE_BY_ZERO signals.
Case (iii): If IEEE_SUPPORT_INF (X) is true and X is infinite, the result is +infinity.
Case (iv): If IEEE_SUPPORT_NAN (X) is true and X is a NaN, the result is a NaN.
17.11.17 IEEE_MAX_NUM (X, Y)1 Description. Maximum numeric value.
2 Class. Elemental function.
3 Arguments.
X shall be of type real.4 Restriction. IEEE_MAX_NUM shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the valueY shall be of the same type and kind type parameter as X.
⃝c ISO/IEC 2017 – All rights reserved 457
ISO/IEC DIS 1539-1:2017 (E)
false.5 Result Characteristics. Same as X.
6 Result Value. The result has the value specified for the maxNum operation in ISO/IEC/IEEE 60559:2011; that is,7 Except when X or Y is a signaling NaN, no exception is signaled.• if X < Y the result has the value of Y;
• if Y < X the result has the value of X;
• if exactly one of X and Y is a quiet NaN the result has the value of the other argument;
• if one or both of X and Y are signaling NaNs, IEEE_INVALID signals and the result is a NaN;
• otherwise, the result is either X or Y (processor dependent).
8 Example. The value of IEEE_MAX_NUM (1.5, IEEE_VALUE (IEEE_QUIET_NAN)) is 1.5. 17.11.18 IEEE_MAX_NUM_MAG (X, Y)1 Description. Maximum magnitude numeric value.
2 Class. Elemental function. 3 Arguments. X shall be of type real.4 Restriction. IEEE_MAX_NUM_MAG shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has theY shall be of the same type and kind type parameter as X.
value false.5 Result Characteristics. Same as X.
6 Result Value. The result has the value specified for the maxNumMag operation in ISO/IEC/IEEE 60559:2011; that is,7 Except when X or Y is a signaling NaN, no exception is signaled.• if ABS (X) < ABS (Y) the result has the value of Y;
• if ABS (Y) < ABS (X) the result has the value of X;
• otherwise, the result has the value of IEEE_MAX_NUM (X, Y).
8 Example. The value of IEEE_MAX_NUM_MAG (1.5, −2.5) is −2.5. 17.11.19 IEEE_MIN_NUM (X, Y)1 Description. Minimum numeric value.
2 Class. Elemental function. 3 Arguments. X shall be of type real.4 Restriction. IEEE_MIN_NUM shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.Y shall be of the same type and kind type parameter as X.
5 Result Characteristics. Same as X. 458 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
6 Result Value. The result has the value specified for the minNum operation in ISO/IEC/IEEE 60559:2011; that is,7 Except when X or Y is a signaling NaN, no exception is signaled.• if X < Y the result has the value of X;
• if Y < X the result has the value of Y;
• if exactly one of X and Y is a quiet NaN the result has the value of the other argument;
• if one or both of X and Y are signaling NaNs, IEEE_INVALID signals and the result is a NaN;
• otherwise, the result is either X or Y (processor dependent).
8 Example. The value of IEEE_MIN_NUM (1.5, IEEE_VALUE (IEEE_QUIET_NAN)) is 1.5. 17.11.20 IEEE_MIN_NUM_MAG (X, Y)1 Description. Minimum magnitude numeric value.
2 Class. Elemental function. 3 Arguments. X shall be of type real.4 Restriction. IEEE_MIN_NUM_MAG shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has theY shall be of the same type and kind type parameter as X.
value false.5 Result Characteristics. Same as X.
6 Result Value. The result has the value specified for the minNumMag operation in ISO/IEC/IEEE 60559:2011; that is,7 Except when X or Y is a signaling NaN, no exception is signaled.• if ABS (X) < ABS (Y) the result has the value of X;
• if ABS (Y) < ABS (X) the result has the value of Y;
• otherwise, the result has the value of IEEE_MIN_NUM (X, Y).
8 Example. The value of IEEE_MIN_NUM_MAG (1.5, −2.5) is 1.5. 17.11.21 IEEE_NEXT_AFTER (X, Y)1 Description. Adjacent machine number.
2 Class. Elemental function. 3 Arguments. The arguments shall be of type real. 4 Restriction. IEEE_NEXT_AFTER (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or IEEE_SUPPORT_DATATYPE (Y) has the value false.5 Result Characteristics. Same as X.
6 Result Value. Case (i): If X == Y, the result is X and no exception is signaled.7 Example. The value of IEEE_NEXT_AFTER (1.0, 2.0) is 1.0 + EPSILON (X).Case (ii): If X ̸= Y, the result has the value of the next representable neighbor of X in the direction of Y.
The neighbors of zero (of either sign) are both nonzero. IEEE_OVERFLOW is signaled when
X is finite but IEEE_NEXT_AFTER (X, Y) is infinite; IEEE_UNDERFLOW is signaled when
IEEE_NEXT_AFTER (X, Y) is subnormal; in both cases, IEEE_INEXACT signals.
⃝c ISO/IEC 2017 – All rights reserved 459
ISO/IEC DIS 1539-1:2017 (E)
17.11.22 IEEE_NEXT_DOWN (X)1 Description. Adjacent lower machine number.
2 Class. Elemental function. 3 Argument. X shall be of type real. 4 Restriction. IEEE_NEXT_DOWN (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false. IEEE_NEXT_DOWN (−HUGE (X)) shall not be invoked if IEEE_SUPPORT_INF (X) has the5 Result Characteristics. Same as X.value false.
6 Result Value. The result has the value specified for the nextDown operation in ISO/IEC/IEEE 60559:2011; that is, it is the greatest value in the representation method of X that compares less than X, except when X is7 Example. If IEEE_SUPPORT_SUBNORMAL (0.0) is true, the value of IEEE_NEXT_DOWN (+0.0) is theequal to −∞ the result has the value −∞, and when X is a NaN the result is a NaN. If X is a signaling NaN,
IEEE_INVALID signals; otherwise, no exception is signaled.
negative subnormal number with least magnitude.1 Description. Adjacent higher machine number.17.11.23 IEEE_NEXT_UP (X)
2 Class. Elemental function. 3 Argument. X shall be of type real. 4 Restriction. IEEE_NEXT_UP (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false. IEEE_NEXT_UP (HUGE (X)) shall not be invoked if IEEE_SUPPORT_INF (X) has the value false.5 Result Characteristics. Same as X.
6 Result Value. The result has the value specified for the nextUp operation in ISO/IEC/IEEE 60559:2011; that is, it is the least value in the representation method of X that compares greater than X, except when X is7 Example. If IEEE_SUPPORT_INF (X) is true, the value of IEEE_NEXT_UP (HUGE (X)) is +∞.equal to +∞ the result has the value +∞, and when X is a NaN the result is a NaN. If X is a signaling NaN,
IEEE_INVALID_signals; otherwise, no exception is signaled.
17.11.24 IEEE_QUIET_EQ (A, B)1 Description. Quiet compares equal.
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_QUIET_EQ (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has theB shall have the same type and kind type parameter as A.
value false.5 Result Characteristics. Default logical.
460 ⃝6 Result Value. The result has the value specified for the compareQuietEqual operation in ISO/IEC/IEEEc ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
60559:2011; that is, it is true if and only if A compares equal to B. If A or B is a NaN, the result will be false. If7 Example. IEEE_QUIET_EQ (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and no exceptionA or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.
is signaled.1 Description. Quiet compares greater than or equal.17.11.25 IEEE_QUIET_GE (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_QUIET_GE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has theB shall have the same type and kind type parameter as A.
value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareQuietGreaterEqual operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares greater than or equal to B. If A or B is a NaN, the result7 Example. IEEE_QUIET_GE (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and no exceptionwill be false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.
is signaled.1 Description. Quiet compares greater than.17.11.26 IEEE_QUIET_GT (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_QUIET_GT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has theB shall have the same type and kind type parameter as A.
value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareQuietGreater operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares greater than B. If A or B is a NaN, the result will be7 Example. IEEE_QUIET_GT (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and no exceptionfalse. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.
is signaled.1 Description. Quiet compares less than or equal.17.11.27 IEEE_QUIET_LE (A, B)
2 Class. Elemental function. ⃝c ISO/IEC 2017 – All rights reserved 4613 Arguments.
ISO/IEC DIS 1539-1:2017 (E)
A shall be of type real.4 Restriction. IEEE_QUIET_LE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has theB shall have the same type and kind type parameter as A.
value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareQuietLessEqual operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares less than or equal to B. If A or B is a NaN, the result will7 Example. IEEE_QUIET_LE (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and no exceptionbe false. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.
is signaled.1 Description. Quiet compares less than.17.11.28 IEEE_QUIET_LT (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_QUIET_LT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has theB shall have the same type and kind type parameter as A.
value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareQuietLess operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares less than B. If A or B is a NaN, the result will be7 Example. IEEE_QUIET_LT (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and no exceptionfalse. If A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.
is signaled.1 Description. Quiet compares not equal.17.11.29 IEEE_QUIET_NE (A, B)
2 Class. Elemental function.
3 Arguments.
A shall be of type real.4 Restriction. IEEE_QUIET_NE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) has theB shall have the same type and kind type parameter as A.
value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareQuietNotEqual operation in ISO/IEC/IEEE
60559:2011; that is, it is true if and only if A compares not equal to B. If A or B is a NaN, the result will be true.7 Example. IEEE_QUIET_NE (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value true and no exceptionIf A or B is a signaling NaN, IEEE_INVALID signals; otherwise, no exception is signaled.
is signaled.1 Description. Conversion to real type.462 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
17.11.30 IEEE_REAL (A [, KIND])
2 Class. Elemental function.
3 Arguments.
A shall be of type integer or real.4 Restriction. IEEE_REAL shall not be invoked if A is of type real and IEEE_SUPPORT_DATATYPE (A)KIND (optional) shall be a scalar integer constant expression.
has the value false, or if IEEE_SUPPORT_DATATYPE (IEEE_REAL (A, KIND)) has the value false.5 Result Characteristics. Real. If KIND is present, the kind type parameter is that specified by the value of
KIND; otherwise, the kind type parameter is that of default real.6 Result Value. The result has the same value as A if that value is representable in the representation method
of the result, and is rounded according to the rounding mode otherwise. This shall be consistent with the7 Example. The value of IEEE_REAL (123) is 123.0.specification of ISO/IEC/IEEE 60559:2011 for the convertFromInt operation when A is of type integer, and with
the convertFormat operation otherwise.
17.11.31 IEEE_REM (X, Y)1 Description. Exact remainder.
2 Class. Elemental function.
3 Arguments. The arguments shall be of type real and have the same radix.
4 Restriction. IEEE_REM (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or IEEE_SUP-
PORT_DATATYPE (Y) has the value false.5 Result Characteristics. Real with the kind type parameter of whichever argument has the greater precision.
6 Result Value. This function computes the remainder operation specified in ISO/IEC/IEEE 60559:2011.
7 The result value when X and Y are finite, and Y is nonzero, regardless of the rounding mode, shall be exactly X
− Y*N, where N is the integer nearest to the exact value X/Y; whenever |N − X/Y| = 12 , N shall be even. If the8 When X is finite and Y is infinite, the result value is X. If Y is zero or X is infinite, and neither is a NaN, theresult value is zero, the sign shall be that of X.
IEEE_INVALID exception shall occur; if IEEE_SUPPORT_NAN(X+Y) is true, the result is a NaN. If X is9 Examples. The value of IEEE_REM (4.0, 3.0) is 1.0, the value of IEEE_REM (3.0, 2.0) is −1.0, and the valuesubnormal and Y is infinite, the IEEE_UNDERFLOW exception shall occur. No exception shall signal if X is
finite and normal, and Y is infinite.
of IEEE_REM (5.0, 2.0) is 1.0.1 Description. Round to integer.17.11.32 IEEE_RINT (X [, ROUND])
2 Class. Elemental function.
3 Arguments.
X shall be of type real.4 Restriction. IEEE_RINT (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.ROUND (optional) shall be of type IEEE_ROUND_TYPE.
⃝c ISO/IEC 2017 – All rights reserved 463
ISO/IEC DIS 1539-1:2017 (E)
5 Result Characteristics. Same as X.
6 Result Value. If ROUND is present, the value of the result is the value of X rounded to an integer according
to the mode specified by ROUND; this is the ISO/IEC/IEEE 60559:2011 operation roundToInteger{rounding}.7 Examples. If the rounding mode is round to nearest, the value of IEEE_RINT (1.1) is 1.0. The value ofOtherwise, the value of the result is that specified for the operation roundIntegralToExact in ISO/IEC/IEEE
60559:2011; this is the value of X rounded to an integer according to the rounding mode. If the result has the
value zero, the sign is that of X.
IEEE_RINT (1.1, IEEE_UP) is 2.0.1 Description. X × 2I .17.11.33 IEEE_SCALB (X, I)
2 Class. Elemental function.
3 Arguments.
X shall be of type real.4 Restriction. IEEE_SCALB (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value false.I shall be of type integer.
5 Result Characteristics. Same as X.
6 Result Value.
Case (i): If X × 2I is representable as a normal number, the result has this value.7 Example. The value of IEEE_SCALB (1.0, 2) is 4.0.Case (ii): If X is finite and X × 2I is too large, the IEEE_OVERFLOW exception shall occur. If IEEE_-
SUPPORT_INF (X) is true, the result value is infinity with the sign of X; otherwise, the result
value is SIGN (HUGE (X), X).
Case (iii): If X × 2I is too small and there is loss of accuracy, the IEEE_UNDERFLOW exception shall occur.
The result is the representable number having a magnitude nearest to |2I | and the same sign as X.
Case (iv): If X is infinite, the result is the same as X; no exception signals.
17.11.34 IEEE_SELECTED_REAL_KIND ([P, R, RADIX])1 Description. IEEE kind type parameter value.
2 Class. Transformational function.
3 Arguments. At least one argument shall be present.
P (optional) shall be an integer scalar.4 Result Characteristics. Default integer scalar.R (optional) shall be an integer scalar.
RADIX (optional) shall be an integer scalar.
5 Result Value. If P or R is absent, the result value is the same as if it were present with the value zero. If
RADIX is absent, there is no requirement on the radix of the selected kind. The result has a value equal to a6 Otherwise, the result is −1 if the processor supports an IEEE real type with radix RADIX and exponent rangevalue of the kind type parameter of an ISO/IEC/IEEE 60559:2011 floating-point format with decimal precision,
as returned by the intrinsic function PRECISION, of at least P digits, a decimal exponent range, as returned
by the intrinsic function RANGE, of at least R, and a radix, as returned by the intrinsic function RADIX, of
RADIX, if such a kind type parameter is available on the processor.
464 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
of at least R but not with precision of at least P, −2 if the processor supports an IEEE real type with radix7 If more than one kind type parameter value meets the criteria, the value returned is the one with the smallestRADIX and precision of at least P but not with exponent range of at least R, −3 if the processor supports an
IEEE real type with radix RADIX but with neither precision of at least P nor exponent range of at least R, −4 if
the processor supports an IEEE real type with radix RADIX and either precision of at least P or exponent range
of at least R but not both together, and −5 if the processor supports no IEEE real type with radix RADIX.
decimal precision, unless there are several such values, in which case the smallest of these kind values is returned.8 Example. IEEE_SELECTED_REAL_KIND (6, 30) has the value KIND (0.0) on a machine that supports
ISO/IEC/IEEE 60559:2011 single precision arithmetic for its default real approximation method.1 Description. Set an exception flag.17.11.35 IEEE_SET_FLAG (FLAG, FLAG_VALUE)
2 Class. Pure subroutine.
3 Arguments.
FLAG shall be a scalar or array of type IEEE_FLAG_TYPE. If a value of FLAG is IEEE_INVALID,4 Example. CALL IEEE_SET_FLAG (IEEE_OVERFLOW, .TRUE.) sets the IEEE_OVERFLOW flag to beIEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT,
the corresponding exception flag is assigned a value. No two elements of FLAG shall have the same
value.
FLAG_VALUE shall be a logical scalar or array. It shall be conformable with FLAG. If an element has the value
true, the corresponding flag is set to be signaling; otherwise, the flag is set to be quiet.
signaling.1 Description. Set a halting mode.17.11.36 IEEE_SET_HALTING_MODE (FLAG, HALTING)
2 Class. Pure subroutine.
3 Arguments.
FLAG shall be a scalar or array of type IEEE_FLAG_TYPE. It shall have only the values IEEE_-4 Restriction. IEEE_SET_HALTING_MODE (FLAG, HALTING) shall not be invoked if IEEE_SUPPORT_-INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_-
INEXACT. No two elements of FLAG shall have the same value.
HALTING shall be a logical scalar or array. It shall be conformable with FLAG. If an element has the value
true, the corresponding exception specified by FLAG will cause halting. Otherwise, execution will
continue after this exception.
HALTING (FLAG) has the value false.5 Example. CALL IEEE_SET_HALTING_MODE (IEEE_DIVIDE_BY_ZERO, .TRUE.) causes halting after
a divide_by_zero exception.1 Description. Set floating-point modes.17.11.37 IEEE_SET_MODES (MODES)
2 Class. Subroutine.
3 Argument. MODES shall be a scalar of type IEEE_MODES_TYPE. Its value shall be one that was assigned
⃝c ISO/IEC 2017 – All rights reserved 4654 Example.
ISO/IEC DIS 1539-1:2017 (E)
by a previous invocation of IEEE_GET_MODES to its MODES argument. The floating-point modes (17.7) are
restored to the state at that invocation.
To save the floating-point modes, do a calculation with specific rounding and underflow modes, and restore them1 Description. Set rounding mode.later:
USE, INTRINSIC :: IEEE_ARITHMETIC
TYPE (IEEE_MODES_TYPE) SAVE_MODES
...
CALL IEEE_GET_MODES (SAVE_MODES) ! Save all modes.
CALL IEEE_SET_ROUNDING_MODE (IEEE_TO_ZERO))
CALL IEEE_SET_UNDERFLOW_MODE (GRADUAL=.FALSE.)
... ! calculation with abrupt round-to-zero.
CALL IEEE_SET_MODES (SAVE_MODES) ! Restore all modes.
17.11.38 IEEE_SET_ROUNDING_MODE (ROUND_VALUE [, RADIX])
2 Class. Subroutine.
3 Arguments.
ROUND_VALUE shall be a scalar of type IEEE_ROUND_TYPE. It specifies the rounding mode to be set.4 Restriction. IEEE_SET_ROUNDING_MODE (ROUND_VALUE) shall not be invoked unless IEEE_SUP-RADIX (optional) shall be an integer scalar with the value two or ten. If RADIX is present with the value ten,
the rounding mode set is the decimal rounding mode; otherwise it is the binary rounding mode.
PORT_ROUNDING (ROUND_VALUE, X) is true for some X such that IEEE_SUPPORT_DATATYPE (X)5 Example. To save the binary rounding mode, do a calculation with round to nearest, and restore the roundingis true. IEEE_SET_ROUNDING_MODE (ROUND_VALUE, RADIX) shall not be invoked unless IEEE_-
SUPPORT_ROUNDING (ROUND_VALUE, X) is true for some X with radix RADIX such that IEEE_SUP-
PORT_DATATYPE (X) is true.
mode later:1 Description. Restore floating-point status.USE, INTRINSIC :: IEEE_ARITHMETIC
TYPE (IEEE_ROUND_TYPE) ROUND_VALUE
...
CALL IEEE_GET_ROUNDING_MODE (ROUND_VALUE) ! Store the rounding mode
CALL IEEE_SET_ROUNDING_MODE (IEEE_NEAREST)
... ! calculation with round to nearest
CALL IEEE_SET_ROUNDING_MODE (ROUND_VALUE) ! Restore the rounding mode
17.11.39 IEEE_SET_STATUS (STATUS_VALUE)
2 Class. Subroutine.
3 Argument. STATUS_VALUE shall be a scalar of type IEEE_STATUS_TYPE. Its value shall be one that was
assigned by a previous invocation of IEEE_GET_STATUS to its STATUS_VALUE argument. The floating-4 Example. To store all the exceptions flags, do a calculation involving exception handling, and restore thempoint status (17.7 is restored to the state at that invocation).
466 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
later:1 Description. Set underflow mode.USE, INTRINSIC :: IEEE_EXCEPTIONS
TYPE (IEEE_STATUS_TYPE) STATUS_VALUE
...
CALL IEEE_GET_STATUS (STATUS_VALUE) ! Store the flags
CALL IEEE_SET_FLAG (IEEE_ALL, .FALSE.) ! Set them quiet
... ! calculation involving exception handling
CALL IEEE_SET_STATUS (STATUS_VALUE) ! Restore the flags
17.11.40 IEEE_SET_UNDERFLOW_MODE (GRADUAL)
2 Class. Subroutine.
3 Argument. GRADUAL shall be a logical scalar. If it is true, the underflow mode is set to gradual underflow.
If it is false, the underflow mode is set to abrupt underflow.4 Restriction. IEEE_SET_UNDERFLOW_MODE shall not be invoked unless IEEE_SUPPORT_UNDER-
FLOW_CONTROL (X) is true for some X.5 Example. To perform some calculations with abrupt underflow and then restore the previous mode:
USE, INTRINSIC :: IEEE_ARITHMETIC
LOGICAL SAVE_UNDERFLOW_MODE
...
CALL IEEE_GET_UNDERFLOW_MODE (SAVE_UNDERFLOW_MODE)
CALL IEEE_SET_UNDERFLOW_MODE (GRADUAL=.FALSE.)
... ! Perform some calculations with abrupt underflow
CALL IEEE_SET_UNDERFLOW_MODE (SAVE_UNDERFLOW_MODE)
17.11.41 IEEE_SIGNALING_EQ (A, B)
1 Description. Signaling compares equal.
2 Class. Elemental function.
3 Arguments.
A shall be of type real.4 Restriction. IEEE_SIGNALING_EQ (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasB shall be of the same type and kind type parameter as A.
the value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareSignalingEqual operation in ISO/IEC/IEEE
60559:2011; that is, it is true if and only if A compares equal to B. If A or B is a NaN, the result will be false7 Example. IEEE_SIGNALING_EQ (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and signalsand IEEE_INVALID signals; otherwise, no exception is signaled.
IEEE_INVALID.1 Description. Signaling compares greater than or equal.⃝c ISO/IEC 2017 – All rights reserved 467
ISO/IEC DIS 1539-1:2017 (E)
17.11.42 IEEE_SIGNALING_GE (A, B)
2 Class. Elemental function.
3 Arguments.
A shall be of type real.4 Restriction. IEEE_SIGNALING_GE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasB shall be of the same type and kind type parameter as A.
the value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareSignalingGreaterEqual operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares greater than or equal to B. If A or7 Example. IEEE_SIGNALING_GE (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and signalsB is a NaN, the result will be false and IEEE_INVALID signals; otherwise, no exception is signaled.
IEEE_INVALID.1 Description. Signaling compares greater than.17.11.43 IEEE_SIGNALING_GT (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_SIGNALING_GT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasB shall be of the same type and kind type parameter as A.
the value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareSignalingGreater operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares greater than B. If A or B is a NaN, the result will be false7 Example. IEEE_SIGNALING_GT (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and signalsand IEEE_INVALID signals; otherwise, no exception is signaled.
IEEE_INVALID.1 Description. Signaling compares less than or equal.17.11.44 IEEE_SIGNALING_LE (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_SIGNALING_LE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasB shall be of the same type and kind type parameter as A.
the value false.5 Result Characteristics. Default logical.
468 ⃝6 Result Value. The result has the value specified for the compareSignalingLessEqual operation in ISO/IEC/IEEEc ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
60559:2011; that is, it is true if and only if A compares less than or equal to B. If A or B is a NaN, the result will7 Example. IEEE_SIGNALING_LE (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and signalsbe false and IEEE_INVALID signals; otherwise, no exception is signaled.
IEEE_INVALID.1 Description. Signaling compares less than.17.11.45 IEEE_SIGNALING_LT (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_SIGNALING_LT (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasB shall be of the same type and kind type parameter as A.
the value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareSignalingLess operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares less than B. If A or B is a NaN, the result will be false7 Example. IEEE_SIGNALING_LT (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value false and signalsand IEEE_INVALID signals; otherwise, no exception is signaled.
IEEE_INVALID.1 Description. Signaling compares not equal.17.11.46 IEEE_SIGNALING_NE (A, B)
2 Class. Elemental function. 3 Arguments. A shall be of type real.4 Restriction. IEEE_SIGNALING_NE (A, B) shall not be invoked if IEEE_SUPPORT_DATATYPE (A) hasB shall be of the same type and kind type parameter as A.
the value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the compareSignalingNotEqual operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if A compares not equal to B. If A or B is a NaN, the result will be true7 Example. IEEE_SIGNALING_NE (1.0, IEEE_VALUE (IEEE_QUIET_NAN)) has the value true and signalsand IEEE_INVALID signals; otherwise, no exception is signaled.
IEEE_INVALID.1 Description. Test sign bit.17.11.47 IEEE_SIGNBIT (X)
2 Class. Elemental function. 3 Argument. X shall be of type real. ⃝c ISO/IEC 2017 – All rights reserved 4694 Restriction. IEEE_SIGNBIT (X) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has the value
ISO/IEC DIS 1539-1:2017 (E)
false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value specified for the isSignMinus operation in ISO/IEC/IEEE 60559:2011; that is, it is true if and only if the sign bit of X is nonzero. No exception is signaled even if X is a signaling NaN.7 Example. IEEE_SIGNBIT (−1.0) has the value true.
17.11.48 IEEE_SUPPORT_DATATYPE () or1 Description. Query IEEE arithmetic support.IEEE_SUPPORT_DATATYPE (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. The result has the value true if the processor supports IEEE arithmetic for all reals (X does not appear) or for real variables of the same kind type parameter as X; otherwise, it has the value false. Here,6 Example. If default real kind conforms to ISO/IEC/IEEE 60559:2011 except that underflow values flush to zerosupport is as defined in the first paragraph of 17.9.
instead of being subnormal, IEEE_SUPPORT_DATATYPE (1.0) has the value true.1 Description. Query subnormal number support.17.11.49 IEEE_SUPPORT_DENORMAL () or
IEEE_SUPPORT_DENORMAL (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_DENORMAL (X) has the value true if IEEE_SUPPORT_DATATYPE (X) has6 Example. IEEE_SUPPORT_DENORMAL (X) has the value true if the processor supports subnormal valuesthe value true and the processor supports arithmetic operations and assignments with subnormal
numbers (biased exponent e = 0 and fraction f ̸= 0, see subclause 3.2 of ISO/IEC/IEEE 60559:2011)
for real variables of the same kind type parameter as X; otherwise, it has the value false.
Case (ii): IEEE_SUPPORT_DENORMAL () has the value true if IEEE_SUPPORT_DENORMAL (X) has
the value true for all real X; otherwise, it has the value false.
for X.1 Description. Query IEEE division support.NOTE 17.12
A reference to IEEE_SUPPORT_DENORMAL will have the same result value as a reference to IEEE_-
SUPPORT_SUBNORMAL with the same argument list.
470 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
17.11.50 IEEE_SUPPORT_DIVIDE () or IEEE_SUPPORT_DIVIDE (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_DIVIDE (X) has the value true if the processor supports division with the6 Example. IEEE_SUPPORT_DIVIDE (X) has the value true if division of operands with the same kind as Xaccuracy specified by ISO/IEC/IEEE 60559:2011 for real variables of the same kind type parameter
as X; otherwise, it has the value false.
Case (ii): IEEE_SUPPORT_DIVIDE () has the value true if IEEE_SUPPORT_DIVIDE (X) has the value
true for all real X; otherwise, it has the value false.
conforms to ISO/IEC/IEEE 60559:2011.1 Description. Query exception support.17.11.51 IEEE_SUPPORT_FLAG (FLAG) or IEEE_SUPPORT_FLAG (FLAG,
X)
2 Class. Transformational function. 3 Arguments. FLAG shall be a scalar of type IEEE_FLAG_TYPE. Its value shall be one of IEEE_INVALID, IEEE_-4 Result Characteristics. Default logical scalar.OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT.
X shall be of type real. It may be a scalar or an array.
5 Result Value. Case (i): IEEE_SUPPORT_FLAG (FLAG, X) has the value true if the processor supports detection of the6 Example. IEEE_SUPPORT_FLAG (IEEE_INEXACT) has the value true if the processor supports the inexactspecified exception for real variables of the same kind type parameter as X; otherwise, it has the
value false.
Case (ii): IEEE_SUPPORT_FLAG (FLAG) has the value true if IEEE_SUPPORT_FLAG (FLAG, X) has
the value true for all real X; otherwise, it has the value false.
exception.1 Description. Query halting mode support.17.11.52 IEEE_SUPPORT_HALTING (FLAG)
2 Class. Transformational function. 3 Argument. FLAG shall be a scalar of type IEEE_FLAG_TYPE. Its value shall be one of IEEE_INVALID, IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO, IEEE_UNDERFLOW, or IEEE_INEXACT.4 Result Characteristics. Default logical scalar.
5 Result Value. The result has the value true if the processor supports the ability to control during program execution whether to abort or continue execution after the exception specified by FLAG; otherwise, it has the6 Example. IEEE_SUPPORT_HALTING (IEEE_OVERFLOW) has the value true if the processor supportsvalue false. Support includes the ability to change the mode by CALL IEEE_SET_HALTING_MODE (FLAG).
⃝c ISO/IEC 2017 – All rights reserved 471
ISO/IEC DIS 1539-1:2017 (E)
control of halting after an overflow.1 Description. Query IEEE infinity support.17.11.53 IEEE_SUPPORT_INF () or IEEE_SUPPORT_INF (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_INF (X) has the value true if the processor supports IEEE infinities (positive6 Example. IEEE_SUPPORT_INF (X) has the value true if the processor supports IEEE infinities for X.and negative) for real variables of the same kind type parameter as X; otherwise, it has the value
false.
Case (ii): IEEE_SUPPORT_INF () has the value true if IEEE_SUPPORT_INF (X) has the value true for
all real X; otherwise, it has the value false.
17.11.54 IEEE_SUPPORT_IO () or IEEE_SUPPORT_IO (X)1 Description. Query IEEE formatting support.
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_IO (X) has the value true if base conversion during formatted input/output6 Example. IEEE_SUPPORT_IO (X) has the value true if formatted input/output base conversions conform to(12.5.6.16, 12.6.2.13, 13.7.2.3.8) conforms to ISO/IEC/IEEE 60559:2011 for the modes UP, DOWN,
ZERO, and NEAREST for real variables of the same kind type parameter as X; otherwise, it has
the value false.
Case (ii): IEEE_SUPPORT_IO () has the value true if IEEE_SUPPORT_IO (X) has the value true for all
real X; otherwise, it has the value false.
ISO/IEC/IEEE 60559:2011.1 Description. Query IEEE NaN support.17.11.55 IEEE_SUPPORT_NAN () or IEEE_SUPPORT_NAN (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_NAN (X) has the value true if the processor supports IEEE NaNs for real6 Example. IEEE_SUPPORT_NAN (X) has the value true if the processor supports IEEE NaNs for X.variables of the same kind type parameter as X; otherwise, it has the value false.
Case (ii): IEEE_SUPPORT_NAN () has the value true if IEEE_SUPPORT_NAN (X) has the value true
for all real X; otherwise, it has the value false.
472 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
17.11.56 IEEE_SUPPORT_ROUNDING (ROUND_VALUE) or1 Description. Query IEEE rounding support.IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X)
2 Class. Transformational function. 3 Arguments. ROUND_VALUE shall be of type IEEE_ROUND_TYPE.4 Result Characteristics. Default logical scalar.X shall be of type real. It may be a scalar or an array.
5 Result Value. Case (i): IEEE_SUPPORT_ROUNDING (ROUND_VALUE, X) has the value true if the processor supports6 Example. IEEE_SUPPORT_ROUNDING (IEEE_TO_ZERO) has the value true if the processor supportsthe rounding mode defined by ROUND_VALUE for real variables of the same kind type parameter
as X; otherwise, it has the value false. Support includes the ability to change the mode by CALL
IEEE_SET_ROUNDING_MODE (ROUND_VALUE).
Case (ii): IEEE_SUPPORT_ROUNDING (ROUND_VALUE) has the value true if IEEE_SUPPORT_-
ROUNDING (ROUND_VALUE, X) has the value true for all real X; otherwise, it has the value
false.
rounding to zero for all reals.1 Description. Query IEEE square root support.17.11.57 IEEE_SUPPORT_SQRT () or IEEE_SUPPORT_SQRT (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_SQRT (X) has the value true if the intrinsic function SQRT conforms to6 Example. If IEEE_SUPPORT_SQRT (1.0) has the value true, SQRT (−0.0) will have the value −0.0.ISO/IEC/IEEE 60559:2011 for real variables of the same kind type parameter as X; otherwise,
it has the value false.
Case (ii): IEEE_SUPPORT_SQRT () has the value true if IEEE_SUPPORT_SQRT (X) has the value true
for all real X; otherwise, it has the value false.
17.11.58 IEEE_SUPPORT_STANDARD () or1 Description. Query IEEE standard support.IEEE_SUPPORT_STANDARD (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. ⃝c ISO/IEC 2017 – All rights reserved 4735 Result Value.
ISO/IEC DIS 1539-1:2017 (E)
Case (i): IEEE_SUPPORT_STANDARD (X) has the value true if the results of all the func-6 Example. IEEE_SUPPORT_STANDARD () has the value false if some but not all kinds of reals conform totions IEEE_SUPPORT_DATATYPE (X), IEEE_SUPPORT_DIVIDE (X), IEEE_SUPPORT_-
FLAG (FLAG, X) for valid FLAG, IEEE_SUPPORT_HALTING (FLAG) for valid FLAG, IEEE_-
SUPPORT_INF (X), IEEE_SUPPORT_NAN (X), IEEE_SUPPORT_ROUNDING (ROUND_-
VALUE, X) for valid ROUND_VALUE, IEEE_SUPPORT_SQRT (X), and IEEE_SUPPORT_-
SUBNORMAL (X) are all true; otherwise, it has the value false.
Case (ii): IEEE_SUPPORT_STANDARD () has the value true if IEEE_SUPPORT_STANDARD (X) has
the value true for all real X; otherwise, it has the value false.
ISO/IEC/IEEE 60559:2011.1 Description. Query subnormal number support.17.11.59 IEEE_SUPPORT_SUBNORMAL () or
IEEE_SUPPORT_SUBNORMAL (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_SUBNORMAL (X) has the value true if IEEE_SUPPORT_DATATYPE (X)6 Example. IEEE_SUPPORT_SUBNORMAL (X) has the value true if the processor supports subnormal valueshas the value true and the processor supports arithmetic operations and assignments with subnormal
numbers (biased exponent e = 0 and fraction f ̸= 0, see subclause 3.2 of ISO/IEC/IEEE 60559:2011)
for real variables of the same kind type parameter as X; otherwise, it has the value false.
Case (ii): IEEE_SUPPORT_SUBNORMAL () has the value true if IEEE_SUPPORT_SUBNORMAL (X)
has the value true for all real X; otherwise, it has the value false.
for X.1 Description. Query underflow control support.NOTE 17.13
The subnormal numbers are not included in the 16.4 model for real numbers; they satisfy the inequality
ABS (X) < TINY (X). They usually occur as a result of an arithmetic operation whose exact result is
less than TINY (X). Such an operation causes IEEE_UNDERFLOW to signal unless the result is exact.
IEEE_SUPPORT_SUBNORMAL (X) is false if the processor never returns a subnormal number as the
result of an arithmetic operation.
17.11.60 IEEE_SUPPORT_UNDERFLOW_CONTROL () or
IEEE_SUPPORT_UNDERFLOW_CONTROL (X)
2 Class. Inquiry function. 3 Argument. X shall be of type real. It may be a scalar or an array. 4 Result Characteristics. Default logical scalar. 5 Result Value. Case (i): IEEE_SUPPORT_UNDERFLOW_CONTROL (X) has the value true if the processor supports6 Example. IEEE_SUPPORT_UNDERFLOW_CONTROL (2.5) has the value true if the processor supportscontrol of the underflow mode for floating-point calculations with the same type as X, and false
otherwise.
474 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Case (ii): IEEE_SUPPORT_UNDERFLOW_CONTROL () has the value true if the processor supports
control of the underflow mode for all floating-point calculations, and false otherwise.
underflow mode control for default real calculations.1 Description. Whether two values are unordered.17.11.61 IEEE_UNORDERED (X, Y)
2 Class. Elemental function. 3 Arguments. The arguments shall be of type real. 4 Restriction. IEEE_UNORDERED (X, Y) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) or IEEE_SUPPORT_DATATYPE (Y) has the value false.5 Result Characteristics. Default logical.
6 Result Value. The result has the value true if X or Y is a NaN or both are NaNs; otherwise, it has the value false. If X or Y is a signaling NaN, IEEE_INVALID may signal.7 Example. IEEE_UNORDERED (0.0, SQRT (−1.0)) has the value true if IEEE_SUPPORT_SQRT (1.0) has
the value true.1 Description. Return number in a class.17.11.62 IEEE_VALUE (X, CLASS)
2 Class. Elemental function. 3 Arguments. X shall be of type real.4 Restriction. IEEE_VALUE (X, CLASS) shall not be invoked if IEEE_SUPPORT_DATATYPE (X) has theCLASS shall be of type IEEE_CLASS_TYPE. The value is permitted to be: IEEE_SIGNALING_NAN or
IEEE_QUIET_NAN if IEEE_SUPPORT_NAN (X) has the value true, IEEE_NEGATIVE_INF
or IEEE_POSITIVE_INF if IEEE_SUPPORT_INF (X) has the value true, IEEE_NEGATIVE_-
SUBNORMAL or IEEE_POSITIVE_SUBNORMAL if IEEE_SUPPORT_SUBNORMAL (X) has
the value true, IEEE_NEGATIVE_NORMAL, IEEE_NEGATIVE_ZERO, IEEE_POSITIVE_-
ZERO or IEEE_POSITIVE_NORMAL.
value false.5 Result Characteristics. Same as X.
6 Result Value. The result value is an IEEE value as specified by CLASS. Although in most cases the value is processor dependent, the value shall not vary between invocations for any particular X kind type parameter and7 Example. IEEE_VALUE (1.0, IEEE_NEGATIVE_INF) has the value −infinity.CLASS value.
8 Whenever IEEE_VALUE returns a signaling NaN, it is processor dependent whether or not invalid is raised and processor dependent whether or not the signaling NaN is converted into a quiet NaN.ISO/IEC DIS 1539-1:2017 (E)NOTE 17.14
If the expr in an assignment statement is a reference to the IEEE_VALUE function that returns a signaling
NaN and the variable is of the same type and kind as the function result, it is recommended that the
signaling NaN be preserved.
⃝c ISO/IEC 2017 – All rights reserved 475
17.12 Examples NOTE 17.15
MODULE DOT
! Module for dot product of two real arrays of rank 1.
! The caller needs to ensure that exceptions do not cause halting.
USE, INTRINSIC :: IEEE_EXCEPTIONS
LOGICAL :: MATRIX_ERROR = .FALSE.
INTERFACE OPERATOR(.dot.)
MODULE PROCEDURE MULT
END INTERFACE
CONTAINS
REAL FUNCTION MULT (A, B)
REAL, INTENT (IN) :: A(:), B(:)
INTEGER I
LOGICAL OVERFLOW
IF (SIZE(A) /= SIZE(B)) THEN
MATRIX_ERROR = .TRUE.
RETURN
END IF
! The processor ensures that IEEE_OVERFLOW is quiet.
MULT = 0.0
DO I = 1, SIZE (A)
MULT = MULT + A(I)*B(I)
END DO
CALL IEEE_GET_FLAG (IEEE_OVERFLOW, OVERFLOW)
IF (OVERFLOW) MATRIX_ERROR = .TRUE.
END FUNCTION MULT
END MODULE DOT
This module provides a function that computes the dot product of two real arrays of rank 1. If the sizes
of the arrays are different, an immediate return occurs with MATRIX_ERROR true. If overflow occurs
during the actual calculation, the IEEE_OVERFLOW flag will signal and MATRIX_ERROR will be true.
NOTE 17.16
USE, INTRINSIC :: IEEE_EXCEPTIONSUSE, INTRINSIC :: IEEE_FEATURES, ONLY: IEEE_INVALID_FLAG
! The other exceptions of IEEE_USUAL (IEEE_OVERFLOW and
! IEEE_DIVIDE_BY_ZERO) are always available with IEEE_EXCEPTIONS
TYPE (IEEE_STATUS_TYPE) STATUS_VALUE
LOGICAL, DIMENSION(3) :: FLAG_VALUE
...
CALL IEEE_GET_STATUS (STATUS_VALUE)
CALL IEEE_SET_HALTING_MODE (IEEE_USUAL, .FALSE.) ! Needed in case the
! default on the processor is to halt on exceptions
CALL IEEE_SET_FLAG (IEEE_USUAL, .FALSE.)
476 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 17.16 (cont.)
! First try the "fast" algorithm for inverting a matrix:MATRIX1 = FAST_INV (MATRIX) ! This shall not alter MATRIX.
CALL IEEE_GET_FLAG (IEEE_USUAL, FLAG_VALUE)
IF (ANY(FLAG_VALUE)) THEN
! "Fast" algorithm failed; try "slow" one:
CALL IEEE_SET_FLAG (IEEE_USUAL, .FALSE.)
MATRIX1 = SLOW_INV (MATRIX)
CALL IEEE_GET_FLAG (IEEE_USUAL, FLAG_VALUE)
IF (ANY (FLAG_VALUE)) THEN
WRITE (*, *) ’Cannot invert matrix’
STOP
END IF
END IF
CALL IEEE_SET_STATUS (STATUS_VALUE)
In this example, the function FAST_INV might cause a condition to signal. If it does, another try is made
with SLOW_INV. If this still fails, a message is printed and the program stops. Note, also, that it is
important to set the flags quiet before the second try. The state of all the flags is stored and restored.
NOTE 17.17
USE, INTRINSIC :: IEEE_EXCEPTIONS
LOGICAL FLAG_VALUE
...
CALL IEEE_SET_HALTING_MODE (IEEE_OVERFLOW, .FALSE.)
! First try a fast algorithm for inverting a matrix.
CALL IEEE_SET_FLAG (IEEE_OVERFLOW, .FALSE.)
DO K = 1, N
...CALL IEEE_GET_FLAG (IEEE_OVERFLOW, FLAG_VALUE)
IF (FLAG_VALUE) EXIT
END DO
IF (FLAG_VALUE) THEN
! Alternative code which knows that K-1 steps have executed normally.
...
END IF
Here the code for matrix inversion is in line and the transfer is made more precise by adding extra tests of
the flag.
⃝
c ISO/IEC 2017 – All rights reserved 477
ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
1 Fortran provides a means of referencing procedures that are defined by means of the C programming language
478 c ISO/IEC 2017 – All rights reserved18 Interoperability with C
ISO/IEC DIS 1539-1:2017 (E)
18.1 General
or procedures that can be described by C prototypes as defined in 6.7.6.3 of ISO/IEC 9899:2011, even if they2 The ISO_C_BINDING module provides access to named constants that represent kind type parameters of dataare not actually defined by means of C. Conversely, there is a means of specifying that a procedure defined by a
Fortran subprogram can be referenced from a function defined by means of C. In addition, there is a means of
declaring global variables that are associated with C variables whose names have external linkage as defined in
6.2.2 of ISO/IEC 9899:2011.
representations compatible with C types. Fortran also provides facilities for defining derived types (7.5) and3 The source file ISO_Fortran_binding.h provides definitions and prototypes to enable a C function to interoperateenumerations (7.6) that correspond to C types.
with a Fortran procedure that has a dummy data object that is allocatable, assumed-shape, assumed-rank, pointer,1 The processor shall provide the intrinsic module ISO_C_BINDING. This module shall make accessible theor is of type character with an assumed length.
18.2 The ISO_C_BINDING intrinsic module
18.2.1 Summary of contents
following entities: the named constants C_NULL_PTR, C_NULL_FUNPTR, and those with names listed in1 The entities listed in the second column of Table 18.2 shall be default integer named constants.the first column of Table 18.1 and the second column of Table 18.2, the types C_PTR and C_FUNPTR, and the
procedures in 18.2.3. A processor may provide other public entities in the ISO_C_BINDING intrinsic module
in addition to those listed here.
18.2.2 Named constants and derived types in the module
2 A Fortran intrinsic type whose kind type parameter is one of the values in the module shall have the same
representation as the C type with which it interoperates, for each value that a variable of that type can have.3 The value of C_INT shall be a valid value for an integer kind parameter on the processor. The values ofFor C_BOOL, the internal representation of .TRUE._C_BOOL and .FALSE._C_BOOL shall be the same as those of
the C values (_Bool)1 and (_Bool)0 respectively.
C_SHORT, C_LONG, C_LONG_LONG, C_SIGNED_CHAR, C_SIZE_T, C_INT8_T, C_INT16_T, C_-4 The values of C_FLOAT, C_DOUBLE, and C_LONG_DOUBLE shall each be a valid value for a real kindINT32_T, C_INT64_T, C_INT_LEAST8_T, C_INT_LEAST16_T, C_INT_LEAST32_T, C_INT_LEAST-
64_T, C_INT_FAST8_T, C_INT_FAST16_T, C_INT_FAST32_T, C_INT_FAST64_T, C_INTMAX_T,
and C_INTPTR_T shall each be a valid value for an integer kind type parameter on the processor or shall be
−1 if the companion processor (5.5.7) defines the corresponding C type and there is no interoperating Fortran
processor kind, or −2 if the companion processor does not define the corresponding C type.
type parameter on the processor or shall be −1 if the companion processor’s type does not have a precision equal5 The value of C_BOOL shall be a valid value for a logical kind parameter on the processor or shall be −1.to the precision of any of the Fortran processor’s real kinds, −2 if the companion processor’s type does not have
a range equal to the range of any of the Fortran processor’s real kinds, −3 if the companion processor’s type
⃝c ISO/IEC 2017 – All rights reserved 479
ISO/IEC DIS 1539-1:2017 (E)
has neither the precision nor range of any of the Fortran processor’s real kinds, and equal to −4 if there is no
interoperating Fortran processor kind for other reasons. The values of C_FLOAT_COMPLEX, C_DOUBLE_-
COMPLEX, and C_LONG_DOUBLE_COMPLEX shall be the same as those of C_FLOAT, C_DOUBLE, and
C_LONG_DOUBLE, respectively.
6 The value of C_CHAR shall be a valid value for a character kind type parameter on the processor or shall be −1.
If the value of C_CHAR is nonnegative, the character kind specified is the C character kind; otherwise, there is7 The following entities shall be named constants of type character with a length parameter of one. The kindno C character kind.
parameter value shall be equal to the value of C_CHAR unless C_CHAR = −1, in which case the kind parameter8 The entities C_PTR and C_FUNPTR are described in 18.3.3.value shall be the same as for default kind. The values of these constants are specified in Table 18.1. In the case
that C_CHAR ̸= −1 the value is specified using C syntax. The semantics of these values are explained in 5.2.1
and 5.2.2 of ISO/IEC 9899:2011.
Table 18.1: Names of C characters with special semantics
Value
Name C definition C_CHAR = −1 C_CHAR ̸= −1
C_NULL_CHAR null character CHAR(0) ’\0’
C_ALERT alert ACHAR(7) ’\a’
C_BACKSPACE backspace ACHAR(8) ’\b’
C_FORM_FEED form feed ACHAR(12) ’\f’
C_NEW_LINE new line ACHAR(10) ’\n’
C_CARRIAGE_RETURN carriage return ACHAR(13) ’\r’
C_HORIZONTAL_TAB horizontal tab ACHAR(9) ’\t’
C_VERTICAL_TAB vertical tab ACHAR(11) ’\v’
9 The entity C_NULL_PTR shall be a named constant of type C_PTR. The value of C_NULL_PTR shall be the
same as the value NULL in C. The entity C_NULL_FUNPTR shall be a named constant of type C_FUNPTR.1 In the detailed descriptions below, procedure names are generic and not specific. The C_F_POINTER subroutineThe value of C_NULL_FUNPTR shall be that of a null pointer to a function in C.
NOTE 18.1
The value of NEW_LINE(C_NEW_LINE) is C_NEW_LINE (16.9.140).
18.2.3 Procedures in the module
18.2.3.1 General
is impure; all other procedures in the module are pure.1 Description. Query C pointer status.18.2.3.2 C_ASSOCIATED (C_PTR_1 [, C_PTR_2])
2 Class. Transformational function.
3 Arguments.
C_PTR_1 shall be a scalar of type C_PTR or C_FUNPTR.4 Result Characteristics. Default logical scalar.C_PTR_2 (optional) shall be a scalar of the same type as C_PTR_1.
480 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
5 Result Value.
Case (i): If C_PTR_2 is absent, the result is false if C_PTR_1 is a C null pointer and true otherwise.Case (ii): If C_PTR_2 is present, the result is false if C_PTR_1 is a C null pointer. If C_PTR_1 is not a
C null pointer, the result is true if C_PTR_1 compares equal to C_PTR_2 in the sense of 6.3.2.3
and 6.5.9 of ISO/IEC 9899:2011, and false otherwise.
NOTE 18.2
The following example illustrates the use of C_LOC and C_ASSOCIATED.
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_PTR, C_FLOAT, C_ASSOCIATED, C_LOC
INTERFACE
SUBROUTINE FOO(GAMMA) BIND(C)
IMPORT C_PTR
TYPE(C_PTR), VALUE :: GAMMA
END SUBROUTINE FOO
END INTERFACE
REAL(C_FLOAT), TARGET, DIMENSION(100) :: ALPHA
TYPE(C_PTR) :: BETA
...
IF (.NOT. C_ASSOCIATED(BETA)) THEN
BETA = C_LOC(ALPHA)
ENDIF
CALL FOO(BETA)
18.2.3.3 C_F_POINTER (CPTR, FPTR [, SHAPE]) 1 Description. Associate a data pointer with the target of a C pointer and specify its shape.
2 Class. Subroutine.
3 Arguments.
CPTR shall be a scalar of type C_PTR. It is an INTENT (IN) argument. Its value shall be4 Examples.• the C address of an interoperable data entity,
• the result of a reference to C_LOC with a noninteroperable argument, or
• the C address of a storage sequence that is not in use by any other Fortran entity.
The value of CPTR shall not be the C address of a Fortran variable that does not have the TARGET
attribute.
FPTR shall be a pointer, shall not have a deferred type parameter, and shall not be a coindexed object.
It is an INTENT (OUT) argument. If FPTR is an array, its shape is specified by SHAPE and each
lower bound is equal to 1.
Case (i): If the value of CPTR is the C address of an interoperable data entity, FPTR
shall be a data pointer with type and type parameter values interoperable with
the type of the entity. If the target T of CPTR is scalar, FPTR becomes pointer
associated with T; if FPTR is an array, SHAPE shall specify a size of 1. If T is
an array, and FPTR is scalar, FPTR becomes associated with the first element of
T. If both T and FPTR are arrays, SHAPE shall specify a size that is less than or
equal to the size of T, and FPTR becomes associated with the first PRODUCT
(SHAPE) elements of T (this could be the entirety of T).
⃝c ISO/IEC 2017 – All rights reserved 481
ISO/IEC DIS 1539-1:2017 (E)
Case (ii): If the value of CPTR is the result of a reference to C_LOC with a noninter-
operable effective argument X, FPTR shall be a nonpolymorphic pointer with
the same type and type parameters as X. In this case, X shall not have been
deallocated or have become undefined due to execution of a RETURN or END
statement since the reference. If X is scalar, FPTR becomes pointer associated
with X; if FPTR is an array, SHAPE shall specify a size of 1. If X is an array and
FPTR is scalar, FPTR becomes associated with the first element of X. If both X
and FPTR are arrays, SHAPE shall specify a size that is less than or equal to
the size of X, and FPTR becomes associated with the first PRODUCT (SHAPE)
elements of X (this could be the entirety of X).
Case (iii): If the value of CPTR is the C address of a storage sequence that is not in use by
any other Fortran entity, FPTR becomes associated with that storage sequence.
If FPTR is an array, its shape is specified by SHAPE and each lower bound
is 1. The storage sequence shall be large enough to contain the target object
described by FPTR and shall satisfy any other processor-dependent requirement
for association.
SHAPE (optional) shall be a rank-one integer array. It is an INTENT (IN) argument. SHAPE shall be present
if and only if FPTR is an array; its size shall be equal to the rank of FPTR.
Case (i): extern double c_x;1 Description. Associate a procedure pointer with the target of a C function pointer.void *address_of_x (void)
{
return &c_x;
}
! Assume interface to "address_of_x" is available.
Real (C_double), Pointer :: xp
Call C_F_Pointer (address_of_x (), xp)
Case (ii): Type t
Real, Allocatable :: v(:,:)
End Type
Type(t), Target :: x
Type(C_ptr) :: xloc
xloc = C_Loc (x)
...
Type(t), Pointer :: y
Call C_F_Pointer (xloc, y)
Case (iii): void *getmem (int nbits)
{
return malloc ((nbits+CHAR_BIT-1)/CHAR_BIT);
}
! Assume interface to "getmem" is available,
! and there is a derived type "mytype" accessible.
Type(mytype), Pointer :: x
Call C_F_Pointer (getmem (Storage_Size (x)), x)
482 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
The following statements illustrate the use of C_F_POINTER when the pointer to be set has a deferred type
parameter:
Character(42), Pointer :: C1
Character(:), Pointer :: C2
Call C_F_Pointer (CPTR, C1)
C2 => C1
This will associate C2 with the entity at the C address specified by CPTR, and specify its length to be the same
as that of C1.
NOTE 18.3
In the case of associating FPTR with a storage sequence, there might be processor-dependent requirements
such as alignment of the memory address or placement in memory.
18.2.3.4 C_F_PROCPOINTER (CPTR, FPTR)
2 Class. Pure subroutine.
3 Arguments.
CPTR shall be a scalar of type C_FUNPTR. It is an INTENT (IN) argument. Its value shall be the C1 Description. C address of the argument.address of a procedure that is interoperable, or the result of a reference to the function C_FUNLOC
from the intrinsic module ISO_C_BINDING.
FPTR shall be a procedure pointer, and shall not be a component of a coindexed object. It is an INTENT
(OUT) argument. If the target of CPTR is interoperable, the interface for FPTR shall be interoper-
able with the prototype that describes the target of CPTR; otherwise, the interface for FPTR shall
have the same characteristics as that target. FPTR becomes pointer associated with the target of
CPTR.
NOTE 18.4
The term “target” in the descriptions of C_F_POINTER and C_F_PROCPOINTER denotes the entity
referenced by a C pointer, as described in 6.2.5 of ISO/IEC 9899:2011.
18.2.3.5 C_FUNLOC (X)
2 Class. Transformational function.
3 Argument. X shall be a procedure; if it is a procedure pointer it shall be associated. It shall not be a coindexed
object.4 Result Characteristics. Scalar of type C_FUNPTR.
5 Result Value. The result value is described using the result name FUNPTR. The result is determined as if
C_FUNPTR were a derived type containing a procedure pointer component PX with an implicit interface and6 The result is a value that can be used as an actual CPTR argument in a call to C_F_PROCPOINTER wherethe pointer assignment FUNPTR%PX => X were executed.
the FPTR argument has attributes that would allow the pointer assignment FPTR => X. Such a call to C_F_-1 Description. C address of the argument.PROCPOINTER shall have the effect of the pointer assignment FPTR => X.
⃝c ISO/IEC 2017 – All rights reserved 483
ISO/IEC DIS 1539-1:2017 (E)
18.2.3.6 C_LOC (X)
2 Class. Transformational function.
3 Argument. X shall have either the POINTER or TARGET attribute. It shall not be a coindexed object. It
shall either be a variable with interoperable type and kind type parameters, or be a nonpolymorphic variable4 Result Characteristics. Scalar of type C_PTR.with no length type parameters. If it is allocatable, it shall be allocated. If it is a pointer, it shall be associated.
If it is an array, it shall be contiguous and have nonzero size. It shall not be a zero-length string.
5 Result Value. The result value is described using the result name CPTR.
6 If X is a scalar data entity, the result is determined as if C_PTR were a derived type containing a scalar pointer
component PX of the type and type parameters of X and the pointer assignment CPTR%PX => X were executed.7 If X is an array data entity, the result is determined as if C_PTR were a derived type containing a scalar pointer
component PX of the type and type parameters of X and the pointer assignment of CPTR%PX to the first8 If X is a data entity that is interoperable or has interoperable type and type parameters, the result is the valueelement of X were executed.
that the C processor returns as the result of applying the unary “&” operator (as defined in ISO/IEC 9899:2011,9 The result is a value that can be used as an actual CPTR argument in a call to C_F_POINTER where FPTR6.5.3.2) to the target of CPTR%PX.
has attributes that would allow the pointer assignment FPTR => X. Such a call to C_F_POINTER shall have1 Description. Size of X in bytes.the effect of the pointer assignment FPTR => X.
NOTE 18.5
Where the actual argument is of noninteroperable type or type parameters, the result of C_LOC provides
an opaque “handle” for it. In an actual implementation, this handle might be the C address of the argument;
however, only a C function that treats it as a void (generic) C pointer that cannot be dereferenced (6.5.3.2
in ISO/IEC 9899:2011) is likely to be portable.
18.2.3.7 C_SIZEOF (X)
2 Class. Inquiry function.
3 Argument. X shall be an interoperable data entity that is not an assumed-size array or an assumed-rank array
that is associated with an assumed-size array.4 Result Characteristics. Scalar integer of kind C_SIZE_T (18.3.2).
5 Result Value. If X is scalar, the result value is the value that the companion processor returns as the result
of applying the sizeof operator (ISO/IEC 9899:2011, subclause 6.5.3.4) to an object of a type that interoperates6 If X is an array, the result value is the value that the companion processor returns as the result of applying thewith the type and type parameters of X.
sizeof operator to an object of a type that interoperates with the type and type parameters of X, multiplied by1 Subclause 18.3 defines the conditions under which a Fortran entity is interoperable. If a Fortran entity is inter-the number of elements in X.
484 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
18.3 Interoperability between Fortran and C entities
18.3.1 General
operable, an equivalent entity could be defined by means of C and the Fortran entity would interoperate with the1 Table 18.2 shows the interoperability between Fortran intrinsic types and C types. A Fortran intrinsic type withC entity. There does not have to be such an interoperating C entity.
NOTE 18.6
A Fortran entity can be interoperable with more than one C entity.
18.3.2 Interoperability of intrinsic types
particular type parameter values is interoperable with a C type if the type and kind type parameter value are listed2 The second column of the table refers to the named constants made accessible by the ISO_C_BINDING intrinsicin the table on the same row as that C type. If the type is character, the length type parameter is interoperable
if and only if its value is one. A combination of Fortran type and type parameters that is interoperable with a
C type listed in the table is also interoperable with any unqualified C type that is compatible with the listed C
type.
module. If the value of any of these named constants is negative, there is no combination of Fortran type and3 A combination of intrinsic type and type parameters is interoperable if it is interoperable with a C type. The Ctype parameters interoperable with the C type shown in that row.
types mentioned in table 18.2 are defined in subclauses 6.2.5, 7.19, and 7.20.1 of ISO/IEC 9899:2011.Table 18.2: Interoperability between Fortran and C types
Named constant from the ISO_C_BINDING module
Fortran type C type
(kind type parameter if value is positive)
C_INT int
C_SHORT short int
C_LONG long int
C_LONG_LONG long long int
signed char
C_SIGNED_CHAR
unsigned char
1 C_PTR and C_FUNPTR shall be derived types with only private components. No direct component of either
C_SIZE_T size_t
C_INT8_T int8_t C_INT16_T int16_t C_INT32_T int32_t C_INT64_T int64_t C_INT_LEAST8_T int_least8_t C_INT_LEAST16_T int_least16_t C_INT_LEAST32_T int_least32_t INTEGER C_INT_LEAST64_T int_least64_t C_INT_FAST8_T int_fast8_tC_INT_FAST16_T int_fast16_t
C_INT_FAST32_T int_fast32_t
C_INT_FAST64_T int_fast64_t
C_INTMAX_T intmax_t
⃝c ISO/IEC 2017 – All rights reserved 485
ISO/IEC DIS 1539-1:2017 (E)
Interoperability between Fortran and C types (cont.)Named constant from the ISO_C_BINDING module
Fortran type C type (kind type parameter if value is positive)C_INTPTR_T intptr_t
C_PTRDIFF_T ptrdiff_t
C_FLOAT float
REAL C_DOUBLE double C_LONG_DOUBLE long doubleC_FLOAT_COMPLEX float _Complex
COMPLEX C_DOUBLE_COMPLEX double _Complex C_LONG_DOUBLE_COMPLEX long double _Complex
LOGICAL C_BOOL _Bool CHARACTER C_CHAR char NOTE 18.7
ISO/IEC 9899:2011 specifies that the representations for nonnegative signed integers are the same as the
corresponding values of unsigned integers. Because Fortran does not provide direct support for unsigned
kinds of integers, the ISO_C_BINDING module does not make accessible named constants for their kind
type parameter values. A user can use the signed kinds of integers to interoperate with the unsigned types
and all their qualified versions as well. This has the potentially surprising side effect that the C type
unsigned char is interoperable with the type integer with a kind type parameter of C_SIGNED_CHAR.
18.3.3 Interoperability with C pointer types
of these types is allocatable or a pointer. C_PTR is interoperable with any C object pointer type. C_FUNPTR1 Interoperability between a derived type in Fortran and a struct type in C is provided by the BIND attribute onis interoperable with any C function pointer type.
NOTE 18.8
This means that only a C processor with the same representation method for all C object pointer types,
and the same representation method for all C function pointer types, can be the target of interoperability
of a Fortran processor. ISO/IEC 9899:2011 does not require this to be the case.
NOTE 18.9
The function C_LOC can be used to return a value of type C_PTR that is the C address of an allocated
allocatable variable. The function C_FUNLOC can be used to return a value of type C_FUNPTR that is
the C address of a procedure. For C_LOC and C_FUNLOC the returned value is of an interoperable type
and thus can be used in contexts where the procedure or allocatable variable is not directly allowed. For
example, it could be passed as an actual argument to a C function.
Similarly, type C_FUNPTR or C_PTR can be used in a dummy argument or structure component and
can have a value that is the C address of a procedure or allocatable variable, even in contexts where a
procedure or allocatable variable is not directly allowed.
18.3.4 Interoperability of derived types and C struct types
the Fortran type.2 A derived type is interoperable with a C struct type if and only if the derived type has the BIND attribute (7.5.2),C1801 (R726) A derived type with the BIND attribute shall not have the SEQUENCE attribute.
486 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C1802 (R726) A derived type with the BIND attribute shall not have type parameters.
C1803 (R726) A derived type with the BIND attribute shall not have the EXTENDS attribute.
C1804 (R726) A derived-type-def that defines a derived type with the BIND attribute shall not have a type-
bound-procedure-part.
C1805 (R726) A derived type with the BIND attribute shall have at least one component.
C1806 (R726) Each component of a derived type with the BIND attribute shall be a nonpointer, nonallocatable
data component with interoperable type and type parameters.
NOTE 18.10
The syntax rules and their constraints require that a derived type that is interoperable with a C struct
type have components that are all data entities that are interoperable. No component is permitted to be
allocatable or a pointer, but the value of a component of type C_FUNPTR or C_PTR can be the C address
of such an entity.
the derived type and the C struct type have the same number of components, and the components of the derived3 There is no Fortran type that is interoperable with a C struct type that contains a bit field or that contains atype would interoperate with corresponding components of the C struct type as described in 18.3.5 and 18.3.6 if
the components were variables. A component of a derived type and a component of a C struct type correspond
if they are declared in the same relative position in their respective type definitions.
NOTE 18.11
The names of the corresponding components of the derived type and the C struct type need not be the
same.
flexible array member. There is no Fortran type that is interoperable with a C union type.NOTE 18.12
For example, the C type myctype, declared below, is interoperable with the Fortran type myftype, declared
below.
typedef struct {
int m, n;
float r;
} myctype;
USE, INTRINSIC :: ISO_C_BINDING
TYPE, BIND(C) :: MYFTYPE
INTEGER(C_INT) :: I, J
REAL(C_FLOAT) :: S
END TYPE MYFTYPE
The names of the types and the names of the components are not significant for the purposes of determining
whether a Fortran derived type is interoperable with a C struct type.
NOTE 18.13
ISO/IEC 9899:2011 requires the names and component names to be the same in order for the types to be
compatible (ISO/IEC 9899:2011, subclause 6.2.7). This is similar to Fortran’s rule describing when different
derived type definitions describe the same sequence type. This rule was not extended to determine whether
3 A formal parameter of a C function prototype corresponds to a dummy argument of a Fortran interface if they
⃝c ISO/IEC 2017 – All rights reserved 487
ISO/IEC DIS 1539-1:2017 (E)
NOTE 18.13 (cont.)a Fortran derived type is interoperable with a C struct type because the case of identifiers is significant in
C but not in Fortran.
18.3.5 Interoperability of scalar variables 1 A named scalar Fortran variable is interoperable if and only if its type and type parameters are interoperable, it is not a coarray, it has neither the ALLOCATABLE nor the POINTER attribute, and if it is of type character2 An interoperable scalar Fortran variable is interoperable with a scalar C entity if their types and type parametersits length is not assumed or declared by an expression that is not a constant expression.
are interoperable.1 A Fortran variable that is a named array is interoperable if and only if its type and type parameters are interop-18.3.6 Interoperability of array variables
erable, it is not a coarray, it is of explicit shape or assumed size, and if it is of type character its length is not2 An explicit-shape or assumed-size array of rank r, with a shape of e1 . . . er is interoperable with a C arrayassumed or declared by an expression that is not a constant expression.
if its size is nonzero and1 A Fortran procedure is interoperable if and only if it has the BIND attribute, that is, if its interface is specified(1) either
(a) the array is assumed-size, and the C array does not specify a size, or
(b) the array is an explicit-shape array, and the extent of the last dimension (er ) is the same as
the size of the C array, and
(2) either
(a) r is equal to one, and an element of the array is interoperable with an element of the C array,
or
(b) r is greater than one, and an explicit-shape array with shape of e1 . . . er−1 , with the
same type and type parameters as the original array, is interoperable with a C array of a type
equal to the element type of the original C array.
NOTE 18.14
An element of a multi-dimensional C array is an array type, so a Fortran array of rank one is not interop-
erable with a multidimensional C array.
NOTE 18.15
An allocatable array or array pointer is never interoperable. Such an array does not meet the requirement
of being an explicit-shape or assumed-size array.
NOTE 18.16
For example, a Fortran array declared as
INTEGER(C_INT) :: A(18, 3:7, *)
is interoperable with a C array declared as
int b[][5][18];
488 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 18.17
The C programming language defines null-terminated strings, which are actually arrays of the C type char
that have a C null character in them to indicate the last valid element. A Fortran array of type character
with a kind type parameter equal to C_CHAR is interoperable with a C string.
Fortran’s rules of sequence association (15.5.2.11) permit a character scalar actual argument to correspond
to a dummy argument array. This makes it possible to argument associate a Fortran character string with
a C string.
NOTE 18.21 has an example of interoperation between Fortran and C strings.
18.3.7 Interoperability of procedures and procedure interfaces
with a proc-language-binding-spec.2 A Fortran procedure interface is interoperable with a C function prototype if
(1) the interface has the BIND attribute,NOTE 18.18(2) either
(a) the interface describes a function whose result is a scalar variable that is interoperable with
the result of the prototype or
(b) the interface describes a subroutine and the prototype has a result type of void,
(3) the number of dummy arguments of the interface is equal to the number of formal parameters of the
prototype,
(4) any scalar dummy argument with the VALUE attribute is interoperable with the corresponding
formal parameter of the prototype,
(5) any dummy argument without the VALUE attribute corresponds to a formal parameter of the pro-
totype that is of a pointer type, and either
• the dummy argument is interoperable with an entity of the referenced type (ISO/IEC 9899:2011,
6.2.5, 7.19, and 7.20.1) of the formal parameter,
• the dummy argument is a nonallocatable nonpointer variable of type CHARACTER with
assumed character length and the formal parameter is a pointer to CFI_cdesc_t,
• the dummy argument is allocatable, assumed-shape, assumed-rank, or a pointer without the
CONTIGUOUS attribute, and the formal parameter is a pointer to CFI_cdesc_t, or
• the dummy argument is assumed-type and not allocatable, assumed-shape, assumed-rank, or
a pointer, and the formal parameter is a pointer to void,
(6) each allocatable or pointer dummy argument of type CHARACTER has deferred character length,
and
(7) the prototype does not have variable arguments as denoted by the ellipsis (...).
The referenced type of a C pointer type is the C type of the object that the C pointer type points to.
For example, the referenced type of the pointer type int * is int.
NOTE 18.19
The C language allows specification of a C function that can take a variable number of arguments (ISO/IEC
9899:2011, 7.16). This document does not provide a mechanism for Fortran procedures to interoperate with
such C functions.
are in the same relative positions in the C parameter list and the dummy argument list, respectively.4 In a reference from C to a Fortran procedure with an interoperable interface, a C actual argument shall be the⃝c ISO/IEC 2017 – All rights reserved 489
ISO/IEC DIS 1539-1:2017 (E)
address of a C descriptor for the intended effective argument if the corresponding dummy argument interoperates5 When an interoperable Fortran procedure with a simply contiguous dummy argument is invoked from C and thewith a C formal parameter that is a pointer to CFI_cdesc_t. In this C descriptor, the members other than
attribute and type shall describe an object with the same characteristics as the intended effective argument.
The value of the attribute member of the C descriptor shall be compatible with the characteristics of the dummy
argument. The type member shall have a value that depends on the intended effective argument as follows:
• if the dynamic type of the intended effective argument is an interoperable type listed in Table 18.4, the
corresponding value for that type;
• if the dynamic type of the intended effective argument is an intrinsic type for which the processor defines
a nonnegative type specifier value not listed in Table 18.4, that type specifier value;
• otherwise, CFI_type_other.
actual argument is the address of a C descriptor for a discontiguous object, the Fortran processor shall handle6 When an interoperable C procedure whose Fortran interface has a simply contiguous dummy argument is invokedthe difference in contiguity.
from Fortran and the effective argument is discontiguous, the Fortran processor shall ensure that the C procedure7 When an interoperable C procedure whose Fortran interface has a simply contiguous dummy argument is invokedreceives a descriptor for a contiguous object.
from C, and the actual argument is the address of a C descriptor for a discontiguous object, the C code within8 If an interoperable procedure defined by means other than Fortran has an optional dummy argument, and thethe procedure shall be prepared to handle the discontiguous argument.
corresponding actual argument in a reference from Fortran is absent, the procedure is invoked with a null pointerfor that argument. If an interoperable procedure defined by means of Fortran is invoked by a C function, an
optional dummy argument is absent if and only if the corresponding argument in the invocation is a null pointer.
NOTE 18.20
For example, a Fortran procedure interface described by
INTERFACE
FUNCTION FUNC(I, J, K, L, M) BIND(C)
USE, INTRINSIC :: ISO_C_BINDINGINTEGER(C_SHORT) :: FUNC
INTEGER(C_INT), VALUE :: I
REAL(C_DOUBLE) :: J
INTEGER(C_INT) :: K, L(10)
TYPE(C_PTR), VALUE :: M
END FUNCTION FUNC
END INTERFACE
is interoperable with the C function prototype
short func(int i, double *j, int *k, int l[10], void *m);
A C pointer can correspond to a Fortran dummy argument of type C_PTR with the VALUE attribute or
to a Fortran scalar that does not have the VALUE attribute. In the above example, the C pointers j and
k correspond to the Fortran scalars J and K, respectively, and the C pointer m corresponds to the Fortran
dummy argument M of type C_PTR.
490 c ISO/IEC 2017 – All rights reservedNOTE 18.21
ISO/IEC DIS 1539-1:2017 (E)
The interoperability of Fortran procedure interfaces with C function prototypes is only one part of invocation
of a C function from Fortran. There are four pieces to consider in such an invocation: the procedure
reference, the Fortran procedure interface, the C function prototype, and the C function. Conversely,
the invocation of a Fortran procedure from C involves the function reference, the C function prototype,
the Fortran procedure interface, and the Fortran procedure. In order to determine whether a reference is
allowed, it is necessary to consider all four pieces.
For example, consider a C function that can be described by the C function prototype
void copy(char in[], char out[]);
Such a function can be invoked from Fortran as follows:
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_NULL_CHAR
INTERFACE
SUBROUTINE COPY(IN, OUT) BIND(C)
IMPORT C_CHAR
CHARACTER(KIND=C_CHAR), DIMENSION(*) :: IN, OUT
END SUBROUTINE COPY
END INTERFACE
CHARACTER(LEN=10, KIND=C_CHAR) :: &
& DIGIT_STRING = C_CHAR_’123456789’ // C_NULL_CHAR CHARACTER(KIND=C_CHAR) :: DIGIT_ARR(10)CALL COPY(DIGIT_STRING, DIGIT_ARR)
PRINT ’(1X, A1)’, DIGIT_ARR(1:9)
END
The procedure reference has character string actual arguments. These correspond to character array dummy
arguments in the procedure interface body as allowed by Fortran’s rules of sequence association (15.5.2.11).
Those array dummy arguments in the procedure interface are interoperable with the formal parameters of
the C function prototype. The C function is not shown here, but is assumed to be compatible with the C
function prototype.
NOTE 18.22
The requirements on the Fortran processor when a discontiguous actual argument is being passed to a
simply contiguous dummy argument are such that the C programmer has the same functionality (and
safety) as the Fortran programmer, when either the calling or called procedure are Fortran procedures. The
requirements on the C procedure, in the case when both the called and calling procedure are C procedures,
effectively require that the C procedure not access memory through the descriptor that is not described by
the descriptor; otherwise the program will not conform to this document. A dummy argument is simply
contiguous if it has the CONTIGUOUS attribute or is an array that is not assumed-shape, assumed-rank,
or a pointer.
18.4 C descriptors 1 A C descriptor is a C structure of type CFI_cdesc_t. Together with library functions that have standard
prototypes, it provides a means for describing and manipulating Fortran data objects from within a C function.1 The source file ISO_Fortran_binding.h shall contain the C structure definitions, typedef declarations, macroThis C structure is defined in the source file ISO_Fortran_binding.h.
⃝c ISO/IEC 2017 – All rights reserved 491
ISO/IEC DIS 1539-1:2017 (E)
18.5 The source file ISO_Fortran_binding.h
18.5.1 Summary of contents
definitions, and function prototypes specified in subclauses 18.5.2 to 18.5.5. The definitions and declarations in2 The source file ISO_Fortran_binding.h may be included in any order relative to the standard C headers, andISO_Fortran_binding.h can be used by a C function to interpret and manipulate a C descriptor. These provide
a means to specify a C prototype that interoperates with a Fortran interface that has a non-interoperable dummy
variable (18.3.7).
may be included more than once in a given scope, with no effect different from being included only once, other3 A C source file that includes the ISO_Fortran_binding.h header file shall not use any names starting withthan the effect on line numbers.
CFI_ that are not defined in the header, and shall not define any of the structure names defined in the header1 CFI_dim_t is a typedef name for a C structure. It is used to represent lower bound, extent, and memory strideas macro names. All names other than structure member names defined in the header begin with CFI_ or an
underscore character, or are defined by a standard C header that it includes.
18.5.2 The CFI_dim_t structure type
information for one dimension of an array. The type CFI_index_t is described in 18.5.4. CFI_dim_t contains1 CFI_cdesc_t is a typedef name for a C structure, which contains a flexible array member. It shall contain at leastat least the following members in any order.
CFI_index_t lower_bound; The value is equal to the value of the lower bound for the dimension being
described.
CFI_index_t extent; The value is equal to the number of elements in the dimension being described, or −1
for the final dimension of an assumed-size array.
CFI_index_t sm; The value is equal to the memory stride for a dimension; this is the difference in bytes
between the addresses of successive elements in the dimension being described.
18.5.3 The CFI_cdesc_t structure type
the members described in this subclause. The values of these members of a structure of type CFI_cdesc_t that2 The first three members of the structure shall be base_addr, elem_len, and version in that order. The finalis produced by the functions and macros specified in this document, or received by a C function when invoked
by a Fortran procedure, shall have the properties described in this subclause.
member shall be dim. All other members shall be between version and dim, in any order. The types CFI_-3 For a C descriptor of an array pointer or allocatable array, the value of the lower_bound member of each elementattribute_t, CFI_rank_t, and CFI_type_t are described in 18.5.4. The type CFI_dim_t is described in 18.5.2.
void * base_addr; If the object is an unallocated allocatable variable or a pointer that is disassociated, the
value is a null pointer. If the object has zero size, the value is not a null pointer but is otherwise processor-
dependent. Otherwise, the value is the base address of the object being described. The base address of a
scalar is its C address. The base address of an array is the C address of the first element in Fortran array
element order.
size_t elem_len; If the object is scalar, the value is the storage size in bytes of the object; otherwise, the value
is the storage size in bytes of an element of the object.
int version; The value is equal to the value of CFI_VERSION in the source file ISO_Fortran_binding.h that
defined the format and meaning of this C descriptor when the descriptor was established.
492 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
CFI_rank_t rank; The value is equal to the number of dimensions of the Fortran object being described; if
the object is scalar, the value is zero.
CFI_type_t type; The value is equal to the specifier for the type of the object. Each interoperable intrinsic C
type has a specifier. Specifiers are also provided to indicate that the type of the object is an interoperable
structure, or is unknown. The macros listed in Table 18.4 provide values that correspond to each specifier.
CFI_attribute_t attribute; The value is equal to the value of an attribute code that indicates whether the
object described is allocatable, a data pointer, or a nonallocatable nonpointer data object. The macros
listed in Table 18.3 provide values that correspond to each code.
CFI_dim_t dim; The number of elements in the dim array is equal to the rank of the object. Each element of
the array contains the lower bound, extent, and memory stride information for the corresponding dimension
of the Fortran object.
of the dim member of the descriptor is determined by argument association, allocation, or pointer association.4 There shall be an ordering of the dimensions such that the absolute value of the sm member of the first dimensionFor a C descriptor of a nonallocatable nonpointer object, the value of the lower_bound member of each element
of the dim member of the descriptor is zero.
is not less than the elem_len member of the C descriptor and the absolute value of the sm member of each5 In a C descriptor of an assumed-size array, the extent member of the last element of the dim member has thesubsequent dimension is not less than the absolute value of the sm member of the previous dimension multiplied
by the extent of the previous dimension.
value −1.1 Except for CFI_CDESC_T, each macro defined in ISO_Fortran_binding.h expands to an integer constantNOTE 18.23
The reason for the restriction on the absolute values of the sm members is to ensure that there is no overlap
between the elements of the array that is being described, while allowing for the reordering of subscripts.
Within Fortran, such a reordering can be achieved with the intrinsic function TRANSPOSE or the intrinsic
function RESHAPE with the optional argument ORDER, and an optimizing compiler can accommodate it
without making a copy by constructing the appropriate descriptor whenever it can determine that a copy
is not needed.
NOTE 18.24
The value of elem_len for a Fortran CHARACTER object is equal to the character length times the number
of bytes of a single character of that kind. If the kind is C_CHAR, this value will be equal to the character
length.
18.5.4 Macros and typedefs in ISO_Fortran_binding.h
expression that is either a single token or a parenthesized expression that is suitable for use in #if preprocessing2 CFI_CDESC_T is a function-like macro that takes one argument, which is the rank of the C descriptor to create,directives.
and evaluates to an unqualified type of suitable size and alignment for defining a variable to use as a C descriptor3 CFI_index_t is a typedef name for a standard signed integer type capable of representing the result of subtractingof that rank. The argument shall be an integer constant expression with a value that is greater than or equal to
zero and less than or equal to CFI_MAX_RANK. A pointer to a variable declared using CFI_CDESC_T can
be cast to CFI_cdesc_t *. A variable declared using CFI_CDESC_T shall not have an initializer.
⃝c ISO/IEC 2017 – All rights reserved 493
ISO/IEC DIS 1539-1:2017 (E)
NOTE 18.25
The CFI_CDESC_T macro provides the memory for a C descriptor. The address of an entity declared
using the macro is not usable as an actual argument corresponding to a formal parameter of type CFI_-
cdesc_t * without an explicit cast. For example, the following code uses CFI_CDESC_T to declare a C
descriptor of rank 5 and pass it to CFI_deallocate (18.5.5.4).
CFI_CDESC_T(5) object;
int ind;
... code to define and use C descriptor ...
ind = CFI_deallocate((CFI_cdesc_t *)&object);
two pointers.4 The CFI_MAX_RANK macro has a processor-dependent value equal to the largest rank supported. The value
shall be greater than or equal to 15. CFI_rank_t is a typedef name for a standard integer type capable of5 The CFI_VERSION macro has a processor-dependent value that encodes the version of the ISO_Fortran_-representing the largest supported rank.
binding.h source file containing this macro. This value should be increased if a new version of the source file is6 The macros in Table 18.3 are for use as attribute codes. The values shall be nonnegative and distinct. CFI_-incompatible with the previous version.
attribute_t is a typedef name for a standard integer type capable of representing the values of the attribute7 CFI_attribute_pointer specifies a data object with the Fortran POINTER attribute. CFI_attribute_allocatablecodes.
Table 18.3: ISO_Fortran_binding.h macros for attribute codes
Macro name Attribute
CFI_attribute_pointer data pointer
CFI_attribute_allocatable allocatable
CFI_attribute_other nonallocatable nonpointer
specifies an object with the Fortran ALLOCATABLE attribute. CFI_attribute_other specifies a nonallocatable8 The macros in Table 18.4 are for use as type specifiers. The value for CFI_type_other shall be negative andnonpointer object.
distinct from all other type specifiers. CFI_type_struct specifies a C structure that is interoperable with a9 If the processor supports interoperability of a Fortran intrinsic type with a C type not listed in Table 18.4,Fortran derived type; its value shall be positive and distinct from all other type specifiers. If a C type is not
interoperable with a Fortran type and kind supported by the Fortran processor, its macro shall evaluate to a
negative value. Otherwise, the value for an intrinsic type shall be positive.
the processor shall define a type specifier value for that type which is positive and distinct from all other type10 CFI_type_t is a typedef name for a standard integer type capable of representing the values for the supportedspecifiers.
type specifiers.11 The macros in Table 18.5 are for use as error codes. The macro CFI_SUCCESS shall be defined to be the integerTable 18.4: ISO_Fortran_binding.h macros for type codes
Macro name C Type
CFI_type_signed_char signed char
CFI_type_short short int
494 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
ISO_Fortran_binding.h macros for type codes (cont.)
Macro name C Type
CFI_type_int int
CFI_type_long long int
CFI_type_long_long long long int
CFI_type_size_t size_t
CFI_type_int8_t int8_t
CFI_type_int16_t int16_t
CFI_type_int32_t int32_t
CFI_type_int64_t int64_t
CFI_type_int_least8_t int_least8_t
CFI_type_int_least16_t int_least16_t
CFI_type_int_least32_t int_least32_t
CFI_type_int_least64_t int_least64_t
CFI_type_int_fast8_t int_fast8_t
CFI_type_int_fast16_t int_fast16_t
CFI_type_int_fast32_t int_fast32_t
CFI_type_int_fast64_t int_fast64_t
CFI_type_intmax_t intmax_t
CFI_type_intptr_t intptr_t
CFI_type_ptrdiff_t ptrdiff_t
CFI_type_float float
CFI_type_double double
CFI_type_long_double long double
CFI_type_float_Complex float _Complex
CFI_type_double_Complex double _Complex
CFI_type_long_double_Complex long double _Complex
CFI_type_Bool _Bool
CFI_type_char char
CFI_type_cptr void *
CFI_type_struct interoperable C structure
CFI_type_other Not otherwise specified
NOTE 18.26
The values for different C types can be the same; for example, CFI_type_int and CFI_type_int32_t might
have the same value.
constant 0. The value of each macro other than CFI_SUCCESS shall be nonzero and shall be different from the12 The values of the macros in Table 18.5 indicate the error condition described.values of the other macros specified in this subclause. Error conditions other than those listed in this subclause
should be indicated by error codes different from the values of the macros named in this subclause.
Table 18.5: ISO_Fortran_binding.h macros for error codes
Macro name Error condition CFI_SUCCESS No error detected. CFI_ERROR_BASE_ADDR_NULL The base address member of a C descriptor is a null pointer in a context that requires a non-null pointer value.CFI_ERROR_BASE_ADDR_NOT_NULL In a context that requires a null pointer value, the base
address member of a C descriptor is not a null pointer.
CFI_INVALID_ELEM_LEN The value supplied for the element length member of a C descriptor is not valid.
⃝c ISO/IEC 2017 – All rights reserved 495
ISO/IEC DIS 1539-1:2017 (E)
ISO_Fortran_binding.h macros for error codes (cont.)
Macro name Error condition CFI_INVALID_RANK The value supplied for the rank member of a C descriptor is not valid.
CFI_INVALID_TYPE The value supplied for the type member of a C descriptor is not valid.
CFI_INVALID_ATTRIBUTE The value supplied for the attribute member of a C descriptor is not valid.
CFI_INVALID_EXTENT The value supplied for the extent member of a CFI_dim_t structure is not valid.
CFI_INVALID_DESCRIPTOR A C descriptor is invalid in some way. CFI_ERROR_MEM_ALLOCATION Memory allocation failed. CFI_ERROR_OUT_OF_BOUNDS A reference is out of bounds.
18.5.5 Functions declared in ISO_Fortran_binding.h 18.5.5.1 Arguments and results of the functions 1 Some of the functions described in 18.5.5 return an error indicator; this is an integer value that indicates whether an error condition was detected. The value zero indicates that no error condition was detected, and a nonzero2 In function arguments representing subscripts, bounds, extents, or strides, the ordering of the elements is thevalue indicates which error condition was detected. Table 18.5 lists standard error conditions and macro names
for their corresponding error codes. A processor is permitted to detect other error conditions. If an invocation of
a function defined in 18.5.5 could detect more than one error condition and an error condition is detected, which
error condition is detected is processor dependent.
same as the ordering of the elements of the dim member of a C descriptor.3 Prototypes for these functions, or equivalent macros, are provided in the ISO_Fortran_binding.h file as described
in 18.5.5. It is unspecified whether the functions defined by this header are macros or identifiers declared with1 Synopsis. C address of an object described by a C descriptor.external linkage. If a macro definition is suppressed in order to access an actual function, the behavior is undefined.
NOTE 18.27
These functions are allowed to be macros to provide extra implementation flexibility. For example, CFI_-
establish could include the value of CFI_VERSION in the header used to compile the call to CFI_establish
as an extra argument of the actual function used to establish the C descriptor.
18.5.5.2 The CFI_address function
void *CFI_address(const CFI_cdesc_t *dv, const CFI_index_t subscripts[]);2 Formal Parameters.
dv shall be the address of a C descriptor describing the object. The object shall not be an unallocated3 Result Value. If the object is an array of rank n, the result is the C address of the element of the object thatallocatable variable or a pointer that is not associated.
subscripts shall be a null pointer or the address of an array of type CFI_index_t. If the object is an array,
subscripts shall be the address of an array of CFI_index_t with at least n elements, where n
is the rank of the object. The value of subscripts[i] shall be within the bounds of dimension i
specified by the dim member of the C descriptor except for the last dimension of a C descriptor for
an assumed-size array. For the C descriptor of an assumed-size array, the value of the subscript for
the last dimension shall not be less than the lower bound, and the subscript order value specified
by the subscripts shall not exceed the size of the array.
496 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
the first n elements of the subscripts argument would specify if used as subscripts. If the object is scalar, the4 Example. If dv is the address of a C descriptor for the Fortran array A declared asresult is its C address.
REAL(C_FLOAT) :: A(100, 100)the following code calculates the C address of A(5, 10):
CFI_index_t subscripts[2];float *address;
subscripts[0] = 4;
subscripts[1] = 9;
address = (float *) CFI_address(dv, subscripts );
18.5.5.3 The CFI_allocate function 1 Synopsis. Allocate memory for an object described by a C descriptor. int CFI_allocate(CFI_cdesc_t *dv, const CFI_index_t lower_bounds[],2 Formal Parameters.const CFI_index_t upper_bounds[], size_t elem_len);
dv shall be the address of a C descriptor specifying the rank and type of the object. The base_-addr member of the C descriptor shall be a null pointer. If the type is not a character type, the
elem_len member shall specify the element length. The attribute member shall have a value of
CFI_attribute_allocatable or CFI_attribute_pointer.
lower_bounds shall be the address of an array with at least dv->rank elements, if dv->rank>0.
upper_bounds shall be the address of an array with at least dv->rank elements, if dv->rank>0.
elem_len If the type specified in the C descriptor type is a Fortran character type, the value of elem_len
shall be the storage size in bytes of an element of the object; otherwise, elem_len is ignored.
3 Description. Successful execution of CFI_allocate allocates memory for the object described by the C descriptor with the address dv using the same mechanism as the Fortran ALLOCATE statement, and assigns the4 Result Value. The result is an error indicator.address of that memory to dv->base_addr. The first dv->rank elements of the lower_bounds and upper_bounds
arguments provide the lower and upper Fortran bounds, respectively, for each corresponding dimension of the
object. The supplied lower and upper bounds override any current dimension information in the C descriptor.
If the rank is zero, the lower_bounds and upper_bounds arguments are ignored. If the type specified in the C
descriptor is a character type, the supplied element length overrides the current element-length information in
the descriptor.
If an error is detected, the C descriptor is not modified.
5 Example. If dv is the address of a C descriptor for the Fortran array A declared as REAL, ALLOCATABLE :: A(:, :)and the array is not allocated, the following code allocates it to be of shape [100, 500]:
CFI_index_t lower[2], upper[2];int ind;
⃝c ISO/IEC 2017 – All rights reserved 497
ISO/IEC DIS 1539-1:2017 (E)
lower[0] = 1; lower[1] = 1;upper[0] = 100; upper[1] = 500;
ind = CFI_allocate(dv, lower, upper, 0);
18.5.5.4 The CFI_deallocate function 1 Synopsis. Deallocate memory for an object described by a C descriptor. int CFI_deallocate(CFI_cdesc_t *dv);2 Formal Parameter. dv shall be the address of a C descriptor describing the object. It shall have been allocated
using the same mechanism as the Fortran ALLOCATE statement. If the object is a pointer, it shall be associated3 Description. Successful execution of CFI_deallocate deallocates memory for the object using the same mech-with a target satisfying the conditions for successful deallocation by the Fortran DEALLOCATE statement
(9.7.3).
anism as the Fortran DEALLOCATE statement, and the base_addr member of the C descriptor becomes a null4 Result Value. The result is an error indicator.pointer.
If an error is detected, the C descriptor is not modified.
5 Example. If dv is the address of a C descriptor for the Fortran array A declared as
REAL, ALLOCATABLE :: A(:, :)and the array is allocated, the following code deallocates it:
int ind;ind = CFI_deallocate(dv);
18.5.5.5 The CFI_establish function 1 Synopsis. Establish a C descriptor.
int CFI_establish(CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,2 Formal Parameters.CFI_type_t type, size_t elem_len, CFI_rank_t rank,
const CFI_index_t extents[]);
dv shall be the address of a data object large enough to hold a C descriptor of the rank specified by3 Description. Successful execution of CFI_establish updates the object with the address dv to be an establishedrank. It shall not have the same value as either a C formal parameter that corresponds to a Fortran
actual argument or a C actual argument that corresponds to a Fortran dummy argument. It shall
not be the address of a C descriptor that describes an allocated allocatable object.
base_addr shall be a null pointer or the base address of the object to be described. If it is not a null pointer,
it shall be the address of a contiguous storage sequence that is appropriately aligned (ISO/IEC
9899:2011 3.2) for an object of the type specified by type.
attribute shall be one of the attribute codes in Table 18.3. If it is CFI_attribute_allocatable, base_addr
shall be a null pointer.
type shall be one of the type codes in Table 18.4.
498 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
elem_len If the type is equal to CFI_type_struct, CFI_type_other, or a Fortran character type code, elem_-
len shall be greater than zero and equal to the storage size in bytes of an element of the object.
Otherwise, elem_len will be ignored.
rank shall have a value in the range 0 ≤ rank ≤ CFI_MAX_RANK. It specifies the rank of the object.
extents is ignored if rank is equal to zero or if base_addr is a null pointer. Otherwise, it shall be the address
of an array with rank elements; the value of each element shall be nonnegative, and extents[i]
specifies the extent of dimension i of the object.
C descriptor for a nonallocatable nonpointer data object of known shape, an unallocated allocatable object, or a4 Result Value. The result is an error indicator.data pointer. If base_addr is not a null pointer, it is for a nonallocatable entity that is a scalar or a contiguous
array; if the attribute argument has the value CFI_attribute_pointer, the lower bounds of the object described
by dv are set to zero. If base_addr is a null pointer, the established C descriptor is for an unallocated allocatable,
a disassociated pointer, or is a C descriptor that has the attribute CFI_attribute_other but does not describe
a data object. If base_addr is the C address of a Fortran data object, the type and elem_len arguments shall be
consistent with the type and type parameters of the Fortran data object. The remaining properties of the object
are given by the other arguments.
If an error is detected, the object with the address dv is not modified.
NOTE 18.285 Examples.CFI_establish is used to initialize a C descriptor declared in C with CFI_CDESC_T before passing it to
any other functions as an actual argument, in order to set the rank, attribute, type and element length.
NOTE 18.29
A C descriptor with attribute CFI_attribute_other and base_addr a null pointer can be used as the
argument result in calls to CFI_section or CFI_select_part, which will produce a C descriptor for a
nonallocatable nonpointer data object.
Case (i): The following code fragment establishes a C descriptor for an unallocated rank-one allocatable arraythat can be passed to Fortran for allocation there.
CFI_rank_t rank;
CFI_CDESC_T(1) field;
int ind;
rank = 1;
ind = CFI_establish((CFI_cdesc_t *)&field, NULL, CFI_attribute_allocatable,
CFI_type_double, 0, rank, NULL);
Case (ii): Given the Fortran type definition
TYPE, BIND(C) :: T
REAL(C_DOUBLE) :: X
COMPLEX(C_DOUBLE_COMPLEX) :: Y
END TYPE
and a Fortran subprogram that has an assumed-shape dummy argument of type T, the following
code fragment creates a descriptor a_fortran for an array of size 100 that can be used as the actual
argument in an invocation of the subprogram from C:
typedef struct {double x; double _Complex y;} t;t a_c[100];
CFI_CDESC_T(1) a_fortran;
⃝c ISO/IEC 2017 – All rights reserved 499
ISO/IEC DIS 1539-1:2017 (E)
int ind;CFI_index_t extent[1];
extent[0] = 100;
ind = CFI_establish((CFI_cdesc_t *)&a_fortran, a_c, CFI_attribute_other,
CFI_type_struct, sizeof(t), 1, extent);
18.5.5.6 The CFI_is_contiguous function 1 Synopsis. Test contiguity of an array. int CFI_is_contiguous(const CFI_cdesc_t * dv);2 Formal Parameter. dv shall be the address of a C descriptor describing an array. The base_addr member of
the C descriptor shall not be a null pointer.3 Result Value. The value of the result is 1 if the array described by dv is contiguous, and 0 otherwise.
NOTE 18.30Assumed-size and allocatable arrays are always contiguous, and therefore the result of CFI_is_contiguous
on a C descriptor for such an array will be equal to 1.
18.5.5.7 The CFI_section function 1 Synopsis. Update a C descriptor for an array section for which each element is an element of a given array. int CFI_section(CFI_cdesc_t *result, const CFI_cdesc_t *source,2 Formal Parameters.const CFI_index_t lower_bounds[], const CFI_index_t upper_bounds[],
const CFI_index_t strides[]);
result shall be the address of a C descriptor with rank equal to the rank of source minus the number of3 Description. Successful execution of CFI_section updates the base_addr and dim members of the C descriptorzero strides. The attribute member shall have the value CFI_attribute_other or CFI_attribute_-
pointer. If the value of result is the same as either a C formal parameter that corresponds to a
Fortran actual argument or a C actual argument that corresponds to a Fortran dummy argument,
the attribute member shall have the value CFI_attribute_pointer.
source shall be the address of a C descriptor that describes a nonallocatable nonpointer array, an allocated
allocatable array, or an associated array pointer. The elem_len and type members of source shall
have the same values as the corresponding members of result.
lower_bounds shall be a null pointer or the address of an array with at least source->rank elements. If it is not
a null pointer, and stridei is zero or (upperi − lower_bounds[i] + stridei )/stridei > 0, the value
of lower_bounds[i] shall be within the bounds of dimension i of SOURCE.
upper_bounds shall be a null pointer or the address of an array with at least source->rank elements. If source
describes an assumed-size array, upper_bounds shall not be a null pointer. If it is not a null pointer
and stridei is zero or (upper_bounds[i] − loweri + stridei )/stridei > 0, the value of upper_-
bounds[i] shall be within the bounds of dimension i of SOURCE.
strides shall be a null pointer or the address of an array with at least source->rank elements.
with the address result to describe the array section determined by source, lower_bounds, upper_bounds, and4 Result Value. The result is an error indicator.strides, as follows.
500 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
The array section is equivalent to the Fortran array section SOURCE(sectsub1 , sectsub2 , ... sectsubn ), where
SOURCE is the array described by source, n is the rank of that array, and sectsubi is the subscript loweri if
stridei is zero, and the section subscript loweri : upperi : stridei otherwise. The value of loweri is the lower
bound of dimension i of SOURCE if lower_bounds is a null pointer and lower_bounds[i] otherwise. The value
of upperi is the upper bound of dimension i of SOURCE if upper_bounds is a null pointer and upper_bounds[i]
otherwise. The value of stridei is 1 if strides is a null pointer and strides[i] otherwise. If stridei has the
value zero, loweri shall have the same value as upperi .
If an error is detected, the C descriptor with the address result is not modified.
5 Examples.
Case (i): If source is already the address of a C descriptor for the rank-one Fortran array A, the lower1 Synopsis. Update a C descriptor for an array section for which each element is a part of the correspondingbounds of A are equal to 1, and the lower bounds in the C descriptor are equal to 0, the following
code fragment establishes a new C descriptor section and updates it to describe the array section
A(3::5):
CFI_index_t lower[1], strides[1];
CFI_CDESC_T(1) section;
int ind;
lower[0] = 2;
strides[0] = 5;
ind = CFI_establish((CFI_cdesc_t *)§ion, NULL, CFI_attribute_other,
CFI_type_float, 0, 1, NULL);
ind = CFI_section((CFI_cdesc_t *)§ion, source, lower, NULL, strides);
Case (ii): If source is already the address of a C descriptor for a rank-two Fortran assumed-shape array A
with lower bounds equal to 1, the following code fragment establishes a C descriptor and updates
it to describe the rank-one array section A(:, 42).
CFI_index_t lower[2], upper[2], strides[2];
CFI_CDESC_T(1) section;
int ind;
lower[0] = source->dim[0].lower_bound;
upper[0] = source->dim[0].lower_bound + source->dim[0].extent - 1;
strides[0] = 1;
lower[1] = upper[1] = source->dim[1].lower_bound + 41;
strides[1] = 0;
ind = CFI_establish((CFI_cdesc_t *)§ion, NULL, CFI_attribute_other,
CFI_type_float, 0, 1, NULL);
ind = CFI_section((CFI_cdesc_t *)§ion, source, lower, upper, strides);
18.5.5.8 The CFI_select_part function
element of an array.2 Formal Parameters.int CFI_select_part(CFI_cdesc_t *result, const CFI_cdesc_t *source, size_t displacement,
size_t elem_len);
result shall be the address of a C descriptor; result->rank shall have the same value as source->rank3 Description. Successful execution of CFI_select_part updates the base_addr, dim, and elem_len members ofand result->attribute shall have the value CFI_attribute_other or CFI_attribute_pointer. If
⃝c ISO/IEC 2017 – All rights reserved 501
ISO/IEC DIS 1539-1:2017 (E)
the address specified by result is the value of a C formal parameter that corresponds to a For-
tran actual argument or of a C actual argument that corresponds to a Fortran dummy argument,
result->attribute shall have the value CFI_attribute_pointer. The value of result->type spe-
cifies the type of the array section.
source shall be the address of a C descriptor for an allocated allocatable array, an associated array pointer,
or a nonallocatable nonpointer array that is not assumed-size.
displacement shall have a value 0 ≤ displacement ≤ source->elem_len −1, and the sum of the displacement
and the size in bytes of an element of the array section shall be less than or equal to source->elem_-
len. The address displacement bytes greater than the value of source->base_addr is the base of
the array section and shall be appropriately aligned (ISO/IEC 9899:2011, 3.2) for an object of the
type of the array section.
elem_len shall have a value equal to the storage size in bytes of an element of the array section if result->type
specifies a Fortran character type; otherwise, elem_len is ignored.
the C descriptor with the address result for an array section for which each element is a part of the corresponding4 Result Value. The result is an error indicator.element of the array described by the C descriptor with the address source. The part shall be a component of a
structure, a substring, or the real or imaginary part of a complex value.
If an error is detected, the C descriptor with the address result is not modified.
5 Example. If source is already the address of a C descriptor for the Fortran array A declared with
TYPE, BIND(C) :: TREAL(C_DOUBLE) :: X
COMPLEX(C_DOUBLE_COMPLEX) :: Y
END TYPE
TYPE(T) A(100)
the following code fragment establishes a C descriptor for the array A%Y:
typedef struct {double x; double _Complex y;
} t;
CFI_CDESC_T(1) component;
CFI_cdesc_t * comp_cdesc = (CFI_cdesc_t *)&component;
CFI_index_t extent[] = { 100 };
(void)CFI_establish(comp_cdesc, NULL, CFI_attribute_other, CFI_type_double_Complex,
sizeof(double _Complex), 1, extent);
(void)CFI_select_part(comp_cdesc, source, offsetof(t,y), 0);
18.5.5.9 The CFI_setpointer function 1 Synopsis. Update a C descriptor for a Fortran pointer to be associated with the whole of a given object or to
be disassociated.2 Formal Parameters.int CFI_setpointer(CFI_cdesc_t *result, CFI_cdesc_t *source,
const CFI_index_t lower_bounds[]);
502 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
result shall be the address of a C descriptor for a Fortran pointer. It is updated using information fromthe source and lower_bounds arguments.
source shall be a null pointer or the address of a C descriptor for an allocated allocatable object, a data
pointer object, or a nonallocatable nonpointer data object that is not an assumed-size array. If
source is not a null pointer, the corresponding values of the elem_len, rank, and type members
shall be the same in the C descriptors with the addresses source and result.
lower_bounds If source is not a null pointer and source->rank is nonzero, lower_bounds shall be a null pointer
or the address of an array with at least source->rank elements.
3 Description. Successful execution of CFI_setpointer updates the base_addr and dim members of the C descriptor with the address result as follows:4 Result Value. The result is an error indicator.• if source is a null pointer or the address of a C descriptor for a disassociated pointer, the updated C
descriptor describes a disassociated pointer;
• otherwise, the C descriptor with the address result becomes a C descriptor for the object described by
the C descriptor with the address source, except that if source->rank is nonzero and lower_bounds is
not a null pointer, the lower bounds are replaced by the values of the first source->rank elements of the
lower_bounds array.
If an error is detected, the C descriptor with the address result is not modified.
5 Example. If ptr is already the address of a C descriptor for an array pointer of rank 1, the following code updates it to be a C descriptor for a pointer to the same array with lower bound 0.1 A C descriptor shall not be initialized, updated, or copied other than by calling the functions specified in 18.5.5.CFI_index_t lower_bounds[1];
int ind;
lower_bounds[0] = 0;
ind = CFI_setpointer(ptr, ptr, lower_bounds);
18.6 Restrictions on C descriptors
2 If the address of a C descriptor is a formal parameter that corresponds to a Fortran actual argument or a C
actual argument that corresponds to a Fortran dummy argument,3 If the address of a C descriptor is a C actual argument that corresponds to an assumed-shape Fortran dummy• the C descriptor shall not be modified if either the corresponding dummy argument in the Fortran interface
has the INTENT (IN) attribute or the C descriptor is for a nonallocatable nonpointer object, and
• the base_addr member of the C descriptor shall not be accessed before it is given a value if the corresponding
dummy argument in the Fortran interface has the POINTER and INTENT (OUT) attributes.
NOTE 18.31
In this context, modification refers to any change to the location or contents of the C descriptor, including
establishment and update. The intent of these restrictions is that C descriptors remain intact at all times
they are accessible to an active Fortran procedure, so that the Fortran code is not required to copy them.
argument, that descriptor shall not be for an assumed-size array.1 Within a C function, an allocatable object shall be allocated or deallocated only by execution of the CFI_-⃝c ISO/IEC 2017 – All rights reserved 503
ISO/IEC DIS 1539-1:2017 (E)
18.7 Restrictions on formal parameters
allocate and CFI_deallocate functions. A Fortran pointer can become associated with a target by execution of2 Calling CFI_allocate or CFI_deallocate for a C descriptor changes the allocation status of the Fortran variablethe CFI_allocate function.
it describes.3 If the address of an object is the value of a formal parameter that corresponds to a nonpointer dummy argument
in an interface with the BIND attribute, then4 If a formal parameter that is a pointer to CFI_cdesc_t corresponds to a dummy argument in an interoperable• if the dummy argument has the INTENT (IN) attribute, the object shall not be defined or become undefined,
and
• if the dummy argument has the INTENT (OUT) attribute, the object shall not be referenced before it is
defined.
procedure interface, a pointer based on the base_addr in that C descriptor shall not be used to access memory1 A C descriptor of, or C pointer to, any part of a Fortran object becomes undefined under the same conditionsthat is not part of the object described by the C descriptor.
18.8 Restrictions on lifetimes
that the association status of a Fortran pointer associated with that object would become undefined, and any2 A C descriptor whose address is a formal parameter that corresponds to a Fortran dummy argument becomesfurther use of it is undefined behavior (ISO/IEC 9899:2011, 3.4.3).
undefined on return from a call to the function from Fortran. If the dummy argument does not have either the3 If the address of a C descriptor is passed as an actual argument to a Fortran procedure, the lifetime (ISO/IECTARGET or ASYNCHRONOUS attribute, all C pointers to any part of the object described by the C descriptor
become undefined on return from the call, and any further use of them is undefined behavior.
9899:2011, 6.2.4) of the C descriptor shall not end before the return from the procedure call. If an object is passed4 If the lifetime of a C descriptor for an allocatable object that was established by C ends before the program exits,to a Fortran procedure as a nonallocatable, nonpointer dummy argument, its lifetime shall not end before the
return from the procedure call.
the object shall be unallocated at that time.5 If a Fortran pointer becomes associated with a data object defined by the companion processor, the association
status of the Fortran pointer becomes undefined when the lifetime of that data object ends.NOTE 18.32
The following example illustrates how a C descriptor becomes undefined upon returning from a call to a C
function.
REAL, TARGET :: X(1000), B
INTERFACE
REAL FUNCTION CFUN(ARRAY) BIND(C, NAME="Cfun")
REAL ARRAY(:)
END FUNCTION
END INTERFACE
B = CFUN(X)
1 A C variable whose name has external linkage may interoperate with a common block or with a variable declared in
504 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)NOTE 18.32 (cont.)
Cfun is a C function. Before or during the invocation of Cfun, the processor will create a C descriptor
for the array x. On return from Cfun, that C descriptor will become undefined. In addition, because the
dummy argument ARRAY does not have the TARGET or ASYNCHRONOUS attribute, a C pointer whose
value was set during execution of Cfun to be the address of any part of X will become undefined.
18.9 Interoperation with C global variables
18.9.1 General
the scope of a module. The common block or variable shall be specified to have the BIND attribute.2 At most one variable that is associated with a particular C variable whose name has external linkage is permitted
to be declared within all the Fortran program units of a program. A variable shall not be initially defined by3 If a common block is specified in a BIND statement, it shall be specified in a BIND statement with the same binding label in eachmore than one processor.
scoping unit in which it is declared. A C variable whose name has external linkage interoperates with a common block that has been4 There does not have to be an associated C entity for a Fortran entity with the BIND attribute.specified in a BIND statement if
• the C variable is of a struct type and the variables that are members of the common block are interoperable with corresponding
components of the struct type, or
• the common block contains a single variable, and the variable is interoperable with the C variable.
NOTE 18.33The following are examples of the usage of the BIND attribute for variables and for a common block. The
Fortran variables, C_EXTERN and C2, interoperate with the C variables, c_extern and myVariable,
respectively. The Fortran common blocks, COM and SINGLE, interoperate with the C variables, com and single, respectively.
MODULE LINK_TO_C_VARS
USE, INTRINSIC :: ISO_C_BINDING
INTEGER(C_INT), BIND(C) :: C_EXTERN
INTEGER(C_LONG) :: C2
BIND(C, NAME=’myVariable’) :: C2
COMMON /COM/ R, S
REAL(C_FLOAT) :: R, S, T
BIND(C) :: /COM/, /SINGLE/
COMMON /SINGLE/ T
END MODULE LINK_TO_C_VARS
/* Global variables. */
int c_extern;
long myVariable;
struct { float r, s; } com;
float single;
1 The binding label of a variable or common block is a default character value that specifies the name by which the
⃝c ISO/IEC 2017 – All rights reserved 505
ISO/IEC DIS 1539-1:2017 (E)
18.9.2 Binding labels for common blocks and variables
variable or common block is known to the companion processor.2 If a variable or common block has the BIND attribute with the NAME= specifier and the value of its expression,
after discarding leading and trailing blanks, has nonzero length, the variable or common block has this as its binding3 The binding label of a C variable whose name has external linkage is the same as the name of the C variable. Alabel. The case of letters in the binding label is significant. If a variable or common block has the BIND attribute
specified without a NAME= specifier, the binding label is the same as the name of the entity using lower case
letters. Otherwise, the variable or common block has no binding label.
Fortran variable or common block with the BIND attribute that has the same binding label as a C variable whose1 A procedure that is interoperable may be defined either by means other than Fortran or by means of a Fortranname has external linkage is linkage associated (19.5.1.5) with that variable.
18.10 Interoperation with C functions
18.10.1 Definition and reference of interoperable procedures
subprogram, but not both. A C function that has an inline definition and no external definition is not considered2 If the procedure is defined by means other than Fortran,to be defined in this sense.
• it shall be describable by a C prototype that is interoperable with the interface, and3 A reference to such a procedure causes the function described by the C prototype to be called as specified in• if it is accessed using its binding label, it shall
– have a name that has external linkage as defined by 6.2.2 of ISO/IEC 9899:2011, and
– have the same binding label as the interface.
ISO/IEC 9899:2011.4 A reference in C to a procedure that has the BIND attribute, has the same binding label, and is defined by means
of Fortran, causes the Fortran procedure to be invoked. A C function shall not invoke a function pointer whose5 A procedure defined by means of Fortran shall not invoke setjmp or longjmp (ISO/IEC 9899:2011, 7.13). If avalue is the result of a reference to C_FUNLOC with a noninteroperable argument.
procedure defined by means other than Fortran invokes setjmp or longjmp, that procedure shall not cause any6 If a procedure defined by means of Fortran and a procedure defined by means other than Fortran performprocedure defined by means of Fortran to be invoked. A procedure defined by means of Fortran shall not be
invoked as a signal handler (ISO/IEC 9899:2011, 7.14.1).
input/output operations on the same external file, the results are processor dependent (12.5.4).7 If the value of a C function pointer will be the result of a reference to C_FUNLOC with a noninteroperable
argument, it is recommended that the C function pointer be declared to have the type void (*)().1 The binding label of a procedure is a default character value that specifies the name by which a procedure with18.10.2 Binding labels for procedures
the BIND attribute is known to the companion processor.2 If a procedure has the BIND attribute with the NAME= specifier and the value of its expression, after discarding
leading and trailing blanks, has nonzero length, the procedure has this as its binding label. The case of letters3 The binding label for a C function whose name has external linkage is the same as the C function name.in the binding label is significant. If a procedure has the BIND attribute with no NAME= specifier, and the
506 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
procedure is not a dummy procedure, internal procedure, or procedure pointer, then the binding label of the
procedure is the same as the name of the procedure using lower case letters. Otherwise, the procedure has no
binding label.
C1807 A procedure defined in a submodule shall not have a binding label unless its interface is declared in the
ancestor module.
NOTE 18.34In the following sample, the binding label of C_SUB is "c_sub", and the binding label of C_FUNC is
"C_funC".
SUBROUTINE C_SUB() BIND(C)
...
END SUBROUTINE C_SUB
INTEGER(C_INT) FUNCTION C_FUNC() BIND(C, NAME="C_funC")
USE, INTRINSIC :: ISO_C_BINDING...
END FUNCTION C_FUNC
ISO/IEC 9899:2011 permits functions to have names that are not permitted as Fortran names; it also
distinguishes between names that would be considered as the same name in Fortran. For example, a C
name can begin with an underscore, and C names that differ in case are distinct names.
The specification of a binding label allows a program to use a Fortran name to refer to a procedure defined
by a companion processor.
18.10.3 Exceptions and IEEE arithmetic procedures 1 A procedure defined by means other than Fortran shall not use signal (ISO/IEC 9899:2011, 7.14.1) to change the
handling of any exception that is being handled by the Fortran processor.2 A procedure defined by means other than Fortran shall not alter the floating-point status (17.7) other than by
setting an exception flag to signaling.3 The values of the floating-point exception flags on entry to a procedure defined by means other than Fortran are
processor dependent.1 Asynchronous communication for a Fortran variable with the ASYNCHRONOUS attribute occurs through the18.10.4 Asynchronous communication
action of procedures defined by means other than Fortran. It is initiated by execution of an asynchronous2 Asynchronous communication is either input communication or output communication. For input communication,communication initiation procedure and completed by execution of an asynchronous communication completion
procedure. Between the execution of the initiation and completion procedures, any variable of which any part
is associated with any part of the asynchronous communication variable is a pending communication affector.
Whether a procedure is an asynchronous communication initiation or completion procedure is processor depend-
ent.
a pending communication affector shall not be referenced, become defined, become undefined, become associatedISO/IEC DIS 1539-1:2017 (E)with a dummy argument that has the VALUE attribute, or have its pointer association status changed. For
output communication, a pending communication affector shall not be redefined, become undefined, or have its
pointer association status changed. The restrictions for asynchronous input communication are the same as for
⃝c ISO/IEC 2017 – All rights reserved 507
asynchronous input data transfer. The restrictions for asynchronous output communication are the same as for
asynchronous output data transfer.
NOTE 18.35Asynchronous communication can be used for nonblocking MPI calls such as MPI_IRECV and MPI_-
ISEND. For example,
REAL :: BUF(100,100)
... ! Code that involves BUF
BLOCK
ASYNCHRONOUS :: BUF
CALL MPI_IRECV(BUF,...REQ,...)
... ! Code that does not involve BUFCALL MPI_WAIT(REQ,...)
END BLOCK
... ! Code that involves BUF
In this example, there is asynchronous input communication and BUF is a pending communication affector
between the two calls. MPI_IRECV can return while the communication (reading values into BUF) is still
underway. The intent is that the code between MPI_IRECV and MPI_WAIT can execute without waiting
for this communication to complete.
Similar code with the call of MPI_IRECV replaced by a call of MPI_ISEND is asynchronous output
communication.
508 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)19 Scope, association, and definition
19.1 Scopes, identifiers, and entities 1 An entity is identified by an identifier. 2 The scope of
• a global identifier is a program (5.2.2),excluding any nested scope where the identifier is treated as the identifier of a different entity (19.3, 19.4), or• a local identifier is an inclusive scope,
• an identifier of a construct entity is that construct (10.2.4, 11.1), and
• an identifier of a statement entity is that statement or part of that statement (6.3),
where an IMPORT statement (8.8) makes the identifier inaccessible.
3 An entity may be identified by
• an image index (3.85),4 By means of association, an entity may be referred to by the same identifier or a different identifier in a different• a name (3.103),
• a statement label (3.135),
• an external input/output unit number (12.5),
• an identifier of a pending data transfer operation (12.6.2.9, 12.7),
• a submodule identifier (14.2.3),
• a generic identifier (3.79), or
• a binding label (3.15).
scope, or by a different identifier in the same scope.1 Program units, common blocks, external procedures, entities with binding labels, external input/output units,19.2 Global identifiers
pending data transfer operations, and images are global entities of a program. The name of a common block with2 The global identifier of an entity shall not be the same as the global identifier of any other entity. Furthermore, ano binding label, external procedure with no binding label, or program unit that is not a submodule is a global
identifier. The submodule identifier of a submodule is a global identifier. A binding label of an entity of the
program is a global identifier. An entity of the program shall not be identified by more than one binding label.
binding label shall not be the same as the global identifier of any other global entity, ignoring differences in case.1 Identifiers of entities, other than statement or construct entities (19.4), in the classesA processor may assign a global identifier to an entity that is not specified by this document to have a global
identifier (such as an intrinsic procedure); in such a case, the processor shall ensure that this assigned global
identifier differs from all other global identifiers in the program.
NOTE 19.1
An intrinsic module is not a program unit, so a global identifier can be the same as the name of an intrinsic
module.
⃝c ISO/IEC 2017 – All rights reserved 509
ISO/IEC DIS 1539-1:2017 (E)
NOTE 19.2
Submodule identifiers are global identifiers, but because they consist of a module name and a descendant
submodule name, the name of a submodule can be the same as the name of another submodule so long as
they do not have the same ancestor module.
19.3 Local identifiers
19.3.1 Classes of local identifiers
(1) named variables, named constants, named procedure pointers, named constructs, statement functions,are local identifiers.internal procedures, module procedures, dummy procedures, intrinsic procedures, external procedures
that have binding labels, intrinsic modules, abstract interfaces, generic interfaces, derived types,
namelist groups, external procedures accessed via USE, and statement labels,
(2) type parameters, components, and type-bound procedure bindings, in a separate class for each type,
(3) argument keywords, in a separate class for each procedure with an explicit interface, and
(4) common blocks that have binding labels
2 Within its scope, a local identifier of an entity of class (1) or class (4) shall not be the same as a global identifier
used in that scope unless the global identifier3 Within its scope, a local identifier of one class shall not be the same as another local identifier of the same class,• is used only as the use-name of a rename in a USE statement,
• is a common block name (19.3.2),
• is an external procedure name that is also a generic name, or
• is an external function name and the inclusive scope is its defining subprogram (19.3.3).
except that a generic name may be the same as the name of a procedure as explained in 15.4.3.4 or the same asthe name of a derived type (7.5.10). A local identifier of one class may be the same as a local identifier of another
class.
NOTE 19.3
An intrinsic procedure is inaccessible by its own name in a scoping unit that uses the same name as a local
identifier of class (1) for a different entity. For example, in the program fragment
SUBROUTINE SUB
...
A = SIN (K)
...
CONTAINS
FUNCTION SIN (X)
...
END FUNCTION SIN
END SUBROUTINE SUB
any reference to function SIN in subroutine SUB refers to the internal function SIN, not to the intrinsic
function of the same name.
4 A local identifier identifies an entity in a scope and may be used to identify an entity in another scope except in
the following cases.1 A name that identifies a common block in a scoping unit shall not be used to identify a constant or an intrinsic procedure in that510 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
• The name that appears as a subroutine-name in a subroutine-stmt has limited use within the scope estab-
lished by the subroutine-stmt. It can be used to identify recursive references of the subroutine or to identify
a common block (the latter is possible only for internal and module subroutines).
• The name that appears as a function-name in a function-stmt has limited use within the scope established
by that function-stmt. It can be used to identify the function result, to identify recursive references of the
function, or to identify a common block (the latter is possible only for internal and module functions).
• The name that appears as an entry-name in an entry-stmt has limited use within the scope of the subprogram in which
the entry-stmt appears. It can be used to identify the function result if the subprogram is a function, to identify recursive
references, or to identify a common block (the latter is possible only if the entry-stmt is in a module subprogram).
19.3.2 Local identifiers that are the same as common block names
scoping unit. If a local identifier of class (1) is also the name of a common block, the appearance of that name in any context other1 For each FUNCTION statement or ENTRY statement in a function subprogram, there is a function result. A functionthan as a common block name in a BIND, COMMON, or SAVE statement is an appearance of the local identifier.
19.3.3 Function results
result is either a variable or a procedure pointer, and thus the name of a function result is a local identifier of1 A component name has the scope of its derived-type definition. Outside the type definition, it may also appearclass (1).
19.3.4 Components, type parameters, and bindings
within a designator of a component of a structure of that type or as a component keyword in a structure2 A type parameter name has the scope of its derived-type definition. Outside the derived-type definition, it mayconstructor for that type.
also appear as a type parameter keyword in a derived-type-spec for the type or as the type-param-name of a3 The binding name (7.5.5) of a type-bound procedure has the scope of its derived-type definition. Outside of thetype-param-inquiry.
derived-type definition, it may also appear as the binding-name in a procedure reference.4 A generic binding for which the generic-spec is not a generic-name has a scope that consists of all scoping units
in which an entity of the type is accessible.5 A component name or binding name may appear only in a scope in which it is accessible.
6 The accessibility of components and bindings is specified in 7.5.4.8 and 7.5.5.
19.3.5 Argument keywords1 As an argument keyword, a dummy argument name in an internal procedure, module procedure, or an interface
body has a scope of the scoping unit of the host of the procedure or interface body. As an argument keyword,2 A dummy argument name in an intrinsic procedure has a scope as an argument keyword of the scoping unitthe name of a dummy argument of a procedure declared by a procedure declaration statement that specifies an
explicit interface has a scope of the scoping unit containing the procedure declaration statement. It may appear
only in a procedure reference for the procedure of which it is a dummy argument. If the procedure is accessible
in another scoping unit by use or host association (19.5.1.3, 19.5.1.4), the argument keyword is accessible for
procedure references for that procedure in that scoping unit.
⃝c ISO/IEC 2017 – All rights reserved 511
ISO/IEC DIS 1539-1:2017 (E)
in which the reference to the procedure occurs. As an argument keyword, it may appear only in a procedure1 A variable that appears as a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor,reference for the procedure of which it is a dummy argument.
19.4 Statement and construct entities
as a dummy argument in a statement function statement, or as an index-name in a FORALL statement is a statement entity. A2 Even if the name of a statement entity is the same as another identifier and the statement is in the scope of thatvariable that appears as an index-name in a FORALL or DO CONCURRENT, as an associate-name in a SELECT
TYPE or ASSOCIATE construct, or as a coarray-name in a codimension-decl in a CHANGE TEAM construct is
a construct entity. A variable that has LOCAL or LOCAL_INIT locality in a DO CONCURRENT construct is a
construct entity. An entity that is explicitly declared in the specification part of a BLOCK construct, other than
only in ASYNCHRONOUS and VOLATILE statements, is a construct entity. A USE statement in a BLOCK
construct explicitly declares the entities accessed by use association to be construct entities. Two construct
entities of the same construct shall not have the same identifier.
identifier, within the scope of the statement entity the name is interpreted as that of the statement entity.3 The name of a statement entity shall not be the same as an accessible global identifier or local identifier of class
(1) (19.3.1), except for a common block name or a scalar variable name. Within the scope of a statement entity,4 The name of a data-i-do-variable in a DATA statement or an ac-do-variable in an array constructor has a scopeanother statement entity shall not have the same name.
of its data-implied-do or ac-implied-do. It is a scalar variable. If integer-type-spec appears in data-implied-do or5 The name of a variable that appears as an index-name in a DO CONCURRENT construct, FORALL statement, orac-implied-do-control it has the specified type and type parameters; otherwise it has the type and type parameters
that it would have if it were the name of a variable in the innermost executable construct or scoping unit that
includes the DATA statement or array constructor, and this type shall be integer type. It has no other attributes.
The appearance of a name as a data-i-do-variable of an implied DO in a DATA statement or an ac-do-variable
in an array constructor is not an implicit declaration of a variable whose scope is the scoping unit that contains
the statement.
FORALL construct has a scope of the statement or construct. It is a scalar variable. If integer-type-spec appears in6 A variable that has LOCAL or LOCAL_INIT locality in a DO CONCURRENT construct has the scope of thatconcurrent-header it has the specified type and type parameters; otherwise it has the type and type parameters
that it would have if it were the name of a variable in the innermost executable construct or scoping unit that
includes the DO CONCURRENT or FORALL, and this type shall be integer type. It has no other attributes.
The appearance of a name as an index-name in a DO CONCURRENT construct, FORALL statement, or FORALL
construct is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement or
construct.
construct. Its attributes are specified in 11.1.7.5.7 If integer-type-spec does not appear in a concurrent-header, an index-name shall not be the same as an accessible
global identifier, local identifier, or identifier of an outer construct entity, except for a common block name or8 The associate name of a SELECT TYPE construct has a separate scope for each block of the construct. Withina scalar variable name. An index-name of a contained DO CONCURRENT construct, FORALL statement, or
FORALL construct shall not be the same as an index-name of any of its containing DO CONCURRENT or FORALL
constructs.
512 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
each block, it has the declared type, dynamic type, type parameters, rank, and bounds specified in 11.1.11.2.9 The associate names of an ASSOCIATE construct have the scope of the block. They have the declared type,
dynamic type, type parameters, rank, and bounds specified in 11.1.3.2.10 The associate names of a CHANGE TEAM construct have the scope of the block. They have the declared type,
dynamic type, type parameters, rank, corank, bounds, and cobounds specified in 11.1.5.11 The name of a variable that appears as a dummy argument in a statement function statement has a scope of the statement in which
it appears. It is a scalar that has the type and type parameters that it would have if it were the name of a variable in the scoping1 There are five forms of name association: argument association, use association, host association, linkage asso-unit that includes the statement function; it has no other attributes.
19.5 Association
19.5.1 Name association
19.5.1.1 Forms of name association
ciation, and construct association. Argument, use, and host association provide mechanisms by which entities1 The rules governing argument association are given in Clause 15. As explained in 15.5, execution of a procedureknown in one scope may be accessed in another scope.
19.5.1.2 Argument association
reference establishes a correspondence between each actual argument and a dummy argument and thus an associ-2 The name of the dummy argument may be different from the name, if any, of its effective argument. The dummyation between each present dummy argument and its effective argument. Argument association can be sequence
association (15.5.2.11).
argument name is the name by which the effective argument is known, and by which it may be accessed, in the3 Upon termination of execution of a procedure reference, all argument associations established by that referencereferenced procedure.
NOTE 19.4
An effective argument can be a nameless data entity, such as the result of evaluating an expression that is
not simply a variable or constant.
are terminated. A dummy argument of that procedure can be associated with an entirely different effective1 Use association is the association of names in different scopes specified by a USE statement. The rules governingargument in a subsequent invocation of the procedure.
19.5.1.3 Use association
use association are given in 14.2.2. They allow for renaming of entities being accessed. Use association allowsISO/IEC DIS 1539-1:2017 (E)access in one scope to entities defined or declared in another scope; it remains in effect throughout the execution
of the program.
⃝c ISO/IEC 2017 – All rights reserved 513
19.5.1.4 Host association 1 A nested scoping unit has access to named entities from its host as specified in 8.8. A host-associated variable is
considered to have been previously declared; any other host-associated entity is considered to have been previously2 If an entity that is accessed by use association has the same nongeneric name as a host entity, the host entity isdefined. In the case of an internal subprogram, the access is to the entities in its host instance. The accessed
entities are identified by the same identifier and have the same attributes as in the host, except that a local entity
may have the ASYNCHRONOUS attribute even if the host entity does not, and a noncoarray local entity may
have the VOLATILE attribute even if the host entity does not. The accessed entities are named data objects,
derived types, abstract interfaces, procedures, generic identifiers, and namelist groups.
inaccessible by that name. The name of an external procedure that is given the EXTERNAL attribute (8.5.9)3 If a host entity is inaccessible only because a local variable with the same name is wholly or partially initializedwithin the scoping unit, or a name that appears within the scoping unit as a module-name in a use-stmt is a
global identifier; any entity of the host that has this as its nongeneric name is inaccessible by that name. A name
that appears in the scoping unit as
(1) a function-name in a stmt-function-stmt or in an entity-decl in a type-declaration-stmt, unless it is a
global identifier,
(2) an object-name in an entity-decl in a type-declaration-stmt, in a pointer-stmt, in a save-stmt, in an
allocatable-stmt, or in a target-stmt,
(3) a type-param-name in a derived-type-stmt,
(4) a named-constant in a named-constant-def in a parameter-stmt,
(5) a coarray-name in a codimension-stmt,
(6) an array-name in a dimension-stmt,
(7) a variable-name in a common-block-object in a common-stmt,
(8) a procedure pointer given the EXTERNAL attribute in the scoping unit,
(9) the name of a variable that is wholly or partially initialized in a data-stmt,
(10) the name of an object that is wholly or partially equivalenced in an equivalence-stmt,
(11) a dummy-arg-name in a function-stmt, in a subroutine-stmt, in an entry-stmt, or in a stmt-function-stmt ,
(12) a result-name in a function-stmt or in an entry-stmt ,
(13) the name of an entity declared by an interface body, unless it is a global identifier,
(14) an intrinsic-procedure-name in an intrinsic-stmt,
(15) a namelist-group-name in a namelist-stmt,
(16) a generic-name in a generic-spec in an interface-stmt, or
(17) the name of a named construct
is a local identifier in the scoping unit and any entity of the host that has this as its nongeneric name is inaccessible
by that name by host association. If a scoping unit is the host of a derived-type definition or a subprogram that
does not define a separate module procedure, the name of the derived type or of any procedure defined by the
subprogram is a local identifier in the scoping unit; any entity of the host that has this as its nongeneric name is
inaccessible by that name. Local identifiers of a subprogram are not accessible to its host.
NOTE 19.5
A name that appears in an ASYNCHRONOUS or VOLATILE statement is not necessarily the name of a
local variable. In an internal or module procedure, if a variable that is accessible via host association is spe-
cified in an ASYNCHRONOUS or VOLATILE statement, that host variable is given the ASYNCHRONOUS
or VOLATILE attribute in the local scope.
514 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
in a DATA statement, the local variable shall not be referenced or defined prior to the DATA statement.4 If a derived-type name of a host is inaccessible, data entities of that type or subobjects of such data entities still
can be accessible.5 If an external or dummy procedure with an implicit interface is accessed via host association, then it shall haveNOTE 19.6
An interface body that is not a module procedure interface body accesses by host association only those
entities made accessible by IMPORT statements.
the EXTERNAL attribute in the host scoping unit; if it is invoked as a function in the inner scoping unit, its type6 If an intrinsic procedure is accessed via host association, then it shall be established to be intrinsic in the hostand type parameters shall be established in the host scoping unit. The type and type parameters of a function
with the EXTERNAL attribute are established in a scoping unit if that scoping unit explicitly declares them,
invokes the function, accesses the function from a module, or accesses the function from its host where its type
and type parameters are established.
scoping unit. An intrinsic procedure is established to be intrinsic in a scoping unit if that scoping unit explicitlygives it the INTRINSIC attribute, invokes it as an intrinsic procedure, accesses it from a module, or accesses it
from its host where it is established to be intrinsic.
NOTE 19.7
A host subprogram and an internal subprogram can contain the same and differing use-associated entities,
as illustrated in the following example.
MODULE B; REAL BX, Q; INTEGER IX, JX; END MODULE B
MODULE C; REAL CX; END MODULE C
MODULE D; REAL DX, DY, DZ; END MODULE D
MODULE E; REAL EX, EY, EZ; END MODULE E
MODULE F; REAL FX; END MODULE F
MODULE G; USE F; REAL GX; END MODULE G
PROGRAM A
USE B; USE C; USE D
...
CONTAINS
SUBROUTINE INNER_PROC (Q)
USE C ! Not neededUSE B, ONLY: BX ! Entities accessible are BX, IX, and JX
! if no other IX or JX
! is accessible to INNER_PROC
! Q is local to INNER_PROC,
! because Q is a dummy argument
USE D, X => DX ! Entities accessible are DX, DY, and DZ
! X is local name for DX in INNER_PROC
! X and DX denote same entity if no other
! entity DX is local to INNER_PROC
USE E, ONLY: EX ! EX is accessible in INNER_PROC, not in program A
⃝c ISO/IEC 2017 – All rights reserved 515
ISO/IEC DIS 1539-1:2017 (E)
NOTE 19.7 (cont.)! EY and EZ are not accessible in INNER_PROC
! or in program A
USE G ! FX and GX are accessible in INNER_PROC
...
END SUBROUTINE INNER_PROC
END PROGRAM A
Because program A contains the statement
USE B
all of the entities in module B, except for Q, are accessible in INNER_PROC, even though INNER_PROC
contains the statement
USE B, ONLY: BX
The USE statement with the ONLY option means that this particular statement brings in only the entity
named, not that this is the only variable from the module accessible in this scoping unit.
NOTE 19.8
For more examples of host association, see subclause C.13.
19.5.1.5 Linkage association 1 Linkage association occurs between a module variable that has the BIND attribute and the C variable with which
it interoperates, or between a Fortran common block and the C variable with which it interoperates (18.9). Such association1 Execution of a SELECT RANK or SELECT TYPE statement establishes an association between the selector andremains in effect throughout the execution of the program.
19.5.1.6 Construct association
the associate name of the construct. Execution of an ASSOCIATE or CHANGE TEAM statement statement2 In an ASSOCIATE or SELECT TYPE construct, the following rules apply.establishes an association between each selector and the corresponding associate name of the construct.
• If a selector is allocatable, it shall be allocated; the associate name is associated with the data object and3 If the selector is a variable other than an array section having a vector subscript, the association is with the datadoes not have the ALLOCATABLE attribute.
• If a selector has the POINTER attribute, it shall be associated; the associate name is associated with the
target of the pointer and does not have the POINTER attribute.
object specified by the selector; otherwise, the association is with the value of the selector expression, which is4 Each associate name remains associated with the corresponding selector throughout the execution of the executedevaluated prior to execution of the block.
block. Within the block, each selector is known by and may be accessed by the corresponding associate name.1 Pointer association between a pointer and a target allows the target to be referenced by a reference to the pointer.On completion of execution of the construct, the association is terminated.
516 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
NOTE 19.9
The association between the associate name and a data object is established prior to execution of the block
and is not affected by subsequent changes to variables that were used in subscripts or substring ranges in
the selector.
19.5.2 Pointer association
19.5.2.1 General
At different times during the execution of a program, a pointer may be undefined, associated with different targets1 A pointer may have a pointer association status of associated, disassociated, or undefined. Its association statuson its own image, or be disassociated. If a pointer is associated with a target, the definition status of the pointer
is either defined or undefined, depending on the definition status of the target. If the pointer has deferred type
parameters or shape, their values are assumed from the target. If the pointer is polymorphic, its dynamic type
is assumed from the dynamic type of the target.
19.5.2.2 Pointer association status
may change during execution of a program. Unless a pointer is initialized (explicitly or by default), it has an1 A pointer becomes associated when any of the following events occur.initial association status of undefined. A pointer may be initialized to have an association status of disassociated
or associated.
NOTE 19.10
A pointer from a module program unit might be accessible in a subprogram via use association. Such
pointers have a lifetime that is greater than targets that are declared in the subprogram, unless such targets
are saved. Therefore, if such a pointer is associated with a local target, there is the possibility that when
a procedure defined by the subprogram completes execution, the target will cease to exist, leaving the
pointer “dangling”. This document considers such pointers to have an undefined association status. They
are neither associated nor disassociated. They cannot be used again in the program until their status has
been reestablished. A processor is not required to detect when a pointer target ceases to exist.
19.5.2.3 Events that cause pointers to become associated
(1) The pointer is allocated (9.7.1) as the result of the successful execution of an ALLOCATE statementreferencing the pointer.
(2) The pointer is pointer-assigned to a target (10.2.2) that is associated or is specified with the TARGET
attribute and, if allocatable, is allocated.
(3) The pointer is a subobject of an object that is allocated by an ALLOCATE statement in which
SOURCE= appears and the corresponding subobject of source-expr is associated.
(4) The pointer is a dummy argument and its corresponding actual argument is not a pointer.
(5) The pointer is a default-initialized subcomponent of an object, the corresponding initializer is not a
reference to the intrinsic function NULL, and
(a) a procedure is invoked with this object as an actual argument corresponding to a nonpointer
nonallocatable dummy argument with INTENT (OUT),
⃝c ISO/IEC 2017 – All rights reserved 517
ISO/IEC DIS 1539-1:2017 (E)
(b) a procedure with this object as an unsaved nonpointer nonallocatable local variable is invoked,(c) a BLOCK construct is entered and this object is an unsaved local nonpointer nonallocatable
local variable of the BLOCK construct,
or
(d) this object is allocated other than by an ALLOCATE statement in which SOURCE= appears.
19.5.2.4 Events that cause pointers to become disassociated 1 A pointer becomes disassociated when (1) the pointer is nullified (9.7.2),(2) the pointer is deallocated (9.7.3),
(3) the pointer is pointer-assigned (10.2.2) to a disassociated pointer,
(4) the pointer is a subobject of an object that is allocated by an ALLOCATE statement in which
SOURCE= appears and the corresponding subobject of source-expr is disassociated,
or
(5) the pointer is a default-initialized subcomponent of an object, the corresponding initializer is a
reference to the intrinsic function NULL, and
(a) a procedure is invoked with this object as an actual argument corresponding to a nonpointer
nonallocatable dummy argument with INTENT (OUT),
(b) a procedure with this object as an unsaved nonpointer nonallocatable local variable is invoked,
(c) a BLOCK construct is entered and this object is an unsaved local nonpointer nonallocatable
local variable of the BLOCK construct,
or
(d) this object is allocated other than by an ALLOCATE statement in which SOURCE= appears.
19.5.2.5 Events that cause the association status of pointers to become undefined 1 The association status of a pointer becomes undefined when (1) the pointer is pointer-assigned to a target that has an undefined association status,(2) the pointer is pointer-assigned to a target on a different image,
(3) the target of the pointer is deallocated other than through the pointer,
(4) the target of the pointer is a data object defined by the companion processor and the lifetime of that
data object ends,
(5) the allocation transfer procedure (16.9.137) is executed, the pointer is associated with the argument
FROM, and the argument TO does not have the TARGET attribute,
(6) completion of execution of an instance of a subprogram causes the pointer’s target to become un-
defined (item (3) of 19.6.6),
(7) completion of execution of a BLOCK construct causes the pointer’s target to become undefined (item
(23) of 19.6.6),
(8) execution of the host instance of a procedure pointer is completed,
(9) execution of an instance of a subprogram completes and the pointer is declared or accessed in the
subprogram that defines the procedure if the pointer
(a) does not have the SAVE attribute,
518 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
(b) is not in blank common, (c) is not in a named common block that is declared in any other scoping unit that is in execution, (d) is not accessed by host association, and (e) is not the result of a function declared to have the POINTER attribute, (10) execution of an instance of a subprogram completes, the pointer is associated with a dummy argument of the procedure, and(11) a BLOCK construct completes execution and the pointer is an unsaved construct entity of that(a) the effective argument does not have the TARGET attribute or is an array section with a
vector subscript, or
(b) the dummy argument has the VALUE attribute,
BLOCK construct,(12) a DO CONCURRENT construct is terminated and the pointer’s association status was changed in
more than one iteration of the construct,(13) an iteration of a DO CONCURRENT construct completes and the pointer is associated with a
variable of that construct that has LOCAL or LOCAL_INIT locality,(14) the pointer is a subcomponent of an object that is allocated and either
(a) the pointer is not default-initialized and SOURCE= does not appear, or(15) the pointer is a subcomponent of an object, the pointer is not default-initialized, and a procedure is(b) SOURCE= appears and the association status of the corresponding subcomponent of source-
expr is undefined,
invoked with this object as an actual argument corresponding to a dummy argument with INTENT(16) a procedure is invoked with the pointer as an actual argument corresponding to a pointer dummy(OUT),
argument with INTENT (OUT), or(17) evaluation of an expression containing a function reference that need not be evaluated completes, if
execution of that function would change the association status of the pointer.
19.5.2.6 Other events that change the association status of pointers 1 When a pointer becomes associated with another pointer by argument association, construct association, or host association, the effects on its association status are specified in 19.5.5.2 While two pointers are name associated, storage associated, or inheritance associated, if the association status of
one pointer changes, the association status of the other changes accordingly.3 The association status of a pointer object with the VOLATILE attribute might change by means not specified
by the program.1 The definition status of an associated pointer is that of its target. If a pointer is associated with a definable19.5.2.7 Pointer definition status
target, it may be defined or become undefined according to the rules for a variable (19.6). The definition status1 If the association status of a pointer is disassociated or undefined, the pointer shall not be referenced or dealloc-of a pointer that is not associated is undefined.
⃝c ISO/IEC 2017 – All rights reserved 519
ISO/IEC DIS 1539-1:2017 (E)
19.5.2.8 Relationship between association status and definition status
ated. Whatever its association status, a pointer always may be nullified, allocated, or pointer-assigned. A nullified1 Storage sequences are used to describe relationships that exist among variables and common blocks. Storage asso-pointer is disassociated. When a pointer is allocated, it becomes associated but undefined. When a pointer is
pointer-assigned, its association and definition status become those of the specified data-target or proc-target.
19.5.3 Storage association
19.5.3.1 General
ciation is the association of two or more data objects that occurs when two or more storage sequences share or1 A storage sequence is a sequence of storage units. The size of a storage sequence is the number of storage unitsare aligned with one or more storage units.
19.5.3.2 Storage sequence
in the storage sequence. A storage unit is a character storage unit, a numeric storage unit, a file storage unit2 In a storage association context(12.3.5), or an unspecified storage unit. The sizes of the numeric storage unit, the character storage unit and the
file storage unit are the values of constants in the ISO_FORTRAN_ENV intrinsic module (16.10.2).
(1) a nonpointer scalar object that is default integer, default real, or default logical occupies a single3 A sequence of storage sequences forms a storage sequence. The order of the storage units in such a compositenumeric storage unit,
(2) a nonpointer scalar object that is double precision real or default complex occupies two contiguous
numeric storage units,
(3) a default character nonpointer scalar object of character length len occupies len contiguous character
storage units,
(4) if C character kind is not the same as default character kind a nonpointer scalar object of type char-
acter with the C character kind (18.2.2) and character length len occupies len contiguous unspecified
storage units,
(5) a nonpointer scalar object of sequence type occupies a sequence of storage sequences corresponding
to the sequence of its ultimate components,
(6) a nonpointer scalar object of any type not specified in items (1)-(5) occupies a single unspecified
storage unit that is different for each case and each set of type parameter values, and that is different
from the unspecified storage units of item (4),
(7) a nonpointer array occupies a sequence of contiguous storage sequences, one for each array element,
in array element order (9.5.3.2), and
(8) a data pointer occupies a single unspecified storage unit that is different from that of any nonpointer
object and is different for each combination of type, type parameters, and rank. A data pointer that
has the CONTIGUOUS attribute occupies a storage unit that is different from that of a data pointer
that does not have the CONTIGUOUS attribute.
storage sequence is that of the individual storage units in each of the constituent storage sequences taken in4 Each common block has a storage sequence (8.10.2.2).succession, ignoring any zero-sized constituent sequences.
520 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
19.5.3.3 Association of storage sequences1 Two nonzero-sized storage sequences s1 and s2 are storage associated if the ith storage unit of s1 is the same as
the jth storage unit of s2 . This causes the (i + k)th storage unit of s1 to be the same as the (j + k)th storage2 Storage association also is defined between two zero-sized storage sequences, and between a zero-sized storageunit of s2 , for each integer k such that 1 ≤ i + k ≤ size of s1 and 1 ≤ j + k ≤ size of s2 where size of measures
the number of storage units.
sequence and a storage unit. A zero-sized storage sequence in a sequence of storage sequences is storage associated1 Two scalar data objects are storage associated if their storage sequences are storage associated. Two scalar entitieswith its successor, if any. If the successor is another zero-sized storage sequence, the two sequences are storage
associated. If the successor is a nonzero-sized storage sequence, the zero-sized sequence is storage associated with
the first storage unit of the successor. Two storage units that are each storage associated with the same zero-sized
storage sequence are the same storage unit.
19.5.3.4 Association of scalar data objects
are totally associated if they have the same storage sequence. Two scalar entities are partially associated if they2 The definition status and value of a data object affects the definition status and value of any storage associatedare associated without being totally associated.
entity. An EQUIVALENCE statement, a COMMON statement, or an ENTRY statement can cause storage association of storage3 An EQUIVALENCE statement causes storage association of data objects only within one scoping unit, unless one of the equivalencedsequences.
entities is also in a common block (8.10.1.2, 8.10.2.2).4 COMMON statements cause data objects in one scoping unit to become storage associated with data objects in another scoping unit.
5 A common block is permitted to contain a sequence of differing storage units. All scoping units that access named common blocks
with the same name shall specify an identical sequence of storage units. Blank common blocks may be declared with differing sizes6 An ENTRY statement in a function subprogram causes storage association of the function results that are variables.in different scoping units. For any two blank common blocks, the initial sequence of storage units of the longer blank common block
shall be identical to the sequence of storage units of the shorter common block. If two blank common blocks are the same length,
they shall have the same sequence of storage units.
7 Partial association shall exist only between
• an object that is default character or of character sequence type and an object that is default character or8 For noncharacter entities, partial association may occur only through the use of COMMON, EQUIVALENCE, or ENTRY statements.of character sequence type, or
• an object that is default complex, double precision real, or of numeric sequence type and an object that is
default integer, default real, default logical, double precision real, default complex, or of numeric sequence
type.
For character entities, partial association may occur only through argument association or the use of COMMON or9 Partial association of character entities occurs when some, but not all, of the storage units of the entities are theEQUIVALENCE statements.
⃝c ISO/IEC 2017 – All rights reserved 521
ISO/IEC DIS 1539-1:2017 (E)
same.10 A storage unit shall not be explicitly initialized more than once in a program. Explicit initialization overrides
default initialization, and default initialization for an object of derived type overrides default initialization for1 Inheritance association occurs between components of the parent component and components inherited by typea component of the object (7.5.4.6). Default initialization may be specified for a storage unit that is storage
associated provided the objects supplying the default initialization are of the same type and type parameters,
and supply the same value for the storage unit.
19.5.4 Inheritance association
extension into an extended type (7.5.7.2). This association is persistent; it is not affected by the accessibility of1 When an association is established between two entities by argument association, host association, or constructthe inherited components.
19.5.5 Establishing associations
association, certain properties of the associating entity become those of the pre-existing entity.2 For argument association, the pre-existing entity is the effective argument and the associating entity is the dummy
argument.3 For host association, the associating entity is the entity in the contained scoping unit. When a procedure is
invoked, the pre-existing entity that participates in the association is the one from its host instance (15.6.2.4).4 For construct association, the associating entity is identified by the associate name and the pre-existing entity isOtherwise the pre-existing entity that participates in the association is the entity in the host scoping unit.
the selector.5 When an association is established by argument association, host association, or construct association, the fol-
lowing applies.• If the entities have the POINTER attribute, the pointer association status of the associating entity becomes
the same as that of the pre-existing entity. If the pre-existing entity has a pointer association status of
associated, the associating entity becomes pointer associated with the same target and, if they are arrays,
the bounds of the associating entity become the same as those of the pre-existing entity.
• If the associating entity has the ALLOCATABLE attribute, its allocation status becomes the same as that
of the pre-existing entity. If the pre-existing entity is allocated, the bounds (if it is an array), values of
deferred type parameters, definition status, and value (if it is defined) become the same as those of the
pre-existing entity. If the associating entity is polymorphic and the pre-existing entity is allocated, the
dynamic type of the associating entity becomes the same as that of the pre-existing entity.
• If the associating entity is neither a pointer nor allocatable, its definition status, value (if it is defined), and
dynamic type (if it is polymorphic) become the same as those of the pre-existing entity. If the entities are
arrays and the association is not argument association, the bounds of the associating entity become the
same as those of the pre-existing entity.
• If the associating entity is a pointer dummy argument and the pre-existing entity is a nonpointer actual
argument the associating entity becomes pointer associated with the pre-existing entity and, if the entities
are arrays, the bounds of the associating entity become the same as those of the pre-existing entity.
522 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
19.6 Definition and undefinition of variables 19.6.1 Definition of objects and subobjects 1 A variable may be defined or may be undefined and its definition status may change during execution of a
program. An action that causes a variable to become undefined does not imply that the variable was previously2 Arrays, including sections, and variables of derived, character, or complex type are objects that consist of zerodefined. An action that causes a variable to become defined does not imply that the variable was previously
undefined.
or more subobjects. Associations may be established between variables and subobjects and between subobjects3 An array is defined if and only if all of its elements are defined.of different variables. These subobjects may become defined or undefined.
4 A derived-type scalar object is defined if and only if all of its nonpointer components are defined.
5 A complex or character scalar object is defined if and only if all of its subobjects are defined.
6 If an object is undefined, at least one (but not necessarily all) of its subobjects are undefined.
19.6.2 Variables that are always defined1 Zero-sized arrays and zero-length strings are always defined.
19.6.3 Variables that are initially defined1 The following variables are initially defined:
(1) variables specified to have initial values by DATA statements;NOTE 19.11(2) variables specified to have initial values by type declaration statements;
(3) nonpointer default-initialized subcomponents of saved variables that do not have the ALLOCAT-
ABLE or POINTER attribute;
(4) pointers specified to be initially associated with a variable that is initially defined;
(5) variables that are always defined;
(6) variables with the BIND attribute that are initialized by means other than Fortran.
Fortran code:
module mod
integer, bind(c,name="blivet") :: fooend module mod
C code:
int blivet = 123;
In the above example, the Fortran variable foo is initially defined to have the value 123 by means other
than Fortran.
⃝c ISO/IEC 2017 – All rights reserved 523
ISO/IEC DIS 1539-1:2017 (E)
19.6.4 Variables that are initially undefined 1 Variables that are not initially defined are initially undefined. 19.6.5 Events that cause variables to become defined1 Variables become defined by the following events.
(1) Execution of an intrinsic assignment statement other than a masked array assignment or FORALLassignment statement causes the variable that precedes the equals to become defined.
(2) Execution of a masked array assignment or FORALL assignment statement might cause some or all of
the array elements in the assignment statement to become defined (10.2.3).
(3) As execution of an input statement proceeds, each variable that is assigned a value from the input
file becomes defined at the time that data are transferred to it. (See (4) in 19.6.6.) Execution of a
WRITE statement whose unit specifier identifies an internal file causes each record that is written
to become defined.
(4) Execution of a DO statement causes the DO variable, if any, to become defined.
(5) Beginning of execution of the action specified by an io-implied-do in a synchronous data transfer
statement causes the do-variable to become defined.
(6) A reference to a procedure causes an entire dummy data object to become defined if the dummy data
object does not have INTENT (OUT) and the entire effective argument is defined.
A reference to a procedure causes a subobject of a dummy argument to become defined if the dummy
argument does not have INTENT (OUT) and the corresponding subobject of the effective argument
is defined.
(7) Execution of an input/output statement containing an IOSTAT= specifier causes the specified integer
variable to become defined.
(8) Execution of a synchronous input statement containing a SIZE= specifier causes the specified integer
variable to become defined.
(9) Execution of a wait operation (12.7.1) corresponding to an asynchronous input statement containing
a SIZE= specifier causes the specified integer variable to become defined.
(10) Execution of an INQUIRE statement causes any variable that is assigned a value during the execution
of the statement to become defined if no error condition exists.
(11) If an error, end-of-file, or end-of-record condition occurs during execution of an input/output state-
ment that has an IOMSG= specifier, the iomsg-variable becomes defined.
(12) When a character storage unit becomes defined, all associated character storage units become defined.
When a numeric storage unit becomes defined, all associated numeric storage units of the same type
become defined. When an entity of double precision real type becomes defined, all totally associated
entities of double precision real type become defined.
When an unspecified storage unit becomes defined, all associated unspecified storage units become
defined.
(13) When a default complex entity becomes defined, all partially associated default real entities become
defined.
(14) When both parts of a default complex entity become defined as a result of partially associated default
real or default complex entities becoming defined, the default complex entity becomes defined.
524 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)(15) When all components of a structure of a numeric sequence type or character sequence type become
defined as a result of partially associated objects becoming defined, the structure becomes defined.(16) Execution of a statement with a STAT= specifier causes the variable specified by the STAT= specifier
to become defined.(17) If an error condition occurs during execution of a statement that has an ERRMSG= specifier, the
variable specified by the ERRMSG= specifier becomes defined.(18) Allocation of a zero-sized array or zero-length character variable causes the array or variable to
become defined.(19) Allocation of an object that has a nonpointer default-initialized subcomponent, except by an AL-
LOCATE statement with a SOURCE= specifier, causes that subcomponent to become defined.(20) Successful execution of an ALLOCATE statement with a SOURCE= specifier causes a subobject of
the allocated object to become defined if the corresponding subobject of the SOURCE= expression(21) Invocation of a procedure causes any automatic data object of zero size or zero character length inis defined.
that procedure to become defined.(22) When a pointer becomes associated with a target that is defined, the pointer becomes defined.
(23) Invocation of a procedure that contains an unsaved nonpointer nonallocatable local variable causes
all nonpointer default-initialized subcomponents of the object to become defined.(24) Invocation of a procedure that has a nonpointer nonallocatable INTENT (OUT) dummy argument
causes all nonpointer default-initialized subcomponents of the dummy argument to become defined.(25) In a DO CONCURRENT or FORALL construct, the index-name becomes defined when the index-
name value set is evaluated.(26) In a DO CONCURRENT construct, a variable with LOCAL_INIT locality becomes defined at the
beginning of each iteration.(27) An object with the VOLATILE attribute that is changed by a means not specified by the program
might become defined (see 8.5.19).(28) Execution of the BLOCK statement of a BLOCK construct that has an unsaved nonpointer non-
allocatable local variable causes all nonpointer default-initialized subcomponents of the variable to(29) Execution of an OPEN statement containing a NEWUNIT= specifier causes the specified integerbecome defined.
variable to become defined.(30) Execution of a LOCK statement containing an ACQUIRED_LOCK= specifier causes the specified
logical variable to become defined. If the logical variable becomes defined with the value true, the(31) Successful execution of a LOCK statement that does not contain an ACQUIRED_LOCK= specifierlock variable in the LOCK statement also becomes defined.
causes the lock variable to become defined.(32) Successful execution of an UNLOCK statement causes the lock variable to become defined.
(33) Failure of an image that locked a lock variable without unlocking it causes the lock variable to become
defined.(34) Successful execution of an EVENT POST or EVENT WAIT statement causes the event variable to
become defined.(35) Successful execution of a FORM TEAM statement causes the team variable to become defined.
⃝
c ISO/IEC 2017 – All rights reserved 525
ISO/IEC DIS 1539-1:2017 (E)1 Variables become undefined by the following events.19.6.6 Events that cause variables to become undefined
(1) When a scalar variable of intrinsic type becomess defined, all totally associated variables of different type becomeundefined. When a double precision scalar variable becomes defined, all partially associated scalar
variables become undefined. When a scalar variable becomes undefined, all partially associated double
precision scalar variables become undefined.
(2) If the evaluation of a function would cause a variable to become defined and if a reference to the
function appears in an expression in which the value of the function is not needed to determine the
value of the expression, the variable becomes undefined when the expression is evaluated.
(3) When execution of an instance of a subprogram completes,
(a) its unsaved local variables become undefined,
(b) unsaved variables in a named common block that appears in the subprogram become undefined if they have been
defined or redefined, unless another active scoping unit is referencing the common block, and
(c) a variable of type C_PTR from the intrinsic module ISO_C_BINDING whose value is the C
address of an unsaved local variable of the subprogram becomes undefined.
(4) When an error condition or end-of-file condition occurs during execution of an input statement, all of
the variables specified by the input list or namelist group of the statement become undefined.
(5) When an error condition occurs during execution of an output statement in which the unit is an internal
file, the internal file becomes undefined.
(6) When an error condition, end-of-file condition, or end-of-record condition occurs during execution of
an input/output statement and the statement contains any io-implied-dos, all of the do-variables in
the statement become undefined (12.11).
(7) Execution of a direct access input statement that specifies a record that has not been written previously
causes all of the variables specified by the input list of the statement to become undefined.
(8) Execution of an INQUIRE statement might cause the NAME=, RECL=, and NEXTREC= variables
to become undefined (12.10).
(9) When a character storage unit becomes undefined, all associated character storage units become un-
defined.
When a numeric storage unit becomes undefined, all associated numeric storage units become undefined
unless the undefinition is a result of defining an associated numeric storage unit of different type (see
(1) above).
When an entity of double precision real type becomes undefined, all totally associated entities of double
precision real type become undefined.
When an unspecified storage unit becomes undefined, all associated unspecified storage units become
undefined.
(10) When an allocatable entity is deallocated, it becomes undefined.
(11) When the allocation transfer procedure (16.9.137) causes the allocation status of an allocatable entity
to become unallocated, the entity becomes undefined.
(12) Successful execution of an ALLOCATE statement with no SOURCE= specifier causes a subcomponent
of an allocated object to become undefined if default initialization has not been specified for that
subcomponent.
526 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)(13) Successful execution of an ALLOCATE statement with a SOURCE= specifier causes a subobject of
the allocated object to become undefined if the corresponding subobject of the SOURCE= expression(14) Execution of an INQUIRE statement causes all inquiry specifier variables to become undefined if anis undefined.
error condition exists, except for any variable in an IOSTAT= or IOMSG= specifier.(15) When a procedure is invoked
(a) an optional dummy argument that has no corresponding actual argument becomes undefined,(16) When the association status of a pointer becomes undefined or disassociated (19.5.2.4, 19.5.2.5), the(b) a dummy argument with INTENT (OUT) becomes undefined except for any nonpointer default-
initialized subcomponents of the argument,
(c) an actual argument corresponding to a dummy argument with INTENT (OUT) becomes un-
defined except for any nonpointer default-initialized subcomponents of the argument,
(d) a subobject of a dummy argument that does not have INTENT (OUT) becomes undefined if the
corresponding subobject of the effective argument is undefined, and
(e) a variable that is the function result of that procedure becomes undefined except for any of its
nonpointer default-initialized subcomponents.
pointer becomes undefined.(17) When a DO CONCURRENT construct terminates, a variable that is defined or becomes undefined
during more than one iteration of the construct becomes undefined.(18) When execution of an iteration of a DO CONCURRENT construct completes, a construct entity of
that construct which has LOCAL or LOCAL_INIT locality becomes undefined.(19) Execution of an asynchronous READ statement causes all of the variables specified by the input list or
SIZE= specifier to become undefined. Execution of an asynchronous namelist READ statement causes(20) When a variable with the TARGET attribute is deallocated, a variable of type C_PTR from theany variable in the namelist group to become undefined if that variable will subsequently be defined
during the execution of the READ statement or the corresponding wait operation (12.7.1).
intrinsic module ISO_C_BINDING becomes undefined if its value is the C address of any part of the(21) When a pointer is deallocated, a variable of type C_PTR from the intrinsic module ISO_C_BINDINGvariable that is deallocated.
becomes undefined if its value is the C address of any part of the target that is deallocated.(22) Execution of the allocation transfer procedure (16.9.137) where the argument TO does not have the
TARGET attribute causes a variable of type C_PTR from the intrinsic module ISO_C_BINDING to(23) When a BLOCK construct completes execution,become undefined if its value is the C address of any part of the argument FROM.
• its unsaved local variables become undefined, and(24) When execution of the host instance of the target of a variable of type C_FUNPTR from the intrinsic• a variable of type C_PTR from the intrinsic module ISO_C_BINDING, whose value is the C
address of an unsaved local variable of the BLOCK construct, becomes undefined.
module ISO_C_BINDING is completed by execution of a RETURN or END statement, the variable(25) Execution of an intrinsic assignment of the type C_PTR or C_FUNPTR from the intrinsic modulebecomes undefined.
ISO_C_BINDING, or of the type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV,⃝in which the variable and expr are not on the same image, causes the variable to become undefined.
c ISO/IEC 2017 – All rights reserved 527
ISO/IEC DIS 1539-1:2017 (E)1 Some variables are prohibited from appearing in a syntactic context that would imply definition or undefinition(26) An object with the VOLATILE attribute (8.5.19) might become undefined by means not specified by
the program.
(27) When a pointer becomes associated with a target that is undefined, the pointer becomes undefined.
(28) When an image fails during execution of a segment, a data object on a nonfailed image becomes
undefined if it is not a lock variable and it might become undefined by execution of a statement of
the segment other than an invocation of an atomic subroutine with the object as an actual argument
corresponding to the ATOM dummy argument.
NOTE 19.12
Execution of a defined assignment statement could leave all or part of the variable undefined.
19.6.7 Variable definition context
of the variable (8.5.10, 8.5.15, 15.7). The following are the contexts in which the appearance of a variable implies2 If a reference to a function appears in a variable definition context the result of the function reference shall be asuch definition or undefinition of the variable:
(1) the variable of an assignment-stmt;
(2) a do-variable in a do-stmt or io-implied-do;
(3) an input-item in a read-stmt;
(4) a variable-name in a namelist-stmt if the namelist-group-name appears in a NML= specifier in a
read-stmt;
(5) an internal-file-variable in a write-stmt;
(6) a SIZE= or IOMSG= specifier in an input/output statement;
(7) a specifier in an INQUIRE statement other than FILE=, ID=, and UNIT=;
(8) a NEWUNIT= specifier in an OPEN statement;
(9) a stat-variable, allocate-object, or errmsg-variable;
(10) an actual argument in a reference to a procedure with an explicit interface if the corresponding
dummy argument is not a pointer and has INTENT (OUT) or INTENT (INOUT);
(11) a variable that is a selector in an ASSOCIATE, CHANGE TEAM, SELECT RANK, or SELECT
TYPE construct if the corresponding associate name or any subobject thereof appears in a variable
definition context;
(12) an event-variable in an EVENT POST or EVENT WAIT statement;
(13) a lock-variable in a LOCK or UNLOCK statement;
(14) a scalar-logical-variable in an ACQUIRED_LOCK= specifier;
(15) a team-variable in a FORM TEAM statement.
pointer that is associated with a definable target. That target is the variable that becomes defined or undefined.1 Some pointers are prohibited from appearing in a syntactic context that would imply alteration of the pointer19.6.8 Pointer association context
association status (19.5.2.2, 8.5.10, 8.5.15, 15.7). The following are the contexts in which the appearance of a⃝pointer implies such alteration of its pointer association status:
528 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
• a pointer-object in a nullify-stmt;
• a data-pointer-object or proc-pointer-object in a pointer-assignment-stmt;
• an allocate-object in an allocate-stmt or deallocate-stmt;
• an actual argument in a reference to a procedure if the corresponding dummy argument is a pointer with
the INTENT (OUT) or INTENT (INOUT) attribute.
c ISO/IEC 2017 – All rights reserved 529
ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
530 c ISO/IEC 2017 – All rights reservedProcessor dependencies
ISO/IEC DIS 1539-1:2017 (E)
Annex A
(Informative)
A.1 Unspecified items 1 This document does not specify the following: • the properties excluded in 1;• a processor’s error detection capabilities beyond those listed in 4.2;
• which additional intrinsic procedures or modules a processor provides (4.2);
• the number and kind of companion processors (5.5.7);
• the number of representation methods and associated kind type parameter values of the intrinsic types
(7.4), except that there shall be at least two representation methods for type real, and a representation
method of type complex that corresponds to each representation method for type real.
A.2 Processor dependencies 1 According to this document, the following are processor dependent: • the order of evaluation of the specification expressions within the specification part of an invoked Fortran⃝procedure (5.3.5);
• how soon an image terminates if another image initiates error termination (5.3.5);
• the value of a reference to to a coindexed object on a failed image (5.3.6);
• the conditions that cause an image to fail (5.3.6);
• whether the processor supports a concept of process exit status, and if so, the process exit status on program
termination (5.3.7);
• the mechanism of a companion processor, and the means of selecting between multiple companion processors
(5.5.7);
• the processor character set (6.1);
• the means for specifying the source form of a program unit (6.3);
• the maximum number of characters allowed on a source line containing characters not of default kind (6.3.2,
6.3.3);
• the maximum depth of nesting of include lines (6.4);
• the interpretation of the char-literal-constant in the include line (6.4);
• the set of values supported by an intrinsic type, other than logical (7.1.3);
• the kind type parameter value of a complex literal constant, if both the real part and imaginary part are of
type real with the same precision, but have different kind type parameter values (7.4.3.3);
• the kind of a character length type parameter (7.4.4.1);
• the blank padding character for nondefault character kind (7.4.4.2)
c ISO/IEC 2017 – All rights reserved 531
ISO/IEC DIS 1539-1:2017 (E)
• whether particular control characters can appear within a character literal constant in fixed source form(7.4.4.3);
• the collating sequence for each character set (7.4.4.4);
• the order of finalization of components of objects of derived type (7.5.6.2);
• the order of finalization when several objects are finalized as the consequence of a single event (7.5.6.2);
• whether and when an object is finalized if it is allocated by pointer allocation and it later becomes un-
reachable due to all pointers associated with the object having their pointer association status changed
(7.5.6.3);
• whether an object is finalized by a deallocation in which an error condition occurs (7.5.6.3);
• the kind type parameter of each enumeration and its enumerators (7.6);
• whether an array is contiguous, except as specified in 8.5.7;
• the set of error conditions that can occur in ALLOCATE and DEALLOCATE statements (9.7.1, 9.7.3);
• the allocation status of a variable after evaluation of an expression if the evaluation of a function would
change the allocation status of the variable and if a reference to the function appears in the expression in
which the value of the function is not needed to determine the value of the expression (9.7.1.3);
• the order of deallocation when several objects are deallocated by a DEALLOCATE statement (9.7.3);
• the order of deallocation when several objects are deallocated due to the occurence of an event described
in 9.7.3.2;
• whether an allocated allocatable subobject is deallocated when an error condition occurs in the deallocation
of an object (9.7.3.2);
• the positive integer values assigned to the stat-variable in a STAT= specifier as the result of an error
condition (9.7.4, 11.6.11);
• the allocation status or pointer association status of an allocate-object if an error condition occurs during
execution of an ALLOCATE or DEALLOCATE statement (9.7.4);
• the value assigned to the errmsg-variable in an ERRMSG= specifier as the result of an error condition
(9.7.5, 11.6.11);
• the kind type parameter value of the result of a numeric intrinsic binary operation where
– both operands are of type integer but with different kind type parameters, and the decimal exponent
ranges are the same,
– one operand is of type real or complex and the other is of type real or complex with a different kind
type parameter, and the decimal precisions are the same,
and for a logical intrinsic binary operation where the operands have different kind type parameters (10.1.9.3);
• the character assigned to the variable in an intrinsic assignment statement if the kind of the expression is
different and the character is not representable in the kind of the variable (10.2.1.3);
• the order of evaluation of the specification expressions within the specification part of a BLOCK construct
when the construct is executed (11.1.4);
• the pointer association status of a pointer that has its pointer association changed in more than one iteration
of a DO CONCURRENT construct, on termination of the construct (11.1.7);
• the ordering between records written by different iterations of a DO CONCURRENT construct if the records
are written to a file connected for sequential access by more than one iteration (11.1.7);
• the manner in which the stop code of a STOP or ERROR STOP statement is made available (11.4);
• the mechanisms available for creating dependencies for cooperative synchronization (11.6.5);
532 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)• the value of the count of the event variable in an EVENT POST or EVENT WAIT statement if an error
condition occurs (11.6.7, 11.6.8);• the image index value established for each image in a team by a FORM TEAM statement without a
NEW_INDEX= specifier (11.6.9);• the set of error conditions that can occur in image control statements (11.6.11);
• the relationship between the file storage units when viewing a file as a stream file, and the records when
viewing that file as a record file (12);• whether particular control characters can appear in a formatted record or a formatted stream file (12.2.2);
• the form of values in an unformatted record (12.2.3);
• at any time, the set of allowed access methods, set of allowed forms, set of allowed actions, and set of
allowed record lengths for a file (12.3);• the set of allowable names for a file (12.3);
• whether a named file on one image is the same as a file with the same name on another image (12.3.1);
• the set of external files that exist for a program (12.3.2);
• the relationship between positions of successive file storage units in an external file that is connected for
formatted stream access (12.3.3.4);• the external unit preconnected for sequential formatted input and identified by an asterisk or the named
constant INPUT_UNIT of the ISO_FORTRAN_ENV intrinsic module (12.5);• the external unit preconnected for sequential formatted output and identified by an asterisk or the named
constant OUTPUT_UNIT of the ISO_FORTRAN_ENV intrinsic module (12.5);• the external unit preconnected for sequential formatted output and identified by the named constant ER-
ROR_UNIT of the ISO_FORTRAN_ENV intrinsic module, and whether this unit is the same as OUT-• at any time, the set of external units that exist for an image (12.5.3);PUT_UNIT (12.5);
• whether a unit can be connected to a file that is also connected to a C stream (12.5.4);
• whether a file can be connected to more than one unit at the same time (12.5.4);
• the effect of performing input/output operations on multiple units while they are connected to the same
external file (12.5.4);• the result of performing input/output operations on a unit connected to a file that is also connected to a C
stream (12.5.4);• whether the files connected to the units INPUT_UNIT, OUTPUT_UNIT, and ERROR_UNIT correspond
to the predefined C text streams standard input, standard output, and standard error, respectively (12.5.4);• the results of performing input/output operations on an external file both from Fortran and from a procedure
defined by means other than Fortran (12.5.4);• the default value for the ACTION= specifier in an OPEN statement (12.5.6.4);
• the encoding of a file opened with ENCODING=’DEFAULT’ (12.5.6.9);
• the file connected by an OPEN statement with STATUS=’SCRATCH’ (12.5.6.10);
• the interpretation of case in a file name (12.5.6.10, 12.10.2.2);
• the position of a file after executing an OPEN statement with a POSITION= specifier of ASIS, when the
file previously existed but was not connected (12.5.6.14);• the default value for the RECL= specifier in an OPEN statement (12.5.6.15);
• the effect of RECL= on a record containing any nondefault characters (12.5.6.15);
⃝
c ISO/IEC 2017 – All rights reserved 533
ISO/IEC DIS 1539-1:2017 (E)
• the default input/output rounding mode (12.5.6.16);• the default sign mode (12.5.6.17);
• the file status when STATUS=’UNKNOWN’ is specified in an OPEN statement (12.5.6.18);
• the value assigned to the variable in the ID= specifier in an asynchronous data transfer statement when
execution of the statement is successfully completed (12.6.2.9);
• whether POS= is permitted with particular files, and whether POS= can position a particular file to a
position prior to its current position (12.6.2.11);
• the form in which a single value of derived type is treated in an unformatted input/output statement if the
effective item is not processed by a defined input/output procedure (12.6.3);
• the result of unformatted input when the value stored in the file has a different type or type parameters
from that of the input list item (12.6.4.5.2);
• the negative value of the unit argument to a defined input/output procedure if the parent data transfer
statement accesses an internal file (12.6.4.8.2);
• the manner in which the processor makes the value of the iomsg argument of a defined input/output
procedure available if the procedure assigns a nonzero value to the iostat argument and the processor
therefore terminates execution of the program (12.6.4.8.2);
• the action caused by the flush operation, whether the processor supports the flush operation for the specified
unit, and the negative value assigned to the IOSTAT= variable if the processor does not support the flush
operation for the specified unit (12.9);
• the case of characters assigned to the variable in a NAME= specifier in an INQUIRE statement (12.10.2.15);
• which of the connected external unit numbers is assigned to the scalar-int-variable in the NUMBER=
specifier in an INQUIRE by file statement, if more than one unit on an image is connected to the file
(12.10.2.18);
• the value of the variable in a POSITION= specifier in an INQUIRE statement if the file has been repositioned
since connection (12.10.2.23);
• the relationship between file size and the data stored in records in a sequential or direct access file
(12.10.2.30);
• the number of file storage units needed to store data in an unformatted file (12.10.3);
• the set of error conditions that can occur in input/output statements (12.11.1);
• when an input/output error condition occurs or is detected (12.11.1);
• the positive integer value assigned to the variable in an IOSTAT= specifier as the result of an error condition
(12.11.5);
• the value assigned to the variable in an IOMSG= specifier as the result of an error condition (12.11.6);
• the result of output of non-representable characters to a Unicode file (13.7.1);
• the interpretation of the optional non-blank characters within the parentheses of a real NaN input field
(13.7.2.3.2);
• the interpretation of a sign in a NaN input field (13.7.2.3.2);
• for output of an IEEE NaN, whether after the letters ’NaN’, the processor produces additional alphanumeric
characters enclosed in parentheses (13.7.2.3.2);
• the choice of binary exponent in EX output editing (13.7.2.3.6);
• the effect of the input/output rounding mode PROCESSOR_DEFINED (13.7.2.3.8);
• which value is chosen if the input/output rounding mode is NEAREST and the value to be converted is
exactly halfway between the two nearest representable values in the result format (13.7.2.3.8);
534 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)• the field width, decimal part width, and exponent width used for the G0 edit descriptor (13.7.5);
• the file position when position editing skips a character of nondefault kind in an internal file of default
character kind or an external unit that is not connected to a Unicode file (13.8.1.1);• when the sign mode is PROCESSOR_DEFINED, whether a plus sign appears in a numeric output field
for a nonnegative value (13.8.4);• the results of list-directed output (13.10.4);
• the results of namelist output (13.11.4);
• the interaction between argument association and pointer association, (15.5.2.4);
• the values returned by some intrinsic functions (16);
• how the sequences of atomic actions in unordered segments interleave (16.5);
• the value assigned to a STAT argument in a reference to an atomic subroutine when an error condition
occurs (16.5);• the effect of calling EXECUTE_COMMAND_LINE on any image other than image 1 in the initial team
(16.7);• whether each image uses a separate random number generator, or if some or all images use common random
number generators (16.7);• whether the results returned from CPU_TIME, DATE_AND_TIME and SYSTEM_CLOCK are depend-
ent on which image calls them (16.7);• the set of error conditions that can occur in some intrinsic subroutines (16.9);
• the value assigned to a CMDSTAT, ERRMSG, EXITSTAT, STAT, or STATUS argument to indicate a
processor-dependent error condition (16.9);• the computed value of the the intrinsic subroutine CO_REDUCE (16.9.49) and the intrinsic subroutine
CO_SUM (16.9.50);• the value assigned to the TIME argument by the intrinsic subroutine CPU_TIME (16.9.57);
• whether date, clock, and time zone information is available (16.9.59);
• whether date, clock, and time zone information on one image is the same as that on another image (16.9.59);
• the value of command argument zero, if the processor does not support the concept of a command name
(16.9.83);• the order of command arguments (16.9.83);
• whether the significant length of a command argument includes trailing blanks (16.9.83);
• the interpretation of case for the NAME argument of the intrinsic subroutine GET_ENVIRONMENT_-
VARIABLE (16.9.84);• whether an environment variable that exists on an image also exists on another image, and if it does exist
on both images, whether the values are the same or different (16.9.84);• the value assigned to the pseudorandom number generator by the intrinsic subroutine RANDOM_INIT
(16.9.155);• the computation of the seed value used by the pseudorandom number generator (16.9.157);
• on images that use a common random number generator, the interleaving of values assigned by RANDOM_-
NUMBER in unordered segments(16.7);• the value assigned to the seed by the intrinsic subroutine RANDOM_SEED when no argument is present
(16.9.157);• the values assigned to its arguments by the intrinsic subroutine SYSTEM_CLOCK (16.9.186);
⃝
c ISO/IEC 2017 – All rights reserved 535
ISO/IEC DIS 1539-1:2017 (E)
• the values of the named constants in the intrinsic module ISO_FORTRAN_ENV (16.10.2);• the values returned by the functions COMPILER_OPTIONS and COMPILER_VERSION in the intrinsic
module ISO_FORTRAN_ENV (16.10.2);
• the extent to which a processor supports IEEE arithmetic (17);
• whether a flag that is quiet on entry to a scoping unit that does not access IEEE_FEATURES, IEEE_-
EXCEPTIONS, or IEEE_ARITHMETIC is signaling on exit (17.1);
• the conditions under which IEEE_OVERFLOW is raised in a calculation involving non-ISO/IEC/IEEE
60559:2011 floating-point data (17.3);
• the conditions under which IEEE_OVERFLOW and IEEE_DIVIDE_BY_ZERO are raised in a floating-
point exponentiation operation (17.3);
• the conditions under which IEEE_DIVIDE_BY_ZERO is raised in a calculation involving floating-point
data that do not conform to ISO/IEC/IEEE 60559:2011 (17.3);
• whether an exception signals at the end of a sequence of statements that has no invocations of IEEE_GET_-
FLAG, IEEE_SET_FLAG, IEEE_GET_STATUS, IEEE_SET_STATUS, or IEEE_SET_HALTING_-
MODE, in which execution of an operation would cause it to signal, if no value of a variable depends upon
the result of the operation (17.3);
• the initial rounding modes (17.4);
• whether the processor supports a particular rounding mode (17.4);
• the effect of the rounding mode IEEE_OTHER, if supported (17.4);
• the initial underflow mode (17.5);
• the initial halting mode (17.6);
• whether IEEE_INT implements the convertToInteger{round} or convertToIntegerExact{round} operation
specified by ISO/IEC/IEEE 60559:2011 (17.11.11);
• which argument is the result value of IEEE_MAX_NUM, IEEE_MAX_NUM_MAG, IEEE_MIN_NUM,
or IEEE_MIN_NUM_MAG when both arguments are quiet NaNs or are zeros (17.11.17, 17.11.18, 17.11.19,
17.11.20);
• the requirements on the storage sequence to be associated with the pointer FPTR by the C_F_POINTER
subroutine (18.2.3.4);
• the order of the members of the CFI_dim_t structure defined in the source file CFI_Fortran_binding.h
(18.5.2);
• members of the CFI_cdesc_t structure defined in the source file CFI_Fortran_binding.h beyond the re-
quirements of 18.5.3;
• the value of CFI_MAX_RANK in the source file CFI_Fortran_binding.h (18.5.4);
• the value of CFI_VERSION in the source file CFI_Fortran_binding.h (18.5.4);
• which error condition is detected if more than one error condition could be detected for an invocation of
one of the functions declared in the source file CFI_Fortran_binding.h (18.5.5.1);
• the values of the attribute specifier macros defined in the source file CFI_Fortran_binding.h (18.5.4);
• the values of the type specifier macros defined in the source file CFI_Fortran_binding.h;
• which additional type specifier values are defined in the source file CFI_Fortran_binding.h (18.5.4);
• the values of the error code macros other than CFI_SUCCESS that are defined in the source file CFI_-
Fortran_binding.h (18.5.4);
• the base address of a zero-sized array (18.5.3);
• the values of the floating-point exception flags on entry to a procedure defined by means other than Fortran
536 c ISO/IEC 2017 – All rights reserved(18.10.3);
ISO/IEC DIS 1539-1:2017 (E)
• whether a procedure defined by means other than Fortran is an asynchronous communication initiation or
completion procedure (18.10.4).⃝
c ISO/IEC 2017 – All rights reserved 537
ISO/IEC DIS 1539-1:2017 (E)
(Blank page)
1 The obsolescent features are those features of Fortran 90 that were redundant and for which better methods were
538 c ISO/IEC 2017 – All rights reservedDeleted and obsolescent features
ISO/IEC DIS 1539-1:2017 (E)
Annex B
(Informative)
B.1 Deleted features from Fortran 90 1 These deleted features are those features of Fortran 90 that were redundant and considered largely unused. 2 The following Fortran 90 features are not required. (1) Real and double precision DO variables.3 See ISO/IEC 1539:1991 for detailed rules of how these deleted features worked.In Fortran 77 and Fortran 90, a DO variable was allowed to be of type real or double precision
in addition to type integer; this has been deleted. A similar result can be achieved by using a DO
construct with no loop control and the appropriate exit test.
(2) Branching to an END IF statement from outside its block.
In Fortran 77 and Fortran 90, it was possible to branch to an END IF statement from outside the
IF construct; this has been deleted. A similar result can be achieved by branching to a CONTINUE
statement that is immediately after the END IF statement.
(3) PAUSE statement.
The PAUSE statement, provided in Fortran 66, Fortran 77, and Fortran 90, has been deleted.
A similar result can be achieved by writing a message to the appropriate unit, followed by reading
from the appropriate unit.
(4) ASSIGN and assigned GO TO statements, and assigned format specifiers.
The ASSIGN statement and the related assigned GO TO statement, provided in Fortran 66,
Fortran 77, and Fortran 90, have been deleted. Further, the ability to use an assigned integer as a
format, provided in Fortran 77 and Fortran 90, has been deleted. A similar result can be achieved
by using other control constructs instead of the assigned GO TO statement and by using a default
character variable to hold a format specification instead of using an assigned integer.
(5) H edit descriptor.
In Fortran 77 and Fortran 90, there was an alternative form of character string edit descriptor,
which had been the only such form in Fortran 66; this has been deleted. A similar result can be
achieved by using a character string edit descriptor.
(6) Vertical format control.
In Fortran 66, Fortran 77, Fortran 90, and Fortran 95 formatted output to certain units resulted
in the first character of each record being interpreted as controlling vertical spacing. There was no
standard way to detect whether output to a unit resulted in this vertical format control, and no
way to specify that it should be applied; this has been deleted. The effect can be achieved by
post-processing a formatted file.
⃝c ISO/IEC 2017 – All rights reserved 5391 These deleted features are those features of Fortran 2008 that were redundant and considered largely unused.
ISO/IEC DIS 1539-1:2017 (E)
B.2 Deleted features from Fortran 2008
2 The following Fortran 2008 features are not required. (1) Arithmetic IF statement.The arithmetic IF statement is incompatible with ISO/IEC/IEEE 60559:2011 and necessarily involves
the use of statement labels; statement labels can hinder optimization, and make code hard to read
and maintain. Similar logic can be more clearly encoded using other conditional statements.
(2) Nonblock DO construct
The nonblock forms of the DO loop were confusing and hard to maintain. Shared termination and
dual use of labeled action statements as do termination and branch targets were especially error-
prone.
B.3 Obsolescent features B.3.1 General
available in Fortran 90. Subclause 4.4.3 describes the nature of the obsolescent features. The obsolescent features1 An alternate return introduces labels into an argument list to allow the called procedure to direct the executionin this document are the following.
(1) Alternate return — see B.3.2.
(2) Computed GO TO — see B.3.3.
(3) Statement functions — see B.3.4.
(4) DATA statements amongst executable statements — see B.3.5.
(5) Assumed length character functions — see B.3.6.
(6) Fixed form source — see B.3.7.
(7) CHARACTER* form of CHARACTER declaration — see B.3.8.
(8) ENTRY statements — see B.3.9.
(9) Label form of DO statement – see B.3.10.
(10) COMMON and EQUIVALENCE statements, and the block data program unit – see B.3.11.
(11) Specific names for intrinsic functions – see B.3.12.
(12) FORALL construct and statement – see B.3.13
B.3.2 Alternate return
of the caller upon return. The same effect can be achieved with a return code that is used in a SELECT CASEconstruct on return. This avoids an irregularity in the syntax and semantics of argument association. For example,
CALL SUBR_NAME (X, Y, Z, *100, *200, *300)
can be replaced by
CALL SUBR_NAME (X, Y, Z, RETURN_CODE)
SELECT CASE (RETURN_CODE)
540 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
CASE (1)
...
CASE (2)
...
CASE (3)
...
CASE DEFAULT
...
END SELECT
B.3.3 Computed GO TO statement 1 The computed GO TO statement has been superseded by the SELECT CASE construct, which is a generalized,
easier to use, and clearer means of expressing the same computation.1 Statement functions are subject to a number of nonintuitive restrictions and are a potential source of error becauseB.3.4 Statement functions
their syntax is easily confused with that of an assignment statement.2 The internal function is a more generalized form of the statement function and completely supersedes it.
B.3.5 DATA statements among executables1 The statement ordering rules allow DATA statements to appear anywhere in a program unit after the specific-
ation statements. The ability to position DATA statements amongst executable statements is very rarely used,1 Assumed character length for functions is an irregularity in the language in that elsewhere in Fortran the philo-unnecessary, and a potential source of error.
B.3.6 Assumed character length functions
sophy is that the attributes of a function result depend only on the actual arguments of the invocation and on2 Note that dummy arguments of a function can have assumed character length.any data accessible by the function through host or use association. Some uses of this facility can be replaced
with an automatic character length function, where the length of the function result is declared in a specification
expression. Other uses can be replaced by the use of a subroutine whose arguments correspond to the function
result and the function arguments.
B.3.7 Fixed form source1 Fixed form source was designed when the principal machine-readable input medium for new programs was punched
cards. Now that new and amended programs are generally entered via keyboards with screen displays, it is an2 It is a simple matter for a software tool to convert from fixed to free form source.unnecessary overhead, and is potentially error-prone, to have to locate positions 6, 7, or 72 on a line. Free form
source was designed expressly for this more modern technology.
⃝c ISO/IEC 2017 – All rights reserved 5411 In addition to the CHARACTER*char-length form introduced in Fortran 77, Fortran 90 provided the CHAR-
ISO/IEC DIS 1539-1:2017 (E)
B.3.8 CHARACTER* form of CHARACTER declaration
ACTER([ LEN = ] type-param-value) form. The older form (CHARACTER*char-length) is redundant.1 ENTRY statements allow more than one entry point to a subprogram, facilitating sharing of data items andB.3.9 ENTRY statements
executable statements local to that subprogram.2 This can be replaced by a module containing the (private) data items, with a module procedure for each entry
point and the shared code in a private module procedure.1 The label in the DO statement is redundant with the construct name. Furthermore, the label allows unrestrictedB.3.10 Label DO statement
branches and, for its main purpose (the target of a conditional branch to skip the rest of the current iteration),1 Common blocks are error-prone and have largely been superseded by modules. EQUIVALENCE similarly isis redundant with the CYCLE statement, which is clearer.
B.3.11 COMMON and EQUIVALENCE statements and the block data program unit
error-prone. Whilst use of these statements was invaluable prior to Fortran 90 they are now redundant and1 The specific names of the intrinsic functions are often obscure and hinder portability. They have been redundantcan inhibit performance. The block data program unit exists only to serve common blocks and hence is also
redundant.
B.3.12 Specific names for intrinsic functions
since Fortran 90. Use generic names for references to intrinsic procedures.1 The FORALL construct and statement were added to the language in the expectation that they would enableB.3.13 FORALL construct and statement
highly efficient execution, especially on parallel processors. However, experience indicates that they are too1 The following features were new in Fortran 2008 but not originally listed in its Introduction as being new features:complex and have too many restrictions for compilers to take advantage of them. They are redundant with the
DO CONCURRENT construct, and many of the manipulations for which they might be used can be done more
effectively using pointers, especially using pointer rank remapping.
542 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Annex C
(Informative)
Extended notes
C.1 Fortran 2008 features not mentioned in its Introduction
• An array or object with a nonconstant length type parameter can have the VALUE attribute.2 All but the last two of the above list were subsequently added to the Introduction by Technical Corrigenda.• Multiple allocations are permitted in a single ALLOCATE statement with the SOURCE= specifier.
• A PROCEDURE statement can have a double colon before the first procedure name.
• An argument to a pure procedure can have default INTENT if it has the VALUE attribute.
• The PROTECTED attribute can be specified by the procedure declaration statement.
• A defined-operator can be used in a specification expression.
• All transformational functions from the intrinsic modules IEEE_ARITHMETIC and IEEE_EXCEPTIONS
can be used in constant expressions. All transformational functions from the intrinsic modules IEEE_-
ARITHMETIC, IEEE_EXCEPTIONS, and ISO_C_BINDING can be used in specification expressions.
• A contiguous array variable that is not interoperable but which has interoperable type and kind type
parameter (if any), and a scalar character variable with length greater than 1 and kind C_CHAR in the
intrinsic module ISO_C_BINDING, can be used as the argument of the function C_LOC in the intrinsic
module ISO_C_BINDING, provided the variable has the POINTER or TARGET attribute.
• The name of an external procedure that has a binding label is a local identifier and not a global identifier.
• A procedure that is not a procedure pointer can be an actual argument that corresponds to a procedure
pointer dummy argument with the INTENT (IN) attribute.
• An interface body for an external procedure that does not exist in a program can be used to specify an
explicit specific interface.
C.2 Clause 7 notes1 One can select the real approximation method for an entire program through the use of a module and theC.2.1 Selection of the approximation methods (7.4.3.2)
parameterized real type. This is accomplished by defining a named integer constant to have a particular kind2 To avoid the use of the processor-dependent values 4 or 8, replace 8 by KIND (0.0) or KIND (0.0D0). Anothertype parameter value and using that named constant in all real, complex, and derived-type declarations. For
example, the specification statements
INTEGER, PARAMETER :: LONG_FLOAT = 8
REAL (LONG_FLOAT) X, Y
COMPLEX (LONG_FLOAT) Z
⃝c ISO/IEC 2017 – All rights reserved 543
ISO/IEC DIS 1539-1:2017 (E)
specify that the approximation method corresponding to a kind type parameter value of 8 is supplied for the data
objects X, Y, and Z in the program unit. The kind type parameter value LONG_FLOAT can be made available
to an entire program by placing the INTEGER specification statement in a module and accessing the named
constant LONG_FLOAT with a USE statement. Note that by changing 8 to 4 once in the module, a different
approximation method is selected.
way to avoid these processor-dependent values is to select the kind value using the intrinsic function SELEC-3 As kind values have no portable meaning, a good practice is to use them in programs only through namedTED_REAL_KIND (16.9.170). In the above specification statement, the 8 might be replaced by, for instance,
SELECTED_REAL_KIND (10, 50), which requires an approximation method to be selected with at least 10
decimal digits of precision and a range from 10−50 to 1050 . There are no magnitude or ordering constraints placed
on kind values, in order that implementers have flexibility in assigning such values and can add new kinds without
changing previously assigned kind values.
constants as described above (for example, SINGLE, IEEE_SINGLE, DOUBLE, and QUAD), rather than using1 The default accessibility of the components of an extended type can be specified in the type definition. Thethe kind values directly.
C.2.2 Type extension and component accessibility (7.5.2.2, 7.5.4)
accessibility of its components can be specified individually. For example:1 The only difference between this example and the same thing rewritten to use generic interface blocks is thatmodule types
type base_type
private !-- Sets default accessibility
integer :: i !-- a private component
integer, private :: j !-- another private component
integer, public :: k !-- a public component
end type base_type
type, extends(base_type) :: my_type
private !-- Sets default for components declared in my_type
integer :: l !-- A private component.
integer, public :: m !-- A public component.
end type my_type
end module types
subroutine sub
use types
type (my_type) :: x
...
call another_sub( &
x%base_type, & !-- ok because base_type is a public subobject of x
x%base_type%k, & !-- ok because x%base_type is ok and has k as a
544 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
!-- public component.
x%k, & !-- ok because it is shorthand for x%base_type%k
x%base_type%i, & !-- Invalid because i is private.
x%i) !-- Invalid because it is shorthand for x%base_type%i
end subroutine sub
C.2.3 Generic type-bound procedures (7.5.5)
Example of a derived type with generic type-bound procedures:
with type-bound procedures,USE rational_numbers, ONLY: rational
does not block the type-bound procedures; the user still gets access to the defined assignment and extended
operations.
MODULE rational_numbers
IMPLICIT NONE
PRIVATE
TYPE,PUBLIC :: rational
PRIVATE
INTEGER n,d
CONTAINS
! ordinary type-bound procedure
PROCEDURE :: real => rat_to_real
! specific type-bound procedures for generic support
PROCEDURE,PRIVATE :: rat_asgn_i, rat_plus_i, rat_plus_rat => rat_plus
PROCEDURE,PRIVATE,PASS(b) :: i_plus_rat
! generic type-bound procedures
GENERIC :: ASSIGNMENT(=) => rat_asgn_i
GENERIC :: OPERATOR(+) => rat_plus_rat, rat_plus_i, i_plus_rat
END TYPE
CONTAINS
ELEMENTAL REAL FUNCTION rat_to_real(this) RESULT(r)
CLASS(rational),INTENT(IN) :: thisr = REAL(this%n)/this%d
END FUNCTION
ELEMENTAL SUBROUTINE rat_asgn_i(a,b)
CLASS(rational),INTENT(OUT) :: aINTEGER,INTENT(IN) :: b
a%n = b
a%d = 1
END SUBROUTINE
ELEMENTAL TYPE(rational) FUNCTION rat_plus_i(a,b) RESULT(r)
CLASS(rational),INTENT(IN) :: aINTEGER,INTENT(IN) :: b
⃝c ISO/IEC 2017 – All rights reserved 545
ISO/IEC DIS 1539-1:2017 (E)
r%n = a%n + b*a%dr%d = a%d
END FUNCTION
ELEMENTAL TYPE(rational) FUNCTION i_plus_rat(a,b) RESULT(r)
INTEGER,INTENT(IN) :: aCLASS(rational),INTENT(IN) :: b
r%n = b%n + a*b%d
r%d = b%d
END FUNCTION
ELEMENTAL TYPE(rational) FUNCTION rat_plus(a,b) RESULT(r)
CLASS(rational),INTENT(IN) :: a,br%n = a%n*b%d + b%n*a%d
r%d = a%d*b%d
END FUNCTION
END
C.2.4 Abstract types (7.5.7.1) 1 The following illustrates how an abstract type can be used as the basis for a collection of related types, and how
a non-abstract member of that collection can be created by type extension.TYPE, ABSTRACT :: DRAWABLE_OBJECT
REAL, DIMENSION(3) :: RGB_COLOR = (/1.0,1.0,1.0/) ! White
REAL, DIMENSION(2) :: POSITION = (/0.0,0.0/) ! Centroid
CONTAINS
PROCEDURE(RENDER_X), PASS(OBJECT), DEFERRED :: RENDER
END TYPE DRAWABLE_OBJECT
ABSTRACT INTERFACE
SUBROUTINE RENDER_X(OBJECT, WINDOW)
IMPORT DRAWABLE_OBJECT, X_WINDOWCLASS(DRAWABLE_OBJECT), INTENT(IN) :: OBJECT
CLASS(X_WINDOW), INTENT(INOUT) :: WINDOW
END SUBROUTINE RENDER_X
END INTERFACE
...
TYPE, EXTENDS(DRAWABLE_OBJECT) :: DRAWABLE_TRIANGLE ! Not ABSTRACT
REAL, DIMENSION(2,3) :: VERTICES ! In relation to centroid
CONTAINS
PROCEDURE, PASS(OBJECT) :: RENDER=>RENDER_TRIANGLE_X
END TYPE DRAWABLE_TRIANGLE
2 The actual drawing procedure will draw a triangle in WINDOW with vertices at x and y coordinates at
OBJECT%POSITION(1)+OBJECT%VERTICES(1,1:3) and OBJECT%POSITION(2)+OBJECT%VERTICES(2,1:3):546 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
SUBROUTINE RENDER_TRIANGLE_X(OBJECT, WINDOW)
CLASS(DRAWABLE_TRIANGLE), INTENT(IN) :: OBJECT
CLASS(X_WINDOW), INTENT(INOUT) :: WINDOW
...
END SUBROUTINE RENDER_TRIANGLE_X
C.2.5 Structure constructors and generic names (7.5.10) 1 A generic name can be the same as a type name. This can be used to emulate user-defined structure constructors
for that type, even if the type has private components. For example:MODULE mytype_module
TYPE mytype
PRIVATE
COMPLEX value
LOGICAL exact
END TYPE
INTERFACE mytype
MODULE PROCEDURE int_to_mytype
END INTERFACE
! Operator definitions etc.
...
CONTAINS
TYPE(mytype) FUNCTION int_to_mytype(i)
INTEGER,INTENT(IN) :: iint_to_mytype%value = i
int_to_mytype%exact = .TRUE.
END FUNCTION
! Procedures to support operators etc.
...
END
PROGRAM example
USE mytype_moduleTYPE(mytype) x
x = mytype(17)
END
2 The type name can still be used as a generic name if the type has type parameters. For example:
MODULE mTYPE t(kind)
INTEGER, KIND :: kind
COMPLEX(kind) value
END TYPE
INTEGER,PARAMETER :: single = KIND(0.0), double = KIND(0d0)
INTERFACE t
⃝c ISO/IEC 2017 – All rights reserved 547
ISO/IEC DIS 1539-1:2017 (E)
MODULE PROCEDURE real_to_t1, dble_to_t2, int_to_t1, int_to_t2
END INTERFACE
...
CONTAINS
TYPE(t(single)) FUNCTION real_to_t1(x)
REAL(single) xreal_to_t1%value = x
END FUNCTION
TYPE(t(double)) FUNCTION dble_to_t2(x)
REAL(double) xdble_to_t2%value = x
END FUNCTION
TYPE(t(single)) FUNCTION int_to_t1(x,mold)
INTEGER xTYPE(t(single)) mold
int_to_t1%value = x
END FUNCTION
TYPE(t(double)) FUNCTION int_to_t2(x,mold)
INTEGER xTYPE(t(double)) mold
int_to_t2%value = x
END FUNCTION
...
END
PROGRAM example
USE mTYPE(t(single)) x
TYPE(t(double)) y
x = t(1.5) ! References real_to_t1
x = t(17,mold=x) ! References int_to_t1
y = t(1.5d0) ! References dble_to_t2
y = t(42,mold=y) ! References int_to_t2
y = t(kind(0d0)) ((0,1)) ! Uses the structure constructor for type t
END
Example of a parameterized derived type with final subroutines:
C.2.6 Final subroutines (7.5.6, 7.5.6.2, 7.5.6.3, 7.5.6.4)
MODULE mTYPE t(k)
INTEGER, KIND :: k
REAL(k),POINTER :: vector(:) => NULL()
CONTAINS
FINAL :: finalize_t1s, finalize_t1v, finalize_t2e
END TYPE
548 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
CONTAINS
SUBROUTINE finalize_t1s(x)
TYPE(t(KIND(0.0))) xIF (ASSOCIATED(x%vector)) DEALLOCATE(x%vector)
END SUBROUTINE
SUBROUTINE finalize_t1v(x)
TYPE(t(KIND(0.0))) x(:)DO i=LBOUND(x,1),UBOUND(x,1)
IF (ASSOCIATED(x(i)%vector)) DEALLOCATE(x(i)%vector)
END DO
END SUBROUTINE
ELEMENTAL SUBROUTINE finalize_t2e(x)
TYPE(t(KIND(0.0d0))),INTENT(INOUT) :: xIF (ASSOCIATED(x%vector)) DEALLOCATE(x%vector)
END SUBROUTINE
END MODULE
SUBROUTINE example(n)
USE mTYPE(t(KIND(0.0))) a,b(10),c(n,2)
TYPE(t(KIND(0.0d0))) d(n,n)
...
! Returning from this subroutine will effectively do
! CALL finalize_t1s(a)
! CALL finalize_t1v(b)
! CALL finalize_t2e(d)
! No final subroutine will be called for variable C because the user
! omitted to define a suitable specific procedure for it.
END SUBROUTINE
Example of extended types with final subroutines:
MODULE mTYPE t1
REAL a,b
END TYPE
TYPE,EXTENDS(t1) :: t2
REAL,POINTER :: c(:),d(:)
CONTAINS
FINAL :: t2f
END TYPE
TYPE,EXTENDS(t2) :: t3
REAL,POINTER :: e
CONTAINS
FINAL :: t3f
END TYPE
...
⃝
c ISO/IEC 2017 – All rights reserved 549
ISO/IEC DIS 1539-1:2017 (E)
CONTAINS
SUBROUTINE t2f(x) ! Finalizer for TYPE(t2)’s extra components
TYPE(t2) :: xIF (ASSOCIATED(x%c)) DEALLOCATE(x%c)
IF (ASSOCIATED(x%d)) DEALLOCATE(x%d)
END SUBROUTINE
SUBROUTINE t3f(y) ! Finalizer for TYPE(t3)’s extra components
TYPE(t3) :: yIF (ASSOCIATED(y%e)) DEALLOCATE(y%e)
END SUBROUTINE
END MODULE
SUBROUTINE example
USE mTYPE(t1) x1
TYPE(t2) x2
TYPE(t3) x3
...
! Returning from this subroutine will effectively do
! ! Nothing to x1; it is not finalizable
! CALL t2f(x2)
! CALL t3f(x3)
! CALL t2f(x3%t2)
END SUBROUTINE
C.3 Clause 8 notes: The VOLATILE attribute (8.5.19) 1 The following example shows the use of a variable with the VOLATILE attribute to communicate with an
asynchronous process, in this case the operating system. The program detects a user keystroke on the terminal2 The VOLATILE attribute is necessary to prevent an optimizing compiler from storing the communication variableand reacts at a convenient point in its processing.
in a register or from doing flow analysis and deciding that the EXIT statement can never be executed.
SUBROUTINE TERMINATE_ITERATIONS
PRINT *, " Hit any key to terminate iterations!"
LOGICAL, VOLATILE :: USER_HIT_ANY_KEY ! Have the OS start to look for a user keystroke and set the variable ! "USER_HIT_ANY_KEY" to TRUE as soon as it detects a keystroke. ! This call is operating system dependent. CALL OS_BEGIN_DETECT_USER_KEYSTROKE( USER_HIT_ANY_KEY ) USER_HIT_ANY_KEY = .FALSE. ! This will ignore any recent keystrokes. DO I = 1,100
... ! Compute a value for R.
550 c ISO/IEC 2017 – All rights reservedPRINT *, I, R
ISO/IEC DIS 1539-1:2017 (E)
IF (USER_HIT_ANY_KEY) EXIT ENDDO
! Have the OS stop looking for user keystrokes.
CALL OS_STOP_DETECT_USER_KEYSTROKE
END SUBROUTINE TERMINATE_ITERATIONS
C.4 Clause 9 notes C.4.1 Structure components (9.4.2) 1 Components of a structure are referenced by writing the components of successive levels of the structure hierarchy
until the desired component is described. For example,
TYPE ID_NUMBERS
INTEGER SSN
INTEGER EMPLOYEE_NUMBER
END TYPE ID_NUMBERS
TYPE PERSON_ID
CHARACTER (LEN=30) LAST_NAME
CHARACTER (LEN=1) MIDDLE_INITIAL
CHARACTER (LEN=30) FIRST_NAME
TYPE (ID_NUMBERS) NUMBER
END TYPE PERSON_ID
TYPE PERSON
INTEGER AGE
TYPE (PERSON_ID) ID
END TYPE PERSON
TYPE (PERSON) GEORGE, MARY
*, GEORGE % AGE ! Print the AGE component *, MARY % ID % LAST_NAME ! Print LAST_NAME of MARY *, MARY % ID % NUMBER % SSN ! Print SSN of MARY *, GEORGE % ID % NUMBER ! Print SSN and EMPLOYEE_NUMBER of GEORGE 2 A structure component can be a data object of intrinsic type as in the case of GEORGE % AGE or it can be
of derived type as in the case of GEORGE % ID % NUMBER. The resultant component can be a scalar or anarray of intrinsic or derived type.
TYPE LARGE
INTEGER ELT (10)
INTEGER VAL
⃝c ISO/IEC 2017 – All rights reserved 551
ISO/IEC DIS 1539-1:2017 (E)END TYPE LARGE
TYPE (LARGE) A (5) ! 5 element array, each of whose elements ! includes a 10 element array ELT and! a scalar VAL.
PRINT *, A (1) ! Prints 10 element array ELT and scalar VAL. PRINT *, A (1) % ELT (3) ! Prints scalar element 3 ! of array element 1 of A.
PRINT *, A (2:4) % VAL ! Prints scalar VAL for array elements ! 2 to 4 of A.3 Components of an object of extensible type that are inherited from the parent type can be accessed as a whole
by using the parent component name, or individually, either with or without qualifying them by the parentcomponent name. For example:
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 parentINTEGER :: COLOR
END TYPE COLOR_POINT
TYPE(POINT) :: PV = POINT(1.0, 2.0)
TYPE(COLOR_POINT) :: CPV = COLOR_POINT(POINT=PV, COLOR=3)
PRINT *, CPV%POINT ! Prints 1.0 and 2.0 PRINT *, CPV%POINT%X, CPV%POINT%Y ! And this does, too PRINT *, CPV%X, CPV%Y ! And this does, too
C.4.2 Allocation with dynamic type (9.7.1) 1 The following example illustrates the use of allocation with the value and dynamic type of the allocated object
given by another object. The example copies a list of objects of any type. It copies the list starting at IN_LIST.After copying, each element of the list starting at LIST_COPY has a polymorphic component, ITEM, for which
both the value and type are taken from the ITEM component of the corresponding element of the list starting at
IN_LIST.
TYPE :: LIST ! A list of anything
TYPE(LIST), POINTER :: NEXT => NULL()
CLASS(*), ALLOCATABLE :: ITEM
END TYPE LIST
...
TYPE(LIST), POINTER :: IN_LIST, LIST_COPY => NULL()
TYPE(LIST), POINTER :: IN_WALK, NEW_TAIL
! Copy IN_LIST to LIST_COPY
IF (ASSOCIATED(IN_LIST)) THEN
552 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)IN_WALK => IN_LIST
ALLOCATE(LIST_COPY)
NEW_TAIL => LIST_COPY
DO
ALLOCATE(NEW_TAIL%ITEM, SOURCE=IN_WALK%ITEM)
IN_WALK => IN_WALK%NEXT
IF (.NOT. ASSOCIATED(IN_WALK)) EXIT
ALLOCATE(NEW_TAIL%NEXT)
NEW_TAIL => NEW_TAIL%NEXT
END DO
END IF
C.5 Clause 10 notes C.5.1 Evaluation of function references (10.1.7) 1 If more than one function reference appears in a statement, they can be executed in any order (subject to a
function result being evaluated after the evaluation of its arguments) and their values cannot depend on the order1 A pointer is considered to be like any other variable when it is used as a primary in an expression. If a pointerof execution. This lack of dependence on order of evaluation enables parallel execution of the function references.
C.5.2 Pointers in expressions (10.1.9.2)
is used as an operand to an operator that expects a value, the pointer will automatically deliver the value stored1 The appearance of a pointer in a context that requires its value is a reference to its target. Similarly, where ain the space described by the pointer, that is, the value of the target object associated with the pointer.
C.5.3 Pointers in variable definition contexts (10.2.1.3, 19.6.7)
pointer appears in a variable definition context the variable that is defined is the target of the pointer.2 Executing the program fragment
REAL, POINTER :: Aproduces “42.0” as output.REAL, TARGET :: B = 10.0
A => B
A = 42.0
PRINT ’(F4.1)’, B
C.6 Clause 11 notes C.6.1 The SELECT CASE construct (11.1.9) 1 At most one case block is selected for execution within a SELECT CASE construct, and there is no fall-through
from one block into another block within a SELECT CASE construct. Thus there is no requirement for the user1 Fortran provides several forms of loop control:to exit explicitly from a block.
⃝c ISO/IEC 2017 – All rights reserved 553
ISO/IEC DIS 1539-1:2017 (E)
C.6.2 Loop control (11.1.7)
(1) With an iteration count and a DO variable. This is the classic Fortran DO loop.(2) Test a logical condition before each execution of the loop (DO WHILE).
(3) DO “forever”.
C.6.3 Examples of DO constructs (11.1.7) 1 The following are all valid examples of DO constructs.
Example 1:SUM = 0.0
READ (IUN) N
OUTER: DO L = 1, N ! A DO with a construct name
READ (IUN) IQUAL, M, ARRAY (1:M)
IF (IQUAL < IQUAL_MIN) CYCLE OUTER ! Skip inner loop
INNER: DO 40 I = 1, M ! A DO with a label and a name
CALL CALCULATE (ARRAY (I), RESULT)
IF (RESULT < 0.0) CYCLE
SUM = SUM + RESULT
IF (SUM > SUM_MAX) EXIT OUTER
40 END DO INNER
END DO OUTER
2 The outer loop has an iteration count of MAX (N, 0), and will execute that number of times or until SUM exceeds
SUM_MAX, in which case the EXIT OUTER statement terminates both loops. The inner loop is skipped by3 After execution of the above program fragment, I = 11, J = 10, K = 6, L = 5, and N = 50.the first CYCLE statement if the quality flag, IQUAL, is too low. If CALCULATE returns a negative RESULT,
the second CYCLE statement prevents it from being summed. Both loops have construct names and the inner
loop also has a label. A construct name is required in the EXIT statement in order to terminate both loops, but
is optional in the CYCLE statements because each belongs to its innermost loop.
Example 2:
N = 0
DO 50, I = 1, 10
J = I
DO K = 1, 5
L = K
N = N + 1 ! This statement executes 50 times
END DO ! Nonlabeled DO inside a labeled DO
50 CONTINUE
554 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Example 3:
N = 0
DO I = 1, 10
J = I
DO 60, K = 5, 1 ! This inner loop is never executed
L = K
N = N + 1
60 CONTINUE ! Labeled DO inside a nonlabeled DO
END DO
4 After execution of the above program fragment, I = 11, J = 10, K = 5, N = 0, and L is not defined by these
statements.1 The following are all examples of invalid skeleton DO constructs:C.6.4 Examples of invalid DO constructs (11.1.7)
Example 1:DO I = 1, 10
...
END DO LOOP ! No matching construct name
Example 2:
LOOP: DO 1000 I = 1, 10 ! No matching construct name
...
1000 CONTINUE
Example 3:
LOOP1: DO
...
END DO LOOP2 ! Construct names don’t match
Example 4:
DO I = 1, 10 ! Label required or ...
...
1010 CONTINUE ! ... END DO required
Example 5:
DO 1020 I = 1, 10
...
1021 END DO ! Labels don’t match
⃝c ISO/IEC 2017 – All rights reserved 555
ISO/IEC DIS 1539-1:2017 (E)
Example 6:
FIRST: DO I = 1, 10
SECOND: DO J = 1, 5
...
END DO FIRST ! Improperly nested DOs
END DO SECOND
C.6.5 Simple example using events 1 A tree is a graph in which every node except one has a single “parent” node to which it is connected by an edge.
The node without a parent is the “root” of the tree. The nodes that have a particular node as their parent are2 A multifrontal code to solve a sparse set of linear equations involves a tree. Work at a node can start after all ofthe “children” of that node. The root is at level 1, its children are at level 2, and so on.
its children’s work is complete and their data have been passed to it.3 Here we assume that each node has been assigned to an image. Each image has a list of its nodes and these
are ordered in decreasing tree level (all those at level L preceding those at level L − 1). For each node, arrayelements hold the number of children, details about the parent, and an event variable. This allows the processing
to proceed asynchronously subject to the rule that a parent has to wait for all its children.
Outline of example code:
PROGRAM TREE
USE, INTRINSIC :: ISO_FORTRAN_ENV
INTEGER, ALLOCATABLE :: NODE (:) ! Tree nodes that this image handles.
INTEGER, ALLOCATABLE :: PARENT (:), SUB (:)
INTEGER, ALLOCATABLE :: NC (:) ! NODE(I) has NC(I) children.
! The parent of NODE (I) is NODE (SUB (I)) [PARENT (I)].TYPE (EVENT_TYPE), ALLOCATABLE :: DONE (:) [:]
INTEGER :: I, J, STATUS
! Set up the tree, including allocation of all arrays.
DO I = 1, SIZE (NODE)
! Wait for children to completeIF (NC (I) > 0) THEN
EVENT WAIT (DONE (I), UNTIL_COUNT=NC (I), STAT=STATUS)
IF (STATUS/=0) EXIT
END IF
! Process node, using data from children.
IF (PARENT (I)>0) THEN
! Node is not the root.! Place result on image PARENT (I) for node NODE (SUB) [PARENT (I)]
! Tell PARENT (I) that this has been done.
EVENT POST (DONE (SUB (I)) [PARENT (I)], STAT=STATUS)
IF (STATUS/=0) EXIT
END IF
END DO
END PROGRAM TREE
556 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C.6.6 Example using three teams 1 The following example illustrates the structure of a routine that will compute fluxes based on surface properties
over land, sea, and ice, each in a different team. Each image will deal with areas containing exactly one of thethree surface types.
SUBROUTINE COMPUTE_FLUXES (FLUX_MOM, FLUX_SENS, FLUX_LAT)
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE
REAL, INTENT (OUT) :: FLUX_MOM (:,:), FLUX_SENS (:,:), FLUX_LAT (:,:)
INTEGER, PARAMETER :: LAND = 1, SEA = 2, ICE = 3
CHARACTER (LEN=10) :: SURFACE_TYPE
INTEGER :: MY_SURFACE_TYPE, N_IMAGE
TYPE (TEAM_TYPE) :: TEAM_SURFACE_TYPE
CALL GET_SURFACE_TYPE(THIS_IMAGE (), SURFACE_TYPE)
SELECT CASE (SURFACE_TYPE)
CASE ("LAND")
MY_SURFACE_TYPE = LAND
CASE ("SEA")
MY_SURFACE_TYPE = SEA
CASE ("ICE")
MY_SURFACE_TYPE = ICE
CASE DEFAULT
ERROR STOP
END SELECT
FORM TEAM (MY_SURFACE_TYPE, TEAM_SURFACE_TYPE)
CHANGE TEAM (TEAM_SURFACE_TYPE)
SELECT CASE (TEAM_NUMBER ( ))CASE (LAND) ! Compute fluxes over land surface
CALL COMPUTE_FLUXES_LAND (FLUX_MOM, FLUX_SENS, FLUX_LAT)
CASE (SEA) ! Compute fluxes over sea surface
CALL COMPUTE_FLUXES_SEA (FLUX_MOM, FLUX_SENS, FLUX_LAT)
CASE (ICE) ! Compute fluxes over ice surface
CALL COMPUTE_FLUXES_ICE (FLUX_MOM, FLUX_SENS, FLUX_LAT)
CASE DEFAULT
ERROR STOP
END SELECT
END TEAM
END SUBROUTINE COMPUTE_FLUXES
C.6.7 Accessing coarrays in sibling teams 1 The following program illustrates subdividing a 4 × 4 grid into 2 × 2 teams, and the denotation of sibling teams.
PROGRAM DEMO
! Initial team : 16 images. Algorithm design is a 4 by 4 grid.
! Desire 4 teams, for the upper left (UL), upper right (UR),
⃝c ISO/IEC 2017 – All rights reserved 557
ISO/IEC DIS 1539-1:2017 (E)
! lower left (LL), lower right (LR)USE,INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE
TYPE (TEAM_TYPE) :: T
INTEGER, PARAMETER :: UL=11, UR=22, LL=33, LR=44
REAL :: A(10,10)[4,*]
INTEGER :: MYPE, TEAMNUM, NEWPE
TYPE TRANS_T
INTEGER :: NEW_TEAM (16), NEW_INDEX (16)
END TYPE
TYPE (TRANS_T) :: TRANS
TRANS = TRANS_T ([UL, UL, LL, LL, UL, UL, LL, LL, UR, UR, LR, LR, UR, UR, LR, LR], &
[1, 2, 1, 2, 3, 4, 3, 4, 1, 2, 1, 2, 3, 4, 3, 4])MYPE = THIS_IMAGE ()
FORM TEAM (TRANS%NEW_TEAM(MYPE), T, NEW_INDEX=TRANS%NEW_INDEX(MYPE))
A = 3.14
CHANGE TEAM (T, B[2,*] => A)
! Inside change team, image pattern for B is a 2 by 2 grid.B (5, 5) = B (1, 1)[2, 1]
! Outside the team addressing:
NEWPE = THIS_IMAGE ()
SELECT CASE (TEAM_NUMBER ())
CASE (UL)
IF (NEWPE==3) THEN
! Right column of UL gets left column of UR.
B (:, 10) = B (:, 1)[1, 1, TEAM_NUMBER=UR]
ELSE IF (NEWPE==4) THEN
B (:, 10) = B (:, 1)[2, 1, TEAM_NUMBER=UR]
END IF
CASE (LL)
! Similar to complete column exchange across middle of the original grid....
END SELECT
END TEAM
END PROGRAM DEMO
C.6.8 Example involving failed images 1 Parallel algorithms often use work sharing schemes based on a specific mapping between image indices and global
data addressing. To allow such programs to continue when one or more images fail, spare images can be used2 The following example illustrates how this might be done. In this example, failure cannot be tolerated for imageto re-establish execution of the algorithm with the failed images replaced by spare images, while retaining the
previous image mapping for nonfailed images.
558 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
1 in the initial team.
PROGRAM possibly_recoverable_simulationUSE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: TEAM_TYPE, STAT_FAILED_IMAGE
IMPLICIT NONE
INTEGER, ALLOCATABLE :: failures (:)
INTEGER :: images_used, i, images_spare, status
INTEGER :: id [*], me [*]
TYPE (TEAM_TYPE) :: simulation_team
LOGICAL :: read_checkpoint, done [*]
! Keep 1% spare images if we have a lot, just 1 if 10-199 images, 0 if <10.
images_spare = MAX (INT (0.01*NUM_IMAGES ()), 0, MIN (NUM_IMAGES () - 10, 1)
images_used = NUM_IMAGES () - images_spare
read_checkpoint = THIS_IMAGE () > images_used
setup : DO
me = THIS_IMAGE ()id = MERGE (1, 2, me<=images_used)
!
! Set up spare images as replacement for failed ones.
!
IF (IMAGE_STATUS (1) == STAT_FAILED_IMAGE) &
ERROR STOP "cannot recover"
IF (me == 1) THEN
failures = FAILED_IMAGES ()
k = images_used
DO i = 1, SIZE (failures)
DO k = k+1, NUM_IMAGES ()
IF (IMAGE_STATUS (k) == 0) EXIT
END DO
IF (k > NUM_IMAGES ()) ERROR STOP "cannot recover"
me [k] = failures (i)
id [k] = 1
END DO
images_used = k
END IF
!
! Set up a simulation team of constant size.
! Team 2 is the set of spares, so does not participate in the simulation.
!
FORM TEAM (id, simulation_team, NEW_INDEX=me, STAT=status)
simulation : CHANGE TEAM (simulation_team, STAT=status)
IF (status == STAT_FAILED_IMAGE) EXIT simulationIF (TEAM_NUMBER () == 1) THEN
iter : DO
⃝c ISO/IEC 2017 – All rights reserved 559
ISO/IEC DIS 1539-1:2017 (E)
CALL simulation_procedure (read_checkpoint, status, done)! The simulation_procedure:
! - sets up and performs some part of the simulation;
! - resets to the last checkpoint if requested;
! - sets status from its internal synchronizations;
! - sets done to .TRUE. when the simulation has completed.
IF (status == STAT_FAILED_IMAGE) THEN
read_checkpoint = .TRUE.
EXIT simulation
ELSE IF (done)
EXIT iter
END IF
read_checkpoint = .FALSE.
END DO iter
END IF
END TEAM simulation (STAT=status)
SYNC ALL (STAT=status)
IF (THIS_IMAGE () > images_used) done = done[1]
IF (done) EXIT setup
END DO setup
END PROGRAM possibly_recoverable_simulation
3 Supporting fault-tolerant execution imposes obligations on library writers who use the parallel language facilities.
Every synchronization statement, allocation or deallocation of coarrays, or invocation of a collective procedure1 This example is an adaptation of the later EVENT_QUERY example of C.11.2 to make it able to execute inwill need to be prepared to handle error conditions, and implicit deallocation of coarrays will need to be avoided.
Also, coarray module variables that are allocated inside the team execution context are not persistent.
C.6.9 EVENT_QUERY example that tolerates image failure
the presence of the failure of one or more of the worker images. The function create_work_item now accepts aninteger argument to indicate which work item is required. It is assumed that the work items are indexed 1, 2,
... . It is also assumed that if an image fails while processing a work item, that work item can subsequently be
processed by another image.
PROGRAM work_share
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: EVENT_TYPE
USE :: mod_work, ONLY: & ! Module that creates work items
work, & ! Type for holding a work item
create_work_item, & ! Function that creates work item
process_item, & ! Function that processes an item
work_done ! Logical function that returns true
! if all work done
TYPE :: worker_type
TYPE (EVENT_TYPE), ALLOCATABLE :: free (:)
END TYPE
560 c ISO/IEC 2017 – All rights reservedISO/IEC DIS 1539-1:2017 (E)
INTEGER :: count, i, k, kk, nbusy [*], np, status
TYPE (EVENT_TYPE) :: submit [*] ! Whether work ready for a worker TYPE (worker_type) :: worker [*] ! Whether worker is free TYPE (work) :: work_item [*] ! Holds the data for a work item INTEGER, ALLOCATABLE :: working (:) ! Items being worked on
INTEGER, ALLOCATABLE :: pending (:) ! Items pending after image failure
IF (THIS_IMAGE () == 1) THEN! Get started
ALLOCATE (worker%free (2:NUM_IMAGES ()))
ALLOCATE (working (2: NUM_IMAGES ()), pending(NUM_IMAGES ()-1))
nbusy = 0 ! This holds the number of workers working
k = 1 ! Index of next work item
np = 0 ! Number of work items in array pending
DO i = 2, NUM_IMAGES () ! Start the workers working
IF (work_done ()) EXIT
working (i) = 0
IF (IMAGE_STATUS (i) == STAT_FAILED_IMAGE) CYCLE
work_item [i] = create_work_item (k)
working (i) = k
k = k + 1
nbusy = nbusy + 1
EVENT POST (submit [i], STAT=status)
END DO
! Main work distribution loop
master : DO
image : DO i = 2, NUM_IMAGES ()IF (IMAGE_STATUS (i) == STAT_FAILED_IMAGE) THEN
IF (working (i)>0) THEN ! It failed while working
np = np + 1
pending (np) = working (i)
working (i) = 0
END IF
CYCLE image
END IF
CALL EVENT_QUERY (worker%free (i), count)
EVENT WAIT (worker%free (i))
IF (count == 0) CYCLE image ! Worker is not free nbusy = nbusy - 1
IF (np>0) THEN
kk = pending (np)np = np - 1
ELSE
IF (work_done ()) CYCLE image
kk = k
k = k + 1
⃝
c ISO/IEC 2017 – All rights reserved 561
ISO/IEC DIS 1539-1:2017 (E)
END IF
nbusy = nbusy + 1
working (i) = kk
work_item [i] = create_work_item (kk)
EVENT POST (submit [i], STAT=status)
! If image i has failed, the failure will be handled on
! the next iteration of the master loop.
END DO image
IF ( nbusy==0 ) THEN ! All done. Exit on all images.
DO i = 2, NUM_IMAGES ()EVENT POST (submit [i], STAT=status)
IF (status == STAT_FAILED_IMAGE) CYCLE
END DO
EXIT master
END IF
END DO master
ELSE
! Work processing loop
worker : DO
EVENT WAIT (submit)END DO workerIF (nbusy [1] == 0) EXIT worker
CALL process_item(work_item)
EVENT POST (worker[1]%free (THIS_IMAGE ()))
END IF
END PROGRAM work_share
C.7 Clause 12 notes
C.7.1 External files (12.3) 1 This document accommodates, but does not require, file cataloging. To do this, several concepts are introduced. C.7.1.1 File existence (12.3.2)1 Totally independent of the connection state is the property of existence, this being a file property. The processor
“knows” of a set of files that exist at a given time for a given program. This set would include tapes ready to2 All four combinations of connection and existence can occur:read, files in a catalog, a keyboard, a printer, etc. The set might exclude files inaccessible to the program because
of security, because they are already in use by another program, etc. This document does not specify which
files exist, hence wide latitude is available to a processor to implement security, locks, privilege techniques, etc.
Existence is a convenient concept to designate all of the files that a program can potentially process.
562 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Connect Exist Examples3 Means are provided to create, delete, connect, and disconnect files.Yes Yes A card reader loaded and ready to be read
Yes No A printer before the first line is written
No Yes A file named ’JOAN’ in the catalog
No No A file on a reel of tape, not known to the processor
C.7.1.2 File access (12.3.3)1 This document does not address problems of security, protection, locking, and many other concepts that might
be part of the concept of “right of access”. Such concepts are considered to be in the province of an operating2 The OPEN and INQUIRE statements can be extended naturally to consider these things.system.
3 Possible access methods for a file are: sequential, stream and direct. The processor might implement three
different types of files, each with its own access method. It might instead implement one type of file with three4 Direct access to files is of a simple and commonly available type, that is, fixed-length records. The key is adifferent access methods.
positive integer.1 Before any input/output can be performed on a file, it needs to be connected to a unit. The unit then serves as aC.7.1.3 File connection (12.5)
designator for that file as long as it is connected. To be connected does not imply that “buffers” have or have not1 A file can have a name. The form of a file name is not specified. If a system does not have some form of catalogingbeen allocated, that “file-control tables” have or have not been filled, or that any other method of implementation
has been used. Connection means that (barring some other fault) a READ or WRITE statement can be executed
on the unit, hence on the file. Without a connection, a READ or WRITE statement cannot be executed.
C.7.1.4 File names (12.5.6.10)
or tape labeling for at least some of its files, all file names disappear at the termination of execution. This is a1 Data transfer statements affect the positioning of an external file. In Fortran 77, if no error or end-of-filevalid implementation. Nowhere does this document require names to survive for any period of time longer than
the execution time span of a program. Therefore, this document does not impose cataloging as a prerequisite.
The naming feature is intended to enable use of a cataloging system where one exists.
C.7.2 Nonadvancing input/output (12.3.4.2)
condition exists, the file is positioned after the record just read or written and that record becomes the preceding2 The tab edit descriptor and the slash are still appropriate for use with this type of record access but the tabrecord. This document contains the ADVANCE= specifier in a data transfer statement that provides the capab-
ility of maintaining a position within the current record from one formatted data transfer statement to the next
data transfer statement. The value NO provides this capability. The value YES positions the file after the record
just read or written. The default is YES.
⃝c ISO/IEC 2017 – All rights reserved 563
ISO/IEC DIS 1539-1:2017 (E)
cannot reposition before the left tab limit.3 A BACKSPACE of a file that is positioned within a record causes the specified unit to be positioned before the
current record.4 If the next input/output operation on a file after a nonadvancing write is a rewind, backspace, end file or close
operation, the file is positioned implicitly after the current record before an ENDFILE record is written to the5 This document provides a SIZE= specifier to be used with formatted data transfer statements. The variable infile, that is, a REWIND, BACKSPACE, or ENDFILE statement following a nonadvancing WRITE statement
causes the file to be positioned at the end of the current output record before the endfile record is written to the
file.
the SIZE= specifier is assigned the count of the number of characters that make up the sequence of values read6 The count is especially helpful if there is only one list item in the input list because it is the number of charactersby the data edit descriptors in the input statement.
that appeared for the item.7 The EOR= specifier is provided to indicate when an EOR condition is encountered during a nonadvancing data
transfer statement. The EOR condition is not an error condition. If this specifier appears, an input list item that8 For nonadvancing input, the processor is not required to read partial records. The processor could read the entirerequires more characters than the record contained is padded with blanks if PAD= ’YES’ is in effect. This means
that the input list item completed successfully. The file is positioned after the current record. If the IOSTAT=
specifier appears, the specified variable is defined with the value of the named constant IOSTAT_EOR from
the intrinsic module ISO_FORTRAN_ENV and the data transfer statement is terminated. Program execution
continues with the statement specified in the EOR= specifier. The EOR= specifier gives the capability of taking
control of execution when the EOR condition is encountered. The do-variables in io-implied-dos retain their last
defined value and any remaining items in the input-item-list retain their definition status when an EOR condition
occurs. If the SIZE= specifier appears, the specified variable is assigned the number of characters read with the
data edit descriptors during the READ statement.
record into an internal buffer and make successive portions of the record available to successive input statements.9 In an implementation of nonadvancing input/output in which a nonadvancing write to a terminal device causes
immediate display of the output, such a write can be used as a mechanism to output a prompt. In this case, the10 The response, which might be read by a statement of the formstatement
WRITE (*, FMT=’(A)’, ADVANCE=’NO’) ’CONTINUE?(Y/N): ’
would result in the prompt
CONTINUE?(Y/N):
being displayed with no subsequent line feed.
READ (*, FMT=’(A)’) ANSWERcan then be entered on the same line as the prompt as in
CONTINUE?(Y/N): Y
564 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)11 This document does not require that an implementation of nonadvancing input/output operate in this manner.
For example, an implementation of nonadvancing output in which the display of the output is deferred until1 A file can become connected to a unit either by preconnection or by execution of an OPEN statement. Precon-the current record is complete is also standard-conforming. Such an implementation will not, however, allow a
prompting mechanism of this kind to operate.
C.7.3 OPEN statement (12.5.6)
nection is performed prior to the beginning of execution of a program by means external to Fortran. For example,2 The OPEN statement provides a means to access existing files that are not preconnected. An OPEN statementit could be done by job control action or by processor-established defaults. Execution of an OPEN statement is
not required in order to access preconnected files (12.5.5).
can be used in either of two ways: with a file name (open-by-name) and without a file name (open-by-unit). A3 Therefore, there are three ways a file can become connected and hence processed: preconnection, open-by-name,unit is given in either case. Open-by-name connects the specified file to the specified unit. Open-by-unit connects
a processor-dependent default file to the specified unit. (The default file might or might not have a name.)
and open-by-unit. Once a file is connected, there is no means in standard Fortran to determine how it became4 An OPEN statement can also be used to create a new file. In fact, any of the foregoing three connection methodsconnected.
can be performed on a file that does not exist. When a unit is preconnected, writing the first record creates the5 When an OPEN statement is executed, the unit specified in the OPEN statement might or might not already befile. With the other two methods, execution of the OPEN statement creates the file.
connected to a file. If it is already connected to a file (either through preconnection or by prior execution of an6 If the value of the ACTION= specifier is WRITE, then a READ statement cannot refer to the connection.OPEN statement), then omitting the FILE= specifier in the OPEN statement implies that the file is to remain
connected to the unit. Such an OPEN statement can be used to change the values of the blank interpretation
mode, decimal edit mode, pad mode, input/output rounding mode, delimiter mode, and sign mode.
ACTION = ’WRITE’ does not restrict positioning by a BACKSPACE statement or positioning specified by the7 The following examples illustrate these rules. In the first example, unit 10 is preconnected to a SCRATCH file;POSITION= specifier with the value APPEND. However, a BACKSPACE statement or an OPEN statement
containing POSITION = ’APPEND’ might fail if the processor needs to read the file to achieve the positioning.
the OPEN statement changes the value of PAD= to YES.8 In the next example, unit 12 is first connected to a file named FRED, with a status of OLD. The second OPENCHARACTER (LEN = 20) CH1
WRITE (10, ’(A)’) ’THIS IS RECORD 1’
OPEN (UNIT = 10, STATUS = ’OLD’, PAD = ’YES’)
REWIND 10
READ (10, ’(A20)’) CH1 ! CH1 now has the value
! ’THIS IS RECORD 1 ’
statement then opens unit 12 again, retaining the connection to the file FRED, but changing the value of the9 The next example is invalid because it attempts to change the value of the STATUS= specifier.DELIM= specifier to QUOTE.
⃝c ISO/IEC 2017 – All rights reserved 565
ISO/IEC DIS 1539-1:2017 (E)
CHARACTER (LEN = 25) CH2, CH3
OPEN (12, FILE = ’FRED’, STATUS = ’OLD’, DELIM = ’NONE’)
CH2 = ’"THIS STRING HAS QUOTES."’
! Quotes in string CH2
WRITE (12, *) CH2 ! Written with no delimiters
OPEN (12, DELIM = ’QUOTE’) ! Now quote is the delimiter
REWIND 12
READ (12, *) CH3 ! CH3 now has the value
! ’THIS STRING HAS QUOTES. ’
OPEN (10, FILE = ’FRED’, STATUS = ’OLD’)10 The previous example could be made valid by closing the unit first, as in the next example.WRITE (10, *) A, B, C
OPEN (10, STATUS = ’SCRATCH’) ! Attempts to make FRED a SCRATCH file
OPEN (10, FILE = ’FRED’, STATUS = ’OLD’)WRITE (10, *) A, B, C
CLOSE (10)
OPEN (10, STATUS = ’SCRATCH’) ! Opens a different SCRATCH file
C.7.4 Connection properties (12.5.4) 1 When a unit becomes connected to a file, either by execution of an OPEN statement or by preconnection, the following connection properties, among others, are established.2 A processor has wide latitude in adapting these concepts and actions to its own cataloging and job control(1) An access method, which is sequential, direct, or stream, is established for the connection (12.5.6.3).
(2) A form, which is formatted or unformatted, is established for a connection to a file that exists or
is created by the connection. For a connection that results from execution of an OPEN statement,
a default form (which depends on the access method, as described in 12.3.3) is established if no
form is specified. For a preconnected file that exists, a form is established by preconnection. For a
preconnected file that does not exist, a form might be established, or the establishment of a form
might be delayed until the file is created (for example, by execution of a formatted or unformatted
WRITE statement) (12.5.6.11).
(3) A record length might be established. If the access method is direct, the connection establishes a
record length that specifies the length of each record of the file. A direct access file can only contain
records that are all of equal length.
(4) A sequential file can contain records of varying lengths. In this case, the record length established
specifies the maximum length of a record in the file (12.5.6.15).
conventions. Some processors might need job control action to specify the set of files that exist or that will3 The meaning of “open” in contexts other than Fortran might include such things as mounting a tape, consolebe created by a program. Some processors might not need any job control action prior to execution. This
document enables processors to perform dynamic open, close, or file creation operations, but it does not require
such capabilities of the processor.
566 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
messages, spooling, label checking, security checking, etc. These actions might occur upon job control action1 Rather than limit support for asynchronous input/output to what has been traditionally provided by facilitiesexternal to Fortran, upon execution of an OPEN statement, or upon execution of the first read or write of the
file. The OPEN statement describes properties of the connection to the file and might or might not cause physical
activities to take place.
C.7.5 Asynchronous input/output (12.6.2.5)
such as BUFFERIN/BUFFEROUT, this document builds upon existing Fortran syntax. This permits alternative2 Not all processors actually perform input/output asynchronously, nor will every processor that does be able toapproaches for implementing asynchronous input/output, and simplifies the task of adapting existing standard-
conforming programs to use asynchronous input/output.
handle data transfer statements with complicated input/output item lists in an asynchronous manner. Such3 This document allows for at least two different conceptual models for asynchronous input/output.processors can still be standard-conforming.
4 Model 1: the processor performs asynchronous input/output when the item list is simple (perhaps one contiguous
named array) and the input/output is unformatted. The implementation cost is reduced, and this is the scenario5 Model 2: The processor is free to do any of the following:most likely to be beneficial on traditional “big-iron” machines.
(1) on output, create a buffer inside the input/output library, completely formatted, and then start an6 A program can issue a large number of asynchronous input/output requests, without waiting for any of them toasynchronous write of the buffer, and immediately return to the next statement in the program. The
processor is free to wait for previously issued WRITEs, or not, or
(2) pass the input/output list addresses to another processor/process, which processes the list items
independently of the processor that executes the user’s code. The addresses of the list items will
need to be computed before the asynchronous READ/WRITE statement completes. There is still
an ordering requirement on list item processing to handle things like READ (...) N,(a(i),i=1,N).
complete, and then wait for any or all of them. That does not constitute a requirement for the processor to keep7 It is not necessary for all requests to be tracked by the runtime library. If an ID= specifier does not appear in on atrack of each individual request separately.
READ or WRITE statement, the runtime library can forget about this particular request once it has successfully8 The requirement to set the IOSTAT variable correctly means that a processor will need to remember whichcompleted. If an error or end-of-file condition occurs for a request, the processor can report this during any
input/output operation to that unit. If an ID= specifier appears, the processor’s runtime input/output library
will need to keep track of any end-of-file or error conditions for that particular input/output request. However, if
the input/output request succeeds without any exceptional conditions occurring, then the runtime can forget that
ID= value. A runtime library might only keep track of the last request made, or perhaps a very few. Then, when
a user WAITs for a particular request, either the library will know about it (and does the right thing with respect
to error handling, etc.), or can assume it is a request that successfully completed and was forgotten about (and
will just return without signaling any end-of-file or error condition). A standard-conforming program can only
pass valid ID= values, but there is no requirement on the processor to detect invalid ID= values. There might
be a processor dependent limit on how many outstanding input/output requests that generate an end-of-file or
⃝c ISO/IEC 2017 – All rights reserved 567
ISO/IEC DIS 1539-1:2017 (E)
error condition can be handled before the processor runs out of memory to keep track of such conditions. The
restrictions on the SIZE= variables are designed to enable the processor to update such variables at any time
(after the request has been processed, but before the wait operation), and then forget about them. Only error and
end-of-file conditions are expected to be tracked by individual request by the runtime, and then only if an ID=
specifier appears. The END= and EOR= specifiers have not been added to all statements that can perform wait
operations. Instead, the IOSTAT variable can be queried after a wait operation to handle this situation. This
choice was made because the WAIT statement is expected to be the usual method of waiting for input/output
to complete (and WAIT does support the END= and EOR= specifiers). This particular choice is philosophical,
and was not based on significant technical difficulties.
input/output requests encountered an end-of-record condition, so that a subsequent wait operation can return1 The number of records read by an explicitly formatted advancing input statement can be determined from thethe correct IOSTAT value. Therefor there might be a processor defined limit on the number of outstanding
nonadvancing input/output requests that have encountered an end-of-record condition (constrained by available
memory to keep track of this information, similar to end-of-file and error conditions).
C.8 Clause 13 notes
C.8.1 Number of records (13.4, 13.5, 13.8.2)
following rule: a record is read at the beginning of the format scan (even if the input list is empty unless the most2 The number of records written by an explicitly formatted advancing output statement can be determined fromrecently previous operation on the unit was not a nonadvancing read operation), at each slash edit descriptor
encountered in the format, and when a format rescan occurs at the end of the format.
the following rule: a record is written when a slash edit descriptor is encountered in the format, when a format1 The following examples illustrate list-directed input. A blank character is represented by b.rescan occurs at the end of the format, and at completion of execution of an advancing output statement (even if
the output list is empty). Thus, the occurrence of n successive slashes between two other edit descriptors causes
n − 1 blank lines if the records are printed. The occurrence of n slashes at the beginning or end of a complete
format specification causes n blank lines if the records are printed. However, a complete format specification
containing n slashes (n > 0) and no other edit descriptors causes n + 1 blank lines if the records are printed. For
example, the statements
PRINT 3
3 FORMAT (/)
will write two records that cause two blank lines if the records are printed.
C.8.2 List-directed input (13.10.3)
2 Example 1:
Program:3 Result: I = 1, J = 3.J = 3
READ *, I
READ *, J
568 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Sequential input file:
record 1: b1b,4bbbbb
record 2: ,2bbbbbbbb
4 Explanation: The second READ statement reads the second record. The initial comma in the record designates
a null value; therefore, J is not redefined.5 Example 2:
Program:6 Result: A = ’bbbbbbbb’, B = ’Q’CHARACTER A *8, B *1
READ *, A, B
Sequential input file:
record 1: ’bbbbbbbb’
record 2: ’QXY’b’Z’
7 Explanation: In the first record, the rightmost apostrophe is interpreted as delimiting the constant (it cannot
be the first of a pair of embedded apostrophes representing a single apostrophe because this would involve1 The name of the main program or of a block data program unit has no explicit use within the Fortran language.the prohibited “splitting” of the pair by the end of a record); therefore, A is assigned the character constant
’bbbbbbbb’. The end of a record acts as a blank, which in this case is a value separator because it occurs between
two constants.
C.9 Clause 14 notes
C.9.1 Main program and block data program unit (14.1, 14.3)
It is available for documentation and for possible use by a processor.2 A processor might implement an unnamed program unit by assigning it a global identifier that is not used
elsewhere in the program. This could be done by using a default name that does not satisfy the rules for Fortran1 This document, like its predecessors, is intended to enable the implementation of conforming processors in whichnames.
C.9.2 Dependent compilation (14.2)
a program can be broken into multiple units, each of which can be separately translated in preparation for2 The dependencies involved here are new only in the sense that the Fortran processor is now aware of them. Theexecution. Such processors are commonly described as supporting separate compilation. There is an important
difference between the way separate compilation can be implemented under this document and the way it could be
implemented under the Fortran 77 International Standard. Under the Fortran 77 standard, any information
⃝c ISO/IEC 2017 – All rights reserved 569
ISO/IEC DIS 1539-1:2017 (E)
required to translate a program unit was specified in that program unit. Each translation was thus totally
independent of all others. Under this document, a program unit can use information that was specified in a
separate module and thus can be dependent on that module. The implementation of this dependency in a
processor might be that the translation of a program unit depends on the results of translating one or more
modules. Processors implementing the dependency this way are commonly described as supporting dependent
compilation.
same information dependencies existed under the Fortran 77 International Standard, but it was the program-3 The exact meaning of the requirement that the public portions of a module be available at the time of referencemer’s responsibility to transport the information necessary to resolve them by making redundant specifications of
the information in multiple program units. The availability of separate but dependent compilation offers several
potential advantages over the redundant textual specification of information.
(1) Specifying information at a single place in the program ensures that different program units using that
information are translated consistently. Redundant specification leaves the possibility that different
information can be erroneously be specified. Even if an INCLUDE line is used to ensure that the
text of the specifications is identical in all involved program units, the presence of other specifications
(for example, an IMPLICIT statement) could change the interpretation of that text.
(2) During the revision of a program, it is possible for a processor to assist in determining whether differ-
ent program units have been translated using different (incompatible) versions of a module, although
there is no requirement that a processor provide such assistance. Inconsistencies in redundant textual
specification of information, on the other hand, tend to be much more difficult to detect.
(3) Putting information in a module provides a way of packaging it. Without modules, redundant spe-
cifications frequently are interleaved with other specifications in a program unit, making convenient
packaging of such information difficult.
(4) Because a processor can be implemented such that the specifications in a module are translated once
and then repeatedly referenced, there is the potential for greater efficiency than when the processor
translates redundant specifications of information in multiple program units.
is processor dependent. For example, a processor could consider a module to be available only after it has been1 Another benefit of the USE statement is its enhanced facilities for name management. If one needs to use onlycompiled and require that if the module has been compiled separately, the result of that compilation be identified
to the compiler when compiling program units that use it.
C.9.2.1 USE statement and dependent compilation (14.2.2)
selected entities in a module, one can do so without having to worry about the names of all the other entities2 A benefit of using the ONLY option consistently, as compared to USE without it, is that the module from whichin that module. If one needs to use two different modules that happen to contain entities with the same name,
there are several ways to deal with the conflict. If none of the entities with the same name are to be used, they
can simply be ignored. If the name happens to refer to the same entity in both modules (for example, if both
modules obtained it from a third module), then there is no confusion about what the name denotes and the name
can be freely used. If the entities are different and one or both is to be used, the local renaming facility in the
USE statement makes it possible to give those entities different names in the program unit containing the USE
statements.
each accessed entity is accessed is explicitly specified in each program unit. This means that one need not search3 A typical implementation of dependent but separate compilation might involve storing the result of translating aother program units to find where each one is defined. This reduces maintenance costs.
570 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
module in a file whose name is derived from the name of the module. Note, however, that the name of a module4 The result of translating a module could reasonably either contain only the information textually specified in theis limited only by the Fortran rules and not by the names allowed in the file system. Thus the processor might
have to provide a mapping between Fortran names and file system names.
module (with “pointers” to information originally textually specified in other modules) or contain all information5 There is an increased potential for undetected errors in a scoping unit that uses both implicit typing and thespecified in the module (including copies of information originally specified in other modules). Although the former
approach would appear to save on storage space, the latter approach can greatly simplify the logic necessary to
process a USE statement and can avoid the necessity of imposing a limit on the logical “nesting” of modules via
the USE statement.
USE statement. For example, in the program fragment
SUBROUTINE SUB
USE MY_MODULE
IMPLICIT INTEGER (I-N), REAL (A-H, O-Z)
X = F (B)
A = G (X) + H (X + 1)
END SUBROUTINE SUB
X could be either an implicitly typed real variable or a variable obtained from the module MY_MODULE and
might change from one to the other because of changes in MY_MODULE unrelated to the action performed by
SUB. Logic errors resulting from this kind of situation can be extremely difficult to locate. Thus, the use of these
features together is discouraged.
C.9.2.2 Accessibility attributes (8.5.2) 1 The PUBLIC and PRIVATE attributes, which can be declared only in modules, divide the entities in a module
into those that are actually relevant to a scoping unit referencing the module and those that are not. This1 A module could contain only data objects, for example:information might be used to improve the performance of a Fortran processor. For example, it might be possible
to discard much of the information about the private entities once a module has been translated, thus saving on
both storage and the time to search it. Similarly, it might be possible to recognize that two versions of a module
differ only in the private entities they contain and avoid retranslating program units that use that module when
switching from one version of the module to the other.
C.9.3 Examples of the use of modules (14.2.1)
C.9.3.1 Global data (14.2.1)
MODULE DATA_MODULE
SAVE
REAL A (10), B, C (20,20)
INTEGER :: I=0
INTEGER, PARAMETER :: J=10
COMPLEX D (J,J)
END MODULE DATA_MODULE
⃝c ISO/IEC 2017 – All rights reserved 571
ISO/IEC DIS 1539-1:2017 (E)2 Data objects made global in this manner can have any combination of data types.
3 Access to some of these can be made by a USE statement with the ONLY option, such as:
USE DATA_MODULE, ONLY: A, B, Dand access to all of them can be made by the following USE statement:
USE DATA_MODULE
4 Access to all of them with some renaming to avoid name conflicts can be made by, for example:
USE DATA_MODULE, AMODULE => A, DMODULE => D
C.9.3.2 Derived types (14.2.1) 1 A derived type can be defined in a module and accessed in a number of program units. For example,
MODULE SPARSE
TYPE NONZERO
REAL A
INTEGER I, J
END TYPE NONZERO
END MODULE SPARSE
defines a type consisting of a real component and two integer components for holding the numerical value of a
nonzero matrix element and its row and column indices.
C.9.3.3 Global allocatable arrays (14.2.1) 1 Many programs need large global allocatable arrays whose sizes are not known before program execution. A
simple form for such a program is:
PROGRAM GLOBAL_WORK
CALL CONFIGURE_ARRAYS ! Perform the appropriate allocations CALL COMPUTE ! Use the arrays in computations END PROGRAM GLOBAL_WORK
MODULE WORK_ARRAYS ! An example set of work arrays INTEGER N
REAL, ALLOCATABLE :: A (:), B (:, :), C (:, :, :)
END MODULE WORK_ARRAYS
SUBROUTINE CONFIGURE_ARRAYS ! Process to set up work arrays USE WORK_ARRAYS
READ (*, *) N
ALLOCATE (A (N), B (N, N), C (N, N, 2 * N))
END SUBROUTINE CONFIGURE_ARRAYS
SUBROUTINE COMPUTE
USE WORK_ARRAYS
... ! Computations involving arrays A, B, and C
END SUBROUTINE COMPUTE
572 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)2 Typically, many subprograms need access to the work arrays, and all such subprograms would contain the
statement
USE WORK_ARRAYS
C.9.3.4 Procedure libraries (14.2.2) 1 Interface bodies for external procedures in a library can be gathered into a module. An interface body specifies
an explicit interface (15.4.2.2).2 An example is the following library module:
MODULE LIBRARY_LLS
INTERFACE
SUBROUTINE LLS (X, A, F, FLAG)
REAL X (:, :)! The SIZE in the next statement is an intrinsic function
REAL, DIMENSION (SIZE (X, 2)) :: A, F
INTEGER FLAG
END SUBROUTINE LLS
...
END INTERFACE
...
END MODULE LIBRARY_LLS
3 This module provides an explicit interface that is necessary for the subroutine LLS to be invoked. for example:
USE LIBRARY_LLS
...
CALL LLS (X = ABC, A = D, F = XX, FLAG = IFLAG)
...4 Because dummy argument names in an interface body for an external procedure are not required to be the same
as in the procedure definition, different versions can be constructed for different applications using argument1 In order to extend an intrinsic operator symbol to have an additional meaning, an interface block specifying thatkeywords appropriate to each application.
C.9.3.5 Operator extensions (14.2.2)
operator symbol in the OPERATOR option of the INTERFACE statement could be placed in a module.2 For example, // can be extended to perform concatenation of two derived-type objects serving as varying length
character strings and + can be extended to specify matrix addition for type MATRIX or interval arithmetic3 A module might contain several such interface blocks. An operator can be defined by an external function (eitheraddition for type INTERVAL.
in Fortran or some other language) and its procedure interface placed in the module.1 In addition to providing a portable means of avoiding the redundant specification of information in multiple⃝c ISO/IEC 2017 – All rights reserved 573
ISO/IEC DIS 1539-1:2017 (E)
C.9.3.6 Data abstraction (14.2.2)
program units, a module provides a convenient means of “packaging” related entities, such as the definitions of2 The transfer function SETF converts a vector of integer values to the corresponding set, with duplicate valuesthe representation and operations of an abstract data type. The following example of a module defines a data
abstraction for a SET type where the elements of each set are of type integer. The usual set operations of UNION,
INTERSECTION, and DIFFERENCE are provided. The CARDINALITY function returns the cardinality of
(number of elements in) its set argument. Two functions returning logical values are included, ELEMENT and
SUBSET. ELEMENT defines the operator .IN. and SUBSET extends the operator <=. ELEMENT determines
if a given scalar integer value is an element of a given set, and SUBSET determines if a given set is a subset of
another given set. (Two sets can be checked for equality by comparing cardinality and checking that one is a
subset of the other, or checking to see if each is a subset of the other.)
removed. Thus, a vector of constant values can be used as set constants. An inverse transfer function VECTOR3 Here is the example module:returns the elements of a set as a vector of values in ascending order. In this SET implementation, set data
objects have a maximum cardinality of 200.
MODULE INTEGER_SETS
! This module is intended to illustrate use of the module facility
! to define a new type, along with suitable operators.
INTEGER, PARAMETER :: MAX_SET_CARD = 200
TYPE SET ! Define SET type PRIVATE
INTEGER CARD
INTEGER ELEMENT (MAX_SET_CARD)
END TYPE SET
INTERFACE OPERATOR (.IN.)
MODULE PROCEDURE ELEMENT
END INTERFACE OPERATOR (.IN.)
INTERFACE OPERATOR (<=)
MODULE PROCEDURE SUBSET
END INTERFACE OPERATOR (<=)
INTERFACE OPERATOR (+)
MODULE PROCEDURE UNION
END INTERFACE OPERATOR (+)
INTERFACE OPERATOR (-)
MODULE PROCEDURE DIFFERENCE
END INTERFACE OPERATOR (-)
574 c ISO/IEC 2017 – All rights reservedISO/IEC DIS 1539-1:2017 (E)
INTERFACE OPERATOR (*)
MODULE PROCEDURE INTERSECTION
END INTERFACE OPERATOR (*)
CONTAINS
INTEGER FUNCTION CARDINALITY (A) ! Returns cardinality of set A TYPE (SET), INTENT (IN) :: ACARDINALITY = A % CARD
END FUNCTION CARDINALITY
LOGICAL FUNCTION ELEMENT (X, A) ! Determines if INTEGER, INTENT(IN) :: X ! element X is in set ATYPE (SET), INTENT(IN) :: A
ELEMENT = ANY (A % ELEMENT (1 : A % CARD) == X)
END FUNCTION ELEMENT
FUNCTION UNION (A, B) ! Union of sets A and B TYPE (SET) UNIONTYPE (SET), INTENT(IN) :: A, B
INTEGER J
UNION = A
DO J = 1, B % CARD
IF (.NOT. (B % ELEMENT (J) .IN. A)) THENIF (UNION % CARD < MAX_SET_CARD) THEN
UNION % CARD = UNION % CARD + 1
UNION % ELEMENT (UNION % CARD) = B % ELEMENT (J)
ELSE
! Maximum set size exceeded . . .
END IF
END IF
END DO
END FUNCTION UNION
FUNCTION DIFFERENCE (A, B) ! Difference of sets A and B TYPE (SET) DIFFERENCETYPE (SET), INTENT(IN) :: A, B
INTEGER J, X
DIFFERENCE % CARD = 0 ! The empty set
DO J = 1, A % CARD
X = A % ELEMENT (J)
IF (.NOT. (X .IN. B)) DIFFERENCE = DIFFERENCE + SET (1, X)
END DO
END FUNCTION DIFFERENCE
FUNCTION INTERSECTION (A, B) ! Intersection of sets A and B ⃝
c ISO/IEC 2017 – All rights reserved 575
ISO/IEC DIS 1539-1:2017 (E)
TYPE (SET) INTERSECTIONTYPE (SET), INTENT(IN) :: A, B
INTERSECTION = A - (A - B)
END FUNCTION INTERSECTION
LOGICAL FUNCTION SUBSET (A, B) ! Determines if set A is TYPE (SET), INTENT(IN) :: A, B ! a subset of set B
INTEGER I
SUBSET = A % CARD <= B % CARD
DO I = 1, A % CARD
IF (.NOT. SUBSET) RETURN ! For efficiency
SUBSET = SUBSET .AND. (A % ELEMENT (I) .IN. B)
END DO
END FUNCTION SUBSET
TYPE (SET) FUNCTION SETF (V) ! Transfer function between a vector INTEGER V (:) ! of elements and a set of elementsINTEGER J ! removing duplicate elements
SETF % CARD = 0
DO J = 1, SIZE (V)
IF (.NOT. (V (J) .IN. SETF)) THEN
IF (SETF % CARD < MAX_SET_CARD) THEN
SETF % CARD = SETF % CARD + 1
SETF % ELEMENT (SETF % CARD) = V (J)
ELSE
! Maximum set size exceeded . . .
END IF
END IF
END DO
END FUNCTION SETF
FUNCTION VECTOR (A) ! Transfer the values of set A TYPE (SET), INTENT (IN) :: A ! into a vector in ascending orderINTEGER, POINTER :: VECTOR (:)
INTEGER I, J, K
ALLOCATE (VECTOR (A % CARD))
VECTOR = A % ELEMENT (1 : A % CARD)
DO I = 1, A % CARD - 1 ! Use a better sort if
DO J = I + 1, A % CARD ! A % CARD is large
IF (VECTOR (I) > VECTOR (J)) THEN
K = VECTOR (J); VECTOR (J) = VECTOR (I); VECTOR (I) = K
END IF
END DO
END DO
END FUNCTION VECTOR
END MODULE INTEGER_SETS
1 At times it might be necessary to rename entities that are accessed with USE statements.
576 c ISO/IEC 2017 – All rights reserved4 Examples of using INTEGER_SETS (A, B, and C are variables of type SET; X is an integer variable):
ISO/IEC DIS 1539-1:2017 (E)
! Check to see if A has more than 10 elementsIF (CARDINALITY (A) > 10) ...
! Check for X an element of A but not of B
IF (X .IN. (A - B)) ...
! C is the union of A and the result of B intersected
! with the integers 1 to 100
C = A + B * SETF ([(I, I = 1, 100)])
! Does A have any even numbers in the range 1:100?
IF (CARDINALITY (A * SETF ([(I, I = 2, 100, 2)])) > 0) ...
PRINT *, VECTOR (B) ! Print out the elements of set B, in ascending order
C.9.3.7 Public entities renamed (14.2.2) 2 The following example illustrates renaming features of the USE statement.
MODULE J; REAL JX, JY, JZ; END MODULE J
MODULE K
USE J, ONLY : KX => JX, KY => JY
! KX and KY are local names to module K
REAL KZ ! KZ is local name to module K REAL JZ ! JZ is local name to module K END MODULE K
PROGRAM RENAME
USE J; USE K
! Module J’s entity JX is accessible under names JX and KX
! Module J’s entity JY is accessible under names JY and KY
! Module K’s entity KZ is accessible under name KZ
! Module J’s entity JZ and K’s entity JZ are different entities
! and cannot be referenced
...
END PROGRAM RENAME
C.9.4 Modules with submodules (14.2.3) 1 Each submodule specifies that it is the child of exactly one parent module or submodule. Therefore, a module
and all of its descendant submodules stand in a tree-like relationship one to another.2 A separate module procedure that is declared in a module to have public accessibility can be accessed by use
association even if it is defined in a submodule. No other entity in a submodule can be accessed by use association.3 By constructing taller trees, one can put entities at intermediate levels that are shared by submodules at lowerEach program unit that references a module by use association depends on it, and each submodule depends on
its ancestor module. Therefore, if one changes a separate module procedure body in a submodule but does not
⃝c ISO/IEC 2017 – All rights reserved 577
ISO/IEC DIS 1539-1:2017 (E)
change its corresponding module procedure interface, a tool for automatic program translation would not need
to reprocess program units that reference the module by use association. This is so even if the tool exploits the
relative modification times of files as opposed to comparing the result of translating the module to the result of
a previous translation.
levels; changing these entities cannot change the interpretation of anything that is accessible from the module4 The following example illustrates a module, color_points, with a submodule, color_points_a, that in turn hasby use association. Developers of modules that embody large complicated concepts can exploit this possibility
to organize components of the concept into submodules, while preserving the privacy of entities that are shared
by the submodules and that ought not to be exposed to users of the module. Putting these shared entities at an
intermediate level also prevents cascades of reprocessing and testing if some of them are changed.
a submodule, color_points_b. Public entities declared within color_points can be accessed by use association.5 The module color_points does not have a module-subprogram-part, but a module-subprogram-part is not pro-The submodules color_points_a and color_points_b can be changed without causing retranslation of program
units that reference the module color_points.
hibited. The module could be published as definitive specification of the interface, without revealing trade secrets6 The only entities within color_points_a that can be accessed by use association are the separate modulecontained within color_points_a or color_points_b. Of course, a similar module without the module prefix in
the interface bodies would serve equally well as documentation – but the procedures would be external procedures.
It would make little difference to the consumer, but the developer would forfeit all of the advantages of modules.
module color_points
type color_point
private
real :: x, y
integer :: color
end type color_point
interface ! Interfaces for procedures with separate
! bodies in the submodule color_points_a
module subroutine color_point_del ( p ) ! Destroy a color_point object
type(color_point), allocatable :: p
end subroutine color_point_del
! Distance between two color_point objects
real module function color_point_dist ( a, b )
type(color_point), intent(in) :: a, b
end function color_point_dist
module subroutine color_point_draw ( p ) ! Draw a color_point object
type(color_point), intent(in) :: p
end subroutine color_point_draw
module subroutine color_point_new ( p ) ! Create a color_point object
type(color_point), allocatable :: p
end subroutine color_point_new
end interface
end module color_points
578 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
procedures that were declared in color_points. If the procedures are changed but their interfaces are not, the7 The variable instance_count in the following example is not accessible by use association of color_points, butinterface from program units that access them by use association is unchanged. If the module and submodule are
in separate files, utilities that examine the time of modification of a file would notice that changes in the module
could affect the translation of its submodules or of program units that reference the module by use association,
but that changes in submodules could not affect the translation of the parent module or program units that
reference it by use association.
is accessible within color_points_a, and its submodules.8 The subroutine inquire_palette is accessible within color_points_a because its interface is declared therein.submodule ( color_points ) color_points_a ! Submodule of color_points
integer :: instance_count = 0
interface ! Interface for a procedure with a separate
! body in submodule color_points_b
module subroutine inquire_palette ( pt, pal )
use palette_stuff ! palette_stuff, especially submodules thereof,
! can reference color_points by use association
! without causing a circular dependence during
! translation because this use is not in the module.
! Furthermore, changes in the module palette_stuff
! do not affect the translation of color_points.
type(color_point), intent(in) :: pt
type(palette), intent(out) :: pal
end subroutine inquire_palette
end interface
contains ! Invisible bodies for public separate module procedures
! declared in the module
module subroutine color_point_del ( p )
type(color_point), allocatable :: p
instance_count = instance_count - 1
deallocate ( p )
end subroutine color_point_del
real module function color_point_dist ( a, b ) result ( dist )
type(color_point), intent(in) :: a, b
dist = SQRT ( (b%x - a%x)**2 + (b%y - a%y)**2 )
end function color_point_dist
module subroutine color_point_new ( p )
type(color_point), allocatable :: p
instance_count = instance_count + 1
allocate ( p )
end subroutine color_point_new
end submodule color_points_a
⃝c ISO/IEC 2017 – All rights reserved 579
ISO/IEC DIS 1539-1:2017 (E)
It is not, however, accessible by use association, because its interface is not declared in the module, color_points.9 There is a use palette_stuff in color_points_a, and a use color_points in palette_stuff. The useSince the interface is not declared in the module, changes in the interface cannot affect the translation of program
units that reference the module by use association.
module palette_stuff
type :: palette ; ... ; end type palette
contains
subroutine test_palette ( p )
! Draw a color wheel using procedures from the color_points module
use color_points ! This does not cause a circular dependency because
! the "use palette_stuff" that is logically within
! color_points is in the color_points_a submodule.
type(palette), intent(in) :: p
...
end subroutine test_palette
end module palette_stuff
submodule ( color_points:color_points_a ) color_points_b ! Subsidiary**2 submodule
contains
! Invisible body for interface declared in the ancestor module
module subroutine color_point_draw ( p )
use palette_stuff, only: palette
type(color_point), intent(in) :: p
type(palette) :: MyPalette
...; call inquire_palette ( p, MyPalette ); ...
end subroutine color_point_draw
! Invisible body for interface declared in the parent submodule
module procedure inquire_palette
... implementation of inquire_palette
end procedure inquire_palette
subroutine private_stuff ! not accessible from color_points_a
...
end subroutine private_stuff
end submodule color_points_b
palette_stuff would cause a circular reference if it appeared in color_points. In this case, it does not cause10 A multilevel submodule system can be used to package and organize a large and interconnected concept withouta circular dependence because it is in a submodule. Submodules cannot be referenced by use association, and
therefore what would be a circular appearance of use palette_stuff is not accessed.
580 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
program main
use color_points
! "instance_count" and "inquire_palette" are not accessible here
! because they are not declared in the "color_points" module.
! "color_points_a" and "color_points_b" cannot be referenced by
! use association.
interface draw ! just to demonstrate it’s possible
module procedure color_point_draw
end interface
type(color_point) :: C_1, C_2
real :: RC
...
call color_point_new (c_1) ! body in color_points_a, interface in color_points
...
call draw (c_1) ! body in color_points_b, specific interface
! in color_points, generic interface here.
...
rc = color_point_dist (c_1, c_2) ! body in color_points_a, interface in color_points
...
call color_point_del (c_1) ! body in color_points_a, interface in color_points
...
end program main
exposing entities of one subsystem to other subsystems.11 Consider a Plasma module from a Tokomak simulator. A plasma simulation requires attention at least to fluid
flow, thermodynamics, and electromagnetism. Fluid flow simulation requires simulation of subsonic, supersonic,12 Entities can be shared among the Subsonic, Supersonic, and Hypersonic submodules by putting them withinand hypersonic flow. This problem decomposition can be reflected in the submodule structure of the Plasma
module:
Plasma module
Flow submodule Thermal submodule Electromagnetics submodule
Subsonic Supersonic Hypersonic
submodule submodule submodule
the Flow submodule. One then need not worry about accidental use of these entities by use association or by theISO/IEC DIS 1539-1:2017 (E)Thermal or Electromagnetics submodules, or the development of a dependency of correct operation of those
subsystems upon the representation of entities of the Flow subsystem as a consequence of maintenance. Since
these entities are not accessible by use association, if any of them are changed, the new values cannot be accessed
in program units that reference the Plasma module by use association; the answer to the question “where are
these entities used” is therefore confined to the set of descendant submodules of the Flow submodule.
⃝c ISO/IEC 2017 – All rights reserved 581
C.10 Clause 15 notes C.10.1 Portability problems with external procedures (15.4.3.5) 1 There is a potential portability problem in a scoping unit that references an external procedure without explicitly
declaring it to have the EXTERNAL attribute (8.5.9). On a different processor, the name of that procedure1 A processor is not required to provide any means other than Fortran for defining external procedures. Among themight be the name of a nonstandard intrinsic procedure and in such a case the processor would interpret those
procedure references as references to that intrinsic procedure. (On that processor, the program would also be
viewed as not conforming to this document because of the references to the nonstandard intrinsic procedure.)
Declaration of the EXTERNAL attribute causes the references to be to the external procedure regardless of the
availability of an intrinsic procedure with the same name. Note that declaration of the type of a procedure is not
enough to make it external, even if the type is inconsistent with the type of the result of an intrinsic procedure
of the same name.
C.10.2 Procedures defined by means other than Fortran (15.6.3)
means that might be supported are the machine assembly language, other high level languages, the Fortran lan-2 A Fortran processor might limit its support of procedures defined by means other than Fortran such that theseguage extended with nonstandard features, and the Fortran language as supported by another Fortran processor
(for example, a previously existing Fortran 77 processor). The means other than Fortran for defining external
procedures, including any restrictions on the structure or organization of those procedures, are not specified by
this document.
procedures can affect entities in the Fortran environment only on the same basis as procedures written in Fortran.1 This is an example of a library module providing lists of callbacks that the user can register and invoke.For example, it might not support the value of a local variable from being changed by a procedure reference unless
that variable were one of the arguments to the procedure.
C.10.3 Abstract interfaces and procedure pointer components (15.4, 7.5)
MODULE callback_list_module!
! Type for users to extend with their own data, if they so desire
!
TYPE callback_data
END TYPE
!
! Abstract interface for the callback procedures
!
ABSTRACT INTERFACE
SUBROUTINE callback_procedure(data)
IMPORT callback_dataCLASS(callback_data),OPTIONAL :: data
END SUBROUTINE
END INTERFACE
!
582 c ISO/IEC 2017 – All rights reservedISO/IEC DIS 1539-1:2017 (E)
! The callback list type.
!
TYPE callback_list
PRIVATE
CLASS(callback_record),POINTER :: first => NULL()
END TYPE
!
! Internal: each callback registration creates one of these
!
TYPE,PRIVATE :: callback_record
PROCEDURE(callback_procedure),POINTER,NOPASS :: procCLASS(callback_record),POINTER :: next
CLASS(callback_data),POINTER :: data => NULL();
END TYPE
PRIVATE invoke,forward_invoke
CONTAINS
!
! Register a callback procedure with optional data
!
SUBROUTINE register_callback(list, entry, data)
TYPE(callback_list),INTENT(INOUT) :: listPROCEDURE(callback_procedure) :: entry
CLASS(callback_data),OPTIONAL :: data
TYPE(callback_record),POINTER :: new,last
ALLOCATE(new)
new%proc => entry
IF (PRESENT(data)) ALLOCATE(new%data,SOURCE=data)
new%next => list%first
list%first => new
END SUBROUTINE
!
! Internal: Invoke a single callback and destroy its record
!
SUBROUTINE invoke(callback)
TYPE(callback_record),POINTER :: callbackIF (ASSOCIATED(callback%data) THEN
CALL callback%proc(list%first%data)
DEALLOCATE(callback%data)
ELSE
CALL callback%proc
END IF
DEALLOCATE(callback)
END SUBROUTINE
!
! Call the procedures in reverse order of registration
!
⃝
c ISO/IEC 2017 – All rights reserved 583
ISO/IEC DIS 1539-1:2017 (E)SUBROUTINE invoke_callback_reverse(list)
TYPE(callback_list),INTENT(INOUT) :: list
TYPE(callback_record),POINTER :: next,current
current => list%first
NULLIFY(list%first)
DO WHILE (ASSOCIATED(current))
next => current%next
CALL invoke(current)
current => next
END DO
END SUBROUTINE
!
! Internal: Forward mode invocation
!
SUBROUTINE forward_invoke(callback)
IF (ASSOCIATED(callback%next)) CALL forward_invoke(callback%next)CALL invoke(callback)
END SUBROUTINE
!
! Call the procedures in forward order of registration
!
SUBROUTINE invoke_callback_forward(list)
TYPE(callback_list),INTENT(INOUT) :: listIF (ASSOCIATED(list%first)) CALL forward_invoke(list%first)
END SUBROUTINE
END
C.10.4 Pointers and targets as arguments (15.5.2.4, 15.5.2.6, 15.5.2.7) 1 If a dummy argument is declared to be a pointer, the corresponding actual argument could be a pointer or could
be a nonpointer variable or procedure. Consider the two cases separately.2 When execution of a procedure completes, any pointer that remains defined and that is associated with a dummyCase (i): The actual argument is a pointer. When procedure execution commences the pointer association
status of the dummy argument becomes the same as that of the actual argument. If the pointer
association status of the dummy argument is changed, the pointer association status of the actual
argument changes in the same way.
Case (ii): The actual argument is not a pointer. This only occurs when the actual argument has the TARGET
attribute or is a procedure, and the dummy argument has the INTENT (IN) attribute. The dummy
argument becomes pointer associated with the actual argument.
argument that has the TARGET attribute and is either a scalar or an assumed-shape array, remains associated3 For example, consider:with the corresponding actual argument if the actual argument has the TARGET attribute and is not an array
section with a vector subscript.
584 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
REAL, POINTER :: PBESTREAL, TARGET :: B (10000)
CALL BEST (PBEST, B) ! Upon return PBEST is associated
... ! with the ‘‘best’’ element of B
CONTAINS
SUBROUTINE BEST (P, A)
REAL, POINTER, INTENT (OUT) :: PREAL, TARGET, INTENT (IN) :: A (:)
... ! Find the ‘‘best’’ element A(I)
P => A (I)
RETURN
END SUBROUTINE BEST
END
When procedure BEST completes, the pointer PBEST is associated with an element of B.
4 An actual argument without the TARGET attribute can become associated with a dummy argument with the
TARGET attribute. This enables a pointer to become associated with the dummy argument during execution ofthe procedure that contains the dummy argument. For example:
INTEGER LARGE(100,100)
CALL SUB (LARGE)
...
CALL SUB ()
CONTAINS
SUBROUTINE SUB(ARG)
INTEGER, TARGET, OPTIONAL :: ARG(100,100)INTEGER, POINTER, DIMENSION(:,:) :: PARG
IF (PRESENT(ARG)) THEN
PARG => ARG
ELSE
ALLOCATE (PARG(100,100))
PARG = 0
ENDIF
... ! Code with lots of references to PARG
IF (.NOT. PRESENT(ARG)) DEALLOCATE(PARG)
END SUBROUTINE SUB
END
Within subroutine SUB the pointer PARG is either associated with the dummy argument ARG or it is associated
with an allocated target. The bulk of the code can reference PARG without further calls to the intrinsic function
PRESENT.
5 If a nonpointer dummy argument has the TARGET attribute and the corresponding actual argument does not,
any pointers that become associated with the dummy argument, and therefore with the actual argument, during1 The following example illustrates the polymorphic argument association rules using the derived types defined inexecution of the procedure, become undefined when execution of the procedure completes.
⃝c ISO/IEC 2017 – All rights reserved 585
ISO/IEC DIS 1539-1:2017 (E)
C.10.5 Polymorphic Argument Association (15.5.2.9)
NOTE 7.55.TYPE(POINT) :: T2
TYPE(COLOR_POINT) :: T3
CLASS(POINT) :: P2
CLASS(COLOR_POINT) :: P3
! Dummy argument is polymorphic and actual argument is of fixed type
SUBROUTINE SUB2 ( X2 ); CLASS(POINT) :: X2; ...
SUBROUTINE SUB3 ( X3 ); CLASS(COLOR_POINT) :: X3; ...
CALL SUB2 ( T2 ) ! Valid -- The declared type of T2 is the same as the
! declared type of X2.
CALL SUB2 ( T3 ) ! Valid -- The declared type of T3 is extended from
! the declared type of X2.
CALL SUB3 ( T2 ) ! Invalid -- The declared type of T2 is neither the
! same as nor extended from the declared type
! type of X3.
CALL SUB3 ( T3 ) ! Valid -- The declared type of T3 is the same as the
! declared type of X3.
! Actual argument is polymorphic and dummy argument is of fixed type
SUBROUTINE TUB2 ( D2 ); TYPE(POINT) :: D2; ...
SUBROUTINE TUB3 ( D3 ); TYPE(COLOR_POINT) :: D3; ...
CALL TUB2 ( P2 ) ! Valid -- The declared type of P2 is the same as the
! declared type of D2.
CALL TUB2 ( P3 ) ! Invalid -- The declared type of P3 differs from the
! declared type of D2.
CALL TUB2 ( P3%POINT ) ! Valid alternative to the above
CALL TUB3 ( P2 ) ! Invalid -- The declared type of P2 differs from the
! declared type of D3.
SELECT TYPE ( P2 ) ! Valid conditional alternative to the above
CLASS IS ( COLOR_POINT ) ! Works if the dynamic type of P2 is the same
CALL TUB3 ( P2 ) ! as the declared type of D3, or a type
! extended therefrom.
CLASS DEFAULT
! Cannot work if not.
END SELECT
CALL TUB3 ( P3 ) ! Valid -- The declared type of P3 is the same as the
! declared type of D3.! Both the actual and dummy arguments are of polymorphic type.
CALL SUB2 ( P2 ) ! Valid -- The declared type of P2 is the same as the
! declared type of X2.CALL SUB2 ( P3 ) ! Valid -- The declared type of P3 is extended from
! the declared type of X2.
586 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)CALL SUB3 ( P2 ) ! Invalid -- The declared type of P2 is neither the
! same as nor extended from the declaredSELECT TYPE ( P2 ) ! Valid conditional alternative to the above! type of X3.
CLASS IS ( COLOR_POINT ) ! Works if the dynamic type of P2 is the
CALL SUB3 ( P2 ) ! same as the declared type of X3, or a! type extended therefrom.
CLASS DEFAULT
! Cannot work if not.
END SELECT
CALL SUB3 ( P3 ) ! Valid -- The declared type of P3 is the same as the
! declared type of X3.
C.10.6 Rules ensuring unambiguous generics (15.4.3.4.5) 1 The rules in 15.4.3.4.5 are intended to ensure
• that it is possible to reference each specific procedure or binding in the generic collection,2 Interfaces of specific procedures or bindings are distinguished by fixed properties of their arguments, specifically• that for any valid generic procedure reference, the determination of the specific procedure referenced is
unambiguous, and
• that the determination of the specific procedure or binding referenced can be made before execution of the
program begins (during compilation).
type, kind type parameters, rank, and whether the dummy argument has the POINTER or ALLOCATABLE3 Although the declared type of a data entity is a fixed property, polymorphic variables allow for a limited degreeattribute. A valid reference to one procedure in a generic collection will differ from another because it has an
argument that the other cannot accept, because it is missing an argument that the other requires, or because one
of these fixed properties is different.
of type mismatch between dummy arguments and actual arguments, so the requirement for distinguishing two4 That same limited type mismatch means that two dummy arguments that are not type incompatible can bedummy arguments is type incompatibility, not merely different types. (This is illustrated in the BAD6 example
later in this note.)
distinguished on the basis of the values of the kind type parameters they have in common; if one of them has a5 Rank is a fixed property, but some forms of array dummy arguments allow rank mismatches when a procedure iskind type parameter that the other does not, that is irrelevant in distinguishing them.
referenced by its specific name. In order to allow rank to always be usable in distinguishing generics, such rank6 For procedures referenced as operators or defined-assignment, syntactically distinguished arguments are mappedmismatches are disallowed for those arguments when the procedure is referenced as part of a generic. Additionally,
the fact that elemental procedures can accept array arguments is not taken into account when applying these rules,
so apparent ambiguity between elemental and nonelemental procedures is possible; in such cases, the reference is
interpreted as being to the nonelemental procedure.
to specific positions in the argument list, so the rule for distinguishing such procedures is that it be possible to7 For defined input/output procedures, only the dtv argument corresponds to something explicitly written in thedistinguish the arguments at one of the argument positions.
⃝c ISO/IEC 2017 – All rights reserved 587
ISO/IEC DIS 1539-1:2017 (E)
program, so it is the dtv that is required to be distinguished. Because dtv arguments are required to be scalar,8 For generic procedure names, the rules are more complicated because optional arguments can be omitted andthey cannot differ in rank. Thus this rule effectively involves only type and kind type parameters.
because arguments can be specified either positionally or by name.9 In the special case of type-bound procedures with passed-object dummy arguments, the passed-object argument
is syntactically distinguished in the reference, so rule (3) in 15.4.3.4.5 can be applied. The type of passed-object10 The primary means of distinguishing named generics is rule (4). The most common application of that rule is aarguments is constrained in ways that prevent passed-object arguments in the same scoping unit from being type
incompatible. Thus this rule effectively involves only kind type parameters and rank.
single argument satisfying both (4a) and (4b):11 Whether one writes GOOD1(1.0) or GOOD1(X=1.0), the reference is to F1A because F1B would require an integerINTERFACE GOOD1
FUNCTION F1A(X)
REAL :: F1A,X
END FUNCTION F1A
FUNCTION F1B(X)
INTEGER :: F1B,X
END FUNCTION F1B
END INTERFACE GOOD1
argument whereas these references provide the real constant 1.0.12 This example and those that follow are expressed using interface bodies, with type as the distinguishing property.
This was done to make it easier to write and describe the examples. The principles being illustrated are equally13 Another common variant is the argument that satisfies (4a) and (4b) by being required in one specific andapplicable when the procedures get their explicit interfaces in some other way or when kind type parameters or
rank are the distinguishing property.
completely missing in the other:14 Whether one writes GOOD2(0.0,1.0), GOOD2(0.0,Y=1.0), or GOOD2(Y=1.0,X=0.0), the reference is to F2B,INTERFACE GOOD2
FUNCTION F2A(X)
REAL :: F2A,X
END FUNCTION F2A
FUNCTION F2B(X,Y)
COMPLEX :: F2B
REAL :: X,Y
END FUNCTION F2B
END INTERFACE GOOD2
because F2A has no argument in the second position or with the name Y. This approach is used as an alternative15 It is possible to construct cases where different arguments are used to distinguish positionally and by name:to optional arguments when one wants a function to have different result type, kind type parameters, or rank,
depending on whether the argument is present. In many of the intrinsic functions, the DIM argument works this
way.
588 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
INTERFACE GOOD316 If one writes GOOD3(1.0,2,3.0,4) to reference S3A, then the third and fourth arguments are consistent with aSUBROUTINE S3A(W,X,Y,Z)
REAL :: W,Y
INTEGER :: X,Z
END SUBROUTINE S3A
SUBROUTINE S3B(X,W,Z,Y)
REAL :: W,Z
INTEGER :: X,Y
END SUBROUTINE S3B
END INTERFACE GOOD3
reference to S3B, but the first and second are not. If one switches to writing the first two arguments as keyword17 The ordering requirement in rule (4) is critical:arguments in order for them to be consistent with a reference to S3B, the latter two arguments will also need
to be written as keyword arguments, GOOD3(X=2,W=1.0,Z=4,Y=3.0), and the named arguments Y and Z are
distinguished.
INTERFACE BAD4 ! this interface is invalid !18 In this example, the positionally distinguished arguments are Y and Z, and it is W and X that are distinguished bySUBROUTINE S4A(W,X,Y,Z)
REAL :: W,Y
INTEGER :: X,Z
END SUBROUTINE S4A
SUBROUTINE S4B(X,W,Z,Y)
REAL :: X,Y
INTEGER :: W,Z
END SUBROUTINE S4B
END INTERFACE BAD4
name. In this order it is possible to write BAD4(1.0,2,Y=3.0,Z=4), which is a valid reference for both S4A and19 Rule (1) can be used to distinguish some cases that are not covered by rule (4):S4B.
INTERFACE GOOD520 In attempting to apply rule (4), position 2 and name Y are distinguished, but they are in the wrong order, just likeSUBROUTINE S5A(X)
REAL :: X
END SUBROUTINE S5A
SUBROUTINE S5B(Y,X)
REAL :: Y,X
END SUBROUTINE S5B
END INTERFACE GOOD5
the BAD4 example. However, when we try to construct a similarly ambiguous reference, we get GOOD5(1.0,X=2.0),21 The application of rule (1) becomes more complicated when extensible types are involved. If FRUIT is an extensible⃝c ISO/IEC 2017 – All rights reserved 589
ISO/IEC DIS 1539-1:2017 (E)
which can’t be a reference to S5A because it would be attempting to associate two different actual arguments
with the dummy argument X. Rule (4) catches this case by recognizing that S5B requires two real arguments, and
S5A cannot possibly accept more than one.
type, PEAR and APPLE are extensions of FRUIT, and BOSC is an extension of PEAR, then22 It is important to try rule (1) for each type that appears:INTERFACE BAD6 ! this interface is invalid !
SUBROUTINE S6A(X,Y)
CLASS(PEAR) :: X,Y
END SUBROUTINE S6A
SUBROUTINE S6B(X,Y)
CLASS(FRUIT) :: X
CLASS(BOSC) :: Y
END SUBROUTINE S6B
END INTERFACE BAD6
might, at first glance, seem distinguishable this way, but because of the limited type mismatching allowed,
BAD6(A_PEAR,A_BOSC) is a valid reference to both S6A and S6B.
INTERFACE GOOD723 Looking at the most general type, S7A has a minimum and maximum of 3 FRUIT arguments, while S7B has aSUBROUTINE S7A(X,Y,Z)
CLASS(PEAR) :: X,Y,Z
END SUBROUTINE S7A
SUBROUTINE S7B(X,Z,W)
CLASS(FRUIT) :: X
CLASS(BOSC) :: Z
CLASS(APPLE),OPTIONAL :: W
END SUBROUTINE S7B
END INTERFACE GOOD7
minimum of 2 and a maximum of three. Looking at the most specific, S7A has a minimum of 0 and a maximum24 In identifying the minimum number of arguments with a particular set of properties, we exclude optional argu-of 3 BOSC arguments, while S7B has a minimum of 1 and a maximum of 2. However, when we look at the
intermediate, S7A has a minimum and maximum of 3 PEAR arguments, while S7B has a minimum of 1 and a
maximum of 2. Because S7A’s minimum exceeds S7B’s maximum, they can be distinguished.
ments and test TKR compatibility, so the corresponding actual arguments are required to have those properties.25 These rules are sufficient to ensure that references to procedures that meet them are unambiguous, but thereIn identifying the maximum number of arguments with those properties, we include the optional arguments and
test not distinguishable, so we include actual arguments which could have those properties but are not required
to have them.
remain examples that fail to meet these rules but which can be shown to be unambiguous:26 This interface fails rule (4) because there are no required arguments that can be distinguished from the positionallyINTERFACE BAD8 ! this interface is invalid !
! despite the fact that it is unambiguous !
590 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
SUBROUTINE S8A(X,Y,Z)
REAL,OPTIONAL :: X
INTEGER :: Y
REAL :: Z
END SUBROUTINE S8A
SUBROUTINE S8B(X,Z,Y)
INTEGER,OPTIONAL :: X
INTEGER :: Z
REAL :: Y
END SUBROUTINE S8B
END INTERFACE BAD8
corresponding argument, but in order for the mismatch of the optional arguments not to be relevant, the later27 If one dummy argument has the POINTER attribute and a corresponding argument in the other interface bodyarguments need to be specified as keyword arguments, so distinguishing by name does the trick. This interface is
nevertheless invalid so a standard-conforming Fortran processor is not required to do such reasoning. The rules
to cover all cases are too complicated to be useful.
has the ALLOCATABLE attribute the generic interface is not ambiguous. If one dummy argument has either the1 Parallel programs sometimes have apparently impossible behavior because data transfers and other messages canPOINTER or ALLOCATABLE attribute and a corresponding argument in the other interface body has neither
attribute, the generic interface might be ambiguous.
C.11 Clause 16 notes
C.11.1 Atomic memory consistency
C.11.1.1 Relaxed memory model
be delayed, reordered and even repeated, by hardware, communication software, and caching and other forms1 When variables are being referenced (atomically) from segments that are unordered with respect to the segmentof optimization. Requiring processors to deliver globally consistent behavior is incompatible with performance
on many systems. This document specifies that all ordered actions will be consistent (5.3.5 and 11.6), but all
consistency between unordered segments is deliberately left processor dependent. Depending on the hardware,
this can be observed even when only two images and one mechanism are involved.
C.11.1.2 Examples with atomic operations
that is atomically defining or redefining the variables, the results are processor dependent. This supports use2 The following examples assume these declarations:of so-called “relaxed memory model” architectures, which can enable more efficient execution on some hardware
implementations.
MODULE EXAMPLE
USE,INTRINSIC :: ISO_FORTRAN_ENV
INTEGER(ATOMIC_INT_KIND) :: X [*] = 0, Y [*] = 0, TMP
3 Example 1
⃝c ISO/IEC 2017 – All rights reserved 591
ISO/IEC DIS 1539-1:2017 (E)
With X [j] and Y [j] still in their initial state (both zero), image j executes the following sequence of statements:CALL ATOMIC_DEFINE (X, 1)
CALL ATOMIC_DEFINE (Y, 1)
and a different image, k, executes the following sequence of statements:
DO
CALL ATOMIC_REF (TMP, Y [j ])
IF (TMP==1) EXIT
END DO
CALL ATOMIC_REF (TMP, X [j ])
PRINT *, TMP
4 The final value of TMP on image k could be either 0 or 1. That is, even though image j thinks that it defined X
[j] before it defined Y [j], this ordering is not guaranteed to be observed on image k. There are many aspects of5 Even if image j executed the sequencehardware and software implementation that can cause this effect, but conceptually this example can be thought
of as the change in the value of Y propagating faster through the inter-image connections than the change in the
value of X.
CALL ATOMIC_DEFINE (X, 1)
SYNC MEMORY
CALL ATOMIC_DEFINE (Y, 1)
the same effect could be seen. That is because even though X and Y are defined in ordered segments, the
references from image k are both from a segment that is unordered with respect to image j.
6 Only if the reference on image k to Y [j] is in a segment that is ordered after the segment on image j that defined
Y, will TMP be guaranteed to have the value 1.7 Example 2:
With the initial state of X and Y on image j (i.e. X [j] and Y [j]) still being zero, execution of8 This can happen by such mechanisms as “load buffering”; one might imagine that what is happening is thatCALL ATOMIC_REF (TMP, X [j ])
CALL ATOMIC_DEFINE (Y [j ], 1)
PRINT *, TMP
on image k1 , and execution of
CALL ATOMIC_REF (TMP, Y [j ])
CALL ATOMIC_DEFINE (X [j ], 1)
PRINT *, TMP
on image k2 , in unordered segments, might print the value 1 both times.
the definitions (ATOMIC_DEFINE) are overtaking the references (ATOMIC_REF). On some processors it is9 Example 3:592 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
possible that insertion of SYNC MEMORY statements between the calls to ATOMIC_REF and ATOMIC_-
DEFINE might be sufficient to make the output print the value 1 at most one time (or even exactly one time),
but this is still processor dependent unless the SYNC MEMORY statement executions cause the relevant segments
on images k1 and k2 to be ordered.
Because there are no segment boundaries implied by collective subroutines, with the initial state as before,execution of
IF (THIS_IMAGE ()==1) THEN
CALL ATOMIC_DEFINE (X [3], 23)
Y = 42
END IF
CALL CO_BROADCAST (Y, 1)
IF (THIS_IMAGE ()==2) THEN
CALL ATOMIC_REF (TMP, X [3])PRINT *, Y, TMP
END IF
could print the values 42 and 0.
10 Example 4:
Assuming the declarationsINTEGER (ATOMIC_INT_KIND) :: X [*] = 0, Z = 0
the statements
CALL ATOMIC_ADD (X [1], 1) ! (A)
IF (THIS_IMAGE() == 2) THEN
wait: DO
CALL ATOMIC_REF (Z, X [1]) ! (B)
IF (Z == NUM_IMAGES ()) EXIT wait
END DO wait ! (C)
END IF
will execute the “wait” loop on image 2 until all images have completed statement (A). The updates of X [1] are
performed by each image in the same manner, but in an arbitrary order. Because the result from the complete
set of updates will eventually become visible by execution of statement (B) for some loop iteration on image 2,
the termination condition is guaranteed to be eventually fulfilled, provided that no image failure occurs, every
image executes the above code, and no other code is executed in an unordered segment that performs an update
to X [1]. Furthermore, if two SYNC MEMORY statements are inserted in the above code before statement (A)
and after statement (C), respectively, the segment started by the second SYNC MEMORY on image 2 is ordered
after the segments on all images that end with the first SYNC MEMORY.
C.11.2 EVENT_QUERY example 1 The following example illustrates the use of events via a program in which image 1 acts as the master image,
distributing work items to the other images. Only one work item at a time can be active on a worker image, andISO/IEC DIS 1539-1:2017 (E)each deals with the result (e.g. via input/output) without directly feeding data back to the master image.
⃝c ISO/IEC 2017 – All rights reserved 593
2 Because the work items are not expected to be balanced, the master keeps cycling through all images to find one
that is waiting for work.3 An event is posted by each worker to indicate that it has completed its work item. Since the corresponding
variables are needed only on the master, we place them in an allocatable array component of a coarray. An eventon each worker is needed for the master to post the fact that it has made a work item available for it.
Example code:
PROGRAM work_share
USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: EVENT_TYPE
USE :: mod_work, ONLY: & ! Module that creates work items
work, & ! Type for holding a work item
create_work_item, & ! Function that creates work item
process_item, & ! Function that processes an item
work_done ! Logical function that returns true
! if all work has been done.
TYPE :: worker_type
TYPE (EVENT_TYPE), ALLOCATABLE :: free (:)
END TYPE
INTEGER :: count, i, nbusy [*]
TYPE (EVENT_TYPE) :: submit [*] ! Post when work ready for a worker TYPE (worker_type) :: worker [*] ! Post when worker is free TYPE (work) :: work_item [*] ! Holds the data for a work item IF (THIS_IMAGE ()==1) THEN
! Get startedALLOCATE (worker%free (2:NUM_IMAGES ()))
nbusy = 0 ! This holds the number of workers working
DO i = 2, NUM_IMAGES () ! Start the workers working
IF (work_done ()) EXIT
nbusy = nbusy + 1
work_item [i] = create_work_item ()
EVENT POST (submit [i])
END DO
! Main work distribution loop
master: DO
image: DO i = 2, NUM_IMAGES ()CALL EVENT_QUERY (worker%free (i), count)
IF (count==0) CYCLE image ! Worker is not free
EVENT WAIT (worker%free (i))
nbusy = nbusy - 1
IF (work_done ()) CYCLE
nbusy = nbusy + 1
work_item [i] = create_work_item ()
EVENT POST (submit [i])
END DO image
594 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)IF (nbusy==0) THEN
! All done. Exit on all images.DO i = 2, NUM_IMAGES ()
EVENT POST (submit [i])
END DO
EXIT master
END IF
END DO master
ELSE
! Work processing loop
worker: DO
EVENT WAIT (submit)END DO workerIF (nbusy[1] == 0) EXIT
CALL process_item (work_item)
EVENT POST (worker [1]%free (THIS_IMAGE ()))
END IF
END PROGRAM work_share
C.11.3 Collective subroutine examples 1 The following example computes a dot product of two scalar coarrays using CO_SUM to store the result in a
noncoarray scalar variable.2 The function below demonstrates passing a noncoarray dummy argument to CO_MAX. The function uses CO_-SUBROUTINE codot (x, y, x_dot_y)
REAL :: x [*], y [*], x_dot_y
x_dot_y = x*y
CALL CO_SUM (x_dot_y)
END SUBROUTINE codot
MAX to find the maximum value of the dummy argument across all images. Then the function flags all imagesthat hold values matching the maximum. The function then returns the maximum image index for an image that
holds the maximum value.
FUNCTION find_max (j) RESULT (j_max_location)
INTEGER, INTENT (IN) :: j
INTEGER j_max, j_max_location
j_max = j
CALL CO_MAX (j_max)
! Flag images that hold the maximum j.
IF (j==j_max) THEN
j_max_location = THIS_IMAGE ()
ELSE
j_max_location = 0
END IF
! Return highest image index associated with a maximal j.
CALL CO_MAX(j_max_location)
END FUNCTION find_max
⃝c ISO/IEC 2017 – All rights reserved 595
ISO/IEC DIS 1539-1:2017 (E)
C.12 Clause 18 notes C.12.1 Runtime environments (18.1) 1 This document allows programs to contain procedures defined by means other than Fortran. That raises the
issues of initialization of and interaction between the runtime environments involved.2 Implementations are free to solve these issues as they see fit, provided that
• heap allocation/deallocation (e.g., (DE)ALLOCATE in a Fortran subprogram and malloc/free in a C func-tion) can be performed without interference,
• input/output to and from external files can be performed without interference, as long as procedures defined
by different means do not do input/output with the same external file,
• input/output preconnections exist as required by the respective standards, and
• initialized data are initialized according to the respective standards.
C Function Prototype:
C.12.2 Example of Fortran calling C (18.3)
int C_Library_Function(void* sendbuf, int sendcount, int *recvcounts);Fortran Module:
MODULE CLIBFUN_INTERFACE
INTERFACE
INTEGER (C_INT) FUNCTION C_LIBRARY_FUNCTION (SENDBUF, SENDCOUNT, RECVCOUNTS) &
BIND(C, NAME=’C_Library_Function’)USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
TYPE (C_PTR), VALUE :: SENDBUF
INTEGER (C_INT), VALUE :: SENDCOUNT
INTEGER (C_INT) :: RECVCOUNTS(*)
END FUNCTION C_LIBRARY_FUNCTION
END INTERFACE
END MODULE CLIBFUN_INTERFACE
1 The module CLIBFUN_INTERFACE contains the declaration of the Fortran dummy arguments, which corres-
pond to the C formal parameters. The NAME= is used in the BIND attribute in order to handle the case-sensitive2 The first C formal parameter is the pointer to void sendbuf, which corresponds to the Fortran dummy argumentname change between Fortran and C from “c_library_function” to “C_Library_Function”.
SENDBUF, which has the type C_PTR and the VALUE attribute.3 The second C formal parameter is the int sendcount, which corresponds to the Fortran dummy argument
SENDCOUNT, which has the type INTEGER (C_INT) and the VALUE attribute.4 The third C formal parameter is the pointer to int recvcounts, which corresponds to the Fortran dummy
argument RECVCOUNTS, which is an assumed-size array of type INTEGER (C_INT).5 This example shows how C_Library_Function might be referenced in a Fortran program unit:596 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT, C_FLOAT, C_LOC
USE CLIBFUN_INTERFACE
...
REAL (C_FLOAT), TARGET :: SEND(100)
INTEGER (C_INT), ALLOCATABLE :: RECVCOUNTS(:)
INTEGER (C_INT) :: SENDCOUNT, RET ...
ALLOCATE( RECVCOUNTS(100) )
...
RET = C_LIBRARY_FUNCTION(C_LOC(SEND), SENDCOUNT, RECVCOUNTS)
...
6 The first Fortran actual argument is a reference to the function C_LOC which returns the value of the C address
of its argument, SEND. This value becomes the value of the first formal parameter, the pointer sendbuf, in7 The second Fortran actual argument is SENDCOUNT of type INTEGER (C_INT). Its value becomes the initialC_Library_Function.
value of the second formal parameter, the int sendcount, in C_Library_Function.8 The third Fortran actual argument is the allocatable array RECVCOUNTS of type INTEGER (C_INT). The
base C address of this array becomes the value of the third formal parameter, the pointer recvcounts, inC_Library_Function. Note that interoperability is based on the characteristics of the dummy arguments in
the specified interface and not on those of the actual arguments. Thus, the fact that the actual argument is
allocatable is not relevant here.
C.12.3 Example of C calling Fortran (18.3)
Fortran Code:
SUBROUTINE SIMULATION(ALPHA, BETA, GAMMA, DELTA, ARRAYS) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
REAL (C_DOUBLE),DIMENSION(*),INTENT(IN) :: DELTA
INTEGER (C_LONG), VALUE :: ALPHA REAL (C_DOUBLE), INTENT(INOUT) :: BETA INTEGER (C_LONG), INTENT(OUT) :: GAMMA TYPE, BIND(C) :: PASS
INTEGER (C_INT) :: LENC, LENFTYPE (C_PTR) :: C, F
END TYPE PASS
TYPE (PASS), INTENT(INOUT) :: ARRAYS
REAL (C_FLOAT), ALLOCATABLE, TARGET, SAVE :: ETA(:)
REAL (C_FLOAT), POINTER :: C_ARRAY(:)
...
! Associate C_ARRAY with an array allocated in C
CALL C_F_POINTER (ARRAYS%C, C_ARRAY, [ ARRAYS%LENC ])
⃝c ISO/IEC 2017 – All rights reserved 597
ISO/IEC DIS 1539-1:2017 (E)
...! Allocate an array and make it available in C
ARRAYS%LENF = 100
ALLOCATE (ETA(ARRAYS%LENF))
ARRAYS%F = C_LOC(ETA)
...
END SUBROUTINE SIMULATION
C Struct Declaration:
struct pass {C Function Prototype:int lenc, lenf;
float *c, *f;
};
void simulation(long alpha, double *beta, long *gamma, double delta[],C Calling Sequence:struct pass *arrays);
simulation(alpha, beta, gamma, delta, arrays);1 The above-listed Fortran code specifies a subroutine SIMULATION. This subroutine corresponds to the C void
function simulation.2 The Fortran subroutine references the intrinsic module ISO_C_BINDING.
3 The first Fortran dummy argument of the subroutine is ALPHA, which has the type INTEGER(C_LONG) and
the VALUE attribute. This dummy argument corresponds to the C formal parameter alpha, which is a long.4 The second Fortran dummy argument of the subroutine is BETA, which has the type REAL(C_DOUBLE) andThe C actual argument is also a long.
the INTENT (INOUT) attribute. This dummy argument corresponds to the C formal parameter beta, which is5 The third Fortran dummy argument of the subroutine is GAMMA, which has the type INTEGER(C_LONG)a pointer to double. An address is passed as the C actual argument.
and the INTENT (OUT) attribute. This dummy argument corresponds to the C formal parameter gamma, which6 The fourth Fortran dummy argument is the assumed-size array DELTA, which has the type REAL (C_DOUBLE)is a pointer to long. An address is passed as the C actual argument.
and the INTENT (IN) attribute. This dummy argument corresponds to the C formal parameter delta, which is7 The fifth Fortran dummy argument is ARRAYS, which is a structure for accessing an array allocated in C anda double array. The C actual argument is also a double array.
an array allocated in Fortran. The lengths of these arrays are held in the components LENC and LENF; their C1 Many Fortran processors support 16-byte real numbers, which might not be supported by the C processor.addresses are held in components C and F.
598 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C.12.4 Example of calling C functions with noninteroperable data (18.10)
Assume a Fortran programmer wants to use a C procedure from a message passing library for an array of thesereals. The C prototype of this procedure is
void ProcessBuffer(void *buffer, int n_bytes);
with the corresponding Fortran interface
USE, INTRINSIC :: ISO_C_BINDING
INTERFACE
SUBROUTINE PROCESS_BUFFER(BUFFER,N_BYTES) BIND(C,NAME="ProcessBuffer")
IMPORT :: C_PTR, C_INTTYPE(C_PTR), VALUE :: BUFFER ! The ‘‘C address’’ of the array buffer
INTEGER (C_INT), VALUE :: N_BYTES ! Number of bytes in buffer
END SUBROUTINE PROCESS_BUFFER
END INTERFACE
2 This can be done using C_LOC if the particular Fortran processor specifies that C_LOC returns an appropriate
address:1 The following example demonstrates how a Fortran processor can make a modern object-oriented random numberREAL(R_QUAD), DIMENSION(:), ALLOCATABLE, TARGET :: QUAD_ARRAY
...
CALL PROCESS_BUFFER(C_LOC(QUAD_ARRAY), INT(16*SIZE(QUAD_ARRAY),C_INT))
! One quad real takes 16 bytes on this processor
C.12.5 Example of opaque communication between C and Fortran (18.3)
generator written in Fortran available to a C program.USE, INTRINSIC :: ISO_C_BINDING
! Assume this code is inside a module
TYPE RANDOM_STREAM
! A (uniform) random number generator (URNG)
CONTAINS
PROCEDURE(RANDOM_UNIFORM), DEFERRED, PASS(STREAM) :: NEXT
! Generates the next number from the stream
END TYPE RANDOM_STREAM
ABSTRACT INTERFACE
! Abstract interface of Fortran URNG
SUBROUTINE RANDOM_UNIFORM(STREAM, NUMBER)
IMPORT :: RANDOM_STREAM, C_DOUBLECLASS(RANDOM_STREAM), INTENT(INOUT) :: STREAM
REAL(C_DOUBLE), INTENT(OUT) :: NUMBER
END SUBROUTINE RANDOM_UNIFORM
END INTERFACE
⃝c ISO/IEC 2017 – All rights reserved 599
ISO/IEC DIS 1539-1:2017 (E)2 A polymorphic object with declared type RANDOM_STREAM is not interoperable with C. However, we can
make such a random number generator available to C by packaging it inside another nonpolymorphic, nonpara-meterized derived type:
TYPE :: URNG_STATE ! No BIND(C), as this type is not interoperable
CLASS(RANDOM_STREAM), ALLOCATABLE :: STREAM
END TYPE URNG_STATE
3 The following two procedures will enable a C program to use our Fortran uniform random number generator:
! Initialize a uniform random number generator:SUBROUTINE INITIALIZE_URNG(STATE_HANDLE, METHOD) &
BIND(C, NAME="InitializeURNG")
TYPE(C_PTR), INTENT(OUT) :: STATE_HANDLE
! An opaque handle for the URNG
CHARACTER(C_CHAR), DIMENSION(*), INTENT(IN) :: METHOD
! The algorithm to be used
TYPE(URNG_STATE), POINTER :: STATE
! An actual URNG object
ALLOCATE(STATE)
! There needs to be a corresponding finalization
! procedure to avoid memory leaks, not shown in this example
! Allocate STATE%STREAM with a dynamic type depending on METHOD
...
STATE_HANDLE=C_LOC(STATE)
! Obtain an opaque handle to return to C
END SUBROUTINE INITIALIZE_URNG
! Generate a random number:
SUBROUTINE GENERATE_UNIFORM(STATE_HANDLE, NUMBER) &
BIND(C, NAME="GenerateUniform")TYPE(C_PTR), INTENT(IN), VALUE :: STATE_HANDLE
! An opaque handle: Obtained via a call to INITIALIZE_URNGREAL(C_DOUBLE), INTENT(OUT) :: NUMBER
TYPE(URNG_STATE), POINTER :: STATE
! A pointer to the actual URNGCALL C_F_POINTER(CPTR=STATE_HANDLE, FPTR=STATE)
! Convert the opaque handle into a usable pointerCALL STATE%STREAM%NEXT(NUMBER)
! Use the type-bound procedure NEXT to generate NUMBER
END SUBROUTINE GENERATE_UNIFORM
600 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
C.12.6 Using assumed type to interoperate with C C.12.6.1 Overview 1 The mechanism for handling unlimited polymorphic entities whose dynamic type is interoperable with C is
designed to handle the following two situations:2 In the first situation, it is the programmer’s responsibility to explicitly provide any information needed on the(1) A formal parameter that is a C pointer to void. This is an address, and no further information
about the entity is provided. The formal parameter corresponds to a dummy argument that is a
nonallocatable nonpointer scalar or is an assumed-size array.
(2) A formal parameter that is the address of a C descriptor. Additional information on the status, type,
size, and shape is implicitly provided. The formal parameter corresponds to a dummy argument that
is assumed-shape or assumed-rank.
status, type, size, and shape of the entity.1 A C interface for message passing or input/output functionality could be provided in the formC.12.6.2 Mapping of interfaces with void * C parameters to Fortran
int EXAMPLE_send(const void *buffer, size_t buffer_size, const HANDLE_t *handle);where the buffer_size argument is given in units of bytes, and the handle argument (which is of a type aliased
to int) provides information about the target the buffer is to be transferred to. In this example, type resolution
is not required.
2 The first method provides a thin binding; a call to EXAMPLE_send from Fortran directly invokes the C function.
INTERFACE
INTEGER (C_INT) FUNCTION example_send(buffer, buffer_size, handle) &
BIND(C, NAME=’EXAMPLE_send’)
USE, INTRINSIC :: ISO_C_BINDINGTYPE(*), INTENT (IN) :: buffer(*)
INTEGER (C_SIZE_T), VALUE :: buffer_size
INTEGER (C_INT), INTENT (IN) :: handle
END FUNCTION
END INTERFACE
3 It is assumed that this interface is declared in the specification part of the module MOD_EXAMPLE_OLD. An
example of its use follows:USE, INTRINSIC :: ISO_C_BINDING
USE MOD_EXAMPLE_OLD
REAL(C_FLOAT) :: x(100)
INTEGER(C_INT) :: y(10,10)
REAL(C_DOUBLE) :: z
INTEGER(C_INT) :: status, handle
...
⃝c ISO/IEC 2017 – All rights reserved 601
ISO/IEC DIS 1539-1:2017 (E)
! Assign values to x, y, z and initialize handle.4 In those invocations, x and y are passed directly with sequence association, but it is necessary to make an array...
! Send values in x, y, and z using EXAMPLE_send.
status = example_send(x, C_SIZEOF(x), handle)
status = example_send(y, C_SIZEOF(y), handle)
status = example_send([ z ], C_SIZEOF(z), handle)
expression containing the value of z to pass it.5 The second method provides a Fortran interface which is easier to use, but requires writing a separate C wrapper
routine. With this method, a C descriptor is created because the buffer is assumed-rank in the Fortran interface;the use of an optional argument is also demonstrated.
INTERFACE
SUBROUTINE example_send(buffer, handle, status) BIND(C, NAME="EG_send_fortran")
USE, INTRINSIC :: ISO_C_BINDINGTYPE(*), CONTIGUOUS, INTENT (IN) :: buffer(..)
INTEGER (C_INT), INTENT (IN) :: handle
INTEGER (C_INT), INTENT(OUT), OPTIONAL :: status
END SUBROUTINE
END INTERFACE
6 It is assumed that this interface is declared in the specification part of a module MOD_EXAMPLE_NEW.
Example invocations from Fortran are thenUSE, INTRINSIC :: iso_c_binding
USE mod_example_new
TYPE, BIND(C) :: my_derived
INTEGER(C_INT) :: len_used
REAL(C_FLOAT) :: stuff(100)
END TYPE
TYPE(my_derived) :: w(3)
REAL(C_FLOAT) :: x(100)
INTEGER(C_INT) :: y(10,10)
REAL(C_DOUBLE) :: z
INTEGER(C_INT) :: status, handle
...
! Assign values to w, x, y, z and initialize handle.
...
! Send values in w, x, y, and z using example_send.
CALL example_send(w, handle, status)
CALL example_send(x, handle)
CALL example_send(y, handle)
CALL example_send(z, handle)
CALL example_send(y(:,5), handle) ! Fifth column of y.
CALL example_send(y(1,5), handle) ! Scalar y(1,5) passed by descriptor.
1 An assumed-type dummy argument in a Fortran procedure can be used as an actual argument corresponding to an
602 c ISO/IEC 2017 – All rights reserved7 The wrapper routine can be written in C as follows.
ISO/IEC DIS 1539-1:2017 (E)
#include "ISO_Fortran_binding.h"void EXAMPLE_send_fortran(const CFI_cdesc_t *buffer, const HANDLE_t *handle,
int *status)
{
int status_local;
size_t buffer_size;
int i;
buffer_size = buffer->elem_len;
for (i=0; i<buffer->rank; i++) {
buffer_size *= buffer->dim[i].extent;
}
status_local = EXAMPLE_send(buffer->base_addr,buffer_size, handle);
if (status != NULL) *status = status_local;
}
C.12.7 Using assumed-type variables in Fortran
assumed-type dummy in a call to another procedure. In the following example, the Fortran subroutine SIMPLE_-SEND serves as a wrapper to hide the complications associated with calls to a C function named ACTUAL_Send.
Module COMM_INFO contains node and address information for the current data transfer operations.
SUBROUTINE SIMPLE_SEND(buffer, nbytes)
USE comm_info, ONLY: my_node, r_node, r_addr
USE, INTRINSIC :: ISO_C_BINDING
IMPLICIT NONE
TYPE(*), INTENT (IN) :: buffer(*)
INTEGER :: nbytes, ierr INTERFACE
SUBROUTINE actual_Send(buffer, nbytes, node, addr, ierr) &
BIND(C, NAME="ACTUAL_Send")
IMPORT :: C_SIZE_T, C_INT, C_INTPTR_TEND SUBROUTINE actual_SendTYPE(*), INTENT (IN) :: buffer(*)
INTEGER(C_SIZE_T), VALUE :: nbytes
INTEGER(C_INT), VALUE :: node
INTEGER(C_INTPTR_T), VALUE :: addr
INTEGER(C_INT), INTENT(OUT) :: ierr
END INTERFACE
CALL actual_Send(buffer, INT(nbytes, C_SIZE_T), r_node, r_addr, ierr)
⃝c ISO/IEC 2017 – All rights reserved 603
ISO/IEC DIS 1539-1:2017 (E)
IF (ierr /= 0) THENPRINT *, "Error sending from node", my_node, "to node", r_node
PRINT *, "Program Aborting" ! Or call a recovery procedure
ERROR STOP ! Omit in the recovery case
END IF
END SUBROUTINE simple_Send
C.12.8 Simplifying interfaces for arbitrary rank procedures 1 There are situations where an assumed-rank dummy argument can be useful in Fortran, although a Fortran
procedure cannot itself access its value. For example, the IEEE inquiry functions in Clause 14 could be written2 In particular, the specific procedures for the IEEE_SUPPORT_DIVIDE function could possibly be implementedusing an assumed-rank dummy argument instead of writing 16 separate specific routines, one for each possible
rank.
in Fortran as follows:1 The example shown below calculates the product of individual elements of arrays A and B and returns the resultINTERFACE ieee_support_divide
MODULE PROCEDURE ieee_support_divide_noarg, ieee_support_divide_onearg_r, &
ieee_support_divide_onearg_d
END INTERFACE ieee_support_divide
...
LOGICAL FUNCTION ieee_support_divide_noarg ()
ieee_support_divide_noarg = .TRUE.
END FUNCTION ieee_support_divide_noarg
LOGICAL FUNCTION ieee_support_divide_onearg_r (x)
REAL, INTENT (IN) :: x(..)
ieee_support_divide_onearg_r4 = .TRUE.
END FUNCTION ieee_support_divide_onearg_r
LOGICAL FUNCTION ieee_support_divide_onearg_d (x)
DOUBLE PRECISION, INTENT (IN) :: x(..)
ieee_support_divide_onearg_r8 = .TRUE.
END FUNCTION ieee_support_divide_onearg_d
C.12.9 Processing assumed-shape arrays in C
in array C. The Fortran interface of elemental_mult will accept arguments of any type and rank. However, the2 The Fortran interface is:C function will return an error code if any argument is not a two-dimensional int array. Note that the arguments
are permitted to be array sections, so the C function does not assume that any argument is contiguous.
604 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
INTERFACE
FUNCTION elemental_mult(a, b, c) BIND(C, NAME="elemental_mult_c") RESULT(err)
USE, INTRINSIC :: ISO_C_BINDINGEND FUNCTION elemental_multINTEGER(C_INT) :: err
TYPE(*), DIMENSION(..) :: a, b, c
END INTERFACE
3 The definition of the C function is:
#include "ISO_Fortran_binding.h"⃝int elemental_mult_c(CFI_cdesc_t * a_desc, CFI_cdesc_t * b_desc, CFI_cdesc_t * c_desc)
{
size_t i, j, ni, nj;
int err = 1; /* this error code represents all errors */
char * a_col = (char*) a_desc->base_addr;
char * b_col = (char*) b_desc->base_addr;
char * c_col = (char*) c_desc->base_addr;
char *a_elt, *b_elt, *c_elt;
/* Only support int. */
if (a_desc->type != CFI_type_int || b_desc->type != CFI_type_int ||
c_desc->type != CFI_type_int) {
return err;
}
/* Only support two dimensions. */
if (a_desc->rank != 2 || b_desc->rank != 2 || c_desc->rank != 2) {
return err;
}
ni = a_desc->dim[0].extent;
nj = a_desc->dim[1].extent;
/* Ensure the shapes conform. */
if (ni != b_desc->dim[0].extent || ni != c_desc->dim[0].extent) return err;
if (nj != b_desc->dim[1].extent || nj != c_desc->dim[1].extent) return err;
/* Multiply the elements of the two arrays. */
for (j = 0; j < nj; j++) {
a_elt = a_col;
b_elt = b_col;
c_elt = c_col;
c ISO/IEC 2017 – All rights reserved 605
ISO/IEC DIS 1539-1:2017 (E)
for (i = 0; i < ni; i++) {}*(int*)a_elt = *(int*)b_elt * *(int*)c_elt;
a_elt += a_desc->dim[0].sm;
b_elt += b_desc->dim[0].sm;
c_elt += c_desc->dim[0].sm;
}
a_col += a_desc->dim[1].sm;
b_col += b_desc->dim[1].sm;
c_col += c_desc->dim[1].sm;
return 0;
}
C.12.10 Creating a contiguous copy of an array 1 A C function might need to create a contiguous copy of an array section, for example, to pass the array section
as an actual argument corresponding to a dummy argument with the CONTIGUOUS attribute. The following2 The C functions are:example provides functions that can be used to copy an array described by a CFI_cdesc_t descriptor to a
contiguous buffer. The input array need not be contiguous.
#include "ISO_Fortran_binding.h"/* Other necessary includes omitted. */
/*
* Returns the number of elements in the object described by desc.
* If it is an array, it need not be contiguous.
* (The number of elements could be zero).
*/
size_t numElements(const CFI_cdesc_t * desc)
{
CFI_rank_t r;
size_t num = 1;
for (r = 0; r < desc->rank; r++) {
num *= desc->dim[r].extent;
}
return num;
}
/*
* Auxiliary recursive function to copy an array of a given rank.
* Recursion is useful because an array of rank n is composed of an
* ordered set of arrays of rank n-1.
*/
static void *_copyToContiguous (const CFI_cdesc_t *vald, void *output,
const void *input, CFI_rank_t rank)
606 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E){
CFI_index_t e;}if (rank == 0) {
/* Copy scalar element. */
memcpy (output, input, vald->elem_len);
output = (void *)((char *)output + vald->elem_len);
}
else {
for (e = 0; e < vald->dim[rank-1].extent; e++) {
/* Recurse on subarrays of lesser rank. */
output = _copyToContiguous (vald, output, input, rank-1);
input = (void *) ((char *)input + vald->dim[rank].sm);
}
}
return output;
/*
*/
o General routine to copy the elements in the array described by vald o to buffer, as done by sequence association. The array itself can o be non-contiguous. This is not the most efficient approach. void copyToContiguous (void * buffer, const CFI_cdesc_t * vald) {
_copyToContiguous (vald, buffer, vald->base_addr, vald->rank);}
C.12.11 Changing the attributes of an array 1 A C programmer might want to call more than one Fortran procedure and the attributes of an array involved
might differ between the procedures. In this case, it is necessary to set up more than one C descriptor for the2 After invocation of the second CFI_establish, the lower bounds stored in the dim member of desc_assum willarray. For example, this code fragment initializes the first C descriptor for an allocatable entity of rank 2, calls
a procedure that allocates the array described by the first C descriptor, constructs the second C descriptor by
invoking CFI_section with the value CFI_attribute_other for the attribute parameter, then calls a procedure
that expects an assumed-shape array.
CFI_CDESC_T(2) loc_alloc, loc_assum;
CFI_cdesc_t * desc_alloc = (CFI_cdesc_t *)&loc_alloc,
* desc_assum = (CFI_cdesc_t *)&loc_assum;
CFI_index_t extents[2];
CFI_rank_t rank = 2;
int flag;
flag = CFI_establish(desc_alloc,
NULL,
CFI_attribute_allocatable,
CFI_type_double,
⃝c ISO/IEC 2017 – All rights reserved 607
ISO/IEC DIS 1539-1:2017 (E)
sizeof(double),
rank,
NULL);
Fortran_factor (desc_alloc, ...); /* Allocates array described by desc_alloc. */
/* Extract extents from descriptor. */
extents[0] = desc_alloc->dim[0].extent;
extents[1] = desc_alloc->dim[1].extent;
flag = CFI_establish(desc_assum,
desc_alloc->base_addr,
CFI_attribute_other,
CFI_type_double,
sizeof(double),
rank,
extents);
Fortran_solve (desc_assum, ...); /* Uses array allocated in Fortran_factor. */
have the value 0 even if the corresponding entries in desc_alloc have different values.1 The C function set_odd sets every second element of an array to a specific value, beginning with the first element.C.12.12 Creating an array section in C using CFI_section
If does this by making an array section descriptor for the elements to be set, and calling a Fortran subroutineSET_ALL that sets every element of an assumed-shape array to a specific value. An interface block for set_odd
permits it to be also called from Fortran.
SUBROUTINE set_all(int_array, val) BIND(C)
INTEGER(C_INT) :: int_array(:)
INTEGER(C_INT), VALUE :: val
int_array = val
END SUBROUTINE
INTERFACE
SUBROUTINE set_odd(int_array, val) BIND(C)
USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_INTINTEGER(C_INT) :: int_array(:)
INTEGER(C_INT), VALUE :: val
END SUBROUTINE
END INTERFACE
#include "ISO_Fortran_binding.h"
void set_odd(CFI_cdesc_t *int_array, int val)
608 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E){
CFI_index_t lower_bound[1], upper_bound[1], stride[1];}CFI_CDESC_T(1) array;
int status;
/* Create a new descriptor which will contain the section. */
status = CFI_establish((CFI_cdesc_t *)&array,
NULL,
CFI_attribute_other,
int_array->type,
int_array->elem_len,
/* rank */ 1,
/* extents is ignored */NULL);
lower_bound[0] = int_array->dim[0].lower_bound;
upper_bound[0] = lower_bound[0] + (int_array->dim[0].extent - 1);
stride[0] = 2;
status = CFI_section((CFI_cdesc_t *)&array,
int_array,
lower_bound,
upper_bound,
stride);
set_all( (CFI_cdesc_t *) &array, val);
/* Here one could make use of int_array and access all its data. */
2 The set_odd procedure can be called from Fortran as follows:
INTEGER(C_INT) :: d(5)3 This program will print something like:d = (/ 1, 2, 3, 4, 5 /)
CALL set_odd(d, -1)
PRINT *, d
-1 2 -1 4 -14 During execution of the subroutine SET_ALL, its dummy argument INT_ARRAY would have size (and upper
bound) 3.5 It is also possible to invoke set_odd() from C. However, it would be the C programmer’s responsibility to make
sure that all members of the C descriptor have the correct value on entry to the function. Inserting additional6 Following is an example C function that dynamically generates a C descriptor for an assumed-shape array andchecking into the function could alleviate this problem.
calls set_odd.1 The C function change_target modifies a pointer to an integer variable to become associated with a global⃝c ISO/IEC 2017 – All rights reserved 609
ISO/IEC DIS 1539-1:2017 (E)
#include <stdio.h>
#include <stdlib.h>
#include "ISO_Fortran_binding.h"
#define ARRAY_SIZE 5
void example_of_calling_set_odd(void)
{
CFI_CDESC_T(1) d;
CFI_index_t extent[1];
CFI_index_t subscripts[1];
void *base;
int i, status;
base = malloc(ARRAY_SIZE*sizeof(int));
extent[0] = ARRAY_SIZE;
status = CFI_establish((CFI_cdesc_t *)&d,
base,
CFI_attribute_other,
CFI_type_int,
/* element length is ignored */ 0,
/* rank */ 1,
extent);
set_odd((CFI_cdesc_t *)&d, -1);
for (i=0; i<ARRAY_SIZE; i++) {
subscripts[0] = i;
printf(" %d",*((int *)CFI_address((CFI_cdesc_t *)&d, subscripts)));
}
putc(10, stdout);
free(base);
}
The above C function will print similar output to that of the preceding Fortran program.
C.12.13 Use of CFI_setpointer
variable defined inside C:2 The restrictions on the use of CFI_establish prohibit direct modification of the incoming pointer entity ip by#include "ISO_Fortran_binding.h"
int y = 2;
void change_target(CFI_cdesc_t *ip) {
CFI_CDESC_T(0) yp;
int status;
610 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
/* Make local yp point at y. */
status = CFI_establish((CFI_cdesc_t *)&yp,
&y,
CFI_attribute_pointer,
CFI_type_int,
/* elem_len is ignored */ sizeof(int),
/* rank */ 0,
/* extents are ignored */ NULL);
/* Pointer-associate ip with (the target of) yp. */
status = CFI_setpointer(ip, (CFI_cdesc_t *)&yp, NULL);
if (status != CFI_SUCCESS) {
... report run time error...
}
}
invoking that function on it.3 The following program illustrates the usage of change_target from Fortran.
PROGRAM change_target_exampleUSE, INTRINSIC :: ISO_C_BINDING
INTERFACE
SUBROUTINE change_target(ip) BIND(C)
IMPORT :: C_INTINTEGER(C_INT), POINTER :: ip
END SUBROUTINE
END INTERFACE
INTEGER(C_INT), TARGET :: it = 1
INTEGER(C_INT), POINTER :: it_ptr
it_ptr => it
WRITE (*,*) it_ptr
CALL change_target(it_ptr)
WRITE (*,*) it_ptr
4 This will print something similar to
1
2
C.12.14 Mapping of MPI interfaces to Fortran 1 The Message Passing Interface (MPI) specifies procedures for exchanging data between MPI processes. This
example shows the usage of MPI_Send and is similar to the second variant of EXAMPLE_Send in C.12.6.2. It also2 MPI_Send has the C prototype:shows the usage of assumed-length character dummy arguments and optional dummy arguments.
int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag,MPI_Comm comm);
⃝c ISO/IEC 2017 – All rights reserved 611
ISO/IEC DIS 1539-1:2017 (E) where MPI_Datatype and MPI_Comm are opaque handles. Most MPI C functions return an error code, which in
Fortran is the last dummy argument to the corresponding subroutine and can be made optional. Thus, the use
of a Fortran subroutine requires a wrapper function, declared as
void MPI_Send_f(CFI_cdesc_t *buf, int count, MPI_Datatype_f datatype, int dest,3 This wrapper function will convert MPI_Datatype_f and MPI_Comm_f to MPI_Datatype and MPI_Comm, and pro-int tag, MPI_Datatype_f comm, int *ierror);
duce a contiguous void * buffer from CFI_cdesc_t *buf (if necessary).4 Similarly, the wrapper function for MPI_Comm_set_name could have the C prototype:
void MPI_Comm_set_name_f(MPI_Comm comm, CFI_cdesc_t *comm_name, int *ierror);5 The Fortran handle types and interfaces are defined in the module MPI_F08. For example,
MODULE mpi_f08...
TYPE, BIND(C) :: mpi_comm
PRIVATE
INTEGER(C_INT) :: mpi_val
END TYPE mpi_comm
INTERFACE
SUBROUTINE MPI_SEND(buf,count,datatype,dest,tag,comm,ierror) &
BIND(C, NAME=’MPI_Send_f’)
USE, INTRINSIC :: ISO_C_BINDINGEND SUBROUTINE mpi_sendIMPORT :: MPI_Datatype, MPI_Comm
TYPE(*), DIMENSION(..), INTENT (IN) :: buf
INTEGER(C_INT), VALUE, INTENT (IN) :: count, dest, tag
TYPE(mpi_datatype), INTENT (IN) :: datatype
TYPE(mpi_comm), INTENT (IN) :: comm
INTEGER(C_INT), OPTIONAL, INTENT (OUT) :: ierror
SUBROUTINE mpi_comm_set_name(comm,comm_name,ierror) &
BIND(C, NAME=’MPI_Comm_set_name_f’)
USE, INTRINSIC :: ISO_C_BINDINGEND SUBROUTINE mpi_comm_set_nameIMPORT :: mpi_comm
TYPE(mpi_comm), INTENT (IN) :: comm
CHARACTER(KIND=C_CHAR, LEN=*), INTENT (IN) :: comm_name
INTEGER(C_INT), OPTIONAL, INTENT (OUT) :: ierror
END INTERFACE
...
END MODULE mpi_f08
612 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)6 Some examples of invocation from Fortran are:
USE, INTRINSIC :: ISO_C_BINDING7 The first example sends the entire array X and includes the optional error argument return value. The secondUSE :: MPI_f08
TYPE(mpi_comm) :: comm
REAL :: x(100)
INTEGER :: y(10,10)
REAL(KIND(1.0d0)) :: z
INTEGER :: dest, tag, ierror
...
! Assign values to x, y, z and initialize MPI variables.
...
! Set the name of the communicator.
CALL mpi_comm_set_name(comm, "Communicator Name", ierror)
! Send values in x, y, and z.
CALL mpi_send(x, 100, MPI_REAL, dest, tag, comm, ierror)
IF (ierror/=0) PRINT *, ’WARNING: X send error’, ierror
CALL mpi_send(y(3,:), 10, MPI_INTEGER, dest, tag, comm)
CALL mpi_send(z, 1, MPI_DOUBLE_PRECISION, dest, tag, comm)
example sends a noncontiguous subarray (the third row of Y) and the third example sends a scalar Z. Note the1 The first two examples are examples of valid host association. The third example is an example of invalid hostdifferences between the calls in this example and those in C.12.6.2.
C.13 Clause 19 notes : Examples of host association (19.5.1.4)
association.Example 1:
PROGRAM A
INTEGER I, J
...
CONTAINS
SUBROUTINE B
INTEGER I ! Declaration of I hides ! program A’s declaration of I...
I = J ! Use of variable J from program A ! through host association
END SUBROUTINE B
END PROGRAM A
⃝c ISO/IEC 2017 – All rights reserved 613
ISO/IEC DIS 1539-1:2017 (E)Example 2:
PROGRAM A
TYPE T
...
END TYPE T
...
CONTAINS
SUBROUTINE B
IMPLICIT TYPE (T) (C) ! Refers to type T declared below ! in subroutine B, not type T...! declared above in program A
TYPE T
...
END TYPE T
...
END SUBROUTINE B
END PROGRAM A
Example 3:
PROGRAM Q
REAL (KIND = 1) :: C
...
CONTAINS
SUBROUTINE R
REAL (KIND = KIND (C)) :: D ! Invalid declaration ! See belowREAL (KIND = 2) :: C
...
END SUBROUTINE R
END PROGRAM Q
2 In the declaration of D in subroutine R, the use of C would refer to the declaration of C in subroutine R, not
program Q. However, it is invalid because the declaration of C is required to occur before it is used in theIn the index, entries in italics denote BNF terms, and page numbers in bold face denote primary text ordeclaration of D (10.1.12).
614 ⃝
c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
Index
definitions.
Symbols
−, 155A edit descriptor, 278 <, 159, 446 ABS, 350, 449 <=, 159 ABSTRACT, 69, 70, 85, 302, 303 >, 159 ABSTRACT attribute, 23, 69, 85 >=, 159 abstract interface, 15, 15, 294, 301, 303, 309, 328, 510, *, 55, 58, 60, 65, 100, 104, 114, 138, 155, 240, 241, 271, 514 283, 288, 311, 330 abstract interface block, 15, 15, 303
**, 155 abstract type, 23, 59, 82, 85, 85, 88, 131, 139 +, 155 ac-do-variable (R776), 93, 93, 164, 166, 512 -stmt, 20 ac-implied-do (R774), 93, 93, 153, 512 .AND., 150, 151, 154, 158, 158, 352 ac-implied-do-control (R775), 93, 93, 153, 164–166, 512 .EQ., 149, 151, 154, 158, 159, 159, 161, 302, 446 ac-spec (R770), 92, 93 .EQV., 150, 151, 154, 158, 158 ac-value (R773), 93, 93 .FALSE., 68, 479 access-id (R828), 111, 111 .GE., 149, 151, 154, 158, 159, 161, 302, 446 access-name, 111 .GT., 149, 151, 154, 158, 159, 161, 302, 446 access-spec (R807), 69, 74, 75, 80–83, 95, 98, 98, 111, .LE., 149, 151, 154, 158, 159, 161, 302, 446 112, 304, 308 .LT., 149, 151, 154, 158, 159, 161, 302, 446 access-stmt (R827), 36, 98, 111, 111, 112 .NE., 149, 151, 154, 158, 159, 159, 161, 302, 446 ACCESS= specifier, 226, 227, 254, 255 .NEQV., 150, 151, 154, 158, 158, 413 accessibility attribute, 98, 111, 294 .NOT., 150, 151, 154, 158, 158 accessibility statement, 111 .OR., 150, 151, 154, 158, 158, 353 ACHAR, 68, 169, 350 .TRUE., 68, 479 ACOS, 350 /, 155 ACOSH, 350 / edit descriptor, 281 ACQUIRED_LOCK= specifier, 213, 525, 528 //, 157 action, 218 /=, 159, 446 action-stmt (R515), 7, 37, 37, 153, 196, 204 : edit descriptor, 281 ACTION= specifier, 226, 228, 254, 255, 565 ;, 54 active image, 14, 41, 140, 144, 145, 186, 213, 216, 341, <=, 446 407 ==, 159, 446 actual argument, 5, 16, 30, 31, 41, 45–47, 60, 63, 72, >, 446 84, 85, 103–108, 131, 133, 141, 143, 153, 162, >=, 446 163, 193, 246, 305–307, 310–324, 332–338, 342, &, 54, 288 348, 349, 370, 394, 395, 411, 420, 433–435, 438, ⃝c ISO/IEC 2017 – All rights reserved 615
ISO/IEC DIS 1539-1:2017 (E)
450, 483, 484, 486, 489–491, 513, 517–519, 522, ancestor-module-name, 297527–529, 541, 543, 584, 585, 587, 590 and-op (R1019), 51, 150, 150
actual-arg (R1524), 311, 311 and-operand (R1014), 150, 150 actual-arg-spec (R1523), 88, 311, 311 ANINT, 352 add-op (R1009), 51, 148, 148 ANY, 353 add-operand (R1005), 148, 148, 151, 152 arg-name, 75, 77, 82 ADJUSTL, 351 argument ADJUSTR, 351 dummy, 316 ADVANCE= specifier, 232, 233, 234, 245, 563 argument association, 6, 6, 23, 58, 66, 76, 77, 100, 103, advancing input/output statement, 221 110, 111, 143, 144, 299, 313, 314, 323, 330, AIMAG, 351 513, 519, 521, 522, 540, 586 AINT, 351 argument keyword, 12, 16, 47, 301, 304, 313, 337, 342, ALL, 120, 352 450, 510, 511, 512, 573 alloc-opt (R928), 138, 138, 139, 144 arithmetic IF statement, 540 allocatable, 5, 5, 20, 31, 45, 46, 58, 60, 61, 71, 76, 77, array, 5, 7, 13, 20, 46, 102–104, 133–136 79, 84, 87, 89, 90, 96, 100, 103–106, 110, 113, assumed-shape, 5, 60, 101, 103, 122, 123, 136, 137,124, 125, 131, 132, 138, 139, 141–144, 163, 165, 301, 315–319, 321, 322, 328, 479, 489, 491, 503,
167–170, 172, 173, 193, 207, 237, 238, 243, 285, 584, 601, 607, 609
300, 301, 311, 315, 317, 321, 329, 335, 337, 352, assumed-size, 5, 104, 105, 110, 123, 133, 134, 147,
369, 379, 394–396, 407, 408, 410, 411, 421, 424, 164, 167, 189, 200, 237, 315, 316, 320, 395,
426, 428, 431, 434, 435, 444, 450, 479, 484, 424, 426, 427, 434, 484, 488, 493, 496, 500,
486–488, 493, 500, 502–504, 516, 517, 526 502, 503, 596, 598, 601
ALLOCATABLE attribute, 5, 58–60, 68, 69, 74, 75, 98, deferred-shape, 5, 103 98–100, 103, 108, 110, 112, 131, 134, 183, 189, explicit-shape, 5, 60, 76, 100, 103, 166, 315, 320,199, 200, 298, 301, 306, 307, 317, 320, 328, 488
336, 488, 516, 522, 523, 587, 591 array bound, 7, 76, 78, 97, 165
ALLOCATABLE statement, 112 array constructor, 92, 92 allocatable-decl (R830), 112, 112 array element, 5, 45, 134 allocatable-stmt (R829), 36, 112, 514 array element order, 134–135 ALLOCATE statement, 58, 59, 66, 101, 103, 138, 141, array pointer, 5, 101, 103, 104, 163, 354, 488 144, 145, 172, 206, 438, 497, 498, 517, 518, array section, 5, 101, 113, 114, 132, 134–137, 183, 223,525–527, 532, 543 315, 316, 321, 322, 516, 519
allocate-coarray-spec (R936), 138, 138, 139 array-constructor (R769), 92, 93, 147 allocate-coshape-spec (R937), 138, 138, 139 array-element (R917), 113, 114, 124, 129, 130, 133 allocate-object (R932), 66, 138, 138–145, 206, 438, 440, array-name, 115, 514 528, 529, 532 array-section (R918), 5, 129, 133, 134, 135
allocate-shape-spec (R933), 138, 138–141 array-spec (R815), 28, 95–97, 102, 102–105, 112, 115, allocate-stmt (R927), 37, 138, 529 117, 125 ALLOCATED, 75, 141, 145, 352 ASCII character, 5, 65, 68, 167, 223, 238, 270, 284, allocation (R931), 138, 138–141 350, 365, 386, 389, 396–398, 409, 422 allocation status, 46, 87, 89, 90, 106, 109, 110, 141, ASCII collating sequence, 68, 350, 365, 386, 389, 397, 141–145, 193, 207, 210, 317, 321, 352, 407, 411, 398, 409504, 522, 526 ASIN, 353
alphanumeric-character (R601), 49, 49, 50 ASINH, 354 alt-return-spec (R1525), 7, 204, 311, 311 ASSIGN statement, 539 ancestor component, 86 assigned format, 539 616 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
assigned GO TO statement, 539 123–125, 164, 165, 172, 294, 293–297, 303, ASSIGNMENT, 82, 170, 171, 302, 306, 307 331, 334, 511–514, 517 assignment, 167–179 association (R1104), 182, 182 defined, 81, 170, 306 association status, see pointer association statuselemental, 12, 171 assumed type parameter, 24, 24, 58, 315, 317
elemental array (FORALL), 177 assumed-implied-spec (R821), 104, 104, 105
masked array (WHERE), 175 assumed-rank dummy data object, 6, 45, 60, 83, 84, 101,
pointer, 171 102, 136, 199, 200, 300, 301, 307, 315–317, 321,
assignment statement, 17, 31, 44, 58, 84, 167, 179, 475, 322, 328, 393–395, 418, 424, 426, 427, 434, 479, 524 484, 489, 491, 601, 602, 604
assignment-stmt (R1032), 37, 167, 167, 175, 177, 178, assumed-rank-spec (R825), 102, 105 528 assumed-shape array, 5, 60, 101, 103, 122, 123, 136, 137,
ASSOCIATE construct, 46, 182, 185, 321, 512, 513, 301, 315–319, 321, 322, 328, 479, 489, 491, 503, 516, 528 584, 601, 607, 609
associate name, 6, 6, 24, 58, 61, 88, 99, 143, 182, 183, assumed-shape-spec (R819), 102, 103, 103 185, 202, 513, 516, 517, 522, 528 assumed-size array, 5, 104, 105, 110, 123, 133, 134, 147,
ASSOCIATE statement, 46, 182, 516 164, 167, 189, 200, 237, 315, 316, 320, 395, associate-construct (R1102), 37, 182, 182 424, 426, 427, 434, 484, 488, 493, 496, 500, associate-construct-name, 182 502, 503, 596, 598, 601 associate-name, 182, 199–203, 512 assumed-size-spec (R822), 102, 104, 104 associate-stmt (R1103), 7, 182, 182, 204 assumed-type, 7, 59, 60, 315, 328, 489, 603 ASSOCIATED, 75, 142, 145, 338, 354 ASYNCHRONOUS attribute, 98, 98, 99, 112, 183, 192, associating entity, 6, 46, 66, 137, 182, 183, 185, 187, 235, 294, 296, 300, 301, 316, 317, 367, 418, 504, 203, 330, 522, 522 505, 507, 514
association, 6 asynchronous communication, 98, 507 argument, 6, 6, 23, 58, 66, 76, 77, 100, 103, 110, asynchronous input/output, 98, 226, 228, 230, 234–236,111, 143, 144, 299, 313, 314, 323, 330, 513, 239, 240, 247, 250, 251, 253, 255, 257, 258
519, 521, 522, 540, 586 ASYNCHRONOUS statement, 112, 184, 298, 512, 514
common, 126 asynchronous-stmt (R831), 36, 112
construct, 6, 6, 143, 144, 513, 516, 519, 522 ASYNCHRONOUS= specifier, 227, 228, 232, 233, 234,
equivalence, 124 254, 255
host, 6, 6, 39, 59, 60, 66, 98, 111, 113, 118, 126, 164, ATAN, 355
165, 172, 297, 299, 320, 333–335, 511, 513–516, ATAN2, 32, 355
519, 522, 613 ATANH, 356
inheritance, 6, 6, 9, 47, 86, 88, 519, 522 atomic subroutine, 22, 41, 207, 208, 337, 340, 342, 356–
linkage, 6, 6, 506, 513, 516, 516 360, 377, 437, 441, 528
name, 6, 6, 47, 513, 519 ATOMIC_ADD, 356, 438
pointer, 6, 6, 12, 22, 23, 44, 47, 85, 87, 89, 101, ATOMIC_AND, 356
106, 108, 110, 111, 131, 143, 145, 171, 173, ATOMIC_CAS, 357
174, 193, 207, 210, 240, 300, 314, 316, 318, ATOMIC_DEFINE, 357, 592, 593
320, 321, 329, 330, 343, 354, 407, 411, 482, ATOMIC_FETCH_ADD, 357
483, 517–520, 522, 528 ATOMIC_FETCH_AND, 358
sequence, 320 ATOMIC_FETCH_OR, 358
storage, 6, 6, 46, 47, 123–125, 331, 334, 429, 519– ATOMIC_FETCH_XOR, 359
522 ATOMIC_INT_KIND, 356–360, 437
use, 6, 6, 31, 39, 47, 60, 66, 86, 98, 109, 111, 118, ATOMIC_LOGICAL_KIND, 357, 360, 437
⃝c ISO/IEC 2017 – All rights reserved 617
ISO/IEC DIS 1539-1:2017 (E)
ATOMIC_OR, 359 PASS, 75, 77, 82, 311 ATOMIC_REF, 359, 592, 593 POINTER, 5, 17, 58–60, 68, 69, 74, 75, 96, 103, ATOMIC_XOR, 360 105, 108, 108, 110, 115, 117, 131, 134, 142, attr-spec (R802), 95, 95–97, 117 172, 183, 192, 199, 200, 299–301, 303, 306, 307, attribute, 7, 59, 68, 72, 95–111, 296 309, 317, 320–323, 328, 334, 336, 484, 488, 503, ABSTRACT, 23, 69, 85 516, 519, 522, 523, 543, 587, 591accessibility, 98, 111, 294 PRIVATE, 71, 86, 98, 98, 111, 123, 335, 571
ALLOCATABLE, 5, 58–60, 68, 69, 74, 75, 98, 98– PROTECTED, 31, 109, 109, 117, 124, 192, 295,
100, 103, 108, 110, 112, 131, 134, 183, 189, 543
199, 200, 298, 301, 306, 307, 317, 320, 328, PUBLIC, 86, 98, 98, 111, 123, 571
336, 488, 516, 522, 523, 587, 591 SAVE, 19, 24, 33, 46, 78, 85, 97, 99, 100, 109, 109,
ASYNCHRONOUS, 98, 98, 99, 112, 183, 192, 235, 110, 113, 117, 124, 126, 144, 192, 309, 334, 518
294, 296, 300, 301, 316, 317, 367, 418, 504, SEQUENCE, 19, 69, 71, 71, 72, 85, 125, 172, 173,
505, 507, 514 202, 486
BIND, 6, 7, 44, 69–71, 85, 90, 99, 99, 110, 112, TARGET, 6, 22, 31, 78, 108, 110, 110, 117, 124,
124, 125, 172, 173, 192, 202, 298, 300, 301, 126, 142, 143, 172, 183, 192, 193, 200, 301, 307,
327, 329, 486, 487, 489, 504–506, 516, 523, 596 315, 316, 318, 321–323, 367, 407, 418, 481, 484,
CODIMENSION, 60, 75, 96, 99, 99, 105, 113 504, 505, 517–519, 527, 543, 584, 585
CONTIGUOUS, 75, 77, 101, 101, 102, 113, 136, VALUE, 60, 77, 83, 105, 110, 110, 118, 192, 240,
137, 173, 192, 300, 315, 317–319, 321, 322, 489, 300, 301, 303, 305, 306, 314–318, 328, 334, 336,
491, 520 367, 418, 489, 490, 507, 519, 543, 596, 598
VOLATILE, 31, 110, 110, 111, 118, 172, 173, 183,
DEFERRED, 81, 82, 85
192, 294, 296, 300, 301, 316–318, 334, 514, 519,
DIMENSION, 75, 96, 102, 102, 115, 125
525, 528, 550
EXTENDS, 23, 85, 85, 487
attribute specification statements, 111–127
EXTERNAL, 17, 29, 30, 105, 105, 108, 117, 118,
automatic data object, 7, 32, 96, 97, 100, 110, 113, 124,
120, 172, 294, 298, 300, 303, 308, 320, 324,
125, 525, 541
326, 514, 515, 582
INTENT, 105, 105–107, 116, 192, 543 B
INTENT (IN), 105, 106, 107, 111, 189, 305–307, B edit descriptor, 277
315, 318, 320–322, 334, 335, 338, 356–360, BACKSPACE statement, 218, 221, 247, 250, 251, 252,
365–368, 377, 378, 383, 384, 408, 416, 451, 564, 565
481–483, 503, 504, 543, 584, 598 backspace-stmt (R1224), 37, 251, 335
INTENT (INOUT), 30, 105, 106, 107, 110, 193, base object, 7, 98, 101, 124, 131, 137, 164, 235, 321,
306, 316, 318, 324, 335, 336, 356–360, 365–368, 334, 336
378, 382–384, 407, 408, 438, 440, 528, 529, 598 BESSEL_J0, 360
INTENT (OUT), 31, 60, 83–85, 104, 105, 105– BESSEL_J1, 360
107, 110, 143, 164, 306, 316, 318, 324, 334–336, BESSEL_JN, 361
356–360, 365–368, 370, 372, 377, 378, 382–384, BESSEL_Y0, 361
407, 408, 416, 430, 453–455, 481, 483, 503, 504, BESSEL_Y1, 361
517–519, 524, 525, 527–529, 598 BESSEL_YN, 362
INTRINSIC, 105, 107, 107, 108, 294, 310, 324, 325, BGE, 362
515 BGT, 362
NON_OVERRIDABLE, 81, 82 binary-constant (R765), 92, 92
NON_RECURSIVE, 301, 327, 327, 331, 332 BIND (C), see BIND attribute
OPTIONAL, 108, 108, 110, 116, 164, 183, 189, 301 BIND attribute, 6, 7, 44, 69–71, 85, 90, 99, 99, 110, 112,
PARAMETER, 9, 44, 91, 97, 108, 108, 116, 130 124, 125, 172, 173, 192, 202, 298, 300, 301, 327,
618 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
329, 486, 487, 489, 504–506, 516, 523, 596 362–365, 373–375, 387, 389, 391, 392, 403, 404,
BIND statement, 112, 298, 505, 511 418
bind-entity (R833), 112, 112 branch, 204, 332, 539 bind-stmt (R832), 37, 112 branch target statement, 7, 40, 52, 175, 192, 204, 204, binding, 7, 81, 82, 82, 86, 87, 160, 171, 243, 249, 307, 205, 227, 231, 232, 250, 251, 253, 255, 312, 332 326, 510, 511 BTEST, 364
binding label, 7, 99, 301, 309, 327, 329, 505–507, 509, BZ edit descriptor, 282 510, 543binding name, 7, 81, 82, 86, 311, 511
C
C address, 7, 481–484, 486, 487, 492, 497, 499, 526, 527,
binding-attr (R752), 81, 82, 82
598binding-name, 81, 82, 311, 326, 511
C descriptor, 8, 143, 490–505binding-private-stmt (R747), 81, 81, 83
C_ALERT, 480bit model, 338
C_ASSOCIATED, 480BIT_SIZE, 339, 363, 408
C_BACKSPACE, 480blank common, 8, 96, 113, 125, 126, 519, 521
C_BOOL, 479, 480blank interpretation mode, 228
C_CARRIAGE_RETURN, 480blank-interp-edit-desc (R1318), 267, 268
C_CHAR, 480, 543BLANK= specifier, 227, 228, 232, 233, 235, 247, 254,
C_DOUBLE, 479255, 282
C_DOUBLE_COMPLEX, 480BLE, 363
C_F_POINTER, 480, 481block, 7
C_F_PROCPOINTER, 483interface, 295
C_FLOAT, 479block (R1101), 7, 181, 182, 184–188, 190, 191, 194–196,
C_FLOAT_COMPLEX, 480199, 201
C_FORM_FEED, 480
BLOCK construct, 19, 31, 41, 43, 84, 97, 99, 101, 103, C_FUNLOC, 483, 483, 506 109, 111, 118, 120–122, 143, 164, 183, 334, C_FUNPTR, 74, 85, 99, 131, 139, 140, 170, 479, 480,512, 518, 519, 525, 527, 532 483, 486, 487, 527
block data program unit, 297 C_HORIZONTAL_TAB, 480 BLOCK DATA statement, 53, 293, 297 C_INT, 479 block scoping unit, 14, 19 C_INT16_T, 479 BLOCK statement, 97, 101, 103, 184, 525 C_INT32_T, 479 block-construct (R1107), 37, 184, 184 C_INT64_T, 479 block-construct-name, 184 C_INT8_T, 479 block-data (R1420), 35, 120, 297, 298 C_INT_FAST16_T, 479 block-data-name, 297 C_INT_FAST32_T, 479 block-data-stmt (R1421), 35, 297, 297 C_INT_FAST64_T, 479 block-specification-part (R1109), 20, 184, 184 C_INT_FAST8_T, 479 block-stmt (R1108), 7, 184, 184, 204 C_INT_LEAST16_T, 479 BLT, 363 C_INT_LEAST32_T, 479 BN edit descriptor, 282 C_INT_LEAST64_T, 479 bound, 5, 7, 7, 45, 46, 75, 87, 90, 103, 138, 140, 144, C_INT_LEAST8_T, 479 145, 173, 207, 407, 513 C_INTMAX_T, 479
bounds, 102–105, 133–136 C_INTPTR_T, 479 bounds-remapping (R1036), 171, 172, 172, 173 C_LOC, 60, 105, 335, 484, 543 bounds-spec (R1035), 171, 172, 172, 173 C_LONG, 479 boz-literal-constant (R764), 51, 92, 92, 115, 277, 339, C_LONG_DOUBLE, 479 ⃝c ISO/IEC 2017 – All rights reserved 619
ISO/IEC DIS 1539-1:2017 (E)
C_LONG_DOUBLE_COMPLEX, 480 char-variable (R905), 129, 129, 223 C_LONG_LONG, 479 character context, 8, 49, 53–55, 67 C_NEW_LINE, 480 character literal constant, 66 C_NULL_CHAR, 480 character sequence type, 20, 71, 124–126, 521, 525 C_NULL_FUNPTR, 479, 480 character set, 49 C_NULL_PTR, 479, 480 character storage unit, 21, 21, 104, 124, 126, 437, 520, C_PTR, 74, 85, 99, 131, 139, 140, 170, 479–481, 484, 524, 526 486, 487, 490, 526, 527, 596 character string edit descriptor, 266, 283
C_SHORT, 479 character type, 65–68 C_SIGNED_CHAR, 479 CHARACTER_KINDS, 437 C_SIZE_T, 479 CHARACTER_STORAGE_SIZE, 437 C_SIZEOF, 105, 164, 484 characteristics, 8, 86, 174, 243, 244, 300, 301, 303, 309, C_VERTICAL_TAB, 480 310, 319, 324, 327, 329, 331, 349, 411 CALL statement, 22, 204, 207, 299, 311, 324, 332, 407 dummy argument, 300 call-stmt (R1521), 37, 311, 312, 313 procedure, 300 CASE statement, 197 child data transfer statement, 222, 223, 234–236, 239, case-construct (R1140), 37, 196, 197 245, 243–247, 262, 286 case-construct-name, 197 CLASS, 59, 59, 60, 243 case-expr (R1144), 197, 197 CLASS DEFAULT statement, 202 case-selector (R1145), 197, 197 CLASS IS statement, 202, 379 case-stmt (R1142), 196, 197, 197 CLOSE statement, 218, 219, 223, 225, 226, 230, 230, case-value (R1147), 197, 197 247, 250, 564 case-value-range (R1146), 197, 197 close-spec (R1209), 231, 231 CEILING, 364 close-stmt (R1208), 37, 231, 335 CFI_address, 496 CMPLX, 169, 339, 365, 445 CFI_allocate, 497, 504 CO_BROADCAST, 365 CFI_cdesc_t, 8, 489–491, 492, 492–494, 496–502, 504 CO_MAX, 366 CFI_deallocate, 494, 498, 504 CO_MIN, 366 CFI_establish, 498 CO_REDUCE, 367, 535 CFI_is_contiguous, 500 CO_SUM, 368, 535 CFI_section, 500 coarray, 8, 8, 10, 31, 41, 45, 46, 70, 75, 76, 84, 99–101, CFI_select_part, 501 106, 108, 110, 111, 124, 125, 132, 138–141, 144, CFI_setpointer, 502 145, 167, 168, 170, 172, 173, 183, 185–187, 189, CHANGE TEAM construct, 22, 46, 137, 183, 185, 191, 206–208, 294, 301, 311, 316, 318, 319, 321, 322, 204, 512, 513, 528 324, 328, 341, 342, 345, 347, 356–360, 369, 390,
CHANGE TEAM statement, 22, 40, 46, 185, 206, 215, 395, 407, 431, 432, 434, 435, 440, 488 341, 516 established, 8, 46, 186
change-team-construct (R1111), 37, 185, 185 coarray-association (R1113), 46, 185, 185 change-team-stmt (R1112), 185, 185 coarray-name, 113, 185, 512, 514 changeable mode, 224 coarray-spec (R809), 74–76, 95, 96, 99, 99, 100, 112, CHAR, 67, 364 113, 117 char-length (R723), 65, 65, 66, 74, 75, 95–97, 542 cobound, 8, 45, 46, 99–101, 137, 140, 165, 183, 187, 319, char-literal-constant (R724), 51, 55, 56, 66, 246, 267, 345, 347, 395, 407, 434, 435, 513 268, 531 codimension, 8, 8, 10, 45, 101, 137, 183, 300, 369, 395,
char-selector (R721), 61, 65, 66 435 char-string-edit-desc (R1321), 266, 268 CODIMENSION attribute, 60, 75, 96, 99, 99, 105, 113 620 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
codimension-decl (R835), 113, 113, 183, 185, 186, 512 component definition statement, 74 codimension-stmt (R834), 37, 113, 514 component keyword, 16, 47, 80, 89, 511 coindexed object, 8, 31, 41, 45, 46, 78, 113, 131, 137, component order, 9, 80, 89, 238 139, 167, 168, 170, 172, 173, 182, 208, 212, 311, component-array-spec (R740), 74, 74–76312, 315–318, 321, 322, 334, 356–360, 365–368, component-attr-spec (R738), 74, 74, 75, 77, 78
377, 407, 441, 481, 483, 484 component-data-source (R758), 88, 88, 89
coindexed-named-object (R914), 129, 130, 132, 132 component-decl (R739), 66, 74, 74–76, 78 collating sequence, 8, 67, 68, 159, 270, 350, 364, 365, component-def-stmt (R736), 9, 74, 74, 75 386, 389, 397, 398, 401–406, 409 component-initialization (R743), 74, 77, 78
collective subroutine, 22, 337, 341, 342, 365–368, 380, component-name, 74, 78 428, 441 component-part (R735), 69, 74, 80, 83
COMMAND_ARGUMENT_COUNT, 166, 368, 383 component-spec (R757), 88, 88, 165 comment, 54, 55, 290 computed GO TO statement, 7, 204, 205, 540, 541 common association, 126 computed-goto-stmt (R1158), 38, 205, 205 common block, 8, 33, 38, 44, 96, 97, 99, 109, 110, 112, concat-op (R1011), 51, 149, 149 113, 124–127, 164, 297, 298, 505, 506, 509–512, CONCURRENT, 188516, 519–521, 526, 542 concurrent-control (R1126), 177, 178, 189, 189, 190
common block storage sequence, 126 concurrent-header (R1125), 177–179, 188, 189, 189, 512 COMMON statement, 8, 125, 125–127, 184, 296, 298, concurrent-limit (R1127), 153, 178, 189, 189–191 511, 521, 540 concurrent-locality (R1129), 188, 189, 189
common-block-name, 112, 117, 125, 184, 296 concurrent-step (R1128), 153, 178, 189, 189–191 common-block-object (R874), 125, 125, 296, 514 conformable, 9, 45, 141, 153, 161, 167, 171, 324, 336, common-stmt (R873), 37, 125, 514 380, 387, 388, 392, 401, 402, 404, 405, 413, companion processor, 7, 9, 15, 42, 47, 48, 69, 91, 99, 415, 429, 435, 465 479, 484, 506, 507 CONJG, 368
compatibility connect-spec (R1205), 226, 226, 227 Fortran 77, 32 connected, 9, 13, 16, 18, 218–222, 225, 226, 228–231,Fortran 2003, 31 236, 240, 242, 243
Fortran 2008, 30 connection mode, 224
Fortran 90, 32 constant, 9, 44, 51, 57
Fortran 95, 31 integer, 62
COMPILER_OPTIONS, 164, 437 named, 116 COMPILER_VERSION, 164, 437 constant (R604), 51, 51, 114, 130, 147 completion step, 42, 231 constant expression, 7, 10, 24, 32, 57, 58, 66, 73, 75, 76, complex part designator, 11, 43, 132 78, 93, 97, 101, 103, 104, 113, 114, 116, 124, complex type, 64–65 164, 165, 166, 166, 234, 300, 301, 321, 338, complex-literal-constant (R718), 51, 64 350, 351, 353, 364, 365, 369, 370, 380, 381, 386, complex-part-designator (R915), 129, 132, 132, 133, 137 389, 391, 394–396, 399–401, 405, 409, 418, 420, component, 9, 10, 15, 16, 20, 21, 69–71, 74, 89, 118, 422, 424, 426, 428, 434–436, 488, 543 511 constant-expr (R1029), 24, 58, 77, 78, 96, 97, 104, 105,
direct, 9, 9, 69, 78, 316, 444, 486 108, 116, 166, 166, 197 parent, 6, 9, 80, 84, 86, 89, 522, 552 constant-subobject (R847), 114, 114 potential subobject, 9, 69, 70, 335 construct ultimate, 9, 31, 68–70, 75, 99, 101, 104, 105, 110, ASSOCIATE, 46, 181, 182, 185, 199, 321, 512, 513, 124, 125, 139, 142, 166, 167, 243, 315, 316, 516, 528334, 520 BLOCK, xix, 14, 19, 20, 31, 41, 43, 84, 97, 99,
⃝c ISO/IEC 2017 – All rights reserved 621
ISO/IEC DIS 1539-1:2017 (E)
101, 103, 109, 111, 118, 120–122, 143, 164, 181, 435, 513183, 334, 512, 518, 519, 525, 527, 532 COS, 369
CHANGE TEAM, xx, 22, 46, 137, 181, 183, 185, COSH, 369 191, 204, 512, 513, 528 COSHAPE, 369
CRITICAL, 181, 187, 187, 191, 204, 341 cosubscript, 10, 45, 46, 101, 137, 345, 347, 390, 431, DO, 41, 52, 93, 181, 188, 204, 238, 539, 554, 555 432, 435 DO CONCURRENT, xviii, 30, 31, 188, 191, 195, cosubscript (R925), 131, 137, 137 204, 335, 512, 519, 525, 527, 532, 542 COUNT, 338, 370
FORALL, 177, 335, 512, 525, 540, 542 CPU_TIME, 370 IF, 41, 181, 195, 452, 539 CRITICAL construct, 187, 191, 204 nonblock DO, xviii, 540 CRITICAL statement, 161, 187, 206, 207, 216 SELECT CASE, 41, 181, 196, 540, 541, 553 critical-construct (R1116), 37, 187, 187 SELECT RANK, xviii, 41, 46, 104, 105, 181, 183, critical-construct-name, 187 199, 321, 528 critical-stmt (R1117), 7, 187, 187, 204
SELECT TYPE, 41, 46, 58, 59, 181, 183, 201, 321, CSHIFT, 371 512, 513, 516, 528 current record, 221
WHERE, 17, 175 current team, 22, 84, 137, 140, 141, 144, 145, 185, 186,
construct association, 6, 6, 143, 144, 513, 516, 519, 522 208, 209, 211–213, 215, 341, 365, 380, 385, 390, construct entity, 6, 10, 111, 121, 182, 184, 185, 189, 407, 412, 428, 431, 432, 435, 438, 441 192, 201, 509, 510, 512, 519 CURRENT_TEAM, 385, 438
construct-name, 204 CYCLE statement, 182, 188, 191, 192, 542 constructor cycle-stmt (R1133), 37, 191, 191 array, 92
D
derived-type, 88
d (R1310), 267, 267, 272–276, 279, 280, 286
structure, 88 D edit descriptor, 273
CONTAINS statement, 39, 40, 81, 332 data edit descriptor, 266, 270–280
contains-stmt (R1543), 36, 81, 294, 332 data entity, 8, 9, 10, 17–19, 25, 43–45 contiguous, 10, 20, 30, 71, 77, 101, 130, 137, 173, 174, data object, 7–9, 10, 10, 11, 19, 21, 24, 38–40, 43–46 183, 193, 235, 242, 393, 484, 520, 543 data object designator, 11, 19, 45, 129
CONTIGUOUS attribute, 75, 77, 101, 101, 102, 113, data object reference, 19, 44, 46 136, 137, 173, 192, 300, 315, 317–319, 321, 322, data pointer, 17, 17, 46, 481, 493, 503, 520489, 491, 520 DATA statement, 32, 33, 40, 92, 97, 113, 126, 298, 411,
CONTIGUOUS statement, 113 512, 515, 523, 540, 541 contiguous-stmt (R836), 37, 113 data transfer, 241 continuation, 54, 55 data transfer input statement, 231 CONTINUE statement, 205, 539 data transfer output statement, 231 continue-stmt (R1159), 37, 189, 205 data transfer statement, 33, 52, 217–223, 225, 231, 236, control character, 49, 67, 217, 220 239–241, 246, 250, 252, 260–263, 265, 266, 277, control edit descriptor, 266, 280–283 282, 284–286, 288, 290, 439, 524, 526, 534, 563, control information list, 232 564, 567, 568 control mask, 176 data type, 23, see type control-edit-desc (R1313), 266, 267 data-component-def-stmt (R737), 74, 74–76 conversion data-edit-desc (R1307), 266, 267 numeric, 169 data-i-do-object (R841), 113, 113, 114
corank, 10, 45, 46, 76, 99, 100, 102, 131, 137, 139, 147, data-i-do-variable (R842), 113, 113, 114, 166, 512 183, 187, 300, 318, 369, 390, 395, 407, 431, data-implied-do (R840), 113, 113, 114, 166, 512
622 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
data-pointer-component-name, 171, 172 260 data-pointer-initialization compatible, 77 default-initialized, 10, 78, 106, 328, 517–519, 523, 525, data-pointer-object (R1034), 171, 171–173, 178, 354, 527 529 DEFERRED attribute, 81, 82, 85
data-ref (R911), 7, 130, 131–133, 172, 235, 311, 313, deferred type parameter, 24, 24, 31, 58, 66, 90, 108, 321, 326 126, 132, 139–141, 144, 145, 167, 168, 173,
data-stmt (R837), 36, 113, 303, 334, 514 193, 207, 285, 300, 317, 396, 411, 428, 481, data-stmt-constant (R845), 92, 114, 114, 115 483, 489, 517, 522 data-stmt-object (R839), 113, 113–115 deferred-coshape-spec (R810), 74, 99, 100, 100 data-stmt-repeat (R844), 114, 114 deferred-shape array, 5, 103 data-stmt-set (R838), 113, 113 deferred-shape-spec (R820), 5, 74, 102, 103, 103, 116 data-stmt-value (R843), 113, 114, 114 definable, 10, 106–109, 136, 168, 183, 237, 314, 316, data-target (R1037), 88, 89, 109, 171, 172, 172, 173, 318, 323, 519, 528 178, 321, 334, 354, 520 defined, 10, 11, 25, 44, 46
DATE_AND_TIME, 372 defined assignment, 11, 22, 167, 170, 171, 175, 178, 299, DBLE, 339, 373 306, 311, 316, 335 DC edit descriptor, 283 defined assignment statement, 31, 171, 324, 528 dealloc-opt (R941), 142, 142, 144 defined input/output, 11, 224, 229, 237–239, 243, 245, DEALLOCATE statement, 142, 144, 145, 206, 438, 246, 246, 247, 243–249, 260, 280, 286, 287, 498, 532 291, 299, 305, 307, 311, 324, 335, 439, 588
deallocate-stmt (R940), 37, 142, 529 defined operation, 11, 19, 151, 160, 161–163, 189, 299, decimal edit descriptor, 283 305, 311, 324, 335 decimal edit mode, 228 defined-binary-op (R1023), 17, 52, 150, 150, 151, 160, decimal symbol, 10, 228, 235, 255, 270–276, 283, 284 295 decimal-edit-desc (R1320), 267, 268 defined-io-generic-spec (R1509), 11, 82, 243, 244, 249, DECIMAL= specifier, 227, 228, 232, 233, 235, 247, 302, 302, 305, 307 254, 255, 283 defined-operator (R609), 52, 82, 296, 302, 543
declaration, 10, 39, 95–127 defined-unary-op (R1003), 17, 52, 148, 148, 151, 160, declaration-construct (R507), 36, 36, 184 295 declaration-type-spec (R703), 59, 59, 66, 74, 75, 95, 97, definition, 10, 11 118, 164, 308, 309, 327, 330 definition of variables, 523
declared type, 23, 60, 61, 77, 89, 90, 93, 95, 130, 132, deleted features, 29, 30, 32, 33, 539, 540 139, 140, 142, 160, 162, 167, 170–173, 182, 202, DELIM= specifier, 227, 228, 232, 233, 235, 247, 254,203, 249, 306, 311, 314, 317, 326, 333, 379, 403, 256, 289, 291, 565
407, 421, 438, 440, 513 delimiter mode, 228
DEFAULT, 189, 197, 202 derived type, 11, 21, 23, 42, 43, 46, 57, 68–90, 93, 486, default character, 65 487 default complex, 64 derived type definition statement, see TYPE statement default initialization, 10, 10, 76–79, 88, 89, 97, 104, 105, derived type determination, 71 113, 124, 125, 127, 316, 411, 517, 522, 526 derived-type type specifier, 59
default real, 63 derived-type-def (R726), 36, 59, 60, 69, 70, 73, 487 default-char-constant-expr (R1030), 99, 166, 166, 232, derived-type-spec (R754), 24, 59, 60, 66, 87, 88, 202, 233 243, 511
default-char-expr (R1025), 162, 162, 166, 205, 226–232, derived-type-stmt (R727), 69, 69, 70, 73, 98, 514 234–236 descendant, 11, 39, 70, 80, 81, 83, 109, 297, 510
default-char-variable (R906), 129, 129, 138, 227, 254– designator, 8, 11, 11, 47, 104, 105, 110, 113, 124, 125, ⃝c ISO/IEC 2017 – All rights reserved 623
ISO/IEC DIS 1539-1:2017 (E)
133, 133, 162, 164, 165, 288, 320, 321, 334, 88, 96, 98–100, 103–108, 110, 111, 113, 116,336 118, 122, 124, 125, 139–141, 143, 144, 160, 163,
data object, 129 164, 170, 189, 193, 207, 240, 245, 246, 299–308,
designator (R901), 78, 113, 114, 129, 129, 131, 132, 310, 311, 313–321, 328, 331, 332, 334–336, 438, 147, 172, 182, 287, 334, 369, 390, 395, 431, 489–491, 511–513, 519, 528, 529, 543, 573, 584435 characteristics of, 300
designator, 147 restrictions, 321 digit, 27, 28, 49, 49, 52, 62, 92, 285 dummy data object, 6, 8, 12, 60, 77, 97, 104–106, 110, digit-string (R711), 62, 62, 63, 271, 272, 278 300, 305–307 digit-string, 62 assumed-rank, 6, 45, 60, 83, 84, 101, 102, 136, 199, DIGITS, 373 200, 300, 301, 307, 315–317, 321, 322, 328, DIM, 373 393–395, 418, 424, 426, 427, 434, 479, 484, 489, DIMENSION attribute, 75, 96, 102, 102, 115, 125 491, 601, 602, 604 DIMENSION statement, 115, 298 dummy function, 12, 66, 96 dimension-spec (R814), 102 dummy procedure, 8, 12, 14, 18, 105, 118, 121, 123, 165, dimension-stmt (R848), 37, 115, 514 172, 299, 300, 302–304, 308, 309, 312, 319, 320, direct access, 219 326, 328, 330, 334, 507, 510, 515 direct access data transfer statement, 236 dummy-arg (R1536), 330, 330–332 direct component, 9, 9, 69, 78, 316, 444, 486 dummy-arg-name (R1531), 116, 117, 299, 328, 328, 330, DIRECT= specifier, 254, 256 333, 514 disassociated, 11, 12, 24, 46, 61, 77–79, 97, 103, 115, dynamic type, 17, 23, 24, 60, 61, 84, 85, 87, 90, 93, 142, 144, 145, 163, 171, 173, 309, 321, 337, 110, 140, 142, 144, 160, 162, 168, 170, 171,distinguishable, 307346, 379, 410, 411, 421, 428, 450, 517, 518, 173, 183, 201, 202, 207, 210, 249, 311, 317,
520, 527 326, 347, 379, 403, 407, 421, 429, 490, 513,
517, 522, 552, 601
DO CONCURRENT construct, 30, 31, 188, 191, 195, 204, 335, 512, 519, 525, 527, 532, 542 e (R1311), 267, 267, 273–276, 279, 280, 286
DO CONCURRENT statement, 59, 178, 188 E edit descriptor, 273 DO construct, 41, 52, 93, 188, 204, 238, 539, 554, 555 edit descriptor, 266 DO statement, 188, 524, 540, 542 /, 281 DO WHILE statement, 188 :, 281 do-construct (R1119), 37, 188, 190, 191, 204 A, 278 do-construct-name, 188–191 B, 277 do-stmt (R1120), 7, 188, 188, 190, 204, 528 BN, 282 do-variable (R1124), 93, 113, 188, 188–190, 237, 260, BZ, 282 261, 263, 285, 524, 526, 528, 564 character string, 266, 283
DOT_PRODUCT, 373 control, 266, 280–283 DOUBLE PRECISION, 53, 61, 63, 69 D, 273 DP edit descriptor, 283 data, 266, 270–280 DPROD, 374 DC, 283 DSHIFTL, 374 decimal, 283 DSHIFTR, 375 DP, 283 DT edit descriptor, 280 DT, 280 dtv-type-spec (R1221), 243 E, 273 dummy argument, 5, 6, 8, 12, 12, 16–18, 24, 25, 30, EN, 274 41, 46, 47, 50, 58–61, 66, 72, 75, 77, 82–84, 86, ES, 275
624 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
EX, 276 else-stmt (R1137), 195, 195 F, 272 ELSEWHERE statement, 53, 175 G, 278, 279 elsewhere-stmt (R1048), 175, 175 H, 539 EN edit descriptor, 274 I, 271 ENCODING= specifier, 227, 228, 254, 256, 533 L, 278 END ASSOCIATE statement, 53, 182 O, 277 END BLOCK DATA statement, 53, 297 P, 282 END BLOCK statement, 53, 144, 184 position, 280 END CRITICAL statement, 53, 161, 187, 206, 207 RC, 282 END DO statement, 53, 189 RD, 282 END ENUM statement, 53, 90 RN, 282 END FORALL statement, 53, 177 round, 282 END FUNCTION statement, 53, 328 RP, 282 END IF statement, 53, 195, 539 RU, 282 END INTERFACE statement, 53, 302 RZ, 282 END MODULE statement, 53, 294 S, 282 END PROCEDURE statement, 53, 331 SP, 282 END PROGRAM statement, 53, 293 SS, 282 END SELECT statement, 53, 197, 202 T, 281 END statement, 13, 40, 40, 41, 53, 55, 84, 85, 109, 126, TL, 281 143, 144, 207, 482, 527 TR, 281 END SUBMODULE statement, 53, 297 X, 281 END SUBROUTINE statement, 53, 330 Z, 277 END TEAM statement, 40, 53, 185, 206, 215, 341 effective argument, 5, 6, 12, 24, 58, 60, 61, 66, 101–106, END TYPE statement, 53, 70 207, 314–317, 319, 320, 323, 326, 418, 482, 490, END WHERE statement, 53, 175effective item, 12, 238, 241, 242, 246, 247, 249, 261, 268, end-block-data-stmt (R1422), 13, 35, 40, 297, 297513, 519, 522, 524, 527 end-associate-stmt (R1106), 7, 182, 182, 204
269, 281, 284, 285, 289 end-block-stmt (R1110), 7, 184, 184, 204
effective position, 308 end-change-team-stmt (R1114), 185, 185, 186 element sequence, 320 end-critical-stmt (R1118), 7, 187, 187, 204 ELEMENTAL, 13, 327, 327, 328, 332, 334, 336 end-do (R1131), 188, 189, 190, 192 elemental, 12, 22, 45, 66, 84, 86, 160, 161, 166, 171, 174, end-do-stmt (R1132), 7, 189, 189, 190, 204 175, 177, 299–301, 309, 316, 319, 324, 325, 332, end-enum-stmt (R763), 90, 90336, 337, 342, 361, 362, 408, 450–452 end-forall-stmt (R1054), 177, 177, 178
elemental array assignment (FORALL), 177 end-function-stmt (R1533), 7, 13, 20, 35, 40, 204, 302, elemental assignment, 12, 171 328, 328, 329, 332 elemental operation, 12, 153, 163, 177 end-if-stmt (R1138), 7, 195, 195, 204 elemental operator, 12, 153, 444 end-interface-stmt (R1504), 302, 302 elemental procedure, 12, 45, 163, 173, 309, 312, 321, end-module-stmt (R1406), 13, 35, 40, 294, 294 325, 327, 335, 335–338 end-mp-subprogram-stmt (R1540), 7, 13, 20, 36, 40, 204,
elemental reference, 13, 177, 316, 324–326, 336 330, 331, 331, 332 elemental subprogram, 13, 327, 328, 335, 336 end-program-stmt (R1403), 7, 13, 20, 35, 40, 42, 85, 204, ELSE IF statement, 53, 195 205, 293, 293 ELSE statement, 195 end-select-rank-stmt (R1151), 7, 199, 199, 200, 204 else-if-stmt (R1136), 195, 195 end-select-stmt (R1143), 7, 196, 197, 197, 204 ⃝c ISO/IEC 2017 – All rights reserved 625
ISO/IEC DIS 1539-1:2017 (E)
end-select-type-stmt (R1155), 7, 201, 202, 202–204 error indicator, 496 end-submodule-stmt (R1419), 13, 35, 40, 297, 297 ERROR STOP statement, 41, 42, 205, 532 end-subroutine-stmt (R1537), 7, 13, 20, 35, 40, 204, 302, error termination, 42, 85, 141, 143, 205, 246, 260, 261, 330, 330, 332 341, 356–360, 377, 378, 407, 419, 531, 534
end-type-stmt (R730), 69, 70 error-stop-stmt (R1161), 37, 85, 205 end-where-stmt (R1049), 175, 175 ERROR_UNIT, 224, 225, 229, 438 END= specifier, 7, 232, 233, 250, 251, 261 ES edit descriptor, 275 endfile record, 218 established coarray, 8, 46, 137, 186 ENDFILE statement, 53, 218, 219, 221, 228, 247, 250, evaluation 252, 564 operations, 153
endfile-stmt (R1225), 37, 251, 335 optional, 161 entity-decl (R803), 66, 75, 95, 96, 96, 97, 165, 166, 514 parentheses, 162 entity-name, 112, 117 EVENT POST statement, 206, 207, 211, 212, 215, 377, ENTRY statement, 12, 40, 160, 170, 294, 299, 303, 327, 438, 525, 528, 533 328, 331, 511, 521, 540, 542 event variable, 25, 41, 207, 212, 215, 377, 438, 525
entry-name, 328, 331, 511 EVENT WAIT statement, 206, 207, 212, 212, 215, 438, entry-stmt (R1541), 36, 294, 297, 303, 331, 331, 511, 525, 528, 533 514 event-post-stmt (R1170), 37, 211
ENUM statement, 90 event-variable (R1171), 211, 211, 212, 215, 438, 528 enum-def (R759), 36, 90, 90, 91 event-wait-spec (R1173), 212, 212 enum-def-stmt (R760), 90, 90 event-wait-stmt (R1172), 37, 212, 212 enumeration, 90 EVENT_QUERY, xx, 377, 560, 594 enumerator, 90 EVENT_TYPE, 25, 70, 106, 139, 140, 211, 438 enumerator (R762), 90, 90 EX edit descriptor, 276 ENUMERATOR statement, 90 executable construct, 181 enumerator-def-stmt (R761), 90, 90 executable statement, 20, 20, 39 EOR= specifier, 7, 232, 233, 250, 251, 261, 261, 564 executable-construct (R514), 20, 36, 37, 331 EOSHIFT, 375 EXECUTE_COMMAND_LINE, 347, 378 EPSILON, 376 execution control, 181 equiv-op (R1021), 51, 150, 150 execution-part (R509), 35, 36, 36, 293, 328–330 equiv-operand (R1016), 150, 150 execution-part-construct (R510), 36, 36, 181 equivalence association, 124 exist, 218, 225 EQUIVALENCE statement, 123, 123–126, 184, 296, EXIST= specifier, 254, 256 298, 521, 540, 542 EXIT statement, 182, 192, 204
equivalence-object (R872), 124, 124, 125, 296 exit-stmt (R1156), 37, 204, 204 equivalence-set (R871), 124, 124 EXP, 378 equivalence-stmt (R870), 37, 124, 514 explicit formatting, 265–283 ERF, 376 explicit initialization, 13, 78, 79, 96, 97, 113, 517, 522, ERFC, 376 523 ERFC_SCALED, 377 explicit interface, 15, 31, 77, 81, 118, 123, 174, 300–304, ERR= specifier, 7, 227, 231, 232, 250, 251, 253–255, 309–311, 313, 319, 320, 333, 334, 510, 511, 528, 260 543, 573
errmsg-variable (R929), 138, 138, 140, 142, 143, 145, explicit-coshape-spec (R811), 99, 100, 100 208, 209, 212, 214–216, 528, 532 explicit-shape array, 5, 60, 76, 100, 103, 166, 315, 320,
ERRMSG= specifier, xix, 138, 141–143, 145, 187, 208, 488 215, 525, 532 explicit-shape-spec (R816), 5, 74, 75, 97, 102, 102–104,
626 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
125 FAIL IMAGE statement, 206 EXPONENT, 378, 457 fail-image-stmt (R1163), 37, 206
exponent (R717), 63, 63 failed image, 14, 41, 138, 140, 144, 145, 186, 214, 341, exponent-letter (R716), 63, 63 407 expr (R1022), 28, 84, 88, 89, 93, 138, 147, 150, 150, 162, FAILED_IMAGES, 380 163, 166–173, 177, 178, 182, 185, 197, 237, 311, field, 268312, 333, 334, 475, 527 file
expression, 147, 147–166 connected, 225 constant, 7, 10, 24, 32, 57, 58, 66, 73, 75, 76, 78, external, 13, 13, 32, 217–222, 224–226, 230, 234,93, 97, 101, 103, 104, 113, 114, 116, 124, 164, 253, 270, 280, 289, 335, 506, 563, 596
165, 166, 166, 234, 300, 301, 321, 338, 350, internal, 16, 16, 217, 223, 224, 226, 234, 238, 241,
351, 353, 364, 365, 369, 370, 380, 381, 386, 389, 243, 245, 247, 260, 262, 280, 281, 524, 526
391, 394–396, 399–401, 405, 409, 418, 420, 422, file access method, 218–220
424, 426, 428, 434–436, 488 file connection, 223–231
specification, 20, 24, 41, 73, 75, 84, 98, 133, 164, file inquiry statement, 253
165, 165, 184, 332, 445, 541 file position, 218, 221
extended real model, 340 file positioning statement, 218, 251 extended type, 6, 9, 15, 23, 23, 73, 80, 84–86, 522, 544, file storage unit, 13, 21, 217, 220–223, 229, 234, 236, 549 242, 252, 258–260, 439, 520
extended-intrinsic-op (R610), 52, 52 file-name-expr (R1206), 227, 227, 228, 254–256 EXTENDS attribute, 23, 85, 85, 487 file-unit-number (R1202), 223, 223, 224, 226, 227, 231, EXTENDS_TYPE_OF, 75, 379 233, 245, 250, 251, 253–260, 335, 439 extensible type, 23, 59, 70, 77, 85, 243, 379, 421, 552, FILE= specifier, 226, 227, 228, 229, 230, 254, 255, 255, 590 528, 565
extension operation, 151 FILE_STORAGE_SIZE, 439 extension type, 23, 60, 85, 87, 202, 317, 379, 590 FINAL statement, 13, 83extent, 13, 45, 316
final subroutine, 7, 13, 13, 31, 82–85, 136, 164, 315,EXTERNAL attribute, 17, 29, 30, 105, 105, 108, 117,
548, 549118, 120, 172, 294, 298, 300, 303, 308, 320,
final-procedure-stmt (R753), 81, 83324, 326, 514, 515, 582
final-subroutine-name, 83external file, 13, 13, 32, 217–222, 224–226, 230, 234,
finalizable, 13, 31, 83, 84, 104, 105, 143, 189253, 270, 280, 289, 335, 506, 563, 596
finalization, 13, 19, 84, 85, 136, 178, 299, 311, 324, 334,external input/output unit, 13, 509
335external linkage, 99, 479, 505–507
FINDLOC, 380external procedure, 18, 29, 38, 81, 105, 118, 121, 172,
fixed source form, 54, 54211, 299, 300, 302–304, 308, 309, 312, 320, 326,
FLOOR, 381509, 510, 514, 515, 543, 573, 578, 582
FLUSH statement, 219, 250, 253, 262EXTERNAL statement, 105, 308
flush-spec (R1229), 253, 253external subprogram, 18, 22, 38, 299
flush-stmt (R1228), 37, 253, 335external unit, 13, 224–226, 240, 245–247, 257, 262, 438–
FMT= specifier, 232, 233440
FORALL construct, 177, 335, 512, 525, 540, 542external-name, 308
FORALL statement, 59, 153, 179, 512, 524external-stmt (R1511), 37, 308
forall-assignment-stmt (R1053), 153, 177, 177–179, 335external-subprogram (R503), 35, 35, 120, 331
forall-body-construct (R1052), 177, 177–179
F forall-construct (R1050), 37, 177, 177, 178 F edit descriptor, 272 forall-construct-name, 177, 178 ⃝c ISO/IEC 2017 – All rights reserved 627
ISO/IEC DIS 1539-1:2017 (E)
forall-construct-stmt (R1051), 7, 177, 177, 178, 204 511, 514 forall-stmt (R1055), 38, 177, 178, 179, 179, 204 function-subprogram (R1529), 21, 35, 36, 294, 328, 330 FORM TEAM statement, 22, 40, 137, 186, 206, 207, 212, 215, 525, 528, 533 G
form-team-spec (R1178), 212, 212 G edit descriptor, 278, 279 form-team-stmt (R1175), 37, 212 GAMMA, 382 FORM= specifier, 227, 229, 254, 256 generic identifier, 14, 15, 294, 303–305, 307, 325, 337, format (R1215), 231–233, 234, 234, 241, 265, 266 509, 514 format control, 268 generic interface, 15, 82, 86, 90, 107, 160, 170, 171, 249, format descriptor, see edit descriptor 295, 296, 304, 304–306, 325, 510, 591 FORMAT statement, 29, 40, 52, 234, 265, 265, 294 generic interface block, 15, 15, 303, 304, 307 format-item (R1304), 266, 266 generic procedure reference, 307 format-items (R1303), 265, 266, 266 GENERIC statement, 81, 82, 304, 304, 307, 324 format-specification (R1302), 265, 265 generic-name, 81, 82, 302, 511, 514 format-stmt (R1301), 36, 265, 265, 294, 297, 303 generic-spec (R1508), 15, 81, 82, 86, 111, 160, 171, 295, FORMATTED, 243, 244, 302 296, 302, 302–304, 324, 511, 514 generic-stmt (R1510), 36, 304formatted data transfer, 242
GET_COMMAND, 382formatted input/output statement, 217, 233
GET_COMMAND_ARGUMENT, 383formatted record, 217
GET_ENVIRONMENT_VARIABLE, 384, 535FORMATTED= specifier, 254, 256
GET_TEAM, 385, 438–440formatting
global entity, 509explicit, 265–283
global identifier, 509list-directed, 243, 283–287
GO TO statement, 7, 53, 204, 204namelist, 243, 287–291
goto-stmt (R1157), 37, 204, 204forms, 218
graphic character, 49, 67, 290Fortran 2003 compatibility, 31
Fortran 2008 compatibility, 30
H
Fortran 77 compatibility, 32
halting mode, 443, 448, 448, 451, 453, 454, 465, 471,
Fortran 90 compatibility, 32 472, 507, 536 Fortran 95 compatibility, 31 hex-constant (R767), 92, 92 Fortran character set, 49, 65 hex-digit (R768), 92, 92, 278 FRACTION, 381 hex-digit-string (R1322), 278, 278 free source form, 53, 53 host, 14, 14, 38, 297, 333, 511, 514, 515 function, 13 host association, 6, 6, 17, 39, 59, 60, 66, 98, 111, 113, intrinsic, 337 118, 126, 164, 165, 172, 297, 299, 320, 333–335,intrinsic elemental, 337 511, 513–516, 519, 522, 613
intrinsic inquiry, 337 host instance, 14, 174, 312, 313, 320, 330, 354, 514, 518,
function reference, 19, 43, 44, 324 522, 527 function result, 13, 31, 66, 95, 118, 124, 125, 143, 300, host scoping unit, 14, 38, 118, 121, 324, 325, 515, 522 329, 331, 336, 489, 511, 521, 527 HUGE, 386
FUNCTION statement, 12, 59, 60, 118, 160, 164, 293, HYPOT, 386 327, 328, 331, 332, 511
function-name, 96, 303, 328, 329, 331, 333, 511, 514
function-reference (R1520), 88, 96, 129, 147, 311, 313,I edit descriptor, 271 324 IACHAR, 68, 169, 386
function-stmt (R1530), 35, 302, 303, 327, 328, 328, 329, IALL, 386 628 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
IAND, 356, 387 IEEE_MAX_NUM, 457, 458 IANY, 387 IEEE_MAX_NUM_MAG, 458 IBCLR, 388 IEEE_MIN_NUM, 458, 459 IBITS, 388 IEEE_MIN_NUM_MAG, 459 IBSET, 389 IEEE_MODES_TYPE, 444, 448, 454, 465, 466 ICHAR, 67, 68, 389 IEEE_NAN, 444 id-variable (R1214), 232, 232 IEEE_NEAREST, 444, 447 ID= specifier, 232, 233, 235, 250, 254, 255, 256, 528, IEEE_NEGATIVE_DENORMAL, 444 567, 568 IEEE_NEGATIVE_INF, 444
IEEE infinity, 14 IEEE_NEGATIVE_NORMAL, 444 IEEE NaN, 14, 160, 445, 446, 467 IEEE_NEGATIVE_SUBNORMAL, 444, 444, 452, IEEE_ALL, 444 456, 457 IEEE_ARITHMETIC, 164, 166, 349, 443–475, 543 IEEE_NEGATIVE_ZERO, 444 IEEE_AWAY, 447, 454 IEEE_NEXT_AFTER, 459 IEEE_CLASS, 452, 452 IEEE_NEXT_DOWN, 460, 460 IEEE_CLASS_TYPE, 444, 452, 475 IEEE_NEXT_UP, 460 IEEE_COPY_SIGN, 449, 452 IEEE_OTHER, 444, 447 IEEE_DATATYPE, 444 IEEE_OTHER_VALUE, 444 IEEE_DENORMAL, 444 IEEE_OVERFLOW, 444 IEEE_DIVIDE, 444 IEEE_POSITIVE_DENORMAL, 444 IEEE_DIVIDE_BY_ZERO, 444 IEEE_POSITIVE_INF, 444 IEEE_DOWN, 444, 447 IEEE_POSITIVE_NORMAL, 444 IEEE_EXCEPTIONS, 164, 166, 192, 443–475, 543 IEEE_POSITIVE_SUBNORMAL, 444, 444, 452, 456 IEEE_FEATURES, 443–444 IEEE_POSITIVE_ZERO, 444 IEEE_FEATURES_TYPE, 444 IEEE_QUIET_EQ, 460 IEEE_FLAG_TYPE, 444, 453, 454, 465, 471 IEEE_QUIET_GE, 461 IEEE_FMA, 453 IEEE_QUIET_GT, 461 IEEE_GET_FLAG, 192, 446, 453, 476, 477, 536 IEEE_QUIET_LE, 461 IEEE_GET_HALTING_MODE, 192, 453, 454 IEEE_QUIET_LT, 462 IEEE_GET_MODES, 448, 454, 454, 466 IEEE_QUIET_NAN, 444 IEEE_GET_ROUNDING_MODE, 447, 454, 455, 466 IEEE_QUIET_NE, 462 IEEE_GET_STATUS, 446, 455, 455, 466, 467, 476, IEEE_REAL, 463 536 IEEE_REM, 449, 463
IEEE_GET_UNDERFLOW_MODE, 455, 467 IEEE_RINT, 449, 463 IEEE_HALTING, 444 IEEE_ROUND_TYPE, 444, 454, 455, 463, 466, 473 IEEE_INEXACT, 444 IEEE_ROUNDING, 444 IEEE_INEXACT_FLAG, 444 IEEE_SCALB, 464 IEEE_INF, 444 IEEE_SELECTED_REAL_KIND, 464 IEEE_INT, 455 IEEE_SET_FLAG, 446, 455, 465, 467, 476, 477, 536 IEEE_INVALID, 444 IEEE_SET_HALTING_MODE, 192, 446, 454, 465, IEEE_INVALID_FLAG, 444 471, 476, 477, 536 IEEE_IS_FINITE, 456 IEEE_SET_MODES, 448, 454, 465, 466 IEEE_IS_NAN, 456 IEEE_SET_ROUNDING_MODE, 447, 454, 455, 466, IEEE_IS_NEGATIVE, 456 466 IEEE_IS_NORMAL, 457 IEEE_SET_STATUS, 446, 447, 455, 466, 467, 477, IEEE_LOGB, 449, 457 536 ⃝c ISO/IEC 2017 – All rights reserved 629
ISO/IEC DIS 1539-1:2017 (E)
IEEE_SET_UNDERFLOW_MODE, 454, 455, 466, 322, 324, 337, 341, 346–348, 356–360, 370, 372, 467 384, 390, 407, 411, 412, 416, 430–432, 435, 441,
IEEE_SIGNALING_EQ, 467 448, 509, 517, 518, 525, 527 IEEE_SIGNALING_GE, 468 active, 14, 145 IEEE_SIGNALING_GT, 468 failed, 14, 140, 144, 145, 214, 407 IEEE_SIGNALING_LE, 468 stopped, 14, 140, 144, 145, 407 IEEE_SIGNALING_LT, 469 image control statement, 14, 41, 161, 187, 192, 206, IEEE_SIGNALING_NAN, 444 206–208, 210, 215, 216, 324, 335, 341, 342, 380, IEEE_SIGNALING_NE, 469 428, 441 IEEE_SIGNBIT, 469 image index, 14, 40, 45, 137, 138, 209, 213, 218, 319, IEEE_SQRT, 444 345, 347, 390, 431, 435, 509 IEEE_STATUS_TYPE, 444, 448, 455, 466, 467, 476 image-selector (R924), 8, 10, 40, 130–132, 137, 137, IEEE_SUBNORMAL, 444 138, 287 IEEE_SUPPORT_DATATYPE, 444, 445, 452, 453, image-selector-spec (R926), 137, 137 455, 458–464, 466–469, 470, 470, 474, 475 image-set (R1167), 209, 209
IEEE_SUPPORT_DENORMAL, 470 IMAGE_INDEX, 390 IEEE_SUPPORT_DIVIDE, 471, 474 IMAGE_STATUS, 390 IEEE_SUPPORT_FLAG, 471, 474 imaginary part, 64 IEEE_SUPPORT_HALTING, 471, 474 implicit interface, 15, 75, 174, 294, 309–311, 319, 483, IEEE_SUPPORT_INF, 448, 449, 460, 472, 474, 475 515 IEEE_SUPPORT_IO, 472 IMPLICIT NONE statement, 118 IEEE_SUPPORT_NAN, 445, 446, 448, 472, 474, 475 IMPLICIT statement, 40, 118, 123, 298 IEEE_SUPPORT_ROUNDING, 466, 473, 474 implicit-none-spec (R866), 118, 118 IEEE_SUPPORT_SQRT, 473, 474 implicit-part (R505), 36, 36 IEEE_SUPPORT_STANDARD, 473 implicit-part-stmt (R506), 36, 36 IEEE_SUPPORT_SUBNORMAL, 448, 449, 452, 460, implicit-spec (R864), 118, 118 470, 474, 474, 475 implicit-stmt (R863), 36, 118, 118
IEEE_SUPPORT_UNDERFLOW_CONTROL, 474 implied-shape array, 104 IEEE_TO_ZERO, 444, 447 implied-shape-or-assumed-size-spec (R823), 102, 104, IEEE_UNDERFLOW, 444 104 IEEE_UNDERFLOW_FLAG, 444 implied-shape-spec (R824), 102, 104, 105 IEEE_UNORDERED, 449, 475 IMPORT statement, 40, 120, 509, 515 IEEE_UP, 444, 447 import-name, 120, 121 IEEE_USUAL, 444 import-stmt (R867), 36, 120, 184 IEEE_VALUE, 458, 459, 475 IMPURE, 327, 327, 332, 334, 336 IEOR, 360, 389 IN, 106 IF construct, 41, 195, 539 INCLUDE line, 53, 55 IF statement, 153, 196 inclusive scope, 14, 184, 204, 205, 227, 231, 232, 234, if-construct (R1134), 37, 195, 195 250, 251, 253, 255, 312, 332, 509, 510 if-construct-name, 195 INDEX, 391 if-stmt (R1139), 37, 196, 196 index-name, 178, 179, 188–191, 512, 525 if-then-stmt (R1135), 7, 195, 195, 204 inherit, 6, 9, 15, 70, 81, 82, 84–87, 522, 552 imag-part (R720), 64, 64 inheritance association, 6, 6, 9, 47, 86, 88, 519, 522 image, 1, 14, 14, 22, 40–42, 45, 46, 84, 100, 138–141, initial team, 22, 46, 137, 224, 347, 385, 390, 412, 431, 144, 170, 172, 173, 186–188, 205–211, 213–216, 439218, 219, 224, 225, 257, 311, 315, 318, 319, 321, initial-data-target (R744), 31, 77, 78, 78, 96, 97, 109,
630 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
114, 115 INT8, 439
initial-proc-target (R1518), 78, 309, 309, 310 integer constant, 62
INITIAL_TEAM, 385, 439 integer editing, 271 initialization, 97 integer model, 340 default, 10, 10, 76–79, 88, 89, 97, 104, 105, 113, integer type, 61–62124, 125, 127, 316, 517, 522, 526 integer-type-spec (R705), 59, 61, 61, 73, 93, 113, 189,
explicit, 13, 78, 79, 96, 97, 113, 517, 522, 523 512
initialization (R805), 96, 96, 97, 166 INTEGER_KINDS, 439 INOUT, 53, 106 INTENT (IN) attribute, 105, 106, 107, 111, 189, 305– input statement, 231 307, 315, 318, 320–322, 334, 335, 338, 356– input-item (R1216), 231, 232, 237, 237, 249, 263, 528 360, 365–368, 377, 378, 383, 384, 408, 416, 451, input/output editing, 265–291 481–483, 503, 504, 543, 584, 598 input/output list, 236 INTENT (INOUT) attribute, 30, 105, 106, 107, 110, input/output statement, 524 193, 306, 316, 318, 324, 335, 336, 356–360, input/output statements, 217–262 365–368, 378, 382–384, 407, 408, 438, 440, 528, input/output unit, 16, 24, 40 529, 598 INPUT_UNIT, 224, 225, 229, 245, 439 INTENT (OUT) attribute, 31, 60, 83–85, 104, 105, INQUIRE statement, 32, 219, 220, 222, 223, 225, 226, 105–107, 110, 143, 164, 306, 316, 318, 324, 235, 236, 246, 247, 250, 253, 262, 263, 439, 334–336, 356–360, 365–368, 370, 372, 377, 378,524, 526–528, 534, 563 382–384, 407, 408, 416, 430, 453–455, 481, 483,
inquire-spec (R1231), 254, 254, 255, 263 503, 504, 517–519, 524, 525, 527–529, 598 inquire-stmt (R1230), 37, 254, 335 INTENT attribute, 105, 105–107, 116, 192, 543 inquiry function, 15, 22, 100, 103, 105, 131, 141, 164, INTENT statement, 116, 184 314, 315, 337–339, 342, 352, 354, 363, 369, 373, intent-spec (R826), 95, 106, 116, 309376, 379, 386, 390, 393–396, 401, 404, 409, 414, intent-stmt (R849), 37, 116
415, 417, 421, 424, 426, 428, 432, 434, 443, 444, interface, 15, 15, 39, 44, 47, 75, 82, 107, 243–245, 280,
446–450, 470–474, 484 300, 301, 311, 319, 320, 324, 325, 331–334,
inquiry, type parameter, 132 489–491, 506, 507, 573 instance, 330 abstract, 15, 15, 294, 301, 303, 309, 328, 510, 514 INT, 115, 169, 339, 374, 375, 387, 389, 391, 392, 404 explicit, 15, 31, 77, 81, 118, 123, 174, 300–304, int-constant (R607), 51, 51, 114 309–311, 313, 319, 320, 333, 334, 510, 511, 528, int-constant-expr (R1031), 61, 65, 73, 90, 91, 113, 166, 543, 573 166, 199, 200 generic, 15, 82, 86, 90, 107, 160, 170, 171, 249, 295,
int-constant-name, 62 296, 304, 304–306, 325, 510 int-constant-subobject (R846), 114, 114 implicit, 15, 75, 174, 294, 309–311, 319, 483, 515 int-expr (R1026), 40, 58, 93, 130, 133, 137, 138, 153, procedure, 301 162, 162, 164–166, 188–190, 205, 209, 212, specific, 15, 249, 303, 303, 304, 309, 325, 543213, 223, 224, 227, 232, 237, 239, 250, 254, interface block, 15, 39, 243, 249, 295, 302–304, 324, 325,
332 573
int-literal-constant (R708), 51, 62, 62, 65, 266, 267 interface body, 15, 19, 40, 101, 103, 105, 118, 164, 302, int-variable (R907), 129, 129, 144, 227, 232, 233, 254, 302, 327, 328, 331, 332, 491, 511, 514, 573 257–261, 534 INTERFACE statement, 302, 573
int-variable-name, 188 interface-block (R1501), 36, 302, 302 INT16, 439 interface-body (R1505), 302, 302, 303 INT32, 439 interface-name (R1516), 81, 82, 308, 309, 309 INT64, 439 interface-specification (R1502), 302, 302, 303 ⃝c ISO/IEC 2017 – All rights reserved 631
ISO/IEC DIS 1539-1:2017 (E)
interface-stmt (R1503), 302, 302–305, 514 261, 262, 524 internal file, 16, 16, 217, 223, 224, 226, 234, 238, 241, IOR, 359, 392 243, 245, 247, 260, 262, 280, 281, 524, 526 IOSTAT= specifier, 227, 231, 232, 246, 250, 251, 253,
internal procedure, 14, 18, 38, 172, 299–302, 312, 320, 254, 260, 261, 262, 394, 439, 524, 534, 564 326, 328, 330, 354, 507, 510, 511, 514 IOSTAT_END, 246, 262, 439
internal subprogram, 22, 38, 40, 118, 299, 324, 514 IOSTAT_EOR, 246, 262, 439 internal unit, 16, 16, 224, 226, 240, 245, 246, 255, 262, IOSTAT_INQUIRE_INTERNAL_UNIT, 246, 262, 439 439, 442
internal-file-variable (R1203), 223, 223, 224, 233, 263, IPARITY, 392 528 IS_CONTIGUOUS, 60, 393
internal-subprogram (R512), 36, 36 IS_IOSTAT_END, 394 internal-subprogram-part (R511), 35, 36, 36, 293, 328– IS_IOSTAT_EOR, 394 330 ISHFT, 393
interoperable, 15, 90, 91, 99, 328, 333, 481, 483–491, ISHFTC, 393 505, 506 ISO 10646 character, 16, 65, 68, 167, 223, 228, 238,
interoperate, 485 270, 284, 409, 422 intrinsic, 9, 12, 14, 15, 16, 17, 18, 22, 23, 42, 43, 45, ISO_C_BINDING, 60, 74, 85, 99, 105, 131, 139, 140, 47, 58, 60, 84, 92, 105, 301, 318, 325, 326, 436, 164, 170, 335, 436, 479–486, 526, 527, 543510, 512 ISO_Fortran_binding.h, 491
intrinsic assignment statement, 31, 89, 143, 145, 163, ISO_FORTRAN_ENV, 25, 30, 70, 74, 99, 106, 131, 167, 171, 173, 216, 253, 262, 289, 334, 335, 138–140, 145, 164, 170, 185, 205, 211, 212,524, 532 214–216, 222, 224, 229, 240, 245, 246, 262, 341,
INTRINSIC attribute, 105, 107, 107, 108, 294, 310, 356–360, 380, 385, 390, 391, 407, 412, 428, 429, 324, 325, 515 431, 436–441, 527, 536, 564intrinsic function, 337
intrinsic operation, 153–160
K
k (R1314), 267, 267, 274, 279, 282
intrinsic procedure, 337–436
keyword, 16INTRINSIC statement, 298, 310
argument, 12, 16, 47, 301, 304, 313, 337, 342, 450,intrinsic subroutines, 337
510, 511, 512, 573intrinsic type, 9, 23, 42, 43, 57, 61–68, 490, 494
component, 16, 47, 80, 89, 511intrinsic-operator (R608), 17, 51, 52, 148, 150, 153, 154,
statement, 16, 47160, 305
type parameter, 16, 47, 88intrinsic-procedure-name, 310, 514
keyword (R516), 47, 47, 87, 88, 311intrinsic-stmt (R1519), 37, 310, 514
KIND, 61–65, 68, 73, 91, 132, 169, 394intrinsic-type-spec (R704), 59, 61, 66
kind type parameter, 24, 29, 42, 58, 61–66, 68, 73, 83,io-control-spec (R1213), 231, 232, 232, 233, 236, 245,
84, 91, 93, 165–169, 287, 306, 315, 328, 374,263
379, 421, 439, 479, 480, 485, 543
io-implied-do (R1218), 237, 237, 238, 241, 263, 524, kind-param (R709), 62, 62, 63, 65–68 526, 528, 564 kind-selector (R706), 28, 61, 61, 62, 68io-implied-do-control (R1220), 237, 237, 239
io-implied-do-object (R1219), 237, 237, 241
io-unit (R1201), 24, 223, 223, 224, 232, 233, 335L edit descriptor, 278 IOLENGTH= specifier, 222, 253, 260 label, see statement label iomsg-variable (R1207), 227, 227, 231, 232, 250, 251, label (R611), 7, 52, 52, 188, 190, 204, 205, 227, 231, 253, 254, 261, 262, 524 232, 234, 250, 251, 253–255, 261, 311, 312
IOMSG= specifier, 227, 231, 232, 250, 251, 253, 254, label-do-stmt (R1121), 188, 188, 190 632 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
language-binding-spec (R808), 95, 99, 112, 328 LOCK_TYPE, 25, 31, 70, 106, 139, 140, 214, 440 LBOUND, 60, 168, 173, 183, 200, 394 LOG, 32, 398 lbracket (R771), 74, 92, 93, 95, 96, 112, 113, 117, 137, LOG10, 399 138 LOG_GAMMA, 398
LCOBOUND, 395 LOGICAL, 399 LEADZ, 395 logical intrinsic operation, 157 left tab limit, 281 logical type, 68 LEN, 132, 396 logical-expr (R1024), 162, 162, 175, 188, 190–192, 195, LEN_TRIM, 396 196, 205 length type parameter, 24, 24, 42, 58, 68, 77, 93, 108, logical-literal-constant (R725), 51, 68, 148, 150 141, 167, 168, 315, 396, 484, 485, 543 logical-variable (R904), 129, 129, 213–215, 254, 256,
length-selector (R722), 28, 65, 65, 66 257, 528 letter, 49, 49, 50, 52, 118, 148, 150 LOGICAL_KINDS, 440 letter-spec (R865), 118, 118 loop-control (R1123), 188, 188, 190, 191, 194 level-1-expr (R1002), 148, 148, 151 lower-bound (R817), 102, 102–105 level-2-expr (R1006), 148, 148, 149, 151, 152 lower-bound-expr (R934), 138, 138, 172 level-3-expr (R1010), 149, 149 lower-cobound (R812), 100, 101, 101 level-4-expr (R1012), 149, 149, 150 level-5-expr (R1017), 150, 150
lexical token, 14, 16, 27, 50, 52m (R1309), 267, 267, 271, 272, 277, 278 LGE, 68, 396 main program, 16, 18, 22, 38, 41, 43 LGT, 68, 397 main-program (R1401), 35, 38, 120, 293, 293 line, 16, 53–56 mask-expr (R1046), 175, 175–179, 189, 191 linkage association, 6, 6, 506, 513, 516, 516 masked array assignment, 17, 175, 524 list-directed formatting, 243, 283–287 masked array assignment (WHERE), 175 list-directed input/output statement, 234 masked-elsewhere-stmt (R1047), 175, 175, 176, 178 literal constant, 9, 44, 130, 162 MASKL, 399 literal-constant (R605), 51, 51, 147 MASKR, 399 LLE, 68, 397 MATMUL, 400 LLT, 68, 398 MAX, 336, 338, 401 LOCAL, 189, 192, 193, 195, 512, 519, 527 MAXEXPONENT, 401 local identifier, 509, 510 MAXLOC, 338, 401 local procedure pointer, 17, 330 MAXVAL, 402 local variable, 17, 25, 31, 43, 44, 97, 99, 101, 103, 109, MERGE, 403 111, 141, 143, 312, 330, 334 MERGE_BITS, 403
local-defined-operator (R1414), 295, 295, 296 MIN, 404 local-name, 295, 296 MINEXPONENT, 404 LOCAL_INIT, 189, 192, 193, 512, 519, 525, 527 MINLOC, 404 locality, 192, 193, 512, 519, 525, 527 MINVAL, 405 locality-spec (R1130), 189, 189 MOD, 32, 406 LOCK statement, 206, 207, 213, 216, 440, 441, 525, mode 528 blank interpretation, 228
lock variable, 25, 41, 216, 440, 441, 525, 528 changeable, 224 lock-stat (R1180), 213, 213 connection, 224 lock-stmt (R1179), 37, 213 decimal edit, 228 lock-variable (R1182), 213, 213–215, 440, 528 delimiter, 228 ⃝c ISO/IEC 2017 – All rights reserved 633
ISO/IEC DIS 1539-1:2017 (E)
halting, 443, 448, 448, 451, 453, 454, 465, 471, 472, named-constant (R606), 51, 51, 55, 64, 90, 116, 514507, 536 named-constant-def (R852), 116, 116, 514
IEEE rounding, 443, 444, 447, 448, 449 NAMED= specifier, 254, 257
input/output rounding, 224, 230, 236, 259, 277, namelist formatting, 243, 287–291
282, 472 namelist input/output statement, 234
pad, 229 NAMELIST statement, 123, 184, 288, 296
sign, 230, 282 namelist-group-name, 123, 232–234, 240–242, 265, 288,
underflow, 447, 448, 451, 455, 467, 474, 475, 536 291, 296, 514, 528
model namelist-group-object (R869), 123, 123, 241, 243, 249, bit, 338 263, 287, 288, 296extended real, 340 namelist-stmt (R868), 37, 123, 514, 528
integer, 340 NaN, 17, 272–276, 279, 349, 379, 382, 420, 424, 427,
real, 340 445, 448, 449, 452, 453, 456, 472, 473
MODULE, 302, 303, 327, 327, 330 NEAREST, 408 module, 16, 17, 18, 19, 21, 22, 38, 39, 43, 293 NEW_INDEX= specifier, 212, 533 module (R1404), 35, 120, 294 NEW_LINE, 278, 279, 409 module procedure, 18, 81, 122, 172, 299–304, 309, 312, NEWUNIT= specifier, 224, 227, 229, 245, 525, 528 320, 326, 327, 330, 331, 333, 436, 510, 511 NEXTREC= specifier, 254, 257
module procedure interface body, 121, 303 NINT, 409 module reference, 19, 294 NML= specifier, 232, 234, 528 MODULE statement, 293, 294 NON_INTRINSIC, 295 module subprogram, 22, 38, 40, 118, 324 NON_OVERRIDABLE attribute, 81, 82 module-name, 294, 295, 514 NON_RECURSIVE, 327, 327 module-nature (R1410), 295, 295 NON_RECURSIVE attribute, 301, 327, 327, 331, 332 module-stmt (R1405), 35, 294, 294 nonadvancing input/output statement, 221module-subprogram (R1408), 36, 294, 294, 331
nonblock DO construct, 540module-subprogram-part (R1407), 35, 83, 87, 294, 294,
NONE, 118, 120, 189297, 578
nonexecutable statement, 20, 39MODULO, 32, 406
nonlabel-do-stmt (R1122), 188, 188, 190MOLD= specifier, 138
nonstandard intrinsic, xviii, 16, 29, 582MOVE_ALLOC, 141, 207, 337, 407
NOPASS, 75, 77, 82mp-subprogram-stmt (R1539), 36, 330, 330, 331
NOPASS attribute, see PASS attributemult-op (R1008), 51, 148, 148
NORM2, 410mult-operand (R1004), 148, 148, 151
normal number, 448MVBITS, 337, 338, 408
normal termination, 14, 40, 41, 42, 85, 205, 218, 230,
N 231, 391, 428, 441 n (R1316), 267, 267, 268, 281 NOT, 410 name, 17, 46, 50, 509 not-op (R1018), 51, 150, 150 name (R603), 28, 47, 50, 50, 51, 96, 117, 129, 202, 241, NULL, 89, 96, 163, 165, 166, 320, 338, 410, 517, 518 309, 328 null-init (R806), 77, 78, 96, 96, 97, 114, 115, 309
name association, 6, 6, 47, 513, 519 NULLIFY statement, 142 name-value subsequence, 287, 288 nullify-stmt (R938), 37, 142, 529 NAME= specifier, 95, 99, 112, 254, 255, 256, 309, 309, NUM_IMAGES, 166, 411, 435 328, 506 NUMBER= specifier, 254, 257named constant, 9, 24, 44, 46, 50, 58, 62, 64, 66, 104, numeric conversion, 169
105, 108, 111, 114, 116, 124, 130, 333 numeric editing, 271
634 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
O edit descriptor, 277
numeric intrinsic operation, 154 optional-stmt (R850), 37, 116 numeric sequence type, 20, 71, 124–126, 521, 525 or-op (R1020), 51, 150, 150 numeric storage unit, 21, 21, 126, 440, 520, 524, 526 or-operand (R1015), 150, 150 numeric type, 23, 61–65, 154–156, 158, 162, 169, 373, other-specification-stmt (R513), 36, 36 374, 400, 415, 429 OUT, 106
numeric-expr (R1027), 162, 162 OUT_OF_RANGE, 412 NUMERIC_STORAGE_SIZE, 440 output statement, 231 output-item (R1217), 231, 232, 237, 237, 249, 254
O OUTPUT_UNIT, 224, 225, 229, 245, 440
override, 78, 86, 95, 96, 118, 243, 271, 522object, 10, 10, 42–45
object designator, 11, 43, 44, 110, 114, 130, 164, 287
object-name (R804), 96, 96, 112, 113, 116–118, 129,
P
P edit descriptor, 282
136, 514
PACK, 413obsolescent feature, 29, 30, 33, 540–542
pad mode, 229octal-constant (R766), 92, 92
PAD= specifier, 32, 33, 227, 229, 232, 233, 236, 247,ONLY, 120, 121, 122, 295, 295, 296, 516, 570, 572
254, 257only (R1412), 295, 295, 296
padding, 339, 339, 391, 418only-use-name (R1413), 295, 295, 296
PARAMETER attribute, 9, 44, 91, 97, 108, 108, 116,OPEN statement, 33, 218, 219, 223–225, 226, 226, 230,
130234, 242, 243, 247, 256, 260, 277, 289, 525,
PARAMETER statement, 40, 116, 118, 298528, 533, 534, 563, 565–567
parameter-stmt (R851), 36, 116, 514open-stmt (R1204), 37, 226, 335
OPENED= specifier, 254, 257 parent component, 6, 9, 80, 84, 86, 89, 522, 552 operand, 17 parent data transfer statement, 236, 245, 243–247, 262, operation, 57 286 defined, 11, 19, 81, 151, 160, 161–163, 189, 299, parent team, 22, 22, 46, 137, 186, 211, 212, 380, 385,305, 311, 324, 335 390, 412, 428, 431, 440
elemental, 12, 153, 163, 177 parent type, 9, 23, 70, 73, 80, 84–86, 307, 552
intrinsic, 153–160 parent-identifier (R1418), 297, 297
logical, 157 parent-string (R909), 101, 130, 130
numeric , 154 parent-submodule-name, 297
relational, 158 parent-type-name, 69, 70
OPERATOR, 57, 82, 160, 295, 302, 305, 573 PARENT_TEAM, 385, 440 operator, 17, 51 parentheses, 162 character, 149 PARITY, 413defined binary, 150 part-name, 7, 130–133, 136, 137
defined unary, 148 part-ref (R912), 101, 114, 124, 130, 130–133, 135, 137,
elemental, 12, 153, 444 369, 390, 395, 431, 435
logical, 150 partially associated, 521
numeric, 148 PASS attribute, 75, 77, 82, 311
relational, 149 passed-object dummy argument, 17, 77, 81, 82, 86, 308,
operator precedence, 151 313, 588 OPTIONAL attribute, 108, 108, 110, 116, 164, 183, PAUSE statement, 539 189, 301 pending affector, 98, 235, 240, 507, 508
optional dummy argument, 321 PENDING= specifier, 254, 255, 257 OPTIONAL statement, 116, 184 POINTER, 74, 75, 77 ⃝c ISO/IEC 2017 – All rights reserved 635
ISO/IEC DIS 1539-1:2017 (E)
pointer, 6, 11, 12, 17, 20, 22, 24, 46, 71, 76, 136, 142– preconnection, 226 144, 166, 300, 301, 316, 334, 428, 479, 491, prefix (R1526), 327, 327, 328, 330502, 517, 584 prefix-spec (R1527), 327, 327, 328, 334, 336
procedure, 483 PRESENT, 60, 75, 108, 164, 321, 338, 414, 585 pointer assignment, 17, 103, 105, 142, 170, 171, 172, present, 320 321, 518 primary, 147
pointer assignment statement, 17, 22, 58, 77, 89, 163, primary (R1001), 147, 147, 148, 333 171, 173, 179, 348, 354 PRINT statement, 219, 228, 231, 240, 245, 246, 250
pointer association, 6, 6, 12, 22, 23, 44, 47, 85, 87, 89, print-stmt (R1212), 37, 232, 335 101, 106, 108, 110, 111, 131, 143, 145, 171, PRIVATE attribute, 71, 86, 98, 98, 111, 123, 335, 571173, 174, 193, 207, 210, 240, 300, 314, 316, PRIVATE statement, 80, 81, 83, 111, 296
318, 320, 321, 329, 330, 343, 354, 407, 411, private-components-stmt (R745), 70, 80, 80
482, 483, 517–520, 522, 528, 584 private-or-sequence (R729), 69, 70, 70
pointer association context, 106, 109, 334, 528 proc-attr-spec (R1514), 308, 308, 309 pointer association status, 517 proc-component-attr-spec (R742), 75, 75, 77 POINTER attribute, 5, 17, 58–60, 68, 69, 74, 75, 96, proc-component-def-stmt (R741), 74, 75, 75 103, 105, 108, 108, 110, 115, 117, 131, 134, proc-component-ref (R1039), 172, 172, 311, 321142, 172, 183, 192, 199, 200, 299–301, 303, 306, proc-decl (R1515), 75, 78, 308, 309, 309
307, 309, 317, 320–323, 328, 334, 336, 484, 488, proc-entity-name, 116, 117
503, 516, 519, 522, 523, 543, 587, 591 proc-interface (R1513), 75, 308, 308, 309
POINTER statement, 116, 298 proc-language-binding-spec (R1528), 308, 309, 328, 328, pointer-assignment-stmt (R1033), 37, 171, 177, 178, 330, 333, 489 334, 529 proc-pointer-init (R1517), 309, 309
pointer-decl (R854), 116, 116 proc-pointer-name (R858), 117, 117, 142, 172 pointer-object (R939), 142, 142, 529 proc-pointer-object (R1038), 171, 172, 173, 178, 354, pointer-stmt (R853), 37, 116, 514 529 polymorphic, 17, 31, 60, 61, 77, 90, 104, 105, 131, 142, proc-target (R1040), 88, 89, 171, 172, 173, 178, 321, 162, 167, 168, 173, 182, 183, 189, 192, 201, 203, 354, 520237, 243, 300, 301, 311, 314–317, 334, 335, 379, PROCEDURE, 75, 81, 308, 330
403, 407, 421, 428, 517, 522 procedure, 11, 18, 19, 47, 48, 108, 302
POPCNT, 414 characteristics of, 300 POPPAR, 414 dummy, 8, 12, 14, 18, 105, 118, 121, 123, 165, 172, POS= specifier, 220–222, 232, 233, 236, 236, 254, 258, 299, 300, 302–304, 308, 309, 312, 319, 320, 326, 534 328, 334, 507, 510, 515
position edit descriptor, 280 elemental, 12, 45, 163, 173, 309, 312, 321, 325, 327, position-edit-desc (R1315), 267, 267 335, 335–338 position-spec (R1227), 251, 251 external, 18, 29, 38, 81, 105, 118, 121, 172, 211, POSITION= specifier, 226, 227, 229, 254, 258, 565 299, 300, 302–304, 308, 309, 312, 320, 326, 509, positional arguments, 337 510, 514, 515, 543, 573, 578, 582 potential subobject component, 9, 31, 69, 70, 139, 335, internal, 14, 18, 38, 172, 299–302, 312, 320, 326, 438, 440 328, 330, 354, 507, 510, 511, 514
power-op (R1007), 51, 148, 148 intrinsic, 337–436 pre-existing, 522 module, 18, 81, 122, 172, 299–304, 309, 312, 320, precedence of operators, 151 326, 327, 330, 331, 333, 436, 510, 511 PRECISION, 62, 414, 464 non-Fortran, 332 preconnected, 18, 219, 224–226, 229, 234, 240, 438–440 pure, 18, 31, 178, 189, 333, 335, 337, 342, 407, 636 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
418, 436, 444, 450, 483
type-bound, 7, 15, 17, 18, 68, 70, 77, 82, 82–86, QUIET= specifier, 205 170, 249, 295, 305, 311, 313, 315, 326, 510,511 R
procedure declaration statement, 40, 105, 301, 303, 308, r (R1306), 266, 266–268 332, 348, 511, 543 RADIX, 62, 415, 444, 464
procedure designator, 11, 19, 45 RANDOM_INIT, 348, 416, 535 RANDOM_NUMBER, 348, 416, 417procedure interface, 301
RANDOM_SEED, 338, 348, 416procedure pointer, 8, 14, 17, 17, 38, 96, 105, 106, 108,
RANGE, 61, 62, 417, 464125, 172, 174, 299, 300, 303, 304, 308, 312,
RANK, 60, 417313, 319–321, 326, 330, 483, 511, 514, 543, 584
rank, 18, 20, 43–46, 76, 77, 83, 84, 88, 89, 95, 99, 101–procedure reference, 5, 19, 31, 44, 108, 133, 246, 299,
105, 116, 126, 131–135, 137, 139, 141, 160, 162,305, 311, 313
163, 167–169, 171–175, 183, 209, 300, 305–307,generic, 307
316, 317, 320, 321, 325, 336, 347, 352, 353,resolving, 324
369–371, 375, 376, 380, 381, 387, 388, 392, 394,type-bound, 326
395, 400–407, 410, 411, 413, 415, 416, 419, 424,PROCEDURE statement, 302, 304, 543
426, 427, 429, 431, 433–435, 476, 482, 488, 513,procedure-component-name, 172
520, 587, 588procedure-declaration-stmt (R1512), 36, 308, 309
RANK ( * ), 104, 199procedure-designator (R1522), 311, 311, 321, 326
RANK DEFAULT, 105, 199procedure-entity-name, 309, 310
rbracket (R772), 74, 92, 93, 95, 96, 112, 113, 117, 137,procedure-name, 81, 82, 172, 174, 302, 303, 309, 311,
138312, 330, 331
RC edit descriptor, 282procedure-stmt (R1506), 302, 302, 303
RD edit descriptor, 282processor, 18, 29, 30, 47, 48
READ (FORMATTED), 243, 302
processor dependent, 18, 30, 47, 531–537 READ (UNFORMATTED), 243, 244, 302 PRODUCT, 415 READ statement, 33, 44, 220, 224, 228, 231, 240, 245, program, 18, 29, 30, 38 246, 250, 253, 261, 527, 563–565, 567, 569 program (R501), 35 read-stmt (R1210), 37, 231, 232, 335, 528 PROGRAM statement, 293 READ= specifier, 254, 258 program unit, 16, 17, 18, 18, 19, 21, 29, 35, 38–40, 42, READWRITE= specifier, 254, 258 46, 49, 50, 52–55, 72, 109, 118, 224, 230, 293, REAL, 169, 339, 418, 445297, 385, 505, 509, 517, 541, 544, 570–572, 574, real and complex editing, 272
577–581, 597 real model, 340
program-name, 293 real part, 64 program-stmt (R1402), 35, 293, 293 real type, 62–64, 64 program-unit (R502), 28, 35, 35, 38 real-literal-constant (R714), 51, 63, 63 PROTECTED attribute, 31, 109, 109, 117, 124, 192, real-part (R719), 64, 64 295, 543 REAL128, 441
PROTECTED statement, 117 REAL32, 441 protected-stmt (R855), 37, 117 REAL64, 441 PUBLIC attribute, 86, 98, 98, 111, 123, 571 REAL_KINDS, 440 PUBLIC statement, 111, 296 REC= specifier, 221, 232, 233, 236 PURE, 327, 327, 332, 334 RECL= specifier, 227, 229, 242, 243, 254, 258, 260, pure procedure, 18, 31, 178, 189, 333, 335, 337, 342, 526, 533 407, 418, 436, 444, 450, 483, 543 record, 18, 217
⃝c ISO/IEC 2017 – All rights reserved 637
ISO/IEC DIS 1539-1:2017 (E)
record file, 13, 19, 217, 219, 221–223 save-stmt (R856), 37, 117, 514 record number, 219 saved, 19, 517, 523 RECURSIVE, 66, 327, 332 saved-entity (R857), 117, 117, 184 recursive input/output statement, 262 scalar, 19, 19, 21, 335 REDUCE, 418 scalar-xyz (R403), 28, 28 reference, 19, 45 SCALE, 421 procedure, 31 scale factor, 267, 282
rel-op (R1013), 51, 149, 149, 159, 445 SCAN, 422 relational intrinsic operation, 158 scoping unit, 6, 14, 19, 25, 38, 40, 41, 43, 47, 66, 71, rename (R1411), 295, 295, 296, 510 72, 81, 84, 88, 97–99, 105, 107, 110, 111, 117, rep-char, 66, 67, 268, 284, 289 118, 120–123, 125, 126, 143, 165, 172, 184, 185, REPEAT, 419 189, 192, 193, 235, 238, 294–296, 301, 303, 307, repeat specification, 266 324–328, 331, 333, 443, 445, 505, 510–516, 519, representation method, 61, 62, 65, 68 521, 522, 526, 571, 582, 588 RESHAPE, 94, 420 section subscript, 135 resolving procedure reference, 324 section-subscript (R920), 25, 130, 131, 133, 133, 135– resolving procedure references 137 defined input/output, 249 segment, 207
restricted expression, 164 SELECT CASE construct, 41, 196, 541, 553 RESULT, 328, 328, 329, 331, 332 SELECT CASE statement, 53, 196 result-name, 328, 329, 331, 332, 514 SELECT RANK construct, 41, 46, 104, 105, 183, 199, RETURN statement, 41, 85, 109, 126, 143, 144, 185, 321, 528 187, 192, 332, 482, 527 SELECT RANK statement, 46, 105, 199, 516
return-stmt (R1542), 38, 40, 332, 332 SELECT TYPE construct, 41, 46, 58, 59, 183, 201, REWIND statement, 218, 219, 221, 247, 250, 252, 252, 321, 512, 513, 516, 528 564 SELECT TYPE statement, 46, 53, 201, 516rewind-stmt (R1226), 38, 251, 335
select-case-stmt (R1141), 7, 196, 197, 197, 204RN edit descriptor, 282
select-construct-name, 199–202round edit descriptor, 282
select-rank-case-stmt (R1150), 199, 199, 200round-edit-desc (R1319), 267, 268
select-rank-construct (R1148), 37, 199, 199, 200ROUND= specifier, 227, 230, 232, 233, 236, 247, 254,
select-rank-stmt (R1149), 7, 199, 199, 200, 204259, 283
select-type-construct (R1152), 37, 201, 202rounding mode
select-type-stmt (R1153), 7, 201, 201, 202, 204IEEE, 443, 444, 447, 448, 449, 454, 463, 466, 473
SELECTED_CHAR_KIND, 65, 422input/output, 224, 230, 236, 259, 277, 282, 472
SELECTED_INT_KIND, 61, 73, 423RP edit descriptor, 282
SELECTED_REAL_KIND, 62, 338, 423, 544RRSPACING, 420
selector, 182RU edit descriptor, 282
selector (R1105), 182, 182, 183, 185, 186, 199, 201–203,RZ edit descriptor, 282
321, 517, 528
S separate module procedure, 330 S edit descriptor, 282 separate module subprogram statement, 330 SAME_TYPE_AS, 75, 421 separate-module-subprogram (R1538), 36, 294, 330, SAVE attribute, 19, 24, 33, 46, 78, 85, 97, 99, 100, 109, 330, 331 109, 110, 113, 117, 124, 126, 144, 192, 309, sequence, 19334, 518 sequence association, 320
SAVE statement, 117, 184, 298, 511 SEQUENCE attribute, 19, 69, 71, 71, 72, 85, 125, 172, 638 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
173, 202, 486 specification expression, 20, 24, 41, 73, 75, 84, 98, 133, SEQUENCE statement, 71 164, 165, 165, 184, 332, 445, 541, 543
sequence structure, 19 specification function, 165 sequence type, 19, 19, 31, 69, 71, 71, 124, 487, 520 specification inquiry, 164 character, 20, 71, 124–126, 521, 525 specification-construct (R508), 36, 36, 184numeric, 20, 71, 124–126, 521, 525 specification-expr (R1028), 7, 59, 66, 97, 101, 102, 164,
sequence-stmt (R731), 70, 71 164, 336 sequential access, 219 specification-part (R504), 35, 36, 36, 41, 81, 98, 99, 111, sequential access data transfer statement, 236 165, 166, 293, 294, 297, 298, 302, 328, 330, 334, SEQUENTIAL= specifier, 254, 259 336 SET_EXPONENT, 424 SPREAD, 427 SHAPE, 60, 424 SQRT, 32, 428, 449, 473 shape, 20, 45, 207 SS edit descriptor, 282 SHARED, 189, 192, 193 standard intrinsic, xviii, 16, 29, 436 SHIFTA, 424 standard-conforming program, 20, 29 SHIFTL, 425 stat-variable (R942), 41, 137, 138, 140, 142, 143, 144, SHIFTR, 425 144, 145, 208, 209, 212–216, 227, 231, 232, 250, SIGN, 32, 33, 63, 425 251, 253, 254, 260–262, 394, 528, 532 sign (R712), 62, 62, 63, 272 STAT= specifier, xix, 137, 138, 141–143, 144, 187, 208, sign mode, 230, 271, 282 215, 441, 525, 532 sign-edit-desc (R1317), 267, 268 STAT_FAILED_IMAGE, 41, 138, 145, 215, 216, 341, SIGN= specifier, 227, 230, 232, 233, 236, 254, 259, 380, 407, 408, 441, 442 282 STAT_LOCKED, 216, 441, 442
signed-digit-string (R710), 62, 63, 271–273 STAT_LOCKED_OTHER_IMAGE, 216, 441, 442 signed-int-literal-constant (R707), 62, 62, 64, 114, 267 STAT_STOPPED_IMAGE, 145, 215, 216, 341, 407, signed-real-literal-constant (R713), 63, 64, 114 408, 428, 441, 442 significand (R715), 63, 63 STAT_UNLOCKED, 216, 441, 442 simply contiguous, 20, 136, 137, 137, 173, 315, 317, STAT_UNLOCKED_FAILED_IMAGE, 216, 441, 318, 490, 491 442
SIN, 426 statement, 20, 53 SINH, 426 accessibility, 111 SIZE, 60, 426 ALLOCATABLE, 112 size, 20, 45 ALLOCATE, 58, 59, 66, 101, 103, 138, 141, 144, size of a common block, 126 145, 172, 206, 438, 497, 498, 517, 518, 525–527, SIZE= specifier, 232, 236, 254, 259, 261, 524, 527, 564 532, 543 source-expr (R930), 138, 138–142, 334, 517–519 arithmetic IF, 540 SOURCE= specifier, 138, 140, 142, 334, 438, 525–527, ASSIGN, 539 543 assigned GO TO, 539
SP edit descriptor, 282 assignment, 17, 31, 44, 58, 84, 167, 179, 475, 524 SPACING, 427 ASSOCIATE, 46, 182, 516 special character, 49 ASYNCHRONOUS, 112, 184, 298, 512, 514 specific interface, 15, 249, 303, 303, 304, 309, 325, 543 attribute specification, 111–127 specific interface block, 15, 15, 303 BACKSPACE, 218, 221, 247, 250, 251, 252, 564, specific name, 20 565 specific-procedure (R1507), 302, 302, 304 BIND, 112, 298, 505, 511 specification, 95–127 BLOCK, 97, 101, 103, 184, 525 ⃝c ISO/IEC 2017 – All rights reserved 639
ISO/IEC DIS 1539-1:2017 (E)
BLOCK DATA, 53, 293, 297 END PROCEDURE, 53, 331CALL, 22, 204, 207, 299, 311, 324, 332, 407 END PROGRAM, 53, 293
CASE, 197 END SELECT, 53, 197, 202
CHANGE TEAM, 22, 40, 46, 185, 206, 215, 341, END SUBMODULE, 53, 297
516 END SUBROUTINE, 53, 330
CLASS DEFAULT, 202 END TEAM, 40, 53, 185, 206, 215, 341
CLASS IS, 202, 379 END TYPE, 53, 70
CLOSE, 218, 219, 223, 225, 226, 230, 230, 247, END WHERE, 53, 175
250, 564 ENDFILE, 53, 218, 219, 221, 228, 247, 250, 252,
COMMON, 8, 125, 125–127, 184, 296, 298, 511, 564
521, 540 ENTRY, 12, 40, 160, 170, 294, 299, 303, 327, 328,
component definition, 74 331, 511, 521, 540, 542
computed GO TO, 7, 204, 205, 540, 541 ENUM, 90
CONTAINS, 39, 40, 81, 332 ENUMERATOR, 90
CONTIGUOUS, 113 EQUIVALENCE, 123, 123–126, 184, 296, 298, 521,
CONTINUE, 205, 539 540, 542
CRITICAL, 161, 187, 206, 207, 216 ERROR STOP, 41, 42, 205, 532
CYCLE, 182, 188, 191, 192, 542 EVENT POST, 206, 207, 211, 212, 215, 377, 438,
DATA, 32, 33, 40, 92, 97, 113, 126, 298, 411, 512, 525, 528, 533
515, 523, 540, 541 EVENT WAIT, 206, 207, 212, 212, 215, 438, 525,
data transfer, 33, 52, 217–223, 225, 231, 236, 239– 528, 533
241, 246, 250, 252, 260–263, 265, 266, 277, 282, executable, 20, 20, 39
284–286, 288, 290, 439, 524, 526, 534, 563, 564, EXIT, 182, 192, 204
567, 568 EXTERNAL, 105, 308
DEALLOCATE, 142, 144, 145, 206, 438, 498, 532 FAIL IMAGE, 206
defined assignment, 31, 170, 171, 324, 528 file inquiry, 253
derived type definition, see statement, TYPE file positioning, 218, 251
DIMENSION, 115, 298 FINAL, 13, 83
DO, 188, 524, 540, 542 FLUSH, 219, 250, 253, 262
DO CONCURRENT, 59, 178, 188 FORALL, 59, 153, 179, 512, 524
DO WHILE, 188 FORM TEAM, 22, 40, 137, 186, 206, 207, 212,
ELSE, 195 215, 525, 528, 533
ELSE IF, 53, 195 FORMAT, 29, 40, 52, 234, 265, 265, 294
ELSEWHERE, 53, 175 formatted input/output, 217, 233
END, 13, 40, 109, 126, 143, 144, 207, 482, 527 FUNCTION, 12, 59, 60, 118, 160, 164, 293, 327,
END ASSOCIATE, 53, 182 328, 331, 332, 511
END BLOCK, 53, 144, 184 GENERIC, 81, 82, 304, 304, 307, 324
END BLOCK DATA, 53, 297 GO TO, 7, 53, 204, 204
END CRITICAL, 53, 161, 187, 206, 207 IF, 153, 196
END DO, 53, 189 IMPLICIT, 40, 118, 123, 298
END ENUM, 53, 90 IMPLICIT NONE, 118
END FORALL, 53, 177 IMPORT, 40, 120, 509, 515
END FUNCTION, 53, 328 input/output, 217–262, 524
END IF, 53, 195, 539 INQUIRE, 32, 219, 220, 222, 223, 225, 226, 235,
END INTERFACE, 53, 302 236, 246, 247, 250, 253, 262, 263, 439, 524,
END MODULE, 53, 294 526–528, 534, 563
640 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
INTENT, 116, 184 SYNC ALL, 186, 206, 208, 209, 210, 215, 216 INTERFACE, 302, 573 SYNC IMAGES, 206, 209, 215, 216 INTRINSIC, 298, 310 SYNC MEMORY, 206, 207, 210, 215, 216, 593 intrinsic assignment, 31, 89, 143, 145, 163, 167, SYNC TEAM, 186, 206, 211, 215, 216 171, 173, 216, 253, 262, 289, 334, 335, 524, TARGET, 117, 298532 TYPE, 69, 73, 98, 514
list-directed input/output, 234 type declaration, 40, 59, 60, 78, 95, 95–97, 105, LOCK, 206, 207, 213, 216, 440, 441, 525, 528 118, 123, 126, 165, 294, 298, 329, 331, 333, MODULE, 293, 294 523 NAMELIST, 123, 184, 288, 296 type guard, 66, 202 namelist input/output, 234 TYPE IS, 202, 421 nonexecutable, 20, 39 type parameter definition, 73 NULLIFY, 142 type-bound procedure, 81, 82 OPEN, 33, 218, 219, 223–225, 226, 226, 230, 234, unformatted input/output, 218, 233 242, 243, 247, 256, 260, 277, 289, 525, 528, UNLOCK, 206, 207, 213, 216, 440, 441, 525, 528533, 534, 563, 565–567 USE, 6, 19, 40, 72, 111, 294, 298, 324–326, 510,
OPTIONAL, 116, 184 512, 513, 516, 570–572, 577 PARAMETER, 40, 116, 118, 298 VALUE, 117, 184 PAUSE, 539 VOLATILE, 118, 184, 298, 512, 514 POINTER, 116, 298 WAIT, 225, 235, 250, 250, 567, 568 pointer assignment, 17, 22, 58, 77, 89, 163, 171, WHERE, 17, 153, 175 173, 179, 348, 354 WRITE, 219, 224, 228, 231, 240, 245, 246, 250,
PRINT, 219, 228, 231, 240, 245, 246, 250 262, 524, 563, 564, 566, 567 PRIVATE, 80, 81, 83, 111, 296 statement entity, 21, 192, 509, 510, 512 PROCEDURE, 302, 304, 543 statement function, 333, 541 procedure declaration, 40, 105, 301, 303, 308, 332, statement function statement, 12, 40, 66, 184, 294, 324, 348, 511, 543 332, 333, 512, 513, 541
PROGRAM, 293 statement keyword, 16, 47 PROTECTED, 117 statement label, 7, 21, 52, 52–55, 312, 509 PUBLIC, 111, 296 statement order, 39 READ, 33, 44, 220, 224, 228, 231, 240, 245, 246, STATUS= specifier, 226–229, 230, 231, 231, 533, 534, 250, 253, 261, 527, 563–565, 567, 569 566
RETURN, 41, 85, 109, 126, 143, 144, 185, 187, 192, stmt-function-stmt (R1544), 36, 294, 297, 303, 333, 514 332, 482, 527 STOP statement, 41, 42, 205, 207, 335, 532
REWIND, 218, 219, 221, 247, 250, 252, 252, 564 stop-code (R1162), 205, 205, 206 SAVE, 117, 184, 298, 511 stop-stmt (R1160), 38, 85, 205 SELECT CASE, 53, 196 stopped image, 14, 41, 140, 144, 145, 341, 407 SELECT RANK, 46, 105, 199, 516 STOPPED_IMAGES, 428 SELECT TYPE, 46, 53, 201, 516 storage association, 6, 6, 46, 47, 123–127, 331, 334, 429, separate module subprogram, 330 519–522 SEQUENCE, 71 storage sequence, 21, 69, 71, 124–127, 298, 354, 520, statement function, 12, 40, 66, 184, 294, 324, 332, 520, 521 333, 512, 513, 541 storage unit, 21, 21, 123–127, 235, 239, 247, 250, 298,
STOP, 41, 42, 205, 207, 335, 532 320, 354, 520–522 SUBMODULE, 293, 297 character, 21, 21, 104, 124, 126, 437, 520, 524, 526 SUBROUTINE, 12, 170, 293, 327, 330, 331, 332 file, 13, 21, 217, 220–223, 229, 234, 236, 242, 252, ⃝ c ISO/IEC 2017 – All rights reserved 641
ISO/IEC DIS 1539-1:2017 (E)
258–260, 439, 520 subscript (R919), 114, 133, 133, 136, 239
numeric, 21, 21, 126, 440, 520, 524, 526 subscript triplet, 135 unspecified, 21, 21, 520, 524, 526 subscript-triplet (R921), 133, 133–136
STORAGE_SIZE, 92, 428 substring, 130 stream access, 220 substring (R908), 124, 129, 130 stream access data transfer statement, 236 substring ending point., 130 stream file, 13, 21, 217, 220, 222, 260 substring starting point, 130 STREAM= specifier, 254, 259 substring-range (R910), 101, 130, 130, 132–134, 137, stride (R922), 133, 133, 135, 136, 239 239 structure, 9, 21, 42, 43, 69 suffix (R1532), 328, 328, 331 structure component, 21, 114, 130–132, 486, 551 SUM, 429 structure constructor, 9, 16, 21, 43, 47, 57, 80, 88, 89, SYNC ALL statement, 186, 206, 208, 209, 210, 215, 114, 115, 162, 164, 165, 411, 440, 511, 547 216
structure-component (R913), 113, 114, 129, 130, 131, SYNC IMAGES statement, 206, 209, 215, 216 136, 138, 142 SYNC MEMORY statement, 206, 207, 210, 215, 216,
structure-constructor (R756), 21, 88, 88, 114, 147, 334 593 subcomponent, 9, 10, 78, 88, 172, 517–519, 523, 525– SYNC TEAM statement, 186, 206, 211, 215, 216 527 sync-all-stmt (R1164), 38, 208
submodule, 16, 18, 21, 21, 22, 38, 39, 43, 297 sync-images-stmt (R1166), 38, 209 submodule (R1416), 35, 297 sync-memory-stmt (R1168), 38, 210 submodule identifier, 297 sync-stat (R1165), 185, 187, 208, 208–213, 215, 216 SUBMODULE statement, 293, 297 sync-team-stmt (R1169), 38, 211 synchronous input/output, 228, 234, 236, 239submodule-name, 297
SYSTEM_CLOCK, 430submodule-stmt (R1417), 35, 297, 297
subobject, 5, 9, 10, 21, 43–45, 106, 131, 315, 517, 518
subprogram, 16, 21, 38, 40, 41, 43, 118T edit descriptor, 281 elemental, 13, 327, 328, 335, 336 TAN, 430external, 18, 22, 38, 299 TANH, 430
internal, 22, 38, 40, 299, 514 target, 12, 22, 44, 46, 61, 77–79, 84, 89, 97, 100, 101,
module, 22, 38, 40 103, 105–109, 115, 129, 131, 138, 141, 142, 144,
subroutine, 22 162, 163, 168, 171–173, 178, 179, 237, 241, 243, atomic, 22, 41, 207, 208, 337, 340, 342, 356–360, 309, 312, 314, 316, 318, 320, 481, 483, 484,377, 437, 441, 528 516–519, 522, 525, 527, 528
collective, 22, 337, 341, 342, 365–368, 380, 428, 441 TARGET attribute, 6, 22, 31, 78, 108, 110, 110, 117,
subroutine reference, 324 124, 126, 142, 143, 172, 183, 192, 193, 200, 301, SUBROUTINE statement, 12, 170, 293, 327, 330, 331, 307, 315, 316, 318, 321–323, 367, 407, 418, 481, 332 484, 504, 505, 517–519, 527, 543, 584, 585
subroutine-name, 303, 330, 511 TARGET statement, 117, 298 subroutine-stmt (R1535), 35, 302, 303, 327, 328, 330, target-decl (R860), 117, 117 330, 511, 514 target-stmt (R859), 37, 117, 514
subroutine-subprogram (R1534), 21, 35, 36, 294, 330, team, 14, 22, 22, 40, 45, 46, 137, 138, 144, 186, 208, 330 209, 211, 213, 215, 337, 341, 390, 412, 428,
subroutines 431, 432 intrinsic, 337 current, 341
subscript, 133 team number, 22, 137, 213 section, 135 team variable, 25, 186, 441, 525
642 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
team-construct-name, 185 integer, 61–62 team-number (R1176), 212, 212, 213 intrinsic, 9, 23, 42, 43, 57, 61–68 team-value (R1115), 137, 185, 185, 186, 211 logical, 68 team-variable (R1177), 212, 212, 213, 215, 528 numeric, 23, 61–65, 154–156, 158, 162, 169, 373, TEAM= specifier, 137, 137 374, 400, 415, 429 TEAM_NUMBER, 431 operation, 163 TEAM_NUMBER= specifier, 137, 137 parent, 9, 23, 70, 73, 80, 84–86, 307, 552 TEAM_TYPE, 25, 74, 99, 131, 139, 140, 170, 185, 212, primary, 162 380, 385, 390, 412, 428, 431, 441, 527 real, 62–64, 64
THEN, 195 type compatible, 23, 60, 77, 139, 167, 171, 307, 315, THIS_IMAGE, 166, 431 407 TINY, 427, 432 type conformance, 167 TKR compatible, 307 type declaration statement, 40, 59, 60, 78, 95, 95–97, TL edit descriptor, 281 105, 118, 123, 126, 165, 294, 298, 329, 331, totally associated, 521 333, 523 TR edit descriptor, 281 type equality, 71 TRAILZ, 432 type guard statement, 66, 202 TRANSFER, 166, 432 TYPE IS statement, 202, 421 transfer of control, 181, 204, 261 type parameter, 5, 7, 15, 16, 23, 31, 42, 58, 60, 61, 68, transformational function, 22, 166, 333, 337, 337, 338, 71, 73, 77, 89, 93, 95–97, 116, 126, 162, 165, 342, 361, 362, 437, 450 167, 183, 185, 300, 315, 336, 403, 407, 433,
TRANSPOSE, 433 481, 487, 511, 513 TRIM, 433 type parameter definition statement, 73 truncation, 339, 391, 418 type parameter inquiry, 24, 132, 162, 164 TYPE, 59 type parameter keyword, 16, 47, 88 type, 23, 42, 57–93 type parameter order, 24, 73 abstract, 23, 59, 82, 85, 85, 88, 131, 139 type specifier, 59character, 65–68 CHARACTER, 65
complex, 64–65 CLASS, 60
declared, 23, 60, 61, 77, 89, 90, 93, 95, 130, 132, COMPLEX, 64
139, 140, 142, 160, 162, 167, 170–173, 182, 202, derived type, 59
203, 249, 306, 311, 314, 317, 326, 333, 379, 403, DOUBLE PRECISION, 63
407, 421, 438, 440, 513 INTEGER, 61
derived, 11, 21, 23, 42, 43, 46, 57, 68–90, 93, 486, LOGICAL, 68
487 REAL, 63
dynamic, 17, 23, 24, 60, 61, 84, 85, 87, 90, 93, 110, TYPE, 59
140, 142, 144, 160, 162, 168, 170, 171, 173, TYPE statement, 69, 73, 98, 514
183, 201, 202, 207, 210, 249, 311, 317, 326, type-attr-spec (R728), 69, 69, 85
347, 379, 403, 407, 421, 429, 513, 517, 522, type-bound procedure, 7, 15, 17, 18, 68, 70, 77, 82, 82–
552, 601 86, 170, 249, 295, 305, 311, 313, 315, 326, 510,
expression, 162 511
extended, 6, 9, 15, 23, 23, 73, 80, 84–86, 522, 544, type-bound procedure statement, 81, 82
549 type-bound-generic-stmt (R751), 81, 81, 305
extensible, 23, 59, 70, 77, 85, 243, 379, 421, 552, type-bound-proc-binding (R748), 81, 81
590 type-bound-proc-decl (R750), 81, 81
extension, 23, 60, 85, 87, 202, 317, 379, 590 type-bound-procedure-part (R746), 69, 71, 81, 83, 487
⃝c ISO/IEC 2017 – All rights reserved 643
ISO/IEC DIS 1539-1:2017 (E)
type-bound-procedure-stmt (R749), 81, 81 until-spec (R1174), 212, 212 type-declaration-stmt (R801), 36, 66, 95, 95, 334, 514 UNTIL_COUNT= specifier, 212, 377 type-guard-stmt (R1154), 201, 202, 202 upper-bound (R818), 102, 102, 103 type-name, 69, 70, 72, 82, 87 upper-bound-expr (R935), 138, 138, 172 type-param-attr-spec (R734), 73, 73 upper-cobound (R813), 100, 101, 101 type-param-decl (R733), 73, 73 use association, 6, 6, 17, 31, 39, 47, 60, 66, 86, 98, 109, type-param-def-stmt (R732), 69, 73, 73 111, 112, 118, 123–125, 164, 165, 172, 294, type-param-inquiry (R916), 24, 132, 132, 147, 511 293–297, 303, 331, 334, 511–514, 517 type-param-name, 69, 73, 75, 132, 147, 511, 514 use path, 296 type-param-spec (R755), 87, 87, 88 USE statement, 6, 19, 40, 72, 111, 294, 298, 324–326, type-param-value (R701), xix, 24, 58, 58, 59, 65, 66, 75, 510, 512, 513, 516, 570–572, 577 87, 88, 139, 140, 327, 542 use-defined-operator (R1415), 295, 295, 296
type-spec (R702), 59, 59, 66, 93, 138–141, 202 use-name, 295, 296, 510 use-stmt (R1409), 36, 184, 295, 295, 514
U
UBOUND, 60, 200, 434
UCOBOUND, 434v (R1312), 246, 267, 267, 280 ultimate argument, 24, 140, 144, 314, 318, 319, 321, VALUE attribute, 60, 77, 83, 105, 110, 110, 118, 192, 322, 341 240, 300, 301, 303, 305, 306, 314–318, 328, 334,
ultimate component, 9, 31, 68–70, 75, 99, 101, 104, 105, 336, 367, 418, 489, 490, 507, 519, 543, 596, 598 110, 111, 124, 125, 139, 142, 166, 167, 243, 315, value separator, 283316, 334, 520 VALUE statement, 117, 184
ultimate entity, 296 value-stmt (R861), 37, 117 undefined, 12, 24, 44, 143, 517, 518, 523, 524 variable, 10, 21, 25, 43, 44, 46, 50, 108 undefinition of variables, 523 definition & undefinition, 523 underflow mode, 447, 448, 451, 455, 467, 474, 475, 536 variable (R902), 89, 113, 114, 129, 129, 137, 167–169, underscore (R602), 49, 49 171, 172, 177, 178, 182, 201, 211–213, 237, 311, UNFORMATTED, 243, 244, 302 321, 475, 528 unformatted data transfer, 242 variable-name (R903), 123–125, 129, 129, 130, 138, 142, unformatted input/output statement, 218, 233 171, 172, 189, 514, 528 unformatted record, 217 vector subscript, 25, 45, 78, 101, 131, 135, 136, 182, UNFORMATTED= specifier, 254, 259 201, 223, 287, 315, 316, 321, 322, 516, 519, Unicode file, 228 584 unit, 9, 18, 24, 218–220, 223, 223–226, 228–231, 235, vector-subscript (R923), 133, 133–135 236, 239–241, 245, 250, 251, 253–260, 262, 280, VERIFY, 436286, 438, 439, 524, 526, 563, 565–568 VOLATILE attribute, 31, 110, 110, 111, 118, 172, 173,
UNIT= specifier, 226, 231, 232, 250, 251, 253, 254 183, 192, 294, 296, 300, 301, 316–318, 334, 514, unlimited polymorphic, 24, 60, 60, 93, 125, 139, 171, 519, 525, 528, 550 172, 202, 317, 379, 421, 428, 601 VOLATILE statement, 118, 184, 298, 512, 514
unlimited-format-item (R1305), 265, 266, 266, 269 volatile-stmt (R862), 37, 118 UNLOCK statement, 206, 207, 213, 216, 440, 441, 525, 528 W
unlock-stmt (R1181), 38, 213 w (R1308), 267, 267, 271–280, 284, 286, 289 unordered segments, 207, 207, 340, 348, 377, 416 wait operation, 226, 230, 236, 239, 240, 250, 250–251, UNPACK, 435 253, 257, 258, 260, 261 unsaved, 24, 141, 143, 330, 518, 519, 525–527 WAIT statement, 225, 235, 250, 250, 567, 568 unspecified storage unit, 21, 21, 520, 524, 526 wait-spec (R1223), 250, 250 644 ⃝c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
wait-stmt (R1222), 38, 250, 335 WRITE (UNFORMATTED), 243, 244, 302 WHERE construct, 17, 175 WRITE statement, 219, 224, 228, 231, 240, 245, 246, WHERE statement, 17, 153, 175 250, 262, 524, 563, 564, 566, 567 where-assignment-stmt (R1045), 153, 175, 175, 177, write-stmt (R1211), 38, 231, 232, 335, 528 178 WRITE= specifier, 254, 260where-body-construct (R1044), 175, 175–177
where-construct (R1042), 37, 175, 175, 177, 178
where-construct-name, 175X edit descriptor, 281 where-construct-stmt (R1043), 7, 175, 175, 176, 178, xyz-list (R401), 28 204 xyz-name (R402), 28where-stmt (R1041), 38, 175, 175, 177, 178
WHILE, 188, 190, 191
whole array, 25, 133, 133, 134, 395, 434Z edit descriptor, 277 WRITE (FORMATTED), 243, 244, 302 zero-size array, 45, 103, 114 ⃝ c ISO/IEC 2017 – All rights reserved 645
Generated by manServer 1.08 from f2018.7fortran.txt using man macros.
Nemo Release 3.1 untitled () October 30, 2022