读取格式化的数据 - Fortran运行时错误:错误的实数 [英] Reading formatted data - Fortran runtime error: Bad real number
问题描述
我试图使用下面的代码来读取格式化文件并将其写入另一个文件。但是,在运行时显示以下错误:
$ ./conv.sac.farm< i_conv.farm
#stn comp Delta Tr-time从记录
开始在文件Main / conv.sac.farm.f的第54行(单元= 5,file ='stdin')
Fortran运行时错误:列表输入项目1中的实数不正确
源代码如下 p>
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),零(50)
数据np,cmp / 8,'disp。','vel。 , ACC。 ','orig。'/
common / tbl / ip(110,14),(110,14),secp(110,14),secs(110,14)
read(5, '(a)')事件
read(5,*)alats,alons,depth,hr0,mnu0,sec0,id,delmin,delmax
depth0 = depth
write(22,' (a,a5,3f7.2,23,f6.2)')
#event,cmp(id),alats,alons,depth,hr0,mnu0,sec0
*< J-B旅行时间表>>
OPEN(11,FILE ='jb.ptime')
OPEN(12,FILE ='jb.stime')
1000读取(11,*,结束= 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)
*<<< ;几何因子>>
OPEN(15,FILE ='jb.table')
CALL GEOM(GFACT,PP0,depth0)
close(15)
nstn = 0
print * ,'#stn comp Delta Tr时间开始记录'
5 read(5,'(a)')fname
read(5,'(a)')scode
* ta =相对于标准P / S到达的开始时间提前
* du =持续时间
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)')年,nday,hr, mnu,nsec
read(1,'(5i10)')nmsec,附录,附录,nd
阅读(1,'(/////)')
阅读1,'(a6,2x,a13)')name,charac
read(1,'(////)')
等等。
第54行是
read(5,*)ta,du,dt,f1,f2,iph,nr,iuni
我在这个链接后发现了一个类似的问题。
但是,如果我理解正确,则提到的更正与读取未格式化的数据有关。尽管如此,由于我正在尝试读取的文件是格式化的,因此我尝试了并且如预期的那样失败了。
解决方案这里是一个如果您无法在数据文件中找到有问题的行,请点击这个小诀窍:
将您的阅读内容替换为引发错误的内容:
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
附带声明
整数ios
字符*(200)行
可能只是做调试然后恢复一旦你解决了这个问题,你就可以回到原来的位置。
I am trying to use the code below to read a formatted file and write it into another. However, on running it shows the following error
$ ./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 source code is as follows
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,'(////)')
And so on..
Line 54 is
read(5,*) ta,du,dt,f1,f2,iph,nr,iuni
I found a similar question following this link
Fortran runtime error: Bad real number
However, if I understand correctly, the corrections mentioned were pertaining to reading unformatted data. Despite this, I tried and failed as expected, given that the file I am trying to read is formatted.
here is a little trick if you can't readily find the offending line in the data file:
replace your read that throws the error with this:
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 the declarations
integer ios
character*(200) line
Probably just do that for debugging then revert to the original once you fix the problem.
这篇关于读取格式化的数据 - Fortran运行时错误:错误的实数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!