This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CREAD buggy?


Jerry,
    Good news, bad news. The good news is I found a hack that works around
this problem. The code in xplor-nih resembles the following test case...

      PROGRAM BUG
      CHARACTER*(132) COMLYN
      COMMON /COMMAND/COMLYN
      DOUBLE PRECISION XIN, YIN, ZIN, WIN, QIN
      CHARACTER*4 SID, RID, RID2, REN, IUP
      CHARACTER*5 A       
      COMLYN='ATOM      1  C4  DNP   250      -4.070  58.954 181.339  1.00  0.00
'   
      WRITE(6,*) COMLYN
      READ(COMLYN,'(12X,A4,1X,A4,1X,A5,3X,3F8.3,F6.2,F6.2,6X,A4)',
     &           ERR=8888) IUP,REN,A,XIN,YIN,ZIN,QIN,WIN,SID
      GOTO 9999
8888  WRITE(6,*) ' read failed'
      CALL ABORT()
9999  WRITE(6,*) ' read passed'      
      WRITE(6,'(12X,A4,1X,A4,1X,A5,3X,3F8.3,F6.2,F6.2,6X,A4)') IUP,REN,A,XIN,YIN
,ZIN,QIN,WIN,SID
      END

in that it is reading off of a COMLYN string with the read statement above.
The program never actually segfaults in the read but any future i/o is
unstable and will segfault the program. That is why the program has been
crashing in the write statement at the 8888 label. I decided to make the
test case above and of course it didn't crash. So I decided to add the 
following above the READ statement in xplor-nih's code...

CHARACTER*132 JACKSTR
...
READ(COMLYN,'(A)') JACKSTR

by placing this immediately before the statement...

            READ(COMLYN,'(12X,A4,1X,A4,1X,A5,3X,3F8.3,F6.2,F6.2,6X,A4)',
     &           ERR=8888) IUP,REN,A,XIN,YIN,ZIN,QIN,WIN,SID

I seem to have cleared whatever mess develops in the i/o and now pass the
test case fine. I'll still have to run the complete xplor-nih testsuite
but I am pretty hopeful this hack will work.
   Now why the i/o is so unstable at that point in the program that 
a simple read of the same string keeps things working is beyond me.
                 Jack


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]