Explicit-shape arrays

Explicit-shape arrays are arrays where the bounds are explicitly specified for each dimension.

Explicit_shape_spec_list
Read syntax diagramSkip visual syntax diagram   .-,-------------------------------.
   V                                 |
>>---+----------------+--upper_bound-+-------------------------><
     '-lower_bound--:-'
 
lower_bound, upper_bound
are specification expressions

If any bound is not constant, the array must be declared inside a subprogram. The nonconstant bounds are determined on entry to the subprogram. If a lower bound is omitted, its default value is one.

The rank is the number of specified upper bounds. The shape of an explicit-shape dummy argument can differ from that of the corresponding actual argument.

The size is determined by the specified bounds.

The size of an explicit-shape dummy argument does not need to be the same as the size of the actual argument, but the size of the dummy argument cannot be larger than the size of the actual argument.

Examples of explicit-shape arrays

INTEGER A,B,C(1:10,-5:5)  ! All bounds are constant
A=8; B=3
CALL SUB1(A,B,C)
END
SUBROUTINE SUB1(X,Y,Z)
  INTEGER X,Y,Z(X,Y)      ! Some bounds are not constant
END SUBROUTINE

Automatic arrays

An automatic array is an explicit-shape array that is declared in a subprogram, is not a dummy argument or pointee array, and has at least one bound that is a nonconstant specification expression.. The bounds are evaluated on entry to the subprogram and remain unchanged during execution of the subprogram.

INTEGER X
COMMON X
X = 10
CALL SUB1(5)
END

SUBROUTINE SUB1(Y)
  INTEGER X
  COMMON X
  INTEGER Y
  REAL Z (X:20, 1:Y)         ! Automatic array.  Here the bounds are made
                             ! available through dummy arguments and common
                             ! blocks, although Z itself is not a dummy
END SUBROUTINE               ! argument.

Related information

Adjustable arrays

An adjustable array is an explicit-shape array dummy argument that has at least one non-constant bound.

SUBROUTINE SUB1(X, Y)
INTEGER X, Y(X*3)  ! Adjustable array.  Here the bounds depend on a
                   ! dummy argument, and the array name is also passed in.
END SUBROUTINE
IBM Extension

Pointee arrays

Pointee arrays are explicit-shape or assumed-size arrays that must be declared in integer POINTER statements.

The declarator for a pointee array may only contain variables if the array is declared inside a subprogram, and any such variables must be dummy arguments, members of a common block, or use or host associated. The bounds are evaluated on entry to the subprogram, and remain constant during execution of the subprogram.

With the -qddim compiler option, as explained in the XL Fortran Compiler Reference, the restrictions on which variables may appear in the array declarator are lifted, declarators in the main program may contain variable names, and any specified nonconstant bounds are re-evaluated each time the array is referenced, so that you can change the properties of the pointee array by simply changing the values of the variables used in the bounds expressions:

@PROCESS DDIM
INTEGER PTE, N, ARRAY(10)
POINTER (P, PTE(N))
N = 5
P = LOC(ARRAY(2))  !
PRINT *, PTE       ! Print elements 2 through 6 of ARRAY
N = 7              ! Increase the size
PRINT *, PTE       ! Print elements 2 through 8 of ARRAY
END

Related information:

End of IBM Extension