读取txt文件中的摘录以开发时间序列文件

时间:2018-11-26 10:26:14

标签: fortran

我正在尝试开发一种代码,以从这种格式的模型输出中读取文本文件

awsconfiguration.json

我正在尝试以以下格式制作文本文件

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  

即位置日期时间流

对此有何建议?

1 个答案:

答案 0 :(得分:0)

我只专注于阅读部分。假设我有一个名为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