LF Fortran 95

File Types

Files

Fortran treats all physical devices, such as disk files, the console, printers, and internal files, as files. A file is a sequence of zero or more records. The data format (either formatted or unformatted), file access type (either direct or sequential) and record length determine the structure of the file.

File Position

Certain input/output statements affect the position within an external file. Prior to execution of a data transfer statement, a direct file is positioned at the beginning of the record indicated by the record specifier REC= in the data transfer statement. By default, a sequential file is positioned after the last record read or written. However, if non-advancing input/output is specified using the ADVANCE= specifier, it is possible to read or write partial records and to read variable-length records and be notified of their length.

An ENDFILE statement writes an endfile record after the last record read or written and positions the file after the endfile record. A REWIND statement positions the file at its initial point. A BACKSPACE statement moves the file position back one record.

If an error condition occurs, the position of the file is indeterminate.

If there is no error, and an endfile record is read or written, the file is positioned after the endfile record. The file must be repositioned with a REWIND or BACKSPACE statement before it is read from or written to again.

For non-advancing (partial record) input/output, if there is no error and no end-of-file condition, but an end-of-record condition occurs, the file is positioned after the record just read. If there is no end-of-record condition the file position is unchanged.

File Types

The type of file to be accessed is specified in the OPEN statement using the FORM= and ACCESS= specifiers (see OPEN Statement).

Formatted Sequential
Formatted Direct
Unformatted Sequential
Unformatted Direct
Binary (or Transparent)

See "File Formats" in the User's Guide for more information.

Internal Files

An internal file is always a formatted sequential file and consists of a single CHARACTER variable. If the CHARACTER variable is array-valued, each element of the array is treated as a record in the file. This feature allows conversion from internal representation (binary, unformatted) to external representation (ASCII, formatted) without transferring data to an external device.