Fortran Coder

标题: Fortran runtime error: Bad real number in item 5 of list input [打印本页]

作者: Zhuming    时间: 2020-5-21 10:47
标题: Fortran runtime error: Bad real number in item 5 of list input
报错信息如图
部分数据信息也如图放出来


代码:
[Fortran] 纯文本查看 复制代码
program wwlln_shiyan
    implicit none

    !声明变量
    character(len=512)::cRead
    character(len=20)::filename,DYfilename
    character(len=20)::wwlln_date,wwlln_time
    real::lat,lon
    real::timingerror
    integer::station
    integer::status1=0
    integer,parameter::fileid1=12,fileid2=13
    integer::i
    logical alive
   
    !循环读取文件
    OPEN(14,file="filename.txt",status="old")
    OPEN(15,file="DYfilename.txt",status="old")
    do i=20040810,20151130,1
        READ(14,*)filename
        READ(15,*)DYfilename
        inquire(file=filename,exist=alive)
        if (alive) then
   
        !读取数据
            OPEN(11,file=filename,status='old',form='formatted')
            OPEN(13,file=DYfilename,status='replace')
   
            do while(.true.)
                READ(11,"(A512)",iostat=status1)cRead
                if (status1/=0) exit
                CALL parserRead(cRead)
                if((lat>21).AND.(lat<34).AND.(lon>97).AND.(lon<111)) then
                    write(*,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
                    write(13,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
                end if
            end do
            CLOSE(11)
            CLOSE(13)
        else
            CYCLE
        end if
        
    end do
   
   
        CLOSE(14)
        CLOSE(15)
   
        STOP


contains
    !调用子程序
    subroutine parserRead(c)
        character(len=*)::c
        integer::j
        
        do j=1,LEN_TRIM(c)
            if (c(j:j)=="/") c(j:j)="|"
        end do
        READ(c,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
        do j=1,LEN_TRIM(wwlln_date)
            if (wwlln_date(j:j)=="|") wwlln_date(j:j)="/"
        end do
    end subroutine parserRead
   
end program wwlln_shiyan

请求各路大神帮忙!感谢!



部分数据.png (18.89 KB, 下载次数: 261)

部分数据.png

error.png (10.03 KB, 下载次数: 285)

error.png

作者: fcode    时间: 2020-5-21 12:02
READ(c,*)wwlln_date,wwlln_time,lat,lon,timingerror,station

这里读取的第5项,也就是 timingerror,对应的内容不是一个有效的real值,比如内容可能是 abc 这种字母
作者: Zhuming    时间: 2020-5-21 17:15
fcode 发表于 2020-5-21 12:02
READ(c,*)wwlln_date,wwlln_time,lat,lon,timingerror,station

这里读取的第5项,也就是 timingerror,对 ...

是这个原因。我也没找到txt第五项里面有非real类型,数据量太大了,我直接把timingerror定义字符型了。另外还想请教您一个问题。Fortran runtime error: End of file。我在下面放上错误信息。
作者: Zhuming    时间: 2020-5-21 17:16
C:\Users\zm.com\Desktop\end of file.png
作者: Zhuming    时间: 2020-5-21 17:19
回复加不了图片 ,我复制下来,以下是命令行提示的:
......
2014/04/27          03:44:46.595573        21.6963997       110.456299     10.6 6
2014/04/27          03:51:42.263995        21.1089001       107.036003     24.0 5
2014/04/27          03:58:39.743851        21.1285992       107.184898     21.8 8
At line 62 of file D:\Projects\wwlln\all\temp\2014 miss78mon\wwlln_xinan.f90
Fortran runtime error: End of file

Error termination.
请按任意键继续. . .

程序代码还是上述的,已经运行过其他好几个年份的都没有问题,个别几个年份出现错误。
作者: Zhuming    时间: 2020-5-21 21:56
Zhuming 发表于 2020-5-21 17:19
回复加不了图片 ,我复制下来,以下是命令行提示的:
......
2014/04/27          03:44:46.595573        ...

我找到原因了,在文件里缺失了一条数据,数据见空了一列,导致end of file!平均一个txt25万条数据,,眼睛瞎了




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2