Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 10 HP Fortran statements

RECORD (extension)

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

Declares a record of a previously defined structure.

Syntax

RECORD /struct-name/rec-name [, rec-name]...
[/struct-name/rec-name [, rec-name ] ]...
struct-name

is the name of a structure declared in a previous structure definition.

rec-name

is a record name.

Description

HP 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:

rec-name [. substruct-fieldname]...

Simple references have the following syntax:

rec-name [. substruct-fieldname]... simple-fieldname
rec-name

is the name of the record in which a composite or simple field is being referenced.

substruct-field-name

is the name of a nested structure or nested record field name, if applicable.

simple-field-name

is the name of a lowest-level field, defined with a type declaration statement. As indicated by the syntax, the field could be part of a nested structure or nested record.

Given the following structure definition and record declarations:

STRUCTURE /abc/
REAL a, b, c(5)
STRUCTURE /xyz/ xyz, xyzs(5)
INTEGER x, y, z(3)
END STRUCTURE
END STRUCTURE

RECORD /abc/ abc, abcs(100)
RECORD /xyz/ xyz

the following are composite references:

abc     !composite record references
abcs(1)
xyz
abcs(idx)

abc.xyz !composite field references
abc.xyzs(3)

and the following are simple references:

abc.a
abc.c(1)
xyz.x
xyz.z(1)
abc.xyz.x
abcs(idx).xyz.y(1)
abcs(2).xyzs(3).z(1)

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:

RECORD /student/ students(1000)

or

RECORD /student/ students
DIMENSION students (1000)

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:

COMMON /frosh/ a, b, c, students

Simple field references can appear wherever a variable can appear. The following assigns values to the fields of record r of structure struct:

STRUCTURE /struct/
INTEGER i
REAL a
END STRUCTURE

RECORD /struct/ r
r.i = r.i + 1
r.a = FLOAT(r.i) - 2.7

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:

STRUCTURE /string/
BYTE len
CHARACTER*1 str(254)
END STRUCTURE
RECORD /string/ str1, str2
str1 = str2

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:

STRUCTURE /event/
CHARACTER*20 desc
STRUCTURE /date/ when
BYTE month, day
INTEGER*2 year
END STRUCTURE
END STRUCTURE

RECORD /date/ edate
RECORD /event/ event
edate.month = 1
edate.day = 6edate.year = 62
event.desc = 'Party for Joanne'
! composite assignment of record to field
! of record--both have same structure
event.when = edate

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:

STRUCTURE /intarray/
BYTE elem_count
INTEGER arr(100)
END STRUCTURE

STRUCTURE /iarray/
BYTE elem_count
INTEGER arr(100)
END STRUCTURE

RECORD /intarray/ iarray1
RECORD /iarray/ iarray2
! The next assignment won't work. The two
! records are not of the same structure.
iarray1 = iarray2 ! Invalid

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:

  • Logical constants, .TRUE. and .FALSE.

  • Logical operators, such as .OR., .AND., and .NOT.

  • Relational operators, such as .EQ., .LT., and .NEQV.

  • The name of a defined operator

Related statements

STRUCTURE and TYPE

Related concepts

For related information, see the following:

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.