9.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 opened for sequential access having either relative or sequential organization. Relative files must have formatted, fixed-length records. Files with sequential orgainization must be accessed as formatted or unformatted-segmented files.

An ENDFILE statement must not be issued for a file that is open for direct or keyed access.

An end-of-file record written to a file on magnetic tape is not the same as a tape mark.

End-of-file records should not be written in files that are read by programs written in a language other than Fortran, because other languages do not support the embedded end-of-file concept.


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.

In the following example, an end-of-file record is written to logical unit 2:

ENDFILE 2


Previous Page Next Page Table of Contents