Writes end-of-file record to file.
Syntax
The syntax of the ENDFILE statement can take one of the following forms:
Short form:
ENDFILE integer-expression |
Long form:
ENDFILE (io-specifier-list) |
- integer-expression
is the number of the unit connected to a sequential
file.
- io-specifier-list
is a list of the following comma-separated I/O specifiers:
- [UNIT=]unit
specifies the
unit connected to a device or external file opened for sequential access. unit must be an integer expression that evaluates to a
nonnegative number. If the optional keyword UNIT= is omitted, unit must be the first item in io-specifier-list.
- ERR=stmt-label
specifies the
label of the executable statement to which control passes if an error
occurs during statement execution.
- IOSTAT=integer-variable
returns the
I/O status after the statement executes. If the statement executes
successfully, integer-variable is set to zero. If an error occurs, it is set to
a positive integer that indicates which error occurred.
Description
The ENDFILE statement writes an end-of-file record to the
file or device connected to the specified unit at the current position
and positions the file after the end-of-file record.
An end-of-file record can occur only as the last record of
a disk file. After execution of an ENDFILE statement, the file is positioned beyond the end-of-file
record; any records beyond the current position are lost—that
is, the file is truncated.
Some devices (for example, magnetic tape units) can have multiple
end-of-file records, with or without intervening data records.
An end-of-file record can be written to a sequential file
only.
Examples
The following statement writes an end-of-file record to the
file connected to unit 10:
The following statement writes an end-of-file record to the
file connected to unit 17. If an error occurs during the execution
of the statement, control passes to the statement at label 99, and the
error code is returned in ios:
INTEGER :: ios ... ENDFILE (17, ERR=99, IOSTAT=ios) |
Related statements
BACKSPACE, OPEN, and REWIND
Related concepts
For information about I/O concepts, see Chapter 8 “I/O
and file handling”, which also lists example programs that
use I/O. For information about I/O formatting, see Chapter 9 “I/O
formatting”.