Fortran运行时错误:列表输入的第1项中的实数错误(unit = 5,file ='stdin')

时间:2016-11-07 07:13:32

标签: fortran

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

Fortran运行时错误:列表输入的第1项中的实数错误

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

我的i_conv.farm文件是

1604151625 Japan
 32.79 130.58    10 16 25 06 1 30 100

II.BORG.00.BH1.A
II.BORG.00
II.BORG.00.BH2.A
II.BORG.00
II.BORG.00.BHZ.A
II.BORG.00
20 120 1
0.002 1 1 1 1 
II.DGAR.00.BH1.A
II.DGAR.00
II.DGAR.00.BH2.A
II.DGAR.00
II.DGAR.00.BHZ.A
II.DGAR.00
20 120 1
0.002 1 1 1 1 
II.TAU.00.BH1.A
II.TAU.00
II.TAU.00.BH2.A
II.TAU.00
II.TAU.00.BHZ.A
II.TAU.00
20 120 1
0.002 1 1 1 1 
II.UOSS.00.BH1.A
II.UOSS.00
II.UOSS.00.BH2.A
II.UOSS.00
II.UOSS.00.BHZ.A
II.UOSS.00
20 120 1
0.002 1 1 1 1 
II.WRAB.00.BH1.A
II.WRAB.00
II.WRAB.00.BH2.A
II.WRAB.00
II.WRAB.00.BHZ.A
II.WRAB.00
20 120 1
0.002 1 1 1 1 
IU.AFI.00.BH1.A
IU.AFI.00
IU.AFI.00.BH2.A
IU.AFI.00
IU.AFI.00.BHZ.A
IU.AFI.00
20 120 1
0.002 1 1 1 1 

我真的不知道格式化数据不对的地方?

1 个答案:

答案 0 :(得分:1)

让我们计算read(5),我认为这是从stdin中读取的,在您的情况下是i_conv.farm

read(5,'(a)') event

这将“1604151625 Japan”改为event

read(5,*) alats,alons,depth,hr0,mnu0,sec0,id,delmin,delmax

这读取“32.79 130.58 10 16 25 06 1 30 100”这一行并将其分配给变量。

然后你调用GEOM,但我认为那个子程序不能从stdin读取。接下来是

read(5,'(a)') fname

这是空行。所以已经有些可疑了。接下来是

read(5,'(a)') scode

所以scode变为“II.BORG.00.BH1.A”。现在我们来看看它最终落空的地方:

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

但该行是“II.BORG.00” - 无法将其解析为ta的数字。

查看代码,调试很麻烦,我甚至不知道它应该做什么。应该将i_conv.farm的哪一部分读入哪个值?如果您想阅读标准输入,我强烈建议您使用read(*,代替read(5,,因为您无法保证5将永远是标准输入。

此时,我将手伸向空中,并开始完全重写至少文件i / o部分的程序。

相关问题