XL Fortran for AIX 8.1

Language Reference


Assumed-Size Arrays

Assumed-size arrays are dummy argument arrays where the size is inherited from the associated actual array, but the rank and extents may differ. They can only be declared inside subprograms.

Assumed_size_spec
>>-+----------------------------------------+--+----------------+--*-><
   | .-,-------------------------------.    |  '-lower_bound--:-'
   | V                                 |    |
   '---+----------------+--upper_bound-+--,-'
       '-lower_bound--:-'
 
 

lower_bound, upper_bound
are specification expressions

If any bound is not constant, the array must be declared inside a subprogram and the nonconstant bounds are determined on entry to the subprogram. If a lower bound is omitted, its default value is 1.

The last dimension has no upper bound and is designated instead by an asterisk. You must ensure that references to elements do not go past the end of the actual array.

The rank equals one plus the number of upper_bound specifications in its declaration, which may be different from the rank of the actual array it is associated with.

The size is assumed from the actual argument that is associated with the assumed-size array:

Examples of Assumed-Size Arrays

INTEGER X(3,2)
DO I = 1,3
   DO J = 1,2
      X(I,J) = I * J      ! The elements of X are 1, 2, 3, 2, 4, 6
   END DO
END DO
PRINT *,SHAPE(X)          ! The shape is (/ 3, 2 /)
PRINT *,X(1,:)            ! The first row is (/ 1, 2 /)
CALL SUB1(X)
CALL SUB2(X)
END
SUBROUTINE SUB1(Y)
  INTEGER Y(2,*)          ! The dimensions of y are the reverse of x above
  PRINT *, SIZE(Y,1)      ! We can examine the size of the first dimension
                          ! but not the last one.
  PRINT *, Y(:,1)         ! We can print out vectors from the first
  PRINT *, Y(:,2)         ! dimension, but not the last one.
END SUBROUTINE
SUBROUTINE SUB2(Y)
  INTEGER Y(*)            ! Y has a different rank than X above.
  PRINT *, Y(6)           ! We have to know (or compute) the position of
                          ! the last element.  Nothing prevents us from
                          ! subscripting beyond the end.
END SUBROUTINE

Notes:

  1. An assumed-size array cannot be used as a whole array in an executable construct unless it is an actual argument in a subprogram reference that does not require the shape:
    ! A is an assumed-size array.
    
    PRINT *, UBOUND(A,1) ! OK - only examines upper bound of first dimension.
    PRINT *, LBOUND(A)   ! OK - only examines lower bound of each dimension.
    ! However, 'B=UBOUND(A)' or 'A=5' would reference the upper bound of
    ! the last dimension and are not allowed.  SIZE(A) and SHAPE(A) are
    ! also not allowed.
    

  2. If a section of an assumed-size array has a subscript triplet as its last section subscript, the upper bound must be specified. (Array sections and subscript triplets are explained in a subsequent section.)
    ! A is a 2-dimensional assumed-size array
    PRINT *, A(:, 6)       ! Triplet with no upper bound is not last dimension.
    PRINT *, A(1, 1:10)    ! Triplet in last dimension has upper bound of 10.
    PRINT *, A(5, 5:9:2)   ! Triplet in last dimension has upper bound of 9.
    


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