Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

EOF Question

bhvj
Beginner
759 Views

Hi

   I was trying to implement the EOF function, in order to read until end of the input file, as

DO WHILE (.NOT. EOF(unit number of open file))

It gives the following error:

forrtl: severe (24): end-of-file during read, unit 121,

Attached herewith is the test code and input file.

Any suggestions in this regard would be greatly helpful.

Thank you.

0 Kudos
5 Replies
bhvj
Beginner
759 Views

Hi

   I was trying to implement the EOF function, in order to read until end of the input file, as

DO WHILE (.NOT. EOF(unit number of open file))

It gives the following error:

forrtl: severe (24): end-of-file during read, unit 121,

Attached herewith is the test code and input file.

Any suggestions in this regard would be greatly helpful.

Thank you.

0 Kudos
Steven_L_Intel1
Employee
759 Views

Your program reads from the file in groups of three records, but the file doesn't have a multiple of three lines. The EOF will tell you if the first READ in the DO will get an endfile, but it's the second that is the problem.

0 Kudos
bhvj
Beginner
759 Views

Thank you Steve, I deleted the two READ statements, and now it works fine. Now I learnt that the EOF statement is specific to the DO loop (when you said the EOF will tell  if the first READ in the DO will get an endfile).

Thanks again for everything.

0 Kudos
Steven_L_Intel1
Employee
759 Views

No, EOF is not specific to the DO loop, that;s just where you had it. While you can use EOF to test to see if you are at end of file, most Fortran programmers would add IOSTAT=integer-variable on each READ and test to see if it was negative, indicating an end of file. Or, they might use END= to branch to a label on end of file. I don't see EOF used too often.

Each of your READ statements reads a line from the file. Since you had two READs that had no variables, they simply skipped a line.

0 Kudos
bhvj
Beginner
759 Views

Thank you Steve for the clarification, this is very helpful also.

0 Kudos
Reply