# 12.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.

An ENDFILE statement must not be issued for a file that is open for 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.

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:

- On the UNIT control specifier, see Section 10.2.1.1.
- On the ERR control specifier, see Section 10.2.1.8.
- On the IOSTAT control specifier, see Section 10.2.1.7.
- On record position, advancement, and transfer, see your user manual.

Previous Page Next Page Table of Contents