06.03.2014 Views

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Intrinsic Procedures 9<br />

EOF<br />

Description:<br />

Syntax:<br />

Class:<br />

Arguments:<br />

Results:<br />

Checks whether a file is at or beyond the end-of-file record. This specific<br />

function has no generic function associated with it. It cannot be passed as an<br />

actual argument.<br />

result = EOF (a)<br />

Inquiry function; Specific<br />

a must be of type integer. It represents a unit specifier corresponding to an open<br />

file. It cannot be zero unless you have reconnected unit zero to a unit other than<br />

the screen or keyboard.<br />

The result type is logical. The value of the result is .TRUE. if the file connected<br />

to a is at or beyond the end-of-file record; otherwise, .FALSE..<br />

Example<br />

Consider the following:<br />

! Creates a file of random numbers, and reads them back<br />

REAL x, total<br />

INTEGER count<br />

OPEN (1, FILE = 'TEST.DAT')<br />

DO I = 1, 20<br />

CALL RANDOM_NUMBER(x)<br />

WRITE (1, '(F6.3)') x * 100.0<br />

END DO<br />

CLOSE(1)<br />

OPEN (1, FILE = 'TEST.DAT')<br />

DO WHILE (.NOT. EOF(1))<br />

count = count + 1<br />

READ (1, *) value<br />

total = total + value<br />

END DO<br />

100 IF ( count .GT. 0) THEN<br />

WRITE (*,*) 'Average is: ', total / count<br />

ELSE<br />

WRITE (*,*) 'Input file is empty '<br />

END IF<br />

STOP<br />

END<br />

9-55

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!