Fortran Coder

标题: txt文本有一个类似换行符的东西,导致报错Fortran runtime erro [打印本页]

作者: Zhuming    时间: 2020-5-21 22:14
标题: txt文本有一个类似换行符的东西,导致报错Fortran runtime erro
导致报错:Fortran runtime error: End of file
数据展示如图
Fortran报错如图
代码:
[Fortran] 纯文本查看 复制代码
program wwlln_2009_text
implicit none

    character(len=512)::cRead
    character(len=20)::filename,DYfilename
    character(len=20)::wwlln_date,wwlln_time
    real::lat,lon
    character(len=5)::timingerror
    character(len=2)::station
    integer::status1=0
    integer,parameter::fileid1=12,fileid2=13
    integer::i
    logical alive

    OPEN(14,file="A20090101.txt",status="old",form="formatted")
    OPEN(15,file="20090101.txt",status="replace")

    do while(.true.)
        READ(14,"(A512)",iostat=status1)cRead
        if(status1/=0) exit
        CALL parserRead(cRead)
        write(*,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
        if((lat>21).AND.(lat<34).AND.(lon>97).AND.(lon<111)) then
            write(*,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            write(15,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
        end if
    end do
    CLOSE(14)
    close(15)

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

请问大家,这种情况该怎么让程序继续下去!


text.png (33.78 KB, 下载次数: 307)

Fortran报错

Fortran报错

错误图片.png (51.25 KB, 下载次数: 313)

数据展示

数据展示

作者: Zhuming    时间: 2020-5-21 22:15
救救孩子,谢谢各路大神
作者: fcode    时间: 2020-5-22 08:15
没有数据文件,看不出问题,也不能重现。
作者: Zhuming    时间: 2020-5-22 08:25
fcode 发表于 2020-5-22 08:15
没有数据文件,看不出问题,也不能重现。

我传一个数据文件上来,重新建个帖子
作者: Zhuming    时间: 2020-5-22 08:29
链接:https://pan.baidu.com/s/1hlCBrQ2TBab_a-bgDcIMow
提取码:wsmp
文件太大,没法上传。传至百度云了。在线等!谢谢谢谢!!!
作者: Zhuming    时间: 2020-5-22 08:30
fcode 发表于 2020-5-22 08:15
没有数据文件,看不出问题,也不能重现。

链接:https://pan.baidu.com/s/1hlCBrQ2TBab_a-bgDcIMow
提取码:wsmp
文件太大,没法上传。传至百度云了。在线等!谢谢谢谢!!!
作者: Zhuming    时间: 2020-5-22 08:49
我对这个数据的的理解是,每一个年份和前面一个数字之间是有一个换行符的。而图片中展示的地方,不仅有换行符,还有一个空。这个地方原本应该是有一条数据,可能是某种原因导致这条数据缺失,没有记录下来,但是依旧给他分配了一个存放数据的位置。所以程序每次读到这里,就结束了,但是实际的循环次数远不止这么点,然后报错。是这样吗
作者: Zhuming    时间: 2020-5-22 09:42
fcode 发表于 2020-5-22 08:15
没有数据文件,看不出问题,也不能重现。

我在read(14,"(A512)",iostat=status1)cRead 后面加了一个
if(cRead=="")then
   cycle
end if
跳过那个空行,现在不报错了!
感谢你的帮助!
作者: necrohan    时间: 2020-5-22 11:12
Zhuming 发表于 2020-5-22 09:42
我在read(14,"(A512)",iostat=status1)cRead 后面加了一个
if(cRead=="")then
   cycle

你那个文件就是多了一个空行,而且后面还有,跳过去的方法很好。
用Ultraedit看这种文件吧,每行都能分开。
作者: Zhuming    时间: 2020-5-22 15:09
necrohan 发表于 2020-5-22 11:12
你那个文件就是多了一个空行,而且后面还有,跳过去的方法很好。
用Ultraedit看这种文件吧,每行都能分开 ...

好的!谢谢!




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