Record Types

An I/O record is a collection of data items, called fields, that are logically related and are processed as a unit. The record type refers to the convention for storing fields in records.

The record type of the data within a file is not maintained as an attribute of the file. The results of using a record type other than the one used to create the file are indeterminate.

If you omit /fpscomp:ioformat during compilation, the following six record types are available:

Record Type  Available File Organizations and Portability Considerations
Fixed-length Relative or sequential file organizations.
Variable-length Sequential file organization only. The variable-length record type is generally the most portable record type across multi-vendor platforms.
Segmented Sequential file organization only and only for unformatted sequential access. The segmented record type is unique to Compaq Fortran and should not be used for portability with programs written in languages other than Fortran or for places where Compaq Fortran is not used. However, because the segmented record type is unique to Compaq Fortran products, formatted data in segmented files can be ported across Compaq Fortran platforms.
Stream
(uses no record delimiter)
Sequential file organization only.
Stream_CR
(uses CR as record delimiter)
Sequential file organization only.
Stream_LF
(uses CR and LF as record delimiter)
Sequential file organization only.

Fixed-Length Records

When you specify fixed-length records, you are specifying that all records in the file contain the same number of bytes. When you open a file that is to contain fixed-length records, you must specify the record size using the RECL keyword. A sequentially organized opened file for direct access must contain fixed-length records, to allow the record position in the file to be computed correctly.

For relative files, the layout and overhead of fixed-length records depends upon whether the program accessing the file was compiled using the /vms option or whether the /vms option was omitted:

The following figure shows the record layout of fixed-length records.

Variable-Length Records

Variable-length records can contain any number of bytes, up to a specified maximum record length, and only apply to sequential files. These records are generally prefixed and suffixed by four bytes of control information containing count fields. The 4-byte integer value stored in each count field indicates the number of data bytes (excluding overhead bytes) in that particular variable-length record.

The record layout of variable-length records appears below.

The count field of a variable-length record is available when you read the record by issuing a READ statement with a Q format descriptor. You can then use the count field information to determine how many bytes should be in the associated I/O list.

Files written with variable-length records by Compaq Fortran programs usually cannot be accessed as text files. Instead, use the Stream_LF record format for text files with records of varying length.

Segmented Records

A segmented record is a single logical record consisting of one or more variable-length, unformatted records in a sequentially organized disk file. Unformatted data written to sequentially organized files using sequential access is stored as segmented records by default.

Segmented records are useful when you want to write exceptionally long records but cannot or do not wish to define one long variable-length record, perhaps because virtual memory limitations can prevent program execution. By using smaller, segmented records, you reduce the chance of problems caused by virtual memory limitations on systems on which the program may execute.

For disk files, the segmented record is a single logical record that consists of one or more segments. Each segment is a physical record. A segmented (logical) record can exceed the absolute maximum record length (2.14 billion bytes), but each segment (physical record) individually cannot exceed the maximum record length.

To access an unformatted sequential file that contains segmented records, specify FORM='UNFORMATTED' and RECORDTYPE='SEGMENTED' when you open the file. Otherwise, the file may be processed erroneously.

As shown below, the layout of segmented records consists of 4 bytes of control information followed by the user data.

The control information consists of a 2-byte integer record length count (includes the 2 bytes used by the segment identifier), followed by a 2-byte integer segment identifier that identifies this segment as one of the following:

If the specified record length is an odd number, the user data will be padded with a single blank (1 byte), but this extra byte is not added to the 2-byte integer record length count.

Stream File Data

A stream file is not grouped into records and contains no control information. Stream files are used with CARRIAGECONTROL='NONE' and contain character or binary data that is read or written only to the extent of the variables specified on the input or output statement.

The layout of a stream file appears below.

Stream_CR Records

A stream_CR record is a variable-length record whose length is indicated by explicit record terminators embedded in the data, not by a count. These terminators are automatically added when you write records to a stream-type file, and they are removed when you read records. Stream_CR files use only a carriage-return as the terminator, so Stream_CR files must not contain embedded carriage-return characters.

The layout of stream_CR records appears below.

Stream_LF Records

A stream_LF record is a variable-length record whose length is indicated by explicit record terminators embedded in the data, not by a count. These terminators are automatically added when you write records to a stream-type file, and they are removed when you read records. Stream_LF files use a carriage return followed by line-feed (new line) as the terminator, so Stream_LF files must not contain embedded line-feed (new line) characters. This is the usual operating system text file record type.

The layout of stream_LF records appears below.