Read(*,*) causes (unit = 5, file = 'stdin') Fortran runtime error: End of file

Viewed 1199

I am trying to make a small code snippet in Fortran 90 to read in a file name from the user, and I know that it should be simple, but I just can't figure out what I'm doing wrong.

The script is:

program test
  implicit none
  Character (Len = 15) :: filename

  Write(*,*) 'Input file name'
  Read(*,*) filename
  Write(*,*) 'So the file is called',filename
end program test

And then I compile it on an ubuntu system using gfortran:

$ gfortran test.f90 -o test.exe

It compiles fine, but when I run ./test.exe, I get the following output:

$ ./test.exe 
Input file name 
At line 6 of file test.f90 (unit = 5, file = 'stdin') 
Fortran runtime error: End of file 

Error termination. Backtrace:
#0  0x7f435e83b32a 

when what I was expecting to get was:

$ ./test.exe 
Input file name 
[program pauses while user inputs text] 
So the file is called [text the user inputted]

I just can't seem to find an example of this error or how to fix it online. Can someone please tell me where I'm going wrong here?

0 Answers
Related