- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
After updating my Fortran compiler from composer XE 2016 to 2017 update 1, I run into an issue with EOF (end-of-file) checks when reading from files. This issue is that the EOF check returns .false. when it should return .true. and consequently reading of variables from a file beyond EOF will lead to an error. I used the Intel example from the EOF help entry to reproduce the issue (see code below and attached VS solution). This error is not found with composer XE 2016.
Andi
PROGRAM CheckEOF IMPLICIT NONE REAL(4) :: x, total, value INTEGER(4) :: count, I OPEN (UNIT=1, FILE = 'TEST.DAT') DO I = 1, 10 CALL RANDOM_NUMBER(x) WRITE (1, '(F6.3)') x * 100.0 END DO CLOSE(1) OPEN (1, FILE = 'TEST.DAT') count = 0 total = 0.0D0 DO WHILE (.NOT. EOF(1)) !check for end-of-file property count = count + 1 WRITE (*,*) count READ (1, *) value total = total + value END DO IF ( count .GT. 0) THEN WRITE (*,*) 'Average is: ', total / count ELSE WRITE (*,*) 'Input file is empty ' END IF READ(*,*) END PROGRAM CheckEOF
529984
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for letting us know - I have escalated this as issue DPD200415613.
My recommendation is to not use the EOF intrinsic, which is non-standard, but instead use either END= or IOSTAT= to detect an endfile condition on the READ.
I also noticed that the documentation example, on which your program is based, fails to initialize the COUNT variable - I will let the writers know about that.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for letting us know - I have escalated this as issue DPD200415613.
My recommendation is to not use the EOF intrinsic, which is non-standard, but instead use either END= or IOSTAT= to detect an endfile condition on the READ.
I also noticed that the documentation example, on which your program is based, fails to initialize the COUNT variable - I will let the writers know about that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply, Steve!
I was unaware that the EOF intrinsic was non-standard; using instead the IOSTAT= option with READ solves it in my applications, thanks for this tip.
The documentation example is missing the initialization of both variables count and total. That should be updated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI am wrestling with simply trying to read in 31,215 numbers from a file. Did this years ago; does not work now! stops on EOF Here's the simple code:
dimension number(31215)
open(66,file='TD1.DATnumber')
!!!• read(66,24)(number(i),i=1,31215)
do k=1,3
read(66,24,END=245)(number(i),i=1,200) ! if you change that to 201 you get end-of-file during read
24 format(200i6)
245 write(6,*)'found an EOF'
write(6,*)(number(i),i=1,200)
end do
stop
end
Just reads the initial 200 values over and over; never gets past the EOF. Hope you can help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you post a program to produce this input file (or attach the input file you are working with), so that others can reproduce the problem? This sort of things rather depends on the details, so it makes no sense trying to produce a file with 31215 numbers and read it with the above program.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This seems to be a repost of the contents of your post in the Linux Fortran forum, https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x/topic/776732 . Is this post related to Intel Fortran? If so, what version and what is your OS?
Much depends on the format and contents of the data file. Unlike on old mag-tapes and CPM text files, there is no dedicated/distinct EOF mark in a text file on Windows and Unix/Linux. Therefore, there is no such thing as "getting past EOF" in this context. The I/O system will signal that the file end has been reached when the number of bytes to be read exceeds the remaining number of bytes in the file.
Please post the data file and the complete program text. You can upload and attach the files, or upload them into the Cloud and post a link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much to everyone who tried to help! Really greatly appreciated! Turned out happily: all it was, was that the data file I was trying to read was corrupt. Nothing more than that! Sorry if I wasted your valuable time, but I do really appreciate your responsiveness. Dick Henry

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page