10.4 ENDFILE Statement

The ENDFILE statement writes an end-of-file record to the specified unit. It takes one of the following forms:

ENDFILE ([UNIT=]u [,ERR=s] [,IOSTAT=ios])
ENDFILE u
u
Is a logical unit number.
s
Is the label of the executable statement that receives control if an error occurs.
ios
Is an integer scalar memory reference that is defined as a positive integer if an error occurs and zero if no error occurs.

Rules and Behavior

If the unit specified in the ENDFILE statement is not open, the default file is opened for unformatted output.

An end-of-file record can be written only to files with sequential organization that are accessed as formatted-sequential or unformatted-segmented sequential files. For example, the following statement writes an end-of-file record to the logical unit 2:

ENDFILE 2

An ENDFILE statement must not be issued for a file that is open for direct access. End-of-file records should not be written in files that are read by programs written in a language other than Fortran.


Note
If you specify the compiler option VMS and an ENDFILE is performed on a sequential unit, an actual one byte record containing a Ctrl/Z is written to the file. If this option is not specified, an internal ENDFILE flag is set and the file is truncated. The VMS option does not affect ENDFILE on relative files; such files are truncated.


Previous Page Next Page Table of Contents