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.

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

STRUCTURE (extension)<br />

If /struct-name/ is present in a nested structure definition, the structure struct-name can<br />

also be used in subsequent record declarations. For example, the following code defines a<br />

structure named person, which contains a nested structure named name. The structure’s field<br />

name is nm and contains three CHARACTER*10 fields: last, first, andmid.<br />

STRUCTURE /person/<br />

INTEGER :: person_id<br />

! Define the nested structure 'name' with the field name 'nm'.<br />

STRUCTURE /name/ nm<br />

CHARACTER(LEN=10) :: last, first, mid<br />

END STRUCTURE<br />

END STRUCTURE<br />

Given this definition, the following code defines the record p of structure person and the<br />

record n of structure name:<br />

RECORD /person/p<br />

RECORD /name/n<br />

If /struct-name/ is not present, then the structure can be used only in this declaration. For<br />

example, we could redefine the person structure so that the nested structure no longer has a<br />

name:<br />

STRUCTURE /person/<br />

INTEGER :: person_id<br />

STRUCTURE nm<br />

CHARACTER(LEN=10) :: last, first, mid<br />

END STRUCTURE<br />

END STRUCTURE<br />

There is no way to declare a separate record of the nested structure because it has no name.<br />

Note, however, that the nested structure still has a field name, nm. Thefieldnameisrequired.<br />

To declare an array of nested structures, simply specify a dimension declarator with the<br />

structure’s field name. For example, the following structure definition contains a nested,<br />

3-element array of structures with field name phones of structure phone:<br />

STRUCTURE /person/<br />

INTEGER :: person_id<br />

! Define the nested structure 'name' with the field name 'nm'.<br />

STRUCTURE /name/ nm<br />

CHARACTER(LEN=10) :: last, first, mid<br />

END STRUCTURE<br />

! Nested array of structures.<br />

STRUCTURE /phone/ phones(3)<br />

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

INTEGER :: number<br />

END STRUCTURE<br />

END STRUCTURE<br />

Chapter 10 435

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

Saved successfully!

Ooh no, something went wrong!