Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

References to Record Fields

References to record fields must correspond to the kind of field being referenced. Aggregate field references refer to composite structures (and substructures). Scalar field references refer to singular data items, such as variables.

An operation on a record can involve one or more fields.

Record field references take one of the following forms:

Aggregate Field Reference:

record-name [.aggregate-field-name] ...

Scalar Field Reference:

record-name [.aggregate-field-name] ... .scalar-field-name

record-name

Is the name used in a RECORD statement to identify a record.

aggregate-field-name

Is the name of a field that is a substructure (a record or a nested structure declaration) within the record structure identified by the record name.

scalar-field-name

Is the name of a data item (having a data type) defined within a structure declaration.

Description

Records and record fields cannot be used in DATA statements, but individual fields can be initialized in the STRUCTURE definition.

An automatic array cannot be a record field.

A scalar field reference consists of the name of a record (as specified in a RECORD statement) and zero or more levels of aggregate field names followed by the name of a scalar field. A scalar field reference refers to a single data item (having a data type) and can be treated like a normal reference to a Fortran variable or array element.

You can use scalar field references in statement functions and in executable statements. However, they cannot be used in COMMON, SAVE, NAMELIST, or EQUIVALENCE statements, or as the control variable in an indexed DO-loop.

Type conversion rules for scalar field references are the same as those for variables and array elements.

An aggregate field reference consists of the name of a record (as specified in a RECORD statement) and zero or more levels of aggregate field names.

You can only assign an aggregate field to another aggregate field (record = record) if the records have the same structure. Intel® Fortran supports no other operations (such as arithmetic or comparison) on aggregate fields.

Intel Fortran requires qualification on all levels. While some languages allow omission of aggregate field names when there is no ambiguity as to which field is intended, Intel Fortran requires all aggregate field names to be included in references.

You can use aggregate field references in unformatted I/O statements; one I/O record is written no matter how many aggregate and array name references appear in the I/O list. You cannot use aggregate field references in formatted, namelist, and list-directed I/O statements.

You can use aggregate field references as actual arguments and record dummy arguments. The declaration of the dummy record in the subprogram must match the form of the aggregate field reference passed by the calling program unit; each structure must have the same number and types of fields in the same order. The order of map fields within a union declaration is irrelevant.

Records are passed by reference. Aggregate field references are treated like normal variables. You can use adjustable arrays in RECORD statements that are used as dummy arguments.

Examples

The following examples show record and field references. Consider the following structure declarations:

Structure DATE:

 STRUCTURE /DATE/
   INTEGER*1 DAY, MONTH
   INTEGER*2 YEAR
 STRUCTURE

Structure APPOINTMENT:

 STRUCTURE /APPOINTMENT/
   RECORD /DATE/      APP_DATE
   STRUCTURE /TIME/   APP_TIME(2)
     INTEGER*1        HOUR, MINUTE
   END STRUCTURE
   CHARACTER*20       APP_MEMO(4)
   LOGICAL*1          APP_FLAG
 END STRUCTURE

The following RECORD statement creates a variable named NEXT_APP and a 10-element array named APP_LIST. Both the variable and each element of the array take the form of the structure APPOINTMENT.

 RECORD /APPOINTMENT/    NEXT_APP,APP_LIST(10)

Each of the following examples of record and field references are derived from the previous structure declarations and RECORD statement:

Aggregate Field References

  • The record NEXT_APP:

     NEXT_APP
  • The field APP_DATE, a 4-byte array field in the record array APP_LIST(3):

     APP_LIST(3).APP_DATE

Scalar Field References

  • The field APP_FLAG, a LOGICAL field of the record NEXT_APP:

     NEXT_APP.APP_FLAG
  • The first character of APP_MEMO(1), a CHARACTER*20 field of the record NEXT_APP:

     NEXT_APP.APP_MEMO(1)(1:1)
NOTE:

Because periods are used in record references to separate fields, you should avoid using relational operators (.EQ., .XOR.), logical constants (.TRUE., .FALSE.), and logical expressions (.AND., .NOT., .OR.) as field names in structure declarations. Dots can also be used instead of % to separate fields of a derived type.

Consider the following example:

module mod
   type T1_t
     integer :: i
   end type T1_t
  type T2_t
     type (T1_t) :: eq
     integer     :: i
  end type T2_t

  interface operator (.eq.)
     module procedure eq_func
  end interface operator (.eq.)
contains
  function eq_func(t2, i) result (rslt)
  type(T2_t), intent (in) :: t2
  integer,    intent (in) :: i
      rslt = t2%eq%i + i
  end function eq_func
end module mod

use mod
type(T2_t) :: t2
integer    :: i
  t2%eq%i = 0
  t2%i    = -10
  i       = -10
  print *, t2.eq.i, (t2).eq.i
end

In this case, the reference "t2.eq.i" prints 0. The reference "(t2).eq.i" will invoke eq_func and will print -10.

See Also