Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re-use of unit number

Status
Not open for further replies.

AlanJT

Programmer
Aug 11, 2020
7
GB
Hi everyone.

This is my first post on this forum, so I hope I'm using it appropriately!

I've been developing a program using gfortran under Windows 10. It reads a list of files contained in another file, then opens, reads and closes each file in the list in turn. I find it's correctly reading the filenames and opening them, but I also find that it reads the first one in the list OK but after opening the next file (having closed the first one) it immediately seems to be at end-of-file and reads nothing from it. It then does exactly the same with all the other files.

Clearly, what I need is a way of ensuring that, after opening each file, it starts to be read from the beginning. Maybe it's because I use the same unit number each time, but as the list of files is of variable length, to use a fresh unit number each time could pose a different problem.

I trust I have explained that clearly enough. I would appreciate whatever help anyone could offer.

Thanks in advance.

Alan.
 
The same unit number should not be the problem.
Are you using iostat when opening the file ?
When not try it like this, to see if there isn't an error on opening:
Code:
open(file_unit, file=file_name, status='old', iostat=stat)
if (stat .ne. 0) then
  write(*,*) fname, ' cannot be opened !'  
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top