02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

! will have the shape [ n, n ]<br />

ALLOCATE(matrix(n,n))<br />

! test allocation by assigning to array<br />

matrix(n,n) = 9.1<br />

PRINT *, 'matrix(',n,',',n,') = ', matrix(n,n)<br />

! sts is assigned the value .TRUE. as the allocatable array<br />

! does exist and its allocation status is therefore allocated<br />

sts = ALLOCATED(matrix)<br />

PRINT *, 'Status of matrix after ALLOCATE: ', sts<br />

DEALLOCATE (matrix)<br />

! sts is assigned the value .FALSE. as the<br />

! allocation status of a deallocated array<br />

sts = ALLOCATED (matrix)<br />

PRINT *, 'Status of matrix after DEALLOCATE: ', sts<br />

END SUBROUTINE test_alloc_array<br />

Arrays<br />

Array declarations<br />

Here are the command lines to compile and execute the program, along with the output from<br />

asamplerun:<br />

$ f90 alloc_array.f90<br />

$ a.out<br />

Initial status of matrix: F<br />

Enter an integer (rank of array to be allocated):<br />

4<br />

matrix( 4 , 4 ) = 9.1<br />

Status of matrix after ALLOCATE: T<br />

Status of matrix after DEALLOCATE: F<br />

For information about the ALLOCATABLE, ALLOCATE, DEALLOCATE statements, see Chapter 10,<br />

“<strong>HP</strong> <strong>Fortran</strong> Statements.” See also “ALLOCATED(ARRAY)” on page 486.<br />

Assumed-size arrays<br />

An assumed-size array is a dummy argument whose size is taken from the associated<br />

actual argument. Its declaration specifies the rank and the extents for each dimension except<br />

the last. The extent of the last dimension is represented by an asterisk (*), as in the following:<br />

INTEGER :: a(2,5,*)<br />

All dummy array arguments and their corresponding actual arguments share the same initial<br />

element and are storage associated. In the case of explicit-shape and assumed-size arrays, the<br />

actual and dummy array need not have the same shape or even the same rank. The size of the<br />

dummy array, however, must not exceed the size of the actual argument. Therefore, a<br />

Chapter 4 63

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!