| United States-English |
|
|
|
![]() |
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP
Fortran statementsRECORD (extension) |
|
Declares a record of a previously defined structure. Syntax
DescriptionHP Fortran supports the RECORD statement as a compatibility extension. New programs should use the derived type, a standard feature of Fortran 90. For more information about derived types, see “Derived types” and “TYPE (definition)”. The RECORD statement declares a record variable of a structure that has been previously defined by a STRUCTURE statement. A record variable can consist of multiple data items, called fields. The STRUCTURE statement is described in “STRUCTURE (extension)”. Referencing record fields The syntax for referencing a field in a record depends on whether the field itself is another record (a composite reference) or not (a simple reference). Composite references have the following syntax:
Simple references have the following syntax:
Given the following structure definition and record declarations:
the following are composite references:
and the following are simple references:
Composite references can be either to an entire record or to a record field that is itself a structure or record. Rules for record field Arrays of records can be created as follows:
or
In either case a 1000-record array called students of structure student is declared. Records can be placed in common blocks. The following code places the students array (declared above) in the common block frosh, along with variables a, b, and c:
Simple field references can appear wherever a variable can appear. The following assigns values to the fields of record r of structure struct:
Composite assignment is allowed for two records or two composite fields of the same structure—that is, the record declaration statements for both records must have specified the same struct-name. For example, the following is legal:
The following example is also valid and uses composite assignment to assign the value of the record edate of structure date to a field of the same structure (when) in the record event:
Even though the following records are of identical structures—that is, the fields of both structures have the same type, size, and format—the code is invalid because the structures have a different name:
When performing I/O on structures and records, composite record and field references can appear only in unformatted I/O statements. They are not allowed in formatted, list-directed, or namelist-directed I/O statements. However, simple field references can appear in all types of I/O statements. For information about I/O, see Chapter 9 “I/O formatting”. A record name or composite field reference can appear as either a formal or an actual argument to a subroutine or function. Formal and actual arguments must have the same size as well as the same number, type, and order of fields. Composite record and field arguments to subroutines and functions are passed by reference, just like other HP Fortran arguments. Adjustable arrays are allowed in RECORD statements that declare formal arguments. Do not name a field with any of the following:
Related statementsSTRUCTURE and TYPE Related conceptsFor related information, see the following: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||