public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31618]  New: backspace intrinsic is not working on an unformatted file
@ 2007-04-18 10:27 Patrick dot Begou at hmg dot inpg dot fr
  2007-04-18 14:01 ` [Bug fortran/31618] " jvdelisle at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Patrick dot Begou at hmg dot inpg dot fr @ 2007-04-18 10:27 UTC (permalink / raw)
  To: gcc-bugs

Using backspace when reading an unformatted file after a read error does not
work except if it is on the first record.

The code below show the problem. This code write 3 couples of integer values in
an unformatted file called 'foo' and close it.
File is reopen for read.
Then it reads the first couple of values. It's OK.
Then it try to read 3 values and detects the error (only 2 values in the
record).
The code use backspace to go back at the begining of this record and try to
read again this record, but with only 2 values.
The values obtained are wrong.

Trying to read 3 values at the begining of the file, using backspace and
reading again only 2 values works. 

Code:

      PROGRAM gfort
      IMPLICIT NONE

      INTEGER :: x, z, count
      INTEGER :: nx, nz,LocalTimeStep 


      OPEN (21,FILE='foo',form='UNFORMATTED',err=101)
      REWIND(21)
      x=140
      z=170
      WRITE(21) x,z
      WRITE(6,*)'writing x (',x,') and z(',z,') in foo'
      x=14
      z=17
      WRITE(21) x,z
      WRITE(6,*)'writing x (',x,') and z(',z,') in foo'
      x=1400
      z=1700
      WRITE(21) x,z
      WRITE(6,*)'writing x (',x,') and z(',z,') in foo'
      CLOSE(21)


      OPEN (21,FILE='foo',form='UNFORMATTED',status='OLD',err=101)
      REWIND(21)
      WRITE(6,*)'reading first x, z in foo'
      x=-1
      z=-1
      READ(21,err=103,end=103) x,z
      WRITE(6,*)'x (',x,') and z(',z,')'

      WRITE(6,*)'reading x, z and LocalTimeStep in foo'
      nx=-1
      nz=-1
      READ(21,iostat=count) nx,nz,LocalTimeStep
      WRITE(6,*)'x (',nx,') and z(',nz,') and LocalTimeStep(',
     + LocalTimeStep,')'
         IF (count.NE.0) THEN
            WRITE(6,*)'reading again x and z in foo'
            BACKSPACE(21)
            nx=-1
            nz=-1
            READ(21,err=103,end=103) nx,nz
            LocalTimeStep=0.0
      WRITE(6,*)'x (',nx,') and z(',nz,') and LocalTimeStep(',
     + LocalTimeStep,')'
         ENDIF
      CLOSE(21)
      STOP 'OK'

101   WRITE(6,*) 'foo n''a pas ete trouve.'
      STOP 'FAILED'
103   WRITE(6,*) 'Erreur de lecture'
      CLOSE(21)
      STOP 'FAILED'
      END PROGRAM gfort



NORMAL RESULT:
 ./a.out
 writing x (         140 ) and z(         170 ) in foo
 writing x (          14 ) and z(          17 ) in foo
 writing x (        1400 ) and z(        1700 ) in foo
 reading first x, z in foo
 x (         140 ) and z(         170 )
 reading x, z and LocalTimeStep in foo
 x (          14 ) and z(          17 ) and LocalTimeStep(           0 )
 reading again x and z in foo
 x (          14 ) and z(          17 ) and LocalTimeStep(           0 )
OK

Gfortran RESULT (WRONG) :
./a.out
 writing x (         140 ) and z(         170 ) in foo
 writing x (          14 ) and z(          17 ) in foo
 writing x (        1400 ) and z(        1700 ) in foo
 reading first x, z in foo
 x (         140 ) and z(         170 )
 reading x, z and LocalTimeStep in foo
 x (          14 ) and z(          17 ) and LocalTimeStep(          17 )
 reading again x and z in foo
 x (          17 ) and z(           8 ) and LocalTimeStep(           0 )
STOP OK


-- 
           Summary: backspace intrinsic is not working on an unformatted
                    file
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Patrick dot Begou at hmg dot inpg dot fr
 GCC build triplet: gcc version 4.3.0 20070418 (experimental)
GCC target triplet: i386-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31618


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-05-26  3:14 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-18 10:27 [Bug fortran/31618] New: backspace intrinsic is not working on an unformatted file Patrick dot Begou at hmg dot inpg dot fr
2007-04-18 14:01 ` [Bug fortran/31618] " jvdelisle at gcc dot gnu dot org
2007-04-19  2:47 ` jvdelisle at gcc dot gnu dot org
2007-04-19 20:35 ` tkoenig at gcc dot gnu dot org
2007-04-20 21:29 ` tkoenig at gcc dot gnu dot org
2007-04-21 22:12 ` tkoenig at gcc dot gnu dot org
2007-04-21 22:47 ` jvdelisle at gcc dot gnu dot org
2007-04-22 21:10 ` patchapp at dberlin dot org
2007-04-23 19:44 ` tkoenig at gcc dot gnu dot org
2007-04-23 19:47 ` [Bug fortran/31618] [4.2, 4.1 only] " tkoenig at gcc dot gnu dot org
2007-05-20 21:09 ` tkoenig at gcc dot gnu dot org
2007-05-20 21:12 ` tkoenig at gcc dot gnu dot org
2007-05-26  3:14 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).