next up previous contents
Next: Array-valued Functions Up: Procedures and Array Arguments Previous: Assumed-shape Arrays

 

Automatic Arrays

 

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
     INTERFACE 
      SUBROUTINE une_bus_riot(A,M,N)
       INTEGER, INTENT(IN) :: M, N
       INTEGER, INTENT(INOUT) :: A(:,:)
      END SUBROUTINE une_bus_riot
     END INTERFACE 
      ...
     CALL une_bus_riot(IX,2,3)
     CALL une_bus_riot(IY,7,2)
      ...
    END PROGRAM Main

    SUBROUTINE une_bus_riot(A,M,N)
     IMPLICIT NONE
     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

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.

Now try this question gif


next up previous contents
Next: Array-valued Functions Up: Procedures and Array Arguments Previous: Assumed-shape Arrays

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.