Read start: end of file error in fortran

In summary, the code reads 79 files of varying length and attempts to write out data from each file. However, there is an error when reading the 40th file (1163 lines) saying "read start: end of file". The solution may be to turn off error checking or include a header line in each file stating the number of lines.
  • #1
agalya
9
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
  • #2
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.
 
  • #3
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
 
  • #4
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?
 
  • #5
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?
 

1. What does the "Read start: end of file error" mean in Fortran?

The "Read start: end of file error" in Fortran indicates that the program has reached the end of the file before it was able to read all of the data specified by the READ statement.

2. Why am I getting the "Read start: end of file error" when my file has more data?

This error can occur if the READ statement is not properly reading the data in the file, or if the file is not in the correct format for the READ statement to read it. Make sure that the READ statement is correctly formatted and that the file is in the correct format for the READ statement to read it.

3. How can I fix the "Read start: end of file error" in Fortran?

To fix this error, you may need to check your READ statement to ensure it is correctly reading the data in the file. You may also need to check the format of the file to ensure it is compatible with the READ statement. Additionally, you may need to check for any errors in the file that could be causing the READ statement to reach the end of the file prematurely.

4. Can this error be caused by incorrect file permissions?

No, the "Read start: end of file error" in Fortran is not caused by incorrect file permissions. This error is typically caused by incorrect formatting of the READ statement or errors in the file itself.

5. Is there a way to prevent the "Read start: end of file error" in Fortran?

To prevent this error, make sure to thoroughly test and debug your program to ensure that the READ statement is correctly reading the data in the file. It is also important to ensure that the file is in the correct format for the READ statement to read it. Additionally, be sure to catch any potential errors in the file that could cause the READ statement to reach the end of the file prematurely.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
19
Views
5K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
8K
  • Programming and Computer Science
Replies
2
Views
8K
  • Programming and Computer Science
Replies
2
Views
24K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
4
Views
11K
Back
Top