next up previous

4.3 Dynamic Arrays

Fortran 90 has three varieties of dynamic arrays. All three allow array creation at run time with sizes determined by computed (or input) values. These three varieties of dynamic arrays are:

Automatic Arrays
Automatic arrays are local arrays whose sizes depend upon values associated with dummy arguments. Automatic arrays are automatically created (allocated) upon entry to the procedure and automatically deallocated upon exit from the procedure. The size of an automatic array typically is different in different activations of the procedure. Examples of automatic arrays are:
function F18(A,N)
 integer  N                    ! A scalar
 real A(:,:)                   ! An assumed shape array
 real F18(size(A,1)  )         ! The function result itself is
                               !  an automatic array.

 complex  Local_1(N,2*N+3)     ! Local_1 is an automatic array
                               !  whose size is based on N.

 real Local_2(size(A,1),size(A,2))     ! Local_2 is an automatic array
                               !  exactly the same size as A.

 real Local_3(4*size(A,2))     ! Local_3 is a one-dimensional 
                               !  array 4 times the size of 
                               ! the second dimension of A.
 ...                           !  
end function F18
Note the importance of the intrinsic inquiry functions, such as SIZE (which returns the argument array size in a specified dimension) in declaring automatic arrays. Fortran 90 provides a number of inquiry functions that are allowed to appear in declarations. Array bounds and sizes, character lengths, and type kinds may all be specified with expressions involving these inquiry functions. Roughly, a specification expression, as such expressions are called, is a scalar integer expression that has operands whose values are determinable upon entry to the procedure. Such operands include constants, references to intrinsic procedures, and variables accessible through dummy arguments, modules, common, and (in the case of module and internal procedures) the host procedure.