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 />

STRUCTURE (extension)<br />

Nested records<br />

A field-def can be a record declaration, known as a nested record. See “RECORD<br />

(extension)” on page 414 for information about record declarations.) A nested record<br />

declaration must use a structure that has already been defined. The following code first<br />

defines the structure date. It then declares the structure event, which contains the nested<br />

record when of structure date:<br />

STRUCTURE /date/<br />

BYTE :: month, day<br />

INTEGER :: year<br />

END STRUCTURE<br />

STRUCTURE /event/<br />

CHARACTER :: what, where<br />

RECORD /date/ when<br />

END STRUCTURE<br />

A structure definition can also declare an array of nested records. For example, the following<br />

code defines the structure calendar, which contains a 100-element array of records of<br />

structure event:<br />

STRUCTURE /calendar/<br />

! number of events<br />

INTEGER(KIND=2) :: event_count<br />

RECORD /event/ events(100) ! array of event records<br />

END STRUCTURE<br />

Unions<br />

A field-def can be a union—a form of nested structure in which two or more map blocks<br />

share memory space. The UNION and MAP statements together define a union. The syntax of a<br />

union definition is:<br />

UNION<br />

map-block<br />

map-block<br />

...<br />

END UNION<br />

where map-block is defined by a MAP statement and one or more field definitions. All map<br />

blocks within the enclosing UNION statement share the same memory space in a record. The<br />

syntax for defining a map block is:<br />

MAP<br />

field-def<br />

...<br />

END MAP<br />

where field-def canbeoneofthefollowing:<br />

436<br />

Chapter 10

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

Saved successfully!

Ooh no, something went wrong!