0
votes

I'm currently running a code and I'm always getting to the same end. I am trying to read an input file and it returns the error:

Fortran runtime error: End of file

In an other post they said to put in the iostat specifier so now my code looks like this:

INTEGER    :: m
INTEGER    :: st

Open(Unit = 13,action='read',file='Data_Inp.dat',status='old')
read (13,*, iostat = st) m
write (*,*) st
write (*,*) m

ALLOCATE(winkel(m),energie(m))

Do i = 1,m
  read(13,*),winkel(i),energie(i)
End Do

And the input file looks like this:

12
-17.83 -0.019386527878
-15.83 -0.020125057233
-12.83 -0.020653853148
-11.83 -0.020840036028
-9.83 -0.020974157405
-8.83 -0.021056401707
-6.83 -0.021065517811
-5.83 -0.020992571816
-4.83 -0.020867828448
-1.83 -0.02069158012

Now the terminal prints a -1 for iostat and a constantly changing number for m.

1
Which other post is that? In general, using iostat doesn't magically prevent an error, it just allows you to handle it rather than have the runtime terminate. - francescalus
Okay I got that. But can you imagine, why I get the EOF Error. I can't find a mistake in my input file. The error must be at the read command. - songwriter93
I'm not sure if this is just your example file not being the real file, but you only have 10 data entries in your example file but your code would try to read 12 lines, this is something that could give you an End of file error. - d_1999
Can you expand on your example to include the program statement, implicit none etc. I was able to successfully compile and run your code when I supplied my open program statement etc. so these details may be important. Note, I do get an EOF error but only inside the loop, when i>10. - d_1999
The symptoms described can be explained by the program not finding the input file when it runs. You are probably sure that it is in the right place, but appropriate use of the inquire statement might confirm, or deny, your belief. - High Performance Mark

1 Answers

0
votes

If the first read command is causing an error, check for extraneous characters before or after "12" in your input file, especially if you created it on one platform (Windows?) and using it on another platform (Linux? Mac?)