From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 596 invoked by alias); 16 Jul 2014 10:37:08 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 381 invoked by uid 48); 16 Jul 2014 10:37:04 -0000 From: "manfred99 at gmx dot ch" To: gcc-bugs@gcc.gnu.org Subject: [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 Date: Wed, 16 Jul 2014 10:37:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libfortran X-Bugzilla-Version: 4.7.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: manfred99 at gmx dot ch X-Bugzilla-Status: NEW X-Bugzilla-Priority: P5 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg01062.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59513 --- Comment #25 from Manfred Schwarb --- 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