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:
Rules and Behavior
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.
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.
DEFINE FILE 3(1000,48,U,NREC)