Reading formatted data - Fortran runtime error: bad real number

I am trying to use the below code to read a formatted file and write it to another. However the following error is displayed on startup

$ ./conv.sac.farm < i_conv.farm
  #   stn  comp      Delta    Tr-time   Start in record
At line 54 of file Main/conv.sac.farm.f (unit = 5, file = 'stdin')
Fortran runtime error: Bad real number in item 1 of list input

      

The original code looks like this

      PARAMETER (nd0=100000,pi=3.1415926)
      IMPLICIT COMPLEX*8 (Z)
      CHARACTER name*6,comp*6,fname*60,event*20
     -   ,cmp(0:3)*5,fname0*60,charac*15,scode*60
      REAL*8 GFACT(500),PP0(500),depth0
      integer hr0,mnu0,yr,month,day,hr,mnu
      REAL  x(nd0),y(nd0)
      DIMENSION Z(nd0),zpole(50),zero(50)
      data np,cmp/8,'disp.','vel. ','acc. ','orig.'/
      common /tbl/ip(110,14),is(110,14),secp(110,14),secs(110,14)
      read(5,'(a)') event
      read(5,*) alats,alons,depth,hr0,mnu0,sec0,id,delmin,delmax
      depth0=depth
      write(22,'(a,a5,3f7.2,2i3,f6.2)') 
     #            event,cmp(id),alats,alons,depth,hr0,mnu0,sec0
* << J-B travel time table >>
      OPEN(11,FILE='jb.ptime')
      OPEN(12,FILE='jb.stime')
1000  read(11,*,end=1001) n,(ip(n,i),secp(n,i),i=1,14)
      goto 1000
1001  read(12,*,end=1002) n,(is(n,i),secs(n,i),i=1,14)
      goto 1001
1002  continue
      close(11)
      close(12)
* << Geometrical factor >>
      OPEN(15,FILE='jb.table')
      CALL GEOM(GFACT,PP0,depth0)
      close(15)
      nstn=0
      print *,' #   stn  comp      Delta    Tr-time   Start in record'
5     read(5,'(a)') fname
      read(5,'(a)') scode
*     ta=advance of start-time relative the standard P/S arrival
*     du=duration
c
      if(fname.eq.'dummy') goto 90
      read(5,*) ta,du,dt,f1,f2,iph,nr,iuni
      open(1,file=fname)
      READ(1,'(g15.7)') dt0
      read(1,'(/////5g15.7)') dum, alat, alon, elev
      read(1,'(///////5i10)') yr, nday, hr,mnu, nsec
      read(1,'(5i10)') nmsec,ndum,ndum,ndum,nd
      read(1,'(/////)')
      read(1,'(a6,2x,a13)') name,charac
      read(1,'(////)')

      

Etc..

Line 54 -

      read(5,*) ta,du,dt,f1,f2,iph,nr,iuni

      

I found a similar question following this link

Fortran Runtime Error: Invalid Valid Number

However, if I understand correctly, the mentioned fixes were about reading unformatted data. Regardless, I tried and failed as expected given that the file I am trying to read is formatted.

+1


source to share


1 answer


Here's a little trick if you can't easily find the violation line in your data file:

replace the read that is causing the error:

 read(5,'(a)')line
 read(line,*,iostat=ios) ta,du,dt,f1,f2,iph,nr,iuni
 if(ios>0)then
    write(*,*)'error reading line:',line
    stop
 endif

      



with ads

 integer ios
 character*(200) line

      

Maybe just do it for debugging and then revert the original as soon as you fix the problem.

0


source







All Articles