读取格式化数据 - Fortran运行时错误:错误的实数

时间:2014-06-19 09:19:27

标签: fortran

我正在尝试使用下面的代码来读取格式化文件并将其写入另一个文件。但是,在运行时它会显示以下错误

$ ./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

源代码如下

      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,'(////)')

等等..

第54行

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

我在此链接后发现了一个类似的问题

Fortran runtime error: Bad real number

但是,如果我理解正确,提到的更正与阅读未格式化的数据有关。尽管如此,我试图按预期失败,因为我试图读取的文件是格式化的。

1 个答案:

答案 0 :(得分:0)

如果你不能在数据文件中找到有问题的行,这是一个小技巧:

将您的错误替换为错误:

 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

声明

 integer ios
 character*(200) line

可能只需要进行调试然后在修复问题后恢复原​​状。