Чтение выдержки из файла txt для разработки файла временного ряда - PullRequest
0 голосов
/ 26 ноября 2018

Я пытаюсь разработать код для чтения текстового файла из моделей, который находится в этом формате

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

то есть место, дата, время, поток

есть предложения для этого ???

1 Ответ

0 голосов
/ 27 ноября 2018

Я сосредоточился только на чтении части.Предположим, у меня есть ваш файл с именем 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...