The DEFINE FILE statement establishes the size and structure of
files with relative organization and associates them with a logical
unit number. The DEFINE FILE statement is comparable to the OPEN
statement. In situations where you can use the OPEN statement, OPEN
is the preferable mechanism for creating and opening files.

The DEFINE FILE statement takes the following form:

DEFINE FILE u(m, n, U, asv) [,
u(m, n, U, asv)] . . .

u Is a scalar integer constant or variable that specifies the
logical unit number.

m Is a scalar integer constant or variable that specifies the
number of records in the file.

n Is a scalar integer constant or variable that specifies the
length of each record in 16-bit words (2 bytes).

U Specifies that the file is unformatted (binary); this is the
only acceptable entry in this position.

asv Is a scalar integer variable, called the associated variable of
the file. At the end of each direct access I/O operation, the record
number of the next higher numbered record in the file is assigned to
asv. The asv must not be a dummy argument.

The DEFINE FILE statement specifies that a file containing
m fixed-length records, each composed of n
16-bit words, exists (or will exist) on the specified logical
unit. The records in the file are numbered sequentially from 1
through m.

A DEFINE FILE statement does not itself open a file. However,
the statement must be executed before the first direct access I/O
statement referring to the specified file. The file is opened when
the I/O statement is executed.

If this I/O statement is a WRITE statement, a direct access
sequential file is opened, or created if necessary.

If the I/O statement is a READ or FIND statement, an existing file
is opened, unless the specified file does not exist. If a file does
not exist, an error occurs.

The DEFINE FILE statement establishes the variable asv as
the associated variable of a file. At the end of each direct access
I/O operation, the Fortran I/O system places in asv the
record number of the record immediately following the one just read
or written.

The associated variable always points to the next sequential
record in the file (unless the associated variable is redefined
by an assignment, input, or FIND statement). So, direct access I/O
statements can perform sequential processing on the file by using
the associated variable of the file as the record number specifier.

Examples

In the following example, the DEFINE FILE statement specifies that
the logical unit 3 is to be connected to a file of 1000 fixed-length
records; each record is forty-eight 16-bit words long.
The records are numbered sequentially from 1 through 1000 and are
unformatted. After each direct access I/O operation on this file,
the integer variable NREC will contain the record number of the
record immediately following the record just processed.