Deferred-shape arrays are allocatable arrays or array pointers, where the bounds can be defined or redefined during execution of the program.
.-,-. V | >>---:-+-------------------------------------------------------><
The extent of each dimension (and the related properties of bounds, shape, and size) is undefined until the array is allocated or the pointer is associated with an array that is defined. Before then, no part of the array may be defined, or referenced except as an argument to an appropriate inquiry function. At that point, an array pointer assumes the properties of the target array, and the properties of an allocatable array are specified in an ALLOCATE statement.
The rank is the number of colons in the deferred_shape_spec_list.
Although a deferred_shape_spec_list may sometimes appear identical to an assumed_shape_spec_list, deferred-shape arrays and assumed-shape arrays are not the same. A deferred-shape array must have either the POINTER attribute or the ALLOCATABLE attribute, while an assumed-shape array must be a dummy argument that does not have the POINTER attribute. The bounds of a deferred-shape array, and the actual storage associated with it, can be changed at any time by reallocating the array or by associating the pointer with a different array, while these properties remain the same for an assumed-shape array during the execution of the containing subprogram.
A deferred-shape array that has the ALLOCATABLE attribute is referred to as an allocatable array. Its bounds and shape are determined when storage is allocated for it by an ALLOCATE statement.
INTEGER, ALLOCATABLE, DIMENSION(:,:,:) :: A ALLOCATE(A(10,-4:5,20)) ! Bounds of A are now defined (1:10,-4:5,1:20) DEALLOCATE(A) ALLOCATE(A(5,5,5)) ! Change the bounds of A
Minimize storage used:
FORTRAN 77 source
INTEGER A(1000),B(1000),C(1000) C 1000 is the maximum size WRITE (6,*) "Enter the size of the arrays:" READ (5,*) N
Fortran 90 or Fortran 95 source
INTEGER, ALLOCATABLE, DIMENSION(:) :: A,B,C WRITE (6,*) "Enter the size of the arrays:" READ (5,*) N ALLOCATE (A(N),B(N),C(N))
An array with the POINTER attribute is referred to as an array pointer. Its bounds and shape are determined when it is associated with a target through pointer assignment or execution of an ALLOCATE statement. It can appear in a type declaration, POINTER, or DIMENSION statement.
REAL, POINTER, DIMENSION(:,:) :: B REAL, TARGET, DIMENSION(5,10) :: C, D(10:10) B => C ! Bounds of B are now defined (1:5,1:10) B => D ! B now has different bounds and is associated ! with different storage ALLOCATE(B(5,5)) ! Change bounds and storage association again END