You can refer to a whole record, or to an individual field in a record, and since structures can be nested, a field can itself be a structure, so you can refer to fields within fields, within fields, and so forth.
The syntax of record and field reference is:
record-name[.field-name] ... [.field-name] | |
---|---|
record-name |
Name of a previously defined record variable |
field-name |
Name of a field in the record immediately to the left. |
Example: References that are based on structure and records of the above two examples:
... RECORD /PRODUCT/ CURRENT, PRIOR, NEXT, LINE(10) ... CURRENT = NEXT LINE(1) = CURRENT WRITE ( 9 ) CURRENT NEXT.ID = 82
In the above example:
The first assignment statement copies one whole record (all five fields) to another record.
The second assignment statement copies a whole record into the first element of an array of records.
The WRITE statement writes a whole record.
The last statement sets the ID of one record to 82.
Example: Structure and record declarations, record and field assignments:
demo% cat str1.f * str1.f Simple structure STRUCTURE / S / INTEGER*4 I REAL*4 R END STRUCTURE RECORD / S / R1, R2 R1.I = 82 R1.R = 2.7182818 R2 = R1 WRITE ( *, * ) R2.I, R2.R STOP END demo% f77 -silent str1.f demo% a.out 82 2.718280 demo%