Statement: For sequential files, writes an end-of-file record to the file and positions the file after this record (the terminal point). For direct access files, truncates the file after the current record.
It can have either of the following forms:
Syntax
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 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.
If a parameter of the ENDFILE statement is an expression that calls a function, that function must not cause an I/O statement or the EOF intrinsic function to be executed, because unpredictable results can occur.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: BACKSPACE, REWIND, Data Transfer I/O Statements, Branch Specifiers
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
.
The following shows another example:
WRITE (6, *) x
ENDFILE 6
REWIND 6
READ (6, *) y