Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

EOF

Inquiry Intrinsic Function (Generic): Checks whether a file is at or beyond the end-of-file record.

result = EOF (unit)

unit

(Input) Must be of type integer. It represents a unit specifier corresponding to an open file. It cannot be zero unless you have reconnected unit zero to a unit other than the screen or keyboard.

Results

The result type is default logical. The value of the result is .TRUE. if the file connected to unit is at or beyond the end-of-file record; otherwise, .FALSE..

Example

!  Creates a file of random numbers, reads them back
       REAL x, total
       INTEGER count
       OPEN (1, FILE = 'TEST.DAT')
       DO I = 1, 20
         CALL RANDOM_NUMBER(x)
         WRITE (1, '(F6.3)') x * 100.0
       END DO
       CLOSE(1)
       OPEN (1, FILE = 'TEST.DAT')
       count = 0
       total = 0.0
       DO WHILE (.NOT. EOF(1))
         count = count + 1
         READ (1, *) value
         total = total + value
       END DO
100    IF ( count .GT. 0) THEN
         WRITE (*,*) 'Average is: ', total / count
       ELSE
         WRITE (*,*) 'Input file is empty '
       END IF
        STOP
       END

See Also