Table of Contents
Fortran 2008 New features by John Reid N1828
Return to Fortran Language Specifications, Language Specifications, Fortran 2008, Fortran 2018, Fortran bibliography, Fortran, Fortran glossary, Fortran topics, Fortran glossary, Fortran courses, IBM Mainframe glossary, Awesome Fortran, Awesome IBM Mainframe, IBM Mainframe development, IBM Mainframe bibliography, COBOL, COBOL glossary, High-performance computing (HPC)
Reid, John (2008). The new features of Fortran 2008 - (http://dx.doi.org/10.1145/1408643.1408645). Fortran 2008 New features by John Reid N1828
ISO/IEC JTC1/SC22/WG5 N1828
The new features of Fortran 2008
May 6, 2010
Abstract
The aim of this paper is to summarize the new features of the draft Fortran 2008 standard (Fortran ISO/IEC 2010). We take as our starting point Fortran 2003 (Fortran ISO/IEC 2004).
An official extension for enhanced module facilities has been published as a Type 2 Technical Report (ISO/IEC 2005) and WG5 was committed to include this in Fortran 2008.
For an informal description of Fortran 2003 and enhanced module facilities, see Metcalf, Reid, and Cohen (2004).
The major extension consists of coarrays for parallel computing. Since the author has already summarized coarrays in another WG5 paper (Reid 2010), we refer the reader to this for details.
This article is not an official document and has not been approved by PL22.3
(formerly J3) or WG5.
1
2
ISO/IEC JTC1/SC22/WG5 N1828
Contents
1 Introduction
5
2 Submodules
5
3 Coarrays
7
4 Performance enhancements
7
4.1
do concurrent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
4.2
Contiguous attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
4.3
Simply contiguous arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
5 Data declaration
10
5.1
Maximum rank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
5.2
Long integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
5.3
Allocatable components of recursive type . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
5.4
Implied-shape array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.5
Pointer initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.6
Data statement restrictions lifted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.7
Kind of a forall index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.8
Type statement for intrinsic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.9
Declaring type-bound procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
6 Data usage
13
6.1
Omitting an allocatable component in a structure constructor . . . . . . . . . . . . . . . .
13
6.2
Copying the bounds of a source array in an allocate statement . . . . . . . . . . . . . . .
13
6.3
Allocating a polymorphic variable
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
6.4
Accessing real and imaginary parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
6.5
Pointer functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14
6.6
Elemental dummy argument restrictions lifted . . . . . . . . . . . . . . . . . . . . . . . . .
14
7 Input/Output
14
7.1
Finding a unit when opening a file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14
7.2
g0 edit descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14
7.3
Unlimited format item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14
ISO/IEC JTC1/SC22/WG5 N1828
3
7.4
Recursive input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
8 Execution control
15
8.1
The block construct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
8.2
Exit statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
8.3
Stop code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16
9 Intrinsic procedures and modules
16
9.1
Bit processsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16
9.1.1
Bit sequence comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16
9.1.2
Combined shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
9.1.3
Counting bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
9.1.4
Masking bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
9.1.5
Shifting bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
9.1.6
Merging bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
9.1.7
Bit transformational functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
9.2
Storage size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
9.3
Taking radix into account when selecting a real kind . . . . . . . . . . . . . . . . . . . . .
19
9.4
Extensions to trigonometric and hyperbolic intrinsic functions . . . . . . . . . . . . . . . .
19
9.5
Bessel functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
9.6
Error and gamma functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
9.7
Euclidean vector norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
9.8
Parity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
9.9
Execute command line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
9.10
Location of maximum or minimum value in an array . . . . . . . . . . . . . . . . . . . .
22
9.11
Find location in an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
9.12
String comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
9.13
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
9.14
Module procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
10 Programs and procedures
24
10.1 Save attribute for module and submodule data . . . . . . . . . . . . . . . . . . . . . . . .
24
10.2 Empty contains section
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24
10.3 Form of the end statement for an internal or module procedure . . . . . . . . . . . . . . .
24
4
ISO/IEC JTC1/SC22/WG5 N1828
10.4 Internal procedure as an actual argument or pointer target . . . . . . . . . . . . . . . . .
24
10.5 Null pointer or unallocated allocatable as an absent dummy argument . . . . . . . . . . .
25
10.6 Pointer dummy arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
10.7 Generic resolution by pointer/allocatable or data/procedure . . . . . . . . . . . . . . . . .
25
10.8 Elemental procedures that are not pure . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
10.9 Entry statement becomes obsolescent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
11 Source form
26
11.1 Semicolon at line start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
12 Acknowledgements
26
13 References
26
ISO/IEC JTC1/SC22/WG5 N1828
5
1
Introduction
Fortran is a computer language for scientific and technical programming that is tailored for efficient run-time execution on a wide variety of processors. It was first standardized in 1966
and the standard has since been revised four times (1978, 1991, 1997, 2004). The revisions alternated between being minor (1978 and 1997) and major (1991 and 2004). WG5 decided in 2004 that the fifth revision should be minor, to follow the pattern and allow time for vendors to implement Fortran 2003 and users to learn to use it.
The plan adopted in 2004 (see N15901) involved the preliminary choice of significant features in 2005 and the final choice in 2006. When it came to the crunch, WG5 left some items for J3
to add if it had time. Reductions were made at the 2007 meeting and a further reduction was made at the February 2008 meeting. Further technical changes were made at the November 2008 meeting.
The full document, N1826, is about to be submitted for international ballot as a Final Draft International Standard (FDIS) and is expected to be published later this year. Only extremely minor changes, such as the correction of typos, are permitted after such a ballot. This article provides an informal description of the features. There are plans for further interoperability and coarray features to be defined in Technical Reports.
We use the convention of indicating the optional arguments of an intrinsic procedure by enclosing them in square brackets in the argument list. We also use square brackets for other optional syntax elements.
2
Submodules
The module facilities of Fortran 2003, while adequate for programs of modest size, have shortcomings for very large programs. They all arise from the fact that, although modules are an aid to modularization of the program, they are themselves difficult to modularize.
As a module grows larger, the only way to modularize it is to break it into several modules.
This exposes the internal structure, raising the potential for unnecessary global name clashes and giving the user of the module access to what ought to be private data and/or procedures.
Worse, if the subfeatures of the module are interconnected, they must remain together in a single module, however large.
Another significant shortcoming is that if a change is made to the code inside a module procedure, even a private one, typical use of make or a similar tool results in the recompilation of every file which accesses the module, directly or indirectly.
The solution is to allow a module procedure to have its interface defined in a module while its body is defined in a separate program unit called a submodule. A change in a submodule cannot 1We refer to ISO/IEC JTC1/SC22/WG5 documents by their ‘N numbers’. They are all available from ftp://ftp.nag.co.uk/sc22wg5/
6
ISO/IEC JTC1/SC22/WG5 N1828
alter an interface in the module, and so does not cause the recompilation of program units that use the module.
A submodule has access via host association to entities in the module, and may have entities of its own in addition to providing implementations of module procedures.
Here is a simple example:
module points
type :: point
real :: x,y
end type point
interface
real function point_dist (a,b)
import :: point
type(point), intent(in) :: a,b
end function point_dist
end interface
end module points
submodule (points) points_a
contains
real function point_dist (a,b)
type(point), intent(in) :: a,b
point_dist = sqrt1)) :: x,y
The interpretation is exactly the same as it would have been without the keyword type and the parentheses.
5.9
Declaring type-bound procedures
Multiple type-bound procedures can be declared in a single procedure statement.
2Constant expression were known as “initialization” expressions in Fortran 2003.
ISO/IEC JTC1/SC22/WG5 N1828
13
6
Data usage
6.1
Omitting an allocatable component in a structure constructor It is permitted to omit an allocatable component in a structure constructor. It is given the allocation status of unallocated.
6.2
Copying the bounds of a source array in an allocate statement In a Fortran 2003 allocate statement, if it is required to copy the bounds of an array, they have to be specified explicitly, for example, allocate ( a(lbound(b,1):ubound(b,1)))
allocate ( a(lbound(b,1):ubound(b,1)), source=b ) In Fortran 2008, the bounds may taken from an array given by mold= or source=: allocate ( a, mold=b )
! Bounds copied
allocate ( a, source=b ) ! Bounds and value copied 6.3
Allocating a polymorphic variable
An allocate statement can give a polymorphic variable the shape and type of another variable without copying the value. This is done with mold= replacing source=. For example, allocate (poly, mold=t2)
allocates the polymorphic variable to have the type and shape of t2.
Intrinsic assignment to an allocatable polymorphic variable is allowed. The variable must be type compatible with the expression and of the same rank. If it is allocated but the dynamic type differs from that of the expression, it is deallocated. If it is not allocated or becomes deallocated, it is allocated with the dynamic type of the expression.
6.4
Accessing real and imaginary parts
The real and imaginary parts of a complex entity can be accessed independently with a component-like syntax using the names re and im. For example, complex impedance, x(n), y(n)
impedance%re = 1.0
x%im = 2.0*y%im
The new syntax allows the parts to be used as variables rather than only within expressions and makes array sections such as x%im and y%im available.
14
ISO/IEC JTC1/SC22/WG5 N1828
6.5
Pointer functions
A reference to a pointer function is treated as a variable and is permitted in any variable-definition context. For example, this function might calculate where to store values depending on a key
function storage(key) result(loc)
integer, intent(in) :: key
real, pointer :: loc
loc⇒…
end function
which would allow a value to be set thus:
storage(5)=0.5
6.6
Elemental dummy argument restrictions lifted There are no longer any additional restrictions for elemental procedures on the appearance of dummy arguments in specification expressions.
7
Input/Output
7.1
Finding a unit when opening a file
In an open statement, newunit= automatically selects a unit number that does not interfere with other unit numbers selected by the program, including preconnected files. For example, integer factor
open (newunit = factor, file = ’factor’, status = ’old’) which assigns a suitable value to the integer factor.
7.2
g0 edit descriptor
The g0 edit descriptor specifies that the processor should automatically choose a suitable field width. For real and complex data, it follows the rules of esw.dee format with the values of w, d, and e chosen by the processor. For integers, it behaves as i0. For logicals, it behaves as l1.
For characters, it behaves as a.
7.3
Unlimited format item
A list of edit descriptors in parentheses may be preceded by an asterisk, which has the effect of repeating the list indefinitely, that is, as if it were replaced by a very large integer. For example,
ISO/IEC JTC1/SC22/WG5 N1828
15
write( 10, ’( “iarray =”, *( i0, :, “,”))’) iarray produces a single record with a header and a comma separated list of integer values. Note that this feature can be used with g0 format to process I/O lists with various types (or derived types) present.
7.4
Recursive input/output
It is useful to be able to perform I/O in a subprogram invoked during the processing of an I/O
statement (e.g., for tracing and diagnostic purposes). This is now permitted for an external unit that is distinct from that of an I/O statement that is in execution (that is, any in the current call chain).
8
Execution control
8.1
The block construct
The block construct allows entities to be declared and given the scope of the block, for example, block
integer :: i
real :: a(n)
do i = 1,n
a(i) = i
end do
:
end block
ensures that the do index i and the automatic array a are separate from variables with the same names that are outside the block. Of course, the block construct must be properly nested with other constructs.
8.2
Exit statement
In Fortran 2008, the exit statement may be employed in almost any construct. This will avoid the need for go to statements or extra tests for some algorithms that cannot be expressed in Fortran 2003 without them. Here is an example using the new block construct (Section 8.1) outer: block
do i = 1, num_in_set
if ( x == a(i) ) exit outer
end do
call r
end block outer
16
ISO/IEC JTC1/SC22/WG5 N1828
Here, no action is needed if x is equal to an element of a; otherwise, r is called.
The exceptional case is an exit statement that belongs to a do concurrent (Section 4.1) or critical construct (a coarray feature) or an outer construct. In all these cases, a transfer out of the construct is inappropriate and is not permitted.
8.3
Stop code
The optional stop code on a stop statement is limited in Fortran 2003 to a string of one to five digits or a character constant. This has been extended to any integer or character constant expression, available as ever ‘in a processor-dependent manner’. In addition, it is recommended that
• it is made available by formatted output on the unit error unit of the intrinsic module iso Fortran env and
• that if it is an integer and the processor supports command line execution (see Section 9.9), it is made available as the exit status value returned by execute command line.
9
Intrinsic procedures and modules
9.1
Bit processsing
9.1.1
Bit sequence comparison
Bit sequences are compared from left to right, one bit at a time, until unequal bits are found or all bits have been compared and found to be equal. If unequal bits are found, the sequence with zero in the unequal position is considered to be less than the sequence with one in the unequal position. When bit sequences of unequal length are compared, the shorter sequence is considered to be extended by padding with zero bits on the left. The following elemental functions have been added. i and j are each of type integer or a binary, octal, or hexadecimal constant.
bge (i,j) returns the default logical value true if and only if i is bitwise greater than or equal to j.
bgt (i,j) returns the default logical value true if and only if i is bitwise greater than j.
ble (i,j) returns the default logical value true if and only if i is bitwise less than or equal to j.
blt (i,j) returns the default logical value true if and only if i is bitwise less than j.
ISO/IEC JTC1/SC22/WG5 N1828
17
9.1.2
Combined shifting
The following elemental functions have been added for combined shifting. i and j are each of type integer or a binary, octal, or hexadecimal constant. At least one must be integer. If they are both integer, they must have the same kind. Let bsize be the bit size of this kind of integer. The result is of type integer and of this kind. shift is of type integer with a value in the range 0, 1, 2, . . . , bsize.
dshiftl (i,j,shift) returns the rightmost bsize-shift bits of i followed by the leftmost shift bits of j.
dshiftr (i,j,shift) returns the rightmost shift bits of i followed by the leftmost bsize-shift bits of j.
9.1.3
Counting bits
The following elemental functions have been added for counting bits. i is an integer and the result is a default integer.
leadz(i) returns the number of leading zero bits in i.
popcnt(i) returns the number of one bits in i.
poppar(i) returns the value 1 if popcnt(i) is odd and the value 0 otherwise.
trailz(i) returns the number of trailing zero bits in i.
9.1.4
Masking bits
The following elemental functions have been added for masking bits.
maskl(i[,kind]) returns an integer whose leftmost i bits are 1 and the rest are zero.
maskr(i[,kind]) returns an integer whose rightmost i bits are 1 and the rest are zero.
i is an integer.
kind is a scalar integer constant expression.
The result is of type integer and kind kind if kind is present and of type default integer otherwise.
9.1.5
Shifting bits
The following elemental functions have been added for shifting bits.
shifta(i,shift) has the effect of shifting the bits of i to the right by shift places and replicating the leftmost bit shift times in the vacated positions.
18
ISO/IEC JTC1/SC22/WG5 N1828
shiftl(i,shift) has the effect of shifting the bits of i to the left by shift places and changing the rightmost shift bits to zero. It is the same as ishft(i,shift).
shiftr(i,shift) has the effect of shifting the bits of i to the right by shift places and changing the leftmost shift bits to zero. It is the same as ishft(i,-shift).
i is an integer.
shift is a nonnegative integer.
The result is of type integer with the same kind as i.
9.1.6
Merging bits
The following elemental function has been added for merging bits.
merge bits(i,j,mask) returns an integer that merges the bits of i and j under the control of mask. One of i and j must be of type integer. If both are of type integer, they must be of the same kind. One may be a binary, octal, or hexadecimal constant. mask is of type integer and of the same kind as i or j, or is a binary, octal, or hexadecimal constant. A bit of the result is the corresponding bit of i if the corresponding bit of mask is 1 and is the corresponding bit of j otherwise.
9.1.7
Bit transformational functions
The following transformational functions have been added for bit operations.
iall(array,dim,[,mask]) or iall(array[,mask]) performs bitwise and operations.
iany(array,dim,[,mask]) or iany(array[,mask]) performs bitwise or operations.
iparity(array,dim,[,mask]) or iparity(array[,mask]) performs bitwise exclusive or operations.
array is an integer array.
dim is an integer scalar.
mask conforms with array and is of type logical.
These functions are modelled on the transformational function sum, but use the operators of the functions iand, ior, and ieor instead of +. The result has the type and kind of array and the shape is determined from the shape of array and the value of dim or its absence, just as for sum.
The operators are applied to all the elements of array to yield a scalar or to all the elements of each rank-one section that spans dimension dim to yield a result of rank reduced by one.
ISO/IEC JTC1/SC22/WG5 N1828
19
9.2
Storage size
storage size(a,[kind]) is an inquiry function that returns an integer of kind kind if kind is present or of default kind otherwise. It returns the storage size in bits of a scalar of the dynamic type and kind of a, which may be a scalar or an array of any type.
9.3
Taking radix into account when selecting a real kind An additional optional argument radix has been added to selected real kind at the end of the argument list. It is an integer scalar and its presence results in the search being limited to a particular radix.
9.4
Extensions to trigonometric and hyperbolic intrinsic functions The intrinsic functions acos, asin, atan, cosh, sinh, tan, and tanh may have complex arguments. The inverse functions acosh(x), asinh(x), and atanh(x) have been added. The intrinsic function atan2 may be accessed by the name atan.
9.5
Bessel functions
The following elemental functions have been added bessel j0 (x) returns the Bessel function of the first kind and order zero for a real value x.
bessel j1 (x) returns the Bessel function of the first kind and order one for a real value x.
bessel jn (n,x) returns the Bessel function of the first kind and order n for a real value x.
The argument n must be an integer with a nonnegative value.
bessel y0 (x) returns the Bessel function of the second kind and order zero for a real value x that is positive.
bessel y1 (x) returns the Bessel function of the second kind and order one for a real value x that is positive.
bessel yn (n,x) returns the Bessel function of the second kind and order n for real values x that are positive. The argument n must be an integer with a nonnegative value.
In addition, the functions bessel jn and bessel yn are overloaded with these transformational functions
bessel jn (n1,n2,x) returns a rank-one array of Bessel functions of the first kind and orders n1, n1+1, . . . n2 for real values x. The arguments n1 and n2 must be integers with nonnegative values.
20
ISO/IEC JTC1/SC22/WG5 N1828
bessel yn (n1,n2,x) returns a rank-one array of Bessel functions of the second kind and orders n1, n1+1, . . . n2 for real values x. The arguments n1 and n2 must be integers with nonnegative values.
9.6
Error and gamma functions
The following elemental functions have been added erf (x) returns the error function for a real value x, that is, 2 R x
√
exp(
π
0
−t2)dt.
erfc (x) returns the complementary error function for a real value x, that is, 1-erf(x) =
2
R ∞
√
exp(
π
x
−t2)dt.
erfc scaled (x) returns the exponentially-scaled complementary error function for a real value x, that is, exp(x2) 2 R ∞
√
exp(
π
x
−t2)dt.
gamma (x) returns the gamma function for a real value x, that is, R ∞ tx−1 exp(
0
−t)dt.
hypot (x,y) returns the Euclidean distance function px2 + y2 for real values x and y, without undue overflow or underflow.
log gamma (x) returns the logarithm of the absolute value of the gamma function for a real value x that is not a negative integer or zero.
9.7
Euclidean vector norms
The following transformational function has been added.
norm2(x[,dim]) calculates Euclidean vector norms.
x is a real array.
dim is an integer scalar.
This function is modelled on the transformational function sum, but without the optional argu-q
ment mask and replacing summation by calculation of the Euclidean vector norm P x2. The
i
result has the type and kind of x and the shape is determined from the shape of x and the value of dim or its absence, just as for sum. The operator is applied to all the elements of x to yield a scalar or to the elements of each rank-one section that spans dimension dim to yield a result of rank reduced by one. It is recommended that the result be reasonably accurate even if computing some of the squares of the elements would result in overflow or underflow.
ISO/IEC JTC1/SC22/WG5 N1828
21
9.8
Parity
The following transformational function has been added.
parity(mask[,dim]) tests for the number of true values being odd.
mask is a logical array.
dim is an integer scalar.
This function is modelled on the transformational function all, replacing the test for all values being true with the test for the number of true values being odd. The result has the type and kind of mask and the shape is determined from the shape of mask and the value of dim or its absence, just as for all. The operator is applied to all the elements of mask to yield a scalar or to the elements of each rank-one section that spans dimension dim to yield a result of rank reduced by one.
9.9
Execute command line
call execute command line(command[,wait,exitstat,cmdstat,cmdmsg]) starts execution of another program if the processor supports command line execution.
command has intent in and is a scalar default character holding the command line to be executed.
wait has intent in and is a scalar default logical. If present with the value false, and the processor supports asynchronous execution of the command, the command is executed asynchronously; otherwise it is executed synchronously.
exitstat has intent inout and is a scalar default integer. If the command is executed synchronously, it is assigned the value of the processor-dependent exit status. Otherwise, the value is unchanged.
cmdstat has intent out and is a scalar default integer. It is assigned the value -1 if the processor does not support command line execution, a processor-dependent positive value if an error condition occurs, or the value -2 if no error condition occurs but wait is present with the value false and the processor does not support asynchronous execution. Otherwise it is assigned the value 0.
cmdmsg has intent inout and is a scalar default character. If an error condition occurs, it is assigned a processor-dependent explanatory message. Otherwise, it is unchanged.
When the command is executed synchronously, the subroutine returns after the command line has completed execution. Otherwise, it returns without waiting. If an error condition occurs and cmdstat is not present, error termination of execution is initiated.
22
ISO/IEC JTC1/SC22/WG5 N1828
9.10
Location of maximum or minimum value in an array The intrinsics maxloc and minloc have had an additional optional argument back added at the end of the argument list. The effect of its presence with the value true is that if there is more than one element that satisfies the condition, the last in array element order is taken instead of the first.
9.11
Find location in an array
The following transformational function has been added findloc(array,value[,mask,kind,back]) or
findloc(array,value,dim[,mask,kind,back]) finds the location in array of an element with value value.
array is an array of intrinsic type.
value is a scalar of a type that may be used for intrinsic comparisons.
dim is a scalar integer.
mask conforms with array and is of type logical.
kind is a scalar constant expression.
back is a scalar logical.
This function is modelled on the transformational function maxloc, replacing the search for a maximum value with a search for the value value. The result has the type and kind of array and the shape is determined from the shape of mask and the value of dim or its absence, just as for maxloc. The search is applied to all the elements of array to yield a scalar or to the elements of each rank-one section that spans dimension dim to yield a result of rank reduced by one.
9.12
String comparison
The string comparison functions lge, lgt, lle, and llt are permitted to have arguments of ASCII kind as well as default character kind.
9.13
Constants
The intrinsic module iso Fortran env contains these new constants: character kinds is a default integer array holding the kind values supported by the processor for variables of type character. Its size equals the number of kinds supported.
ISO/IEC JTC1/SC22/WG5 N1828
23
int8, int16, int32, and int64 are default integer scalars holding the kind values for integers of storage size 8, 16, 32, and 64 bits. If there is no such type, the value is -2 if there is a type of larger storage size or -1 otherwise.
integer kinds is a default integer array holding the kind values supported by the processor for variables of type integer. Its size equals the number of kinds supported.
iostat inquire internal unit is a default integer scalar holding the value returned in an iostat= specifier in an inquire statement if the file unit number identifies an internal unit (which can happen only during user-defined derived-type I/O).
logical kinds is a default integer array holding the kind values supported by the processor for variables of type logical. Its size equals the number of kinds supported.
real kinds is a default integer array holding the kind values supported by the processor for variables of type real. Its size equals the number of kinds supported.
real32, real64, and real128 are default integer scalars holding the kind values for reals of storage size 32, 64, and 128 bits. If there is no such type, the value is -2 if there is a type of larger storage size or -1 otherwise.
9.14
Module procedures
The intrinsic module iso Fortran env contains these functions: compiler options is an inquiry function that returns a default character scalar that details the options that the compiler was given.
compiler version is an inquiry function that returns a default character scalar that details the name and version of the compiler used.
The intrinsic module iso C binding contains this function: C sizeof(x) is an inquiry function that returns an integer. If x is scalar, the result is the value that the companion processor returns as the result of applying the C sizeof operator to an object of a type that interoperates with the type and type parameters of x. If x is an array, it is the result for an element multiplied by the number of elements.
In the intrinsic module ieee arithmetic, an additional optional argument radix has been added to ieee selected real kind at the end of the argument list. It is an integer scalar and its presence results in the search being limited to a particular radix.
24
ISO/IEC JTC1/SC22/WG5 N1828
10
Programs and procedures
10.1
Save attribute for module and submodule data A variable, common block, or procedure pointer that is declared in a module or submodule automatically has the save attribute.
10.2
Empty contains section
An empty contains section is permitted in a procedure or type definition.
10.3
Form of the end statement for an internal or module procedure The keyword function or subroutine is not required to appear in an end statement for an internal or module procedure.
10.4
Internal procedure as an actual argument or pointer target An internal procedure may be passed as an actual argument or be the target of a procedure pointer, which permits it to be invoked from outside of its host. This will be very convenient for users of library codes because the internal procedure may have access to any data accessible in the host. We illustrate this with a procedure to calculate R b f (x)dx with the interface a
interface
real function integrate(f, a, b) result(integral) interface
real function f(x) ! Integrand
real, value :: x
end function f
end interface
real, intent(in) :: a, b ! Bounds
end function integrate
end interface
Here it is being used in a function to calculate R b xndx: a
real function my_integration(n, a, b) result(integral)
! Integrate f(x)=x**n over [a,b]
integer, intent(in) :: n
real, intent(in) :: a, b
integral = integrate(my_f, a, b)
contains
real function my_f(x) ! Integrand
ISO/IEC JTC1/SC22/WG5 N1828
25
real, value :: x
my_f = x**n ! n is taken from the host.
end function my_f
end function my_integration
10.5
Null pointer or unallocated allocatable as an absent dummy argument A null pointer or unallocated allocatable that corresponds to an optional non-allocatable non-pointer dummy argument is interpreted as an absent argument.
10.6
Pointer dummy arguments
A pointer dummy argument with intent in may be argument associated with a non-pointer actual argument with the target attribute. During the execution of the procedure it is pointer associated with the actual argument.
10.7
Generic resolution by pointer/allocatable or data/procedure A pair of specific procedures in a generic interface are permitted to be distinguishable by virtue of a pointer argument without intent in of one corresponding to an allocatable argument of the other or a data argument of one corresponding to a procedure argument of the other.
10.8
Elemental procedures that are not pure
An elemental procedure is not required to be pure. This must be explicitly declared with the prefix impure and the effect is that the procedure is called for corresponding array elements in array element order. For example,
module PRNG
integer, save :: seed(4)
contains
impure elemental subroutine random (x)
real :: x
… ! Code that updates the seed and
… ! calculates a pseudo-random value x
end subroutine random
end module PRNG
is a module that calculates pseudo-random numbers, based on a seed that is an integer array of size 4. If random is called for an array, the scalar subroutine is called repeatedly, updating the seed each time.
26
ISO/IEC JTC1/SC22/WG5 N1828
10.9
Entry statement becomes obsolescent
The entry statement becomes obsolescent. A procedure with entry points may be replaced by a module with a separate module procedure for each entry and shared code in a private module procedure.
11
Source form
11.1
Semicolon at line start
The restriction of not permitting a line to start with a semicolon has been removed.
12
Acknowledgements
I would like to express thanks to Malcolm Cohen, Aleksandar Donev, Nick Gould, Jim Giles, Alla Gorelik, Jonathan Hogg, Erik Kruyt, Bill Long, Steve Morgan, Dan Nagle, Jane Sleightholme, Van Snyder, and Stan Whitlock for suggesting improvements.
13
References
WG5 (2010). FDIS revision of the Fortran Standard. ISO/IEC/JTC1/SC22/WG5-N1826, see ftp://ftp.nag.co.uk/sc22wg5/N1801-N1850/N1826.pdf ISO/IEC (2004). ISO/IEC 1539-1:2004(E) Information technology - Programming languages
- Fortran - Part 1: Base language. ISO, Geneva.
ISO/IEC (2005). ISO/IEC TR 19767 Information technology - Programming languages -
Fortran - Enhanced Module Facilities. ISO, Geneva.
Metcalf, Michael, Reid, John, and Cohen, Malcolm (2004). Fortran 95/2003 explained. Oxford University Press.
Reid (2010). ISO/IEC JTC1/SC22/WG5 N1824. Coarrays in the next Fortran Standard, ftp://ftp.nag.co.uk/sc22wg5/N1801-N1850/N1824.pdf
Fair Use Sources
Fortran Programming Language, Fortran Source File, Fortran .f File Extension, Fortran .f90 File Extension, Fortran .f95 File Extension, Fortran .f03 File Extension, Fortran .f08 File Extension, Fortran Free-Form Source, Fortran Fixed-Form Source, Fortran gfortran Compiler, Fortran ifort Compiler, Fortran NAG Compiler, Fortran flang Compiler, Fortran ftn Command, Fortran fpp Preprocessor, Fortran Modules, Fortran USE Statement, Fortran IMPLICIT NONE, Fortran PROGRAM Keyword, Fortran SUBROUTINE Keyword, Fortran FUNCTION Keyword, Fortran END PROGRAM, Fortran END SUBROUTINE, Fortran END FUNCTION, Fortran END MODULE, Fortran CONTAINS Section, Fortran BLOCK Keyword, Fortran INTERFACE Block, Fortran ABSTRACT INTERFACE, Fortran MODULE PROCEDURE, Fortran RECURSIVE Keyword, Fortran PURE Keyword, Fortran ELEMENTAL Keyword, Fortran ALLOCATABLE Attribute, Fortran ALLOCATE Statement, Fortran DEALLOCATE Statement, Fortran INTENT(IN), Fortran INTENT(OUT), Fortran INTENT(INOUT), Fortran OPTIONAL Dummy Arg, Fortran SAVE Attribute, Fortran PRIVATE Attribute, Fortran PUBLIC Attribute, Fortran PROTECTED Attribute, Fortran TARGET Attribute, Fortran POINTER Attribute, Fortran VOLATILE Attribute, Fortran BIND(C) Attribute, Fortran VALUE Attribute, Fortran IMPORT Statement, Fortran SELECTED_REAL_KIND, Fortran SELECTED_INT_KIND, Fortran KIND Parameter, Fortran ISO_C_BINDING Module, Fortran C_INT Type, Fortran C_FLOAT Type, Fortran C_DOUBLE Type, Fortran C_CHAR Type, Fortran C_FUNPTR Type, Fortran C_LOC Function, Fortran C_ASSOCIATED Function, Fortran C_F_POINTER Subroutine, Fortran CHARACTER Type, Fortran INTEGER Type, Fortran REAL Type, Fortran DOUBLE PRECISION Type, Fortran COMPLEX Type, Fortran LOGICAL Type, Fortran PARAMETER Attribute, Fortran DATA Statement, Fortran EQUIVALENCE Statement, Fortran COMMON Block, Fortran BLOCK DATA, Fortran CRITICAL Construct, Fortran DO Loop, Fortran DO CONCURRENT Loop, Fortran DO WHILE Loop, Fortran EXIT Statement, Fortran CYCLE Statement, Fortran IF Statement, Fortran IF...THEN...ELSE Construct, Fortran SELECT CASE Construct, Fortran GOTO Statement, Fortran STOP Statement, Fortran RETURN Statement, Fortran CALL Statement, Fortran WRITE Statement, Fortran READ Statement, Fortran PRINT Statement, Fortran OPEN Statement, Fortran CLOSE Statement, Fortran INQUIRE Statement, Fortran REWIND Statement, Fortran BACKSPACE Statement, Fortran ENDFILE Statement, Fortran FORMAT Statement, Fortran NAMELIST Statement, Fortran INCLUDE Line, Fortran ASSOCIATE Construct, Fortran SELECT TYPE Construct, Fortran RANK Operator (Fortran 2008+), Fortran CONTIGUOUS Attribute, Fortran PURE Procedure, Fortran ELEMENTAL Procedure, Fortran INTENT Declaration, Fortran ALLOCATE with MOLD, Fortran MOVE_ALLOC Subroutine, Fortran EXECUTE_COMMAND_LINE Intrinsic, Fortran CPU_TIME Intrinsic, Fortran DATE_AND_TIME Intrinsic, Fortran SYSTEM_CLOCK Intrinsic, Fortran RANDOM_NUMBER Intrinsic, Fortran RANDOM_SEED Intrinsic, Fortran TRANSFER Intrinsic, Fortran C_F_PROCPOINTER Intrinsic, Fortran ISO_FORTRAN_ENV Module
Fortran: Effective Fortran, Fortran Best Practices, Fortran Fundamentals, Fortran Inventor - Fortran Language Designer: John Backus of IBM in 1957 (see John Backus Oral History); Modern Fortran - Legacy Fortran, Fortran keywords, Fortran data structures - Fortran algorithms, Fortran syntax, IBM Mainframe DevOps, Fortran DevOps, Fortran Development Tools (Fortran IDEs and Code Editors, Fortran Compilers, Fortran CI/CD Build Tools, Fortran Standard Library), Fortran Standards (ISO Fortran: Fortran 202X | 202X, Fortran 2018 | 2018, Fortran 2018 | 2018, Fortran 2008 | 2008, Fortran 2003 | 2003, Fortran 95 | 95, Fortran 90 | 90, Fortran 77 | 77), ANSI Fortran-Fortran 66 | 66, Fortran and Supercomputers (Fortran and High-Performance Computing (HPC)), Parallel Fortran (Embarrassingly Parallel Fortran - Fortran Coarrays), Fortran Paradigms (Imperative Fortran, Procedural Fortran, Object-Oriented Fortran - Fortran OOP, Functional Fortran), Fortran Community, Learning Fortran, Fortran on Windows, Fortran on Linux, Fortran on UNIX, Fortran on macOS, Mainframe Fortran, IBM i Fortran, Fortran installation, Fortran containerization, Fortran configuration, Fortran SRE, Fortran data science - Fortran DataOps, Fortran machine learning, Fortran deep learning, Fortran concurrency, Fortran history, Fortran bibliography, Fortran Glossary - Glossaire de Fortran - French, Fortran topics, Fortran courses, Fortran Standard Library, Fortran libraries, Fortran frameworks, Fortran research, Fortran GitHub, Written in Fortran, Fortran popularity, Fortran Awesome list, Fortran Versions. (navbar_fortran - see also navbar_cobol, navbar_mainframe)
Cloud Monk is Retired ( for now). Buddha with you. © 2025 and Beginningless Time - Present Moment - Three Times: The Buddhas or Fair Use. Disclaimers
SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.