ENDFILE statement
Standard: F77 F90 F95 F2003
ENDFILE expression
ENDFILE ( ef-spec-list )

ef-spec-list ::= ef-spec [ , ef-spec ]...
ef-spec::=[ UNIT= ] expression

In the ENDFILE expression form, the expression shall be a scalar integer with non-negative value; it identifies the unit.

The optional UNIT= are required unless it is the first ef-spec.

ENDFILE may also be spelled as two separate words, END FILE.
The ENDFILE statement writes an endfile record. This is a logical record that indicates the end of the file; any previous records after this point no longer exist. The endfile record need not have any physical existence. Afterwards, the file is positioned after the endfile record, and cannot be further written to unless positioned by REWIND or BACKSPACE; executing a single BACKSPACE will backspace over the endfile record.

ENDFILE is only permitted on a file connected for sequential
or stream access.

The IOMSG= specifier was added in Fortran 2003; this sets a character string variable to an error message if an error occurs. The ERR= or IOSTAT= specifier is still needed to prevent termination on error.
BACKSPACE statement, CLOSE statement, ERR= specifier, IOMSG= specifier, IOSTAT= specifier, OPEN statement, PRINT statement, REWIND statement, READ statement, UNIT= specifier, WRITE statement