I am a beginner Fortran. I would like to be able to read a text file and save its contents in separate variables. I found a very useful Fortran tutorial ( http://www.math.hawaii.edu/~hile/fortran/fort7.htm#read ) and I try to follow one of the examples there. In particular, I created a text file data.txt with the following text:
1.23, 4.56, 7.89 11, 13, "Sally"
I saved this text file in my current directory. Then I created a test.f90 file (also saving it in the current directory) containing the following code:
PROGRAM test IMPLICIT NONE REAL :: x, y, z INTEGER :: m, n CHARACTER first*20 OPEN(UNIT = 7, FILE = "data.txt") READ(7,*) x, y, z READ(7,*) m, n, first PRINT *, x PRINT *, y PRINT *, z PRINT *, m PRINT *, n PRINT *, first END PROGRAM test
I use the GNU Fortran compiler, which I think includes features, at least until Fortran95 and including Fortran95. The above code seems to compile in order, at least with the default settings). But when I run the resulting executable, I get this error message:
At line 10 of file test.f90 (unit = 7, file = 'data.txt') Fortran runtime error: End of file
Line 10 is the line READ (7, *) m, n, the first . Could you help me see what I am doing wrong in the above code?