HP 3000 Manuals

Records [ HP FORTRAN 77/iX Reference ] MPE/iX 5.0 Documentation


HP FORTRAN 77/iX Reference

Records 

A record is a collection of one or more data items called fields.  The
fields of a record can be of any type including records or structures.
Like arrays, records can contain more than one data element.  Unlike
arrays, records can contain data elements of different types.  An array
element is identified with a unique index, a record element is accessed
with a unique name.

Structure Declarations 

Structure declarations are used to define the form of a record.  The
STRUCTURE statement specifies the name of the structure.  The name is
used by the RECORD statement to identify the structure that is used as
the form for a record.

A structure establishes the size, shape, type, and names of the different
fields.  A structure declaration does not allocate storage.  A record
declaration establishes a memory reference using the declared structure.
There can be more than one record for a given structure declaration.

A structure is declared with a statement block, starting with the
STRUCTURE statement and ending with the END STRUCTURE statement.  The
following statements can be used within the block to define the
structure:

   *   Data type declarations that define the fields within the
       structure.

   *   Substructures that are nested structure declarations.

   *   Mapped common area (union declarations).

Examples 

The following example declares the structure birth which contains four
fields:  day, month, birth_yr, and curr_yr.  Notice that curr_yr is
initialized as 1989.  Records defined with the structure birth will have
the field curr_yr initialized to 1989.

     STRUCTURE /birth/
     LOGICAL*1 day, month
     INTEGER*2 birth_yr
     INTEGER*2 curr_yr /1989/
     END STRUCTURE

In the following example, the structure student is declared.  It contains
the fields name, sex, school_yr, and b_date.  Notice that name and b_date
are also structures, or substructures within the structure student.  The
structure name is unnamed because it is not declared with slashes as
student is declared.  However, name does contain the fields last, first,
and middle.  The record b_date has the form of structure birth, the
structure declared in the example above.

     STRUCTURE /student/
     STRUCTURE /name/
     CHARACTER*20 last, first, middle
     END STRUCTURE
     CHARACTER*1 sex
     LOGICAL*1 school_yr
     RECORD /birth/ b_date
     END STRUCTURE

Record Declarations 

Records are comparable to variables and arrays.  The name of a structure
is used to define the data type of the record.  The RECORD statement is
similar to a type declaration, since it can define record scalars and
arrays.

Example 

The following example is based on the structure student (which has the
structure birth used within it), shown in the previous section.

     RECORD /student/ class(30)

The above RECORD statement creates an array of 30 records that have the
structure student.  In all 30 records, the field values are undefined
except b_date.curr_yr which is initialized to 1989 in the birth structure
declaration.

Record References 

A field in a record is referenced by combining the record name and the
field name with a period (.).  If a record or a field is an array, its
name can be subscripted.

Syntax 

recspec [.  fieldspec][...]

-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
|       Item        |        Description/Default         |            Restrictions            |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| recspec           | The name of a record.  If it is an | If the record is an array and a    |
|                   | array, the name may be             | fieldspec is present, the recspec  |
|                   | subscripted.                       | must include a subscript.          |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------
|                   |                                    |                                    |
| fieldspec         | The name of a field within the     | If the field is an array and a     |
|                   | record.  If the field is an array, | following fieldspec is present,    |
|                   | the name may be subscripted.       | the current fieldspec must include |
|                   |                                    | a subscript.                       |
|                   |                                    |                                    |
-----------------------------------------------------------------------------------------------

Examples 

Using the record array class, which was defined in the previous section,
the following variables can be specified:

     class(3).name.first(1:10)     A character substring 

     class(5).school_yr     A LOGICAL*1 element 

     class     An array 

     class(30)     A record 

     class(15).b_date     A record 

     class(15).b_date.birth_yr     An INTEGER*2 element 



MPE/iX 5.0 Documentation