Other arrays can depend on dummy arguments, these are called automatic arrays and their size is determined by the values of dummy arguments. These arrays have local scope and a limited lifespan and, as they have their size determined by dummy arguments and are created and destroyed with each invocation of the procedure, cannot have the SAVE attribute (or be initialised). Arrays of this class are traditionally used for workspace.
Consider,
PROGRAM Main IMPLICIT NONE INTEGER :: IX, IY .... CALL une_bus_riot(IX,2,3) CALL une_bus_riot(IY,7,2) CONTAINS SUBROUTINE une_bus_riot(A,M,N) INTEGER, INTENT(IN) :: M, N INTEGER, INTENT(INOUT) :: A(:,:) REAL :: A1(M,N) ! automatic REAL :: A2(SIZE(A,1),SIZE(A,2)) ! ditto REAL :: A3(A(1,1),A(1,1)) ! automatic ... END SUBROUTINE END PROGRAM Main
The bound specifiers of an automatic array can originate from:
There is currently no way to tell whether an automatic array has been created. Typically, if there is insufficient memory to allocate an automatic array, the program will ungracefully crash. If this is not desired then the less intuitive allocatable array should be used.
Return to corresponding overview page