XL Fortran for AIX 8.1

Language Reference


Deferred-Shape Arrays

Deferred-shape arrays are allocatable arrays or array pointers, where the bounds can be defined or redefined during execution of the program.

Deferred_shape_spec_list
   .-,-.
   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.

Related Information:

Allocation Status
Pointer Assignment
ALLOCATABLE
ALLOCATED(ARRAY) or ALLOCATED(SCALAR)
ASSOCIATED(POINTER, TARGET)

Allocatable Arrays

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



Migration Tip:

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
   
  ·
  ·
  ·
DO I=1,N A(I)=B(I)+C(I) END DO END

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))
   
  ·
  ·
  ·
A=B+C END

Related Information:

Allocation Status

Array Pointers

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


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]