FORTRAN 77 Language Reference

END FILE

The END FILE statement writes an end-of-file record as the next record of the file connected to the specified unit.

END FILE u

END FILE ([UNIT= ] u [, IOSTAT=ios] [, ERR=s])

Parameter 

Description 

u

Unit identifier of an external unit connected to the file. The options can be specified in any order, but if UNIT= is omitted, then u must be first.

iost

I/O status specifier, an integer variable or an integer array element.  

s

Error specifier, s must be the label of an executable statement in the same program in which the END FILE statement occurs. The program control is transferred to the label in the event of an error during the execution of the END FILE statement.

Description

If you are using the ENDFILE statement and other standard FORTRAN I/O for tapes, we recommend that you use the TOPEN() routines instead, because they are more reliable.

Two endfile records signify the end-of-tape mark. When writing to a tape file, ENDFILE writes two endfile records, then the tape backspaces over the second one. If the file is closed at this point, both end-of-file and end-of-tape are marked. If more records are written at this point, either by continued write statements or by another program if you are using no-rewind magnetic tape, the first tape mark stands (endfile record), and is followed by another data file, then by more tape marks, and so on.

Restrictions

u must be connected for sequential access. Execution of an END FILE statement on a direct-access file is not defined in the FORTRAN 77 Standard, and is unpredictable. Do not use an END FILE statement on a direct-access file.

Examples

Example 1: Constants:


       END FILE 2 
       END FILE ( 2 ) 
       END FILE ( UNIT=2 ) 

Example 2: Variables:


       LOGUNIT = 2 
       END FILE LOGUNIT 
       END FILE ( LOGUNIT ) 
       END FILE ( UNIT=LOGUNIT )

Example 3: Error trap:


       NOUT = 2 
       END FILE ( UNIT=NOUT, IOSTAT=KODE, ERR=9) 
       ... 
9      WRITE(*,*) 'Error at END FILE, on unit', NOUT 
       STOP