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.
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
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 ( 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)