- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I appology if this place is not the appropiate place to ask my question.
Suppose that I have a file "sampleFile.dat" with 12 rows.
When i compile the below program with ifort i get 13.
When I compile the same program with gfortran i get 12.
Why i get differents values?
Thank you in advance.
program nlines
implicit none
integer :: nrows, ios
nrows = 0
open(unit=15, file ="sampleFile.dat")
rewind(15)
ios=0
do while (ios == 0)
read(15, * , iostat = ios )
nrows = nrows + 1
end do
print*,nrows
end program nlines
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please attach a data file that shows the problem. Don't paste it in, use the attach feature.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your program executes 13 READs for 12 lines, and thus 13 increments of nrows. The last READ fails with an IOS of -1, but you've already changed nrows to 13. Your edit that tests ios is a correct fix. I don't know why gfortran gives a different result. The file you attached has many more than 12 rows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve.
I have attached the right file. I solved the problem with the "if (ios == 0) nrows = nrows + 1" sentence.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page