FORTRAN 77 Language Reference

STRUCTURE

The STRUCTURE @ statement organizes data into structures.

STRUCTURE [/structure-name/] [field-list]

      field-declaration

     field-declaration

    . . .

END STRUCTURE

Each field declaration can be one of the following:

Description

A STRUCTURE statement defines a form for a record by specifying the name, type, size, and order of the fields that constitute the record. Optionally, it can specify the initial values.

A structure is a template for a record. The name of the structure is included in the STRUCTURE statement, and once a structure is thus defined and named, it can be used in a RECORD statement.

The record is a generalization of the variable or array--where a variable or array has a type, the record has a structure. Where all the elements of an array must be of the same type, the fields of a record can be of different types.

Structures, fields, and records are described in "Structures".

Restrictions

The name is enclosed in slashes and is optional in nested structures only.

If slashes are present, a name must be present.

You can specify the field-list within nested structures only.

There must be at least one field-declaration.

Each structure-name must be unique among structures, although you can use structure names for fields in other structures or as variable names.

The only statements allowed between the STRUCTURE statement and the END STRUCTURE statement are field-declaration statements and PARAMETER statements. A PARAMETER statement inside a structure declaration block is equivalent to one outside.

Restrictions for Fields

Fields that are type declarations use the identical syntax of normal FORTRAN type statements, and all f77 types are allowed, subject to the following rules and restrictions:

In a structure declaration, the offset of field n is the offset of the preceding field, plus the length of the preceding field, possibly corrected for any adjustments made to maintain alignment.

You can initialize a field that is a variable, array, substring, substructure, or union.

Examples

Example 1: A structure of five fields:


       STRUCTURE /PRODUCT/ 
              INTEGER*4 ID / 99 / 
              CHARACTER*16 NAME 
              CHARACTER*8 MODEL / 'Z' / 
              REAL*4 COST 
              REAL*4 PRICE 
       END STRUCTURE 
       RECORD /PRODUCT/ CURRENT, PRIOR, NEXT, LINE(10) 

In the above example, a structure named PRODUCT is defined to consist of the fields ID, NAME, MODEL, COST, and PRICE. Each of the three variables, CURRENT, PRIOR, and NEXT, is a record which has the PRODUCT structure, and LINE is an array of 10 such records. Every such record has its ID initially set to 99, and its MODEL initially set to Z.

Example 2: A structure of two fields:


       STRUCTURE /VARLENSTR/ 
              INTEGER*4 NBYTES 
              CHARACTER A*25 
       END STRUCTURE 
       RECORD /VARLENSTR/ VLS 
       VLS.NBYTES = 0