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.
<IP_ADDRESS> 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 <IP_ADDRESS> 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
(<IP_ADDRESS>) 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 <IP_ADDRESS>.
⃝c ISO/IEC 2017 – All rights reserved 185
ISO/IEC DIS 1539-1:2017 (E)
<IP_ADDRESS> 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 <IP_ADDRESS> 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 (<IP_ADDRESS>.5). An iteration of
the loop can be curtailed by executing a CYCLE statement (<IP_ADDRESS>.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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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 (<IP_ADDRESS>.5).
<IP_ADDRESS> Execution of a DO construct1 When the DO statement is executed, the DO construct becomes active. If loop-control is<IP_ADDRESS>.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 <IP_ADDRESS>.2.4 At the completion of the execution of the DO statement, the execution cycle begins.
<IP_ADDRESS>.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)
. . .
<IP_ADDRESS>.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.<IP_ADDRESS>.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 construct<IP_ADDRESS>.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,<IP_ADDRESS> 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
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.<IP_ADDRESS> 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
<IP_ADDRESS> 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 <IP_ADDRESS> 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.
<IP_ADDRESS> 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)
<IP_ADDRESS> 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 <IP_ADDRESS> 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, <IP_ADDRESS>), 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, the<IP_ADDRESS> Execution of the SELECT RANK construct
associate name identifies an entity which is associated (<IP_ADDRESS>) 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.
<IP_ADDRESS> 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 <IP_ADDRESS>.<IP_ADDRESS> 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 <IP_ADDRESS> 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, <IP_ADDRESS>), 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 variable<IP_ADDRESS> 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 (<IP_ADDRESS>) 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
(<IP_ADDRESS>), 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 <IP_ADDRESS>.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.
<IP_ADDRESS> 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 (<IP_ADDRESS>.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.  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 (<IP_ADDRESS>);
• 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 (<IP_ADDRESS>) and STAT_STOPPED_IMAGE (<IP_ADDRESS>) 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
(<IP_ADDRESS>) 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
(<IP_ADDRESS>) 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 (<IP_ADDRESS>) 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 (<IP_ADDRESS>) 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 (<IP_ADDRESS>) 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 (<IP_ADDRESS>) 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
<IP_ADDRESS> 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.<IP_ADDRESS> 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.
<IP_ADDRESS> 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 (<IP_ADDRESS>).
NOTE 12.7
A record cannot be deleted; however, a record can be rewritten.
<IP_ADDRESS> 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 (<IP_ADDRESS>) 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 (<IP_ADDRESS>).
220 c ISO/IEC 2017 – All rights reserved
ISO/IEC DIS 1539-1:2017 (E)
12.3.4 File position <IP_ADDRESS> 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, unless<IP_ADDRESS> 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.
<IP_ADDRESS> 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 <IP_ADDRESS>.⃝c ISO/IEC 2017 – All rights reserved 221
ISO/IEC DIS 1539-1:2017 (E)
<IP_ADDRESS> 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 (<IP_ADDRESS>) 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 (<IP_ADDRESS>) or the array section (<IP_ADDRESS>). 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 (<IP_ADDRESS>). 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 (<IP_ADDRESS>), or a
NEWUNIT value (<IP_ADDRESS>). 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 (<IP_ADDRESS>). 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 (<IP_ADDRESS>). 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 (<IP_ADDRESS>).
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, <IP_ADDRESS>), 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 (<IP_ADDRESS>.8), pad mode (<IP_ADDRESS>.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
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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)
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> BLANK= specifier in the OPEN statement
connection for formatted input/output. It specifies the blank interpretation mode (13.8.6, <IP_ADDRESS>) 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.
<IP_ADDRESS> DECIMAL= specifier in the OPEN statement
for a connection for formatted input/output. It specifies the decimal edit mode (13.6, 13.8.8, <IP_ADDRESS>) 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.
<IP_ADDRESS> DELIM= specifier in the OPEN statement
permitted only for a connection for formatted input/output. It specifies the delimiter mode (<IP_ADDRESS>) 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 (<IP_ADDRESS>) 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> PAD= specifier in the OPEN statement
for formatted input/output. It specifies the pad mode (<IP_ADDRESS>.3, <IP_ADDRESS>) 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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)
<IP_ADDRESS> 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 (<IP_ADDRESS>.8, <IP_ADDRESS>) 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.
<IP_ADDRESS> 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, <IP_ADDRESS>) 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.
<IP_ADDRESS> 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 (<IP_ADDRESS>).
12.5.7 CLOSE statement
<IP_ADDRESS> 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.
<IP_ADDRESS> 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’)
<IP_ADDRESS> 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
<IP_ADDRESS> 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
<IP_ADDRESS> 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.
<IP_ADDRESS> 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.
<IP_ADDRESS> 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 (<IP_ADDRESS>). 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.
<IP_ADDRESS> 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