[Bug libfortran/59513] [4.8/4.9/4.10 Regression] Fortran runtime error: Sequential READ or WRITE not allowed after EOF marker, possibly use REWIND or BACKSPACE
manfred99 at gmx dot ch
gcc-bugzilla@gcc.gnu.org
Wed Jul 16 10:37:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59513
--- Comment #25 from Manfred Schwarb <manfred99 at gmx dot ch> ---
OK, thanks Jerry and Dominique for the explanations.
It seems the correct syntax then is:
READ(lun,END=100) buffer
GOTO 101
100 BACKSPACE(lun)
101 WRITE(lun,*) "whatever"
Not that the above code would make sense to me as a mere user,
but it works both with gfortran 4.5 and 4.6 upwards.
I just wrote a small test program, the output is identical for
gfortran 4.5 and 4.6+:
CHARACTER*20 buffer,buffer2
INTEGER i
buffer=""
buffer2=""
OPEN(10,FILE="test.txt")
WRITE(10,'(a)') "0123456789"
CLOSE(10)
OPEN(10,FILE="test.txt",POSITION="APPEND")
CALL ftell(10,i)
print*,"file position in append mode:",i
CLOSE(10)
OPEN(10,FILE="test.txt")
READ(10,'(a20)') buffer
print*,"X",buffer,"X"
CALL ftell(10,i)
print*,"file position after reading buffer:",i
CC BACKSPACE(10) ! then below write will overwrite first line
WRITE(10,'(a)') "ABC"
CLOSE(10)
CALL system("cat test.txt")
OPEN(10,FILE="test.txt")
WRITE(10,'(a)') "0123456789"
CLOSE(10)
OPEN(10,FILE="test.txt")
READ(10,'(a20)',END=100) buffer,buffer2
GOTO 101
100 CALL ftell(10,i)
print*,"END clause encountered: file position:",i
BACKSPACE(10)
101 CALL ftell(10,i)
print*,"file position:",i
print*,"X",buffer,"X",buffer2,"X"
WRITE(10,'(a)') "ABC"
CLOSE(10)
CALL system("cat test.txt")
END
More information about the Gcc-bugs
mailing list