HP Fortran Programmer's Reference (September 2007)

Arrays
Array declarations
Chapter 3 65
! will have the shape [ n, n ]
ALLOCATE(matrix(n,n))
! test allocation by assigning to array
matrix(n,n) = 9.1
PRINT *, 'matrix(',n,',',n,') = ', matrix(n,n)
! sts is assigned the value .TRUE. as the allocatable array
! does exist and its allocation status is therefore allocated
sts = ALLOCATED(matrix)
PRINT *, 'Status of matrix after ALLOCATE: ', sts
DEALLOCATE (matrix)
! sts is assigned the value .FALSE. as the
! allocation status of a deallocated array
sts = ALLOCATED (matrix)
PRINT *, 'Status of matrix after DEALLOCATE: ', sts
END SUBROUTINE test_alloc_array
Here are the command lines to compile and execute the program, along with the output from
a sample run:
$ f90 alloc_array.f90
$ a.out
Initial status of matrix: F
Enter an integer (rank of array to be allocated):
4
matrix( 4 , 4 ) = 9.1
Status of matrix after ALLOCATE: T
Status of matrix after DEALLOCATE: F
For information about the ALLOCATABLE, ALLOCATE, DEALLOCATE statements, see Chapter 10,
“HP Fortran Statements.” See also “ALLOCATED(ARRAY)” on page 521.
Assumed-size arrays
An assumed-size array is a dummy argument whose size is taken from the associated
actual argument. Its declaration specifies the rank and the extents for each dimension except
the last. The extent of the last dimension is represented by an asterisk (*), as in the following:
INTEGER :: a(2,5,*)
All dummy array arguments and their corresponding actual arguments share the same initial
element and are storage associated. In the case of explicit-shape and assumed-size arrays, the
actual and dummy array need not have the same shape or even the same rank. The size of the
dummy array, however, must not exceed the size of the actual argument. Therefore, a