Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29274 Discussions

Fortran End of File/Backspace command

Kate_Johnson
Beginner
1,539 Views

I am getting a Fortran runtime error:End of file at the second line of this subroutine:

subroutine errstp(kunit)

      backspace kunit
      read(kunit, '(a)') zline(1:nline)
      call cmerpr('unexpected end of file')
      call cmerpr('last input data line:')
      call cmerpr(zline(1:nline))
      call finish(yes)
                                  stop
      end

kunit is 1 in this case, and the purpose of this subroutine is to echo the last inout line and then close up shop.  Does my error have something to do with the backspace command or is this something else altogether?

Thanks

0 Kudos
1 Reply
Steven_L_Intel1
Employee
1,539 Views
We'd need to see more - ideally a complete program that could be run. We don't know where the file position is before the backspace. If it is "after the end-of-file marker - that is, an EOF condition has already been raised, one BACKSPACE will position the file just before the EOF marker. (The marker in this context is virtual - there is no physical representation, but this is how the standard describes it.) If you want to reread the last record after an EOF condition has been raised, you need two BACKSPACEs.
0 Kudos
Reply