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.
Six record types are available, as shown in the following table. The table also lists the record overhead. This refers to bytes associated with each record that are used internally by the file system and are not available when a record is read or written. Knowing the record overhead helps when estimating the storage requirements for an application. Although the overhead bytes exist on the storage media, do not include them when specifying the record length with the RECL specifier in an OPEN statement.
Record Type | Available File Organizations and Portability Considerations | Record Overhead |
---|---|---|
Fixed-length | Relative or sequential file organizations. | None for sequential or for relative if the -vms (Linux and Mac OS) or /vms (Windows) option was omitted. One byte for relative if the vms option was specified. |
Variable-length | Sequential file organization only. The variable-length record type is generally the most portable record type across multi-vendor platforms. | Eight bytes per record. |
Segmented | Sequential file organization only and only for unformatted sequential access. The segmented record type is unique to Intel Fortran and should not be used for portability with programs written in languages other than Fortran or for places where Intel Fortran is not used. However, because the segmented record type is unique to Intel Fortran products, formatted data in segmented files can be ported across Intel Fortran platforms. | Four bytes per record. One additional padding byte (space) is added if the specified record size is an odd number. |
Stream (uses no record delimiter) |
Sequential file organization only. | None required. |
Stream_CR (uses CR as record delimiter) |
Sequential file organization only. | One byte per record. |
Stream_LF (uses CR and LF as record delimiter) |
Sequential file organization only. | One byte per record. |
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 (Linux and Mac OS) or /vms (Windows and Mac OS) option:
For relative files where the vms option was omitted (the default), each record has no control information.
For relative files where the vms option was specified, each record has one byte of control information at the beginning of the record.
The following figures show the record layout of fixed-length records. The first is for all sequential and relative files where the vms option was omitted. The second is for relative files where the vms option was specified.
Variable-length records can contain any number of bytes up to a specified maximum record length, and apply only to sequential files.
Variable-length records are prefixed and suffixed by 4 bytes of control information containing length fields. The trailing length field allows a BACKSPACE request to skip back over records efficiently. The 4-byte integer value stored in each length field indicates the number of data bytes (excluding overhead bytes) in that particular variable-length record.
The character 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 an I/O list.
The record layout of variable-length records that are less than 2 gigabytes is shown below:
For a record length greater than 2,147,483,639 bytes, the record is divided into subrecords. The subrecord can be of any length from 1 to 2,147,483,639, inclusive.
The sign bit of the leading length field indicates whether the record is continued or not. The sign bit of the trailing length field indicates the presence of a preceding subrecord. The position of the sign bit is determined by the endian format of the file.
A subrecord that is continued has a leading length field with a sign bit value of 1. The last subrecord that makes up a record has a leading length field with a sign bit value of 0. A subrecord that has a preceding subrecord has a trailing length field with a sign bit value of 1. The first subrecord that makes up a record has a trailing length field with a sign bit value of 0. If the value of the sign bit is 1, the length of the record is stored in twos-complement notation.
The record layout of variable-length records that are greater than 2 gigabytes is shown below:
Files written with variable-length records by Intel Fortran programs usually cannot be accessed as text files. Instead, use the Stream_LF record format for text files with records of varying length.
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.
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:
Identifier Value | Segment Identified |
---|---|
0 |
One of the segments between the first and last segments |
1 |
First segment |
2 |
Last segment |
3 |
Only segment |
If the specified record length is an odd number, the user data will be padded with a single blank (one byte), but this extra byte is not added to the 2-byte integer record size count.
Avoid the segmented record type when the application requires that the same file be used for programs written in languages other than Intel Fortran and for non-Intel platforms.
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.
A Stream_CR or 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 are removed when you read records.
Each variety uses a different 1-byte record terminator:
Stream_CR files use only a carriage-return as the terminator, so Stream_CR files must not contain embedded carriage-return characters.
Stream_LF files use only a 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 figure below shows the layout of Stream_CR and Stream_LF records:
Before you choose a record type, consider whether your application will use formatted or unformatted data. If you are using formatted data, you can choose any record type except segmented. If you are using unformatted data, avoid the Stream, Stream_CR, and Stream_LF record types.
The segmented record type can only be used for unformatted sequential access with sequential files. You should not use segmented records for files that are read by programs written in languages other than Intel Fortran.
The Stream, Stream_CR, Stream_LF, and segmented record types can be used only with sequential files.
The default record type (RECORDTYPE) depends on the values for the ACCESS and FORM specifiers for the OPEN statement.
The record type of the 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.
An I/O record is a collection of fields (data items) that are logically related and are usually processed as a unit.
Unless you specify nonadvancing I/O (ADVANCE specifier), each Intel Fortran I/O statement transfers at least one record.