本帖最后由 necrohan 于 2020-5-11 14:43 编辑
把那个文件里的tab分隔用逗号替换,增加读入变量自己修改,计算方差自己增加,对齐输出没有考虑
[Fortran] 纯文本查看 复制代码 implicit none
integer, parameter ::nline = 2 ! 行数
integer::i
character*20::c
! 数据及平均值
real*8::h(nline),avg_h
real*8::hts(nline),avg_hts
real*8::ETAmax(nline),avg_ETAmax
open(10,file='wave.txt')
read(10,*)
do i=1,nline
read(10,'(a18,f,f,f)')c,h(i),hts(i),ETAmax(i) ! 读入数据
write(*,*)trim(c),h(i),hts(i),ETAmax(i)
end do
close(10)
! 计算平均值
avg_h=sum(h)/nline
avg_hts=sum(hts)/nline
avg_ETAmax=sum(ETAmax)/nline
write(*,*)avg_h,avg_hts,avg_ETAmax ! 输出
end |