A.1 DEFINE FILE Statement

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 an integer constant or variable that specifies the logical unit number.
m
Is an integer constant or variable that specifies the number of records in the file.
n
Is an 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 an 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.

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, one of the following events occur:

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 integer 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.

Example

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)


Previous Page Next Page Table of Contents