Fortran Read start: end of file error in fortran

AI Thread Summary
The discussion revolves around a programming issue related to reading multiple files in a loop. The user is encountering an "end of file" error when attempting to read the 40th file, which contains 1163 lines, while all files are confirmed to open correctly. The main concern is that the code attempts to read up to 2000 lines from each file, which is problematic since none of the files reach that length. Suggestions include disabling error checking on the read statement or adding a header line to indicate the number of data lines in each file. Additionally, there is a recommendation to write out the read data immediately to verify what is being processed. There is also a note questioning the use of the format specifier '51a', suggesting that it might need adjustment for compatibility with the compiler.
agalya
Messages
9
Reaction score
0
Hi all,

do i = 1, 79
open(2,file=afiln(i),status='old')
do k = 1,11
read(2,'(51a)')astr1
enddo
do j=12,2000
read(2,22,end=23,err=23)iyr,imn,id,ih,imt,flx
write(7,*)i,j
obstim = float(id)*1440.0+float(ih)*60.0+float(imt)
if(obstim .eq. pt(i).and. flx.ne.1.0E33)then
if(flx .ge. 1.0)then
write(3,*)afiln(i),j,imn,id,ih,imt,flx
endif
endif
enddo
23 write(*,*)i
enddo

In the above program I'm reading 79 files of different length, no file is 2000 lines length. but at 40th file (length 1163) it isays read start: end of file.
Can somebody please help me rectufy this problem
Thanks
 
Technology news on Phys.org
Are you sure that your files are opening correctly? I thought that I've tried opening a file via string array and it not working real well.

Also, you may have problems since the files aren't always at least 2000 lines. You are trying to read data 2000 lines down on each file, for which there may not be there.

There are two ways around this. First, I believe you can basically "turn off" the error checking on the file read. It's an argument in the READ statement.

The better way would be to include a header line in each file stating how many lines of data that file contains. Then, instead of looping from j=12,2000, you loop from j=12,n.
 
HI

Thanks for the reply, but none of the file is having 2000 lines(1450 lines only), up 40th file they go properly. I'm having problem for this file only(1163 lines). Dont understand why it is happening to this file alone since the "end" statement in the read works properly for other files.

* files are opening properly

thanks and regards
 
Directly after you read the file, write it out using the exact same code (substituting READ for WRITE) and see what files are being written. You need to find out exactly what's happening in the code, and that's the best way. Are you actually reading what you think you are?
 
agalya said:
Hi all,

do i = 1, 79
open(2,file=afiln(i),status='old')
do k = 1,11
read(2,'(51a)')astr1
enddo
do j=12,2000
read(2,22,end=23,err=23)iyr,imn,id,ih,imt,flx
write(7,*)i,j
obstim = float(id)*1440.0+float(ih)*60.0+float(imt)
if(obstim .eq. pt(i).and. flx.ne.1.0E33)then
if(flx .ge. 1.0)then
write(3,*)afiln(i),j,imn,id,ih,imt,flx
endif
endif
enddo
23 write(*,*)i
enddo

In the above program I'm reading 79 files of different length, no file is 2000 lines length. but at 40th file (length 1163) it isays read start: end of file.
Can somebody please help me rectufy this problem
Thanks

Don't know what your compiler thinks of 51a format...
shoudn't it be 51a1 or 51a2 or 51a4?
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
8
Views
1K
Replies
12
Views
3K
Replies
5
Views
5K
Replies
19
Views
6K
Replies
5
Views
2K
Replies
1
Views
3K
Replies
4
Views
9K
Replies
2
Views
9K
Replies
2
Views
25K
Back
Top