Fortran Coder

查看: 8904|回复: 2
打印 上一主题 下一主题

[文件读写] 运行完出现fort.28文件

[复制链接]

37

帖子

9

主题

0

精华

专家

F 币
336 元
贡献
182 点

规矩勋章

跳转到指定楼层
楼主
发表于 2020-6-20 18:52:00 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
说明:我是想将年数据,按1-12月提取出来,写入12个txt中。运行结果是:8月的数据和原始年数据一模一样。其他月份看上去正常。接着我将数据写入month8.txt的命令注释掉,运存出来,month8.txt依旧和原始数据文件一样。再接着,我把open()语句中month8.txt的文件通道号改成了33(原先是28),在运行时,month8.txt这次是没有数据的,但是多出来一个fort.28文件,大小和原数据文件一样大。因为原始文件比较大,传不了,我上传一个小一点的版本。
[Fortran] 纯文本查看 复制代码
program fkk
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::month,month1
    integer::i,j
    
    open(11,file='2014.txt',status='old',form='formatted')
    open(12,file='record.txt',status='replace')
    OPEN(21,file='month1.txt',status='replace',form='formatted')
    OPEN(22,file='month2.txt',status='replace',form='formatted')
    OPEN(23,file='month3.txt',status='replace',form='formatted')
    OPEN(24,file='month4.txt',status='replace',form='formatted')
    OPEN(25,file='month5.txt',status='replace',form='formatted')
    OPEN(26,file='month6.txt',status='replace',form='formatted')
    OPEN(27,file='month7.txt',status='replace',form='formatted')
    OPEN(33,file='month8.txt',status='replace',form='formatted')
    OPEN(29,file='month9.txt',status='replace',form='formatted')
    OPEN(30,file='month10.txt',status='replace',form='formatted')
    OPEN(31,file='month11.txt',status='replace',form='formatted')
    OPEN(32,file='month12.txt',status='replace',form='formatted')
    
        do while(.true.)
            READ(11,"(A512)",iostat=status1)cRead
            if (status1/=0) exit
            CALL parserRead(cRead)
!            write(*,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
!            READ(wwlln_date(1:4),"(I4)")year
!            write(*,*)year
            write(*,*) LEN_TRIM(wwlln_date)
            if(LEN_TRIM(wwlln_date)/=10) then    !这里是因为我的文件中大部分日期格式例如:2014/08/12,但有的月份是2014/8/10或者2014/8/1
                CALL specialread(wwlln_date)
                write(12,*)month1
            else
                READ(wwlln_date(6:7),"(I2)")month
                write(*,*)wwlln_date,month
            end if

            if(month==1) write(21,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==2) write(22,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==3) write(23,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==4) write(24,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==5) write(25,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==6) write(26,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==7) write(27,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==8) write(33,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==9) write(29,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==10) write(30,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==11) write(31,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            if(month==12) write(32,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            
            do i=21,32,1
                j=i-20
                if(month1==j) write(i,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            end do
            
        end do
    CLOSE(11)
    CLOSE(12)

        
        
        
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
    
    subroutine specialread(d)
        character(LEN=*)::d
        
        READ(d(6:6),"(I1)")month1

    end subroutine specialread
end program

QQ截图20200620184536.png (53.84 KB, 下载次数: 170)

QQ截图20200620184536.png

20140604.txt

914.83 KB, 下载次数: 0

分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

37

帖子

9

主题

0

精华

专家

F 币
336 元
贡献
182 点

规矩勋章

沙发
 楼主| 发表于 2020-6-20 18:58:43 | 只看该作者
另外改完文件号之后(month8.txt的,原先是28号,改成了33),运行结果month8.txt大小为0kb,就是没有数据写入。也就是说if(month==8) write(33,*)wwlln_date,wwlln_time,lat,lon,timingerror,station,这条命令无作用,是个摆设。
在线等,谢谢!

37

帖子

9

主题

0

精华

专家

F 币
336 元
贡献
182 点

规矩勋章

板凳
 楼主| 发表于 2020-6-20 19:45:43 | 只看该作者
我笨的离谱哈哈哈....fort.28是因为我把文件号改了,但输出的还是28号文件。
另外,我尝试了把下面语句
            do i=21,32,1
                j=i-20
                if(month1==j) write(i,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
            end do
这个语句放到else上边,然后将 if(month==1) write(21,*)wwlln_date,wwlln_time,lat,lon,timingerror,station....这些if都放到end if 前面,就没问题了。这个也可以用do 循环来写,一样的。
还有要加close,close也可以用do来写。我本来写了,后来为了测出到底哪里出问题,然后删了....
最后还是想请问下,为什么原先这样写,month8.txt会是原数据文件呢?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-25 15:21

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表