Fortran 从txt文件中读取摘录以开发时间序列文件
我正试图开发一个代码,从这个格式的模型输出中读取一个文本文件Fortran 从txt文件中读取摘录以开发时间序列文件,fortran,Fortran,我正试图开发一个代码,从这个格式的模型输出中读取一个文本文件 SWMM5 Interface File Angus Road- City of Mitcham 60 - reporting time step in sec 2 - number of constituents as listed below: FLOW CMS TSS MG/L 1 - number of nodes as listed below: Outfall1 Node Year
SWMM5 Interface File
Angus Road- City of Mitcham
60 - reporting time step in sec
2 - number of constituents as listed below:
FLOW CMS
TSS MG/L
1 - number of nodes as listed below:
Outfall1
Node Year Mon Day Hr Min Sec FLOW TSS
Outfall1 2015 12 09 12 25 00 0.000000 0.000000
Outfall1 2015 12 09 12 26 00 0.000000 0.000000
Outfall1 2015 12 09 12 27 00 0.000000 0.000000
Outfall1 2015 12 09 12 28 00 0.000000 0.000000
Outfall1 2015 12 09 12 29 00 0.000000 0.000000
Outfall1 2015 12 09 12 30 00 0.000000 0.000000
我正在尝试用以下格式制作一个文本文件
outfall1 12/09/2015 12:26:00 0.000000
i、 e.地点日期时间流
对此有什么建议吗?我只关注阅读部分。假设我有一个名为test.txt的文件,我会这样读:
program read_test
implicit none
integer :: i !iteration
integer :: number_of_read_lines
integer :: number_of_forgotten_lines
character :: forgotten_line*5
character :: node*12
integer :: time(6)
real :: x(2)
number_of_forgotten_lines=9
number_of_read_lines=3
open (22, FILE='test.txt', STATUS='OLD')
! I do not care what I read here, simple jump the lines
do i=1,number_of_forgotten_lines
read(22,*) forgotten_line
end do
! here I read the data
do i=1,number_of_read_lines
! I think it is easier to read without format specification,
! though type of variable must be correct!
read(22,*) node,time,x
! test what you read, here it is usually better to use format specification
print*, i,node,time,x
end do
close (22)
end program
欢迎来到堆栈溢出。请拿着这本书学习。然后,给我们一个清晰的描述,你想做什么,你错了什么,你期望得到什么,以及。这一行
read(22,*)节点,time(1),time(2),time(3),time(4),time(5),time(6),x(1),x(2)
可能被有效地缩写为read(22,*)节点,time,x
。