02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Deferred-shape arrays<br />

Arrays<br />

Array declarations<br />

A deferred-shape array has either the POINTER attribute or the ALLOCATABLE attribute. Its<br />

shape is not specified until the array is pointer assigned or allocated. Although a<br />

deferred-shape array can have the same form as an assumed-shape array, the two are<br />

different. The assumed-shape array is a dummy argument and must not have the POINTER<br />

attribute.<br />

The array specification for a deferred-shape array has the form:<br />

: [ , : ] ...<br />

The specification for a deferred-shape array defines its rank but not the bounds. The bounds<br />

are defined either when the array is allocated or when an array pointer becomes associated<br />

with a target.<br />

Array pointers and allocatable arrays are described in the following sections.<br />

Array pointers<br />

An array pointer is a deferred-shape array with the POINTER attribute.Itsboundsand<br />

shape are defined only when the array is associated with a target in a pointer assignment<br />

statement or in an ALLOCATE statement. An array pointer must not be referenced until it is<br />

associated.<br />

Following are example declarations of array pointers:<br />

! p1 is declared as a pointer to a rank-one<br />

! array of type real; p1 is not associated with any target<br />

REAL, POINTER, DIMENSION(:) :: p1<br />

! p2 is a pointer to an integer array of rank-two;<br />

! it must be associated with a target before it can be referenced<br />

INTEGER, POINTER :: p2(:,:)<br />

! err is a pointer to a rank-3 array of type err_type<br />

TYPE err_type<br />

INTEGER :: class<br />

REAL :: code<br />

END TYPE err_type<br />

TYPE(err_type), POINTER, DIMENSION(:,:,:) :: err<br />

! The next statement is ILLEGAL: pointers cannot have an<br />

! explicit shape.<br />

INTEGER, POINTER :: p3(n)<br />

For information about associating an array pointer with a target, see “Pointers” on page 49.<br />

For information about the POINTER attribute and ALLOCATE statement, see Chapter 10, “<strong>HP</strong><br />

<strong>Fortran</strong> Statements.”<br />

Chapter 4 61

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

Saved successfully!

Ooh no, something went wrong!