Fortran Coder

标题: 求数据处理代码,谢谢! [打印本页]

作者: shurrik_tao    时间: 2021-3-9 16:25
标题: 求数据处理代码,谢谢!
各位大佬,现在需要进行数据处理,小弟新手,麻烦帮助谢谢!
数据文档有300+个数据模块,附件为其中一个模块,剩下的数据在一个文档内跟在后面,测试的时候可以复制进去。
需求:
1:提取出密度后面的数值到文档1
2:分别提取出“Neutrons”和“Photons”后面的数据的第一列和第二列到文档2和文档3。比如该附件内需要提取出的文档为:
文档1
1.127000
文档2
1001    -0.101327   (注:该处的行数不定)
6000    -0.775501
7014    -0.035057
8016    -0.052316
9019    -0.017422
20000  -0.018378

文档3
1000    -0.101327
6000    -0.775501
7000    -0.035057
8000    -0.052316
9000    -0.017422
20000  -0.018378

谢谢!

Shielding Material Handbook.dat

1.5 KB, 下载次数: 2

数据文档


作者: fcode    时间: 2021-3-9 16:51
[Fortran] 纯文本查看 复制代码
Program Fcode
  Implicit None
  Character(len=512) :: cStr
  integer :: k
  Open(12,File="Shielding Material Handbook.dat")
  Open(21,File="文档1")
  Open(22,File="文档2")
  Open(23,File="文档3")
  Do
    Read(12,"(a512)",ioStat=k) cStr
    if(k/=0) exit
    If( cStr(1:7) == "Density" ) then
      k = index(cStr,"=")
      if(k>3) write(21,*) trim(adjustl(cStr(k+1:)))
    ElseIf( cStr(1:8) == "Neutrons" ) then
      call PutRows(12,22)
    ElseIf( cStr(1:7) == "Photons" ) then
      call PutRows(12,23)
    End If
  End Do
  Close(12)
  Close(21)
  Close(22)
  Close(23)
contains

  Subroutine PutRows(fuIn,fuOut)
    integer :: fuIn , fuOut , j , k
    real :: r
    Do
      read(fuIn,*,ioStat=k) j , r
      if(k/=0) then
        backspace(fuIn)
        return
      end if
      write(fuOut,*) j , r
    End Do
  End Subroutine PutRows
  
End Program Fcode





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