HP Fortran Programmer's Reference (September 2007)

Arrays
Array declarations
Chapter 366
subscript in the last dimension of an assumed-size array may extend from the lower bound to
a value that does not cause the reference to go beyond the storage associated with the actual
argument.
Because the last dimension of an assumed-size array has no upper bound, the dimension has
no extent and the array consequently has no shape. The name of an assumed-size array
therefore cannot appear in contexts in which a shape is required, such as a function result or
a whole array reference.
The following example, assumed_size.f90, illustrates two assumed-size arrays: x (declared in
subr) and i_array (declared in func):
Example 3-2 assumed_size.f90
PROGRAM main
REAL :: a(2,3) ! an explicit-shape array, represented by the
! vector [10, 10]
k = 0
DO i = 1, 3
DO j = 1, 2
k = k + 1
a(j, i) = k
END DO
END DO
PRINT *, 'main: a =', a
CALL subr (a)
END PROGRAM main
SUBROUTINE subr(x)
REAL :: x(2,*) ! an assumed-size array; the subscript for the
! last dimension may take any value 1 - 3
! PRINT *, x ! ILLEGAL, whole array reference not allowed
PRINT *, ‘main: x(2, 2) = ‘, x(2, 2)
PRINT *, 'returned by func: ', func(x), ', the value in x(2,3)'
END SUBROUTINE subr
REAL FUNCTION func(y)
REAL :: y(0:*) ! an assumed-size array; the subscript may
! take any value 0 - 5
func = y(5)
END FUNCTION func
Here are the command lines to compile and execute the program, along with the output from
a sample run: