×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

re-use of unit number

re-use of unit number

re-use of unit number

(OP)
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.

RE: re-use of unit number

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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close