Lahey/Fujitsu Fortran

ENDFILE Statement

Description

The ENDFILE statement writes an endfile record to the specified unit as the next record of a file. The file pointer is then positioned after the end of the file.

Syntax

ENDFILE unit-number
or
ENDFILE (position-spec-list)
Where:

unit-number is a scalar INTEGER expression corresponding to the input/output unit number connected to an external file.

position-spec-list is [[UNIT =] unit-number][, ERR=label][, IOSTAT=stat] where UNIT=, ERR=, and IOSTAT= can be in any order but if UNIT= is omitted, then unit-number must be first.

label is a statement label that is branched to if an error condition occurs during execution of the statement.

stat is of type INTEGER and returns a status indicator.

Remarks

After execution of an ENDFILE statement, a BACKSPACE or REWIND statement must be executed to reposition the file before any further data transfer occurs.

If IOSTAT is present, execution continues after an error or end condition is encountered, and stat is set to a non-zero number. The value of stat is set to zero if the write operation was successful. stat is assigned a positive value if an error condition occurs, and a negative value if an end-of-file, or end-of-record condition occurs.

If unit-number is connected to the console, the ENDFILE statement has no effect.

An ENDFILE statement on a file that is connected but does not yet exist causes the file to be created before writing the endfile record.

Note that ENDFILE may only be used on sequential access files.

Example

integer :: ios endfile 10 endfile(unit=11,iostat=ios) endfile(12, err=20) 20 continue