BLOCKconstruct allows declarations of entities within executable code. For example,
Do i=1,n Block Real tmp tmp = a(i)**3 If (tmp>b(i)) b(i) = tmp End Block End DoHere the variable
tmphas its scope limited to the
BLOCKconstruct, so will not affect anything outside it. This is particularly useful when including code by
INCLUDEor by macro preprocessing.
All declarations are allowed within a
BLOCK construct except for
VALUE; also, statement function
definitions are not permitted.
BLOCK constructs may be nested; like other constructs, branches into a
BLOCK construct from outside are not permitted.
A branch out of a
BLOCK construct “completes” execution of the
Entities within a
BLOCK construct that do not have the
attribute (including implicitly via initialisation), will cease to exist when
execution of the construct is completed.
For example, an allocated
ALLOCATABLE variable will be automatically
deallocated, and a variable with a
FINAL procedure will be finalised.
EXITstatement is no longer restricted to exiting from a
DOconstruct; it can now be used to jump to the end of a named
SELECT TYPEconstruct (i.e. any named construct except
WHERE). Note that an
EXITstatement with no construct-name still exits from the innermost
DOconstruct, disregarding any other named constructs it might be within.
STOPstatement, the stop-code may be any scalar constant expression of type integer or default character. (In the NAG Fortran Compiler this also applies to the
PAUSEstatement, but that statement is no longer standard Fortran.) Additionally, the
STOPstatement with an integer stop-code now returns that value as the process exit status (on most operating systems there are limits on the value that can be returned, so for the NAG Fortran Compiler this returns only the lower eight bits of the value).
ERROR STOPstatement has been added. This is similar to the
STOPstatement, but causes error termination rather than normal termination. The syntax is identical to that of the
STOPstatement apart from the extra keyword ‘
ERROR’ at the beginning. Also, the default process exit status is zero for normal termination, and non-zero for error termination.
IF (x<=0) ERROR STOP 'x must be positive'
FORALLconstruct now has an optional type specifier in the initial statement of the construct, which can be used to specify the type (which must be
INTEGER) and kind of the index variables. When this is specified, the existence or otherwise of any entity in the outer scope that has the same name as an index variable does not affect the index variable in any way. For example,
Complex i(100) Real x(200) ... Forall (Integer :: i=1:Size(x)) x(i) = i
Note that the
FORALL construct is still not recommended for high performance,
as the semantics imply evaluating the right-hand sides into array temps the
size of the iteration space, and then assigning to the variables; this usually
performs worse than ordinary
DO CONCURRENTconstruct is a
DOloop with restrictions and semantics intended to allow efficient execution. The iterations of a
DO CONCURRENTconstruct may be executed in any order, and possibly even in parallel. The loop index variables are local to the construct.
DO CONCURRENT header has similar syntax to the
including the ability to explicitly specify the type and kind of the loop index
variables, and including the scalar mask.
The restrictions on the
DO CONCURRENT construct are:
ERROR STOPis allowed);
EXITstatement cannot be used to terminate the loop;
CYCLEstatement cannot refer to an outer loop;
Integer vsub(n) ... Do Concurrent (i=1:n) ! Safe because vsub has no duplicate values. x(vsub(i)) = i End Do
The full syntax of the
DO CONCURRENT statement is:
[ do-construct-name : ]
DO [ label ] [ , ]
( [ integer-type-spec :: ] triplet-spec [ , triplet-spec ]... [ , mask-expr ] )where mask-expr is a scalar logical expression, and triplet-spec is
name = expr : expr [ : expr ]