Fortran Coder

标题: 对所给文件的一些操作 [打印本页]

作者: 顾雪晴    时间: 2020-5-17 14:42
标题: 对所给文件的一些操作
本帖最后由 顾雪晴 于 2020-5-17 14:42 编辑

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

作者: Zhuming    时间: 2020-5-18 11:20
我也初学,尝试了一下,肯定会有问题,慢慢改。
[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





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