MOVE_ALLOC
now has optional STAT
and
ERRMSG
arguments.
The STAT
argument must be of type Integer, with a decimal range of at
least four (i.e. not an 8-bit integer); it is assigned the value zero if the
subroutine executes successfully, and a nonzero value otherwise.
The ERRMSG
argument must be of type Character with default kind.
If STAT
is present and assigned a nonzero value, ERRMSG
will be
assigned an explanatory message (if it is present); otherwise, ERRMSG
will retain its previous value (if any).
For example,
INTEGER,ALLOCATABLE :: x(:),y(:) INTEGER istat CHARACTER(80) emsg ... CALL MOVE_ALLOC(x,y,istat,emsg) IF (istat/=0) THEN PRINT *,'Unexpected error in MOVE_ALLOC: ',TRIM(emsg)
The purpose of these arguments is to catch errors in multiple image coarray
allocation/deallocation, such as STAT_STOPPED_IMAGE
and
STAT_FAILED_IMAGE
.
DIM
argument to the intrinsic functions ALL
, ANY
, FINDLOC
,
IALL
, IANY
, IPARITY
, MAXLOC
, MAXVAL
, MINLOC
,
MINVAL
, NORM2
, PARITY
, PRODUCT
and SUM
can be an optional
dummy argument, as long as it is present at execution time.
For example,
Subroutine sub(x,n) Real,Intent(In) :: x(:,:,:) Integer,Intent(In),Optional :: n If (Present(n)) Then Print *,Norm2(x,n) ! Rank two array result. Else Print *,Norm2(x) ! Scalar result. End If End Subroutine
SQRT
, the obsolescent usage is
passing as an actual argument, use as a procedure interface, or being the target of a procedure pointer assignment.
RANK
returns the dimensionality of its argument.
It has the following syntax:
RANK ( A )
A
: data object of any type:
Result : scalar Integer of default kind.
The result is the rank of A
, that is, zero for scalar A
, one if A
is a one-dimensional array,
and so on.
This function can be used in a constant expression except when A
is an assumed-rank variable.
REDUCE
performs user-defined array reductions.
It has the following syntax:
REDUCE ( ARRAY, OPERATION [, MASK, IDENTITY, ORDERED ] ) or REDUCE ( ARRAY, OPERATION DIM [, MASK, IDENTITY, ORDERED ] )
ARRAY
: array of any type;
OPERATION
: pure function with two arguments, each argument being scalar, non-allocatable, non-pointer,
non-polymorphic non-optional variables with the same declared type and type parameters as ARRAY
;
if one argument has the ASYNCHRONOUS
, TARGET
or VALUE
attribute, the other must also
have that attribute;
the result must be a non-polymorphic scalar variable with the same type and type parameters as ARRAY
;
DIM
: scalar Integer in the range 1 to N, where N is the rank of ARRAY
;
MASK
: type Logical, and either scalar or an array with the same shape as ARRAY
;
IDENTITY
: scalar with the same declared type and type parameters as ARRAY
;
ORDERED
: scalar of type Logical;
Result : Same type and type parameters as ARRAY
.
The result is ARRAY
reduced by the user-supplied OPERATION
.
If DIM
is absent, the whole (masked) ARRAY
is reduced to a scalar result.
If DIM
is present, the result has rank N-1 and the shape of ARRAY
with dimension DIM
removed; each element of the result is the reduction of the masked elements in that dimension.
If exactly one element contributes to a result value, that value is equal to the element; that is, OPERATION
is only invoked
when more that one element appears.
If no elements contribute to a result value, the IDENTITY
argument must be present, and that value is equal to IDENTITY
.
For example,
Module triplet_m Type triplet Integer i,j,k End Type Contains Pure Type(triplet) Function tadd(a,b) Type(triplet),Intent(In) :: a,b tadd%i = a%i + b%i tadd%j = a%j + b%j tadd%k = a%k + b%k End Function End Module Program reduce_example Use triplet_m Type(triplet) a(2,3) a = Reshape( [ triplet(1,2,3),triplet(1,2,4), & triplet(2,2,5),triplet(2,2,6), & triplet(3,2,7),triplet(3,2,8) ], [ 2,3 ] ) Print 1, Reduce(a,tadd) Print 1, Reduce(a,tadd,1) Print 1, Reduce(a,tadd,a%i/=2) Print 1, Reduce(Array=a,Dim=2,Operation=tadd) Print 1, Reduce(a, Mask=a%i/=2, Dim=1, Operation=tadd, Identity=triplet(0,0,0)) 1 Format(1x,6('triplet(',I0,',',I0,',',I0,')',:,'; ')) End ProgramThis will produce the output:
triplet(12,12,33) triplet(2,4,7); triplet(4,4,11); triplet(6,4,15) triplet(8,8,22) triplet(6,6,15); triplet(6,6,18) triplet(2,4,7); triplet(0,0,0); triplet(6,4,15)
ATOMIC_ADD
, ATOMIC_AND
, ATOMIC_CAS
, ATOMIC_FETCH_ADD
,
ATOMIC_FETCH_AND
, ATOMIC_FETCH_OR
, ATOMIC_FETCH_XOR
, ATOMIC_OR
and ATOMIC_XOR
are described under Advanced coarray programming.
CO_BROADCAST
, CO_MAX
, CO_MIN
, CO_REDUCE
and
CO_SUM
are described under Advanced coarray programming.
COSHAPE
, EVENT_QUERY
, FAILED_IMAGES
, GET_TEAM
, IMAGE_STATUS
,
STOPPED_IMAGES
, and TEAM_NUMBER
, and the changes to the intrinsic functions NUM_IMAGES
and
THIS_IMAGE
, are described under Advanced coarray programming.