13.4 ENDFILE Statement

For sequential files, the ENDFILE statement writes an end-of-file record to the file and positions the file after this record (the terminal point). For direct access files, the ENDFILE statement truncates the file after the current record.

An ENDFILE statement takes one of the following forms:

ENDFILE ([UNIT=]io-unit [, ERR=label] [, IOSTAT=i-var])
ENDFILE io-unit

io-unit
Is an external unit specifier.

label
Is the label of the branch target statement that receives control if an error occurs.

i-var
Is a scalar integer variable 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.

An ENDFILE statement performed on a direct access file always truncates the file.

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 use the compiler option specifying OpenVMS defaults 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 option does not affect ENDFILE on relative files; such files are truncated.

Examples

The following statement writes an end-of-file record to I/O unit 2:

  ENDFILE 2
Suppose the following statement is specified:
  ENDFILE (UNIT=9, IOSTAT=IOS, ERR=10)

An end-of-file record is written to the file connected to unit 9. If an error occurs, control is transferred to the statement labeled 10, and a positive integer is stored in variable IOS.

For More Information:


Previous Page Next Page Table of Contents