## 2.2.5 Records

A record is an aggregate entity containing one or more elements. (Record elements are also called fields or components.) You can use records when you need to declare and operate on multi- field data structures in your programs.

On VAX systems, you can also access records in the VAX common data dictionary (CDD) to use in your programs.

Note
  Do not confuse a Fortran record with an OpenVMS RMS I/O system record or a Tru64 UNIX Fortran I/O system record. Fortran records are named data entities with one or more fields that you create in your program.

A record is similar to an array because they both contain one or more elements. However, a record differs from an array in the following respects:

- Unlike arrays, which are defined by a single declaration statement, creating a record is a two-step process:

  1. You must define the form of the record with a multistatement structure declaration.

  2. You must declare the record as an entity with a symbolic name, thereby establishing its structure in memory. More than one RECORD statement can refer to a given structure.

- Unlike arrays, whose data elements must have the same data type, records can have fields with different data types. Because records have heterogeneous data elements, they are not given data types as arrays are. Record fields can be operated on individually or collectively.

- Unlike array elements, each element of a record can be named. References to a record element consist of both the name of the record containing the element and the name of the desired element.

Structure Declarations

A structure declaration (also called a structure declaration block>cparen> is a named group of statements that define the form of a record. To establish a structure declaration in memory, the name of the structure must be specified in a RECORD statement.

A structure declaration includes one or more of the following items:

- Type declarations (or field declarations): Type declaration statements (for scalars or arrays) have the form of normal Fortran type declaration statements. Data items with different types can be freely mixed within a structure declaration. For example, INTEGER and LOGICAL data items can be declared in the same structure.

  Unnamed fields can be declared in a structure by specifying %FILL in place of an actual field name. You can use this mechanism to generate space in a record for purposes such as alignment. Unnamed fields cannot be initialized. For example, the following field declaration is invalid and generates an error message:

      INTEGER*4 %FILL /1980/

- Substructure declarations: Substructures can be established within a structure by using one of the following:

  - Nested structure declarations: In a nested structure declaration, specify one or more field names in its STRUCTURE statement. This nested structure declaration can optionally be given a structure name for later reference by a RECORD statement.

  - RECORD statements: You can incorporate fields in another, previously declared, structure declaration, by including (within the new structure declaration) a RECORD statement naming the other structure.

    You can use this feature to create a structure declaration, and then include it (if necessary) as a substructure declaration within other structure declarations. Depending on the needs of an application, this can have advantages over the use of nested structure declarations, which are individually coded within a containing, outer structure.

- Union Declarations: Union declarations are made up of one or more mapped field declarations. Mapped field declarations are made up of type declarations, substructure declarations, or other mapped field declarations.

  Unlike type declarations, all mapped field declarations that are made within a single union declaration share a common location within the containing structure. This capability is similar to using EQUIVALENCE statements to give names to variables and arrays. In other languages, it is called a "variant record" capability.

- PARAMETER statements: PARAMETER statements can appear in a structure declaration and have the same effect as if they appeared outside the declaration block.

For More Information:

- On type declarations, in general, see Section 4.5; on structure declarations, see Section 4.17.1.

- On the EQUIVALENCE statement, see Section 4.7.

- On the PARAMETER statement, see Section 4.12.

- On the RECORD statement, see Section 4.15.

- On structure declarations, see Section 4.17.

- On substructure declarations, see Section 4.17.2.

- On union declarations, see Section 4.17.3.

Previous Page Next Page Table of Contents