HP Fortran Programmer's Reference (September 2007)

HP Fortran statements
STRUCTURE (extension)
Chapter 10 469
If /
struct-name
/ is present in a nested structure definition, the structure
struct-name
can
also be used in subsequent record declarations. For example, the following code defines a
structure named person, which contains a nested structure named name. The structure’s field
name is nm and contains three CHARACTER*10 fields: last, first, and mid.
STRUCTURE /person/
INTEGER :: person_id
! Define the nested structure 'name' with the field name 'nm'.
STRUCTURE /name/ nm
CHARACTER(LEN=10) :: last, first, mid
END STRUCTURE
END STRUCTURE
Given this definition, the following code defines the record p of structure person and the
record n of structure name:
RECORD /person/p
RECORD /name/n
If /
struct-name
/ is not present, then the structure can be used only in this declaration. For
example, we could redefine the person structure so that the nested structure no longer has a
name:
STRUCTURE /person/
INTEGER :: person_id
STRUCTURE nm
CHARACTER(LEN=10) :: last, first, mid
END STRUCTURE
END STRUCTURE
There is no way to declare a separate record of the nested structure because it has no name.
Note, however, that the nested structure still has a field name, nm. The field name is required.
To declare an array of nested structures, simply specify a dimension declarator with the
structure’s field name. For example, the following structure definition contains a nested,
3-element array of structures with field name phones of structure phone:
STRUCTURE /person/
INTEGER :: person_id
! Define the nested structure 'name' with the field name 'nm'.
STRUCTURE /name/ nm
CHARACTER(LEN=10) :: last, first, mid
END STRUCTURE
! Nested array of structures.
STRUCTURE /phone/ phones(3)
INTEGER(KIND=2) :: area_code
INTEGER :: number
END STRUCTURE
END STRUCTURE