Fortran Coder

查看: 13931|回复: 1
打印 上一主题 下一主题

[文件读写] 对所给文件的一些操作

[复制链接]

9

帖子

4

主题

0

精华

入门

F 币
20 元
贡献
27 点
跳转到指定楼层
#
发表于 2020-5-17 14:42:38 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
20F 币
本帖最后由 顾雪晴 于 2020-5-17 14:42 编辑

提取TXT中的数据:
将时间(年月日、时分秒)读出到一个文件中,还有另外的数据读出到一个文件,再求每一列的平均值和方差,求出的方差和平均值放入数据文件相应每列的下方

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

37

帖子

9

主题

0

精华

专家

F 币
336 元
贡献
182 点

规矩勋章

楼主
发表于 2020-5-18 11:20:37 | 只看该作者
我也初学,尝试了一下,肯定会有问题,慢慢改。
[Fortran] 纯文本查看 复制代码
program hhhhh
implicit none
integer, parameter ::nline = 657 ! 数据的行数,不含第一行
integer::i
character*20::DDATE
character(len=79)::filename
! 数据及平均值

real*8::h1(nline),h2(nline),h3(nline),h4(nline),h5(nline),h6(nline),h7(nline)
real*8::h8(nline),h9(nline),h10(nline),h11(nline),h12(nline),h13(nline),h14(nline),h15(nline)   !!偷个懒,就是你文件从左往右读的数据名
real*8::avg_h1,avg_h2,avg_h3,avg_h4,avg_h5,avg_h6,avg_h7,avg_h8,avg_h9,avg_h10,avg_h11,avg_h12,avg_h13,avg_h14,avg_h15

    filename='wave P60597 181002 134510.txt'
    open(10,file=filename,status='old')
    OPEN(11,file="date.txt",status="replace")
    OPEN(12,file='data.txt',status="replace")
    
    read(10,*)
    do i=1,nline
        read(10,*) DDATE,h1(i),h2(i),h3(i),h4(i),h5(i),h6(i),h7(i),h8(i),h9(i),h10(i),h11(i),h12(i),h13(i),h14(i),h15(i)! 读入数据
        write(*,*)trim(DDATE),h1(i),h2(i),h3(i),h4(i),h5(i),h6(i),h7(i),h8(i),h9(i),h10(i),h11(i),h12(i),h13(i),h14(i),h15(i)
    end do
    close(10)

        ! 计算平均值
    avg_h1=sum(h1)/nline
    avg_h2=sum(h2)/nline
    avg_h3=sum(h3)/nline
    avg_h4=sum(h4)/nline
    avg_h5=sum(h5)/nline
    avg_h6=sum(h6)/nline
    avg_h7=sum(h7)/nline
    avg_h8=sum(h8)/nline
    avg_h9=sum(h9)/nline
    avg_h10=sum(h10)/nline
    avg_h11=sum(h11)/nline
    avg_h12=sum(h12)/nline
    avg_h13=sum(h13)/nline
    avg_h14=sum(h14)/nline
    avg_h15=sum(h15)/nline
    write(*,*)avg_h1,avg_h2,avg_h3,avg_h4,avg_h5,avg_h6,avg_h7,avg_h8,avg_h9,avg_h10,avg_h11,avg_h12,avg_h13,avg_h14,avg_h15 ! 输出到屏幕
    write(11,*)TRIM(DDATE)!时间输出到ddate.txt
    write(12,*)h1(i),h2(i),h3(i),h4(i),h5(i),h6(i),h7(i),h8(i),h9(i),h10(i),h11(i),h12(i),h13(i),h14(i),h15(i)
    write(12,*)avg_h1,avg_h2,avg_h3,avg_h4,avg_h5,avg_h6,avg_h7,avg_h8,avg_h9,avg_h10,avg_h11,avg_h12,avg_h13,avg_h14,avg_h15
    CLOSE(11)
    CLOSE(12)
end

评分

参与人数 1F 币 +1 收起 理由
fcode + 1 为啥不用二维数组?

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-12-24 01:15

Powered by Tencent X3.4

© 2013-2024 Tencent

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