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.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

TYPE (declaration)<br />

Description<br />

448<br />

must be preceded by the double colon.<br />

The TYPE declaration statement specifies the type and attributes of derived-type objects. A<br />

derived-type object may be an array, which may be deferred shape (pointer or allocatable),<br />

assumed shape (dummy argument), or assumed size (dummy argument).<br />

Assignment is intrinsically defined for each derived type but may be redefined by the user.<br />

Operators appropriate to a derived type may be defined by procedures with the appropriate<br />

interfaces.<br />

When a derived-type object is used as a procedure argument, the types of the associated<br />

actual and dummy arguments must be the same. For sequence derived types different<br />

physical type definitions may be used for the actual and dummy arguments, as long as both<br />

type definitions specify identical type names, components, and component order. For<br />

nonsequenced types the same physical type definition must be used, typically accessed via<br />

host or use association, for both the actual and dummy arguments.<br />

Examples<br />

! Weather is a simple derived type with two<br />

! character components and two integer components.<br />

TYPE Weather<br />

CHARACTER(LEN=32) Place<br />

INTEGER High_temp, Low_temp<br />

CHARACTER(LEN=16) Conditions<br />

END TYPE Weather<br />

TYPE (Weather) July(num_ws, 31)<br />

! A two-dimensional Weather array for July<br />

July(:,:) % Low_temp = -40<br />

! Initialize all low temps in July<br />

TYPE Polar<br />

! Polar is a derived type with two real components that cannot be<br />

! directly accessed in Polar objects outside the module<br />

PRIVATE<br />

REAL rho, theta<br />

END TYPE Polar<br />

! Point is a derived type with three components, one of which is<br />

! itself of derived type<br />

TYPE Point<br />

REAL x, y<br />

TYPE (Polar) p<br />

END TYPE Point<br />

TYPE (Polar) r, q(500)<br />

! Two variables of type Polar<br />

Chapter 10

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

Saved successfully!

Ooh no, something went wrong!