-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTVGM_to_swmm.m
104 lines (98 loc) · 3.42 KB
/
TVGM_to_swmm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function TVGM_to_swmm(input,inp_Precip)
% ------------------------------------------------------------------------------------------------------------
% This function couples TVGM-Urban and SWMM model in a loose way.
% The TVGM-Urban flows is writen as a sequence of timeseries to replace the contents of the [TIMESERIES] module in the SWMM.inp file,
% and modifies START_DATE, START_TIME, REPORT_START_DATE, REPORT_START_TIME, END_DATE, END_TIME.
% The [INFLOWS] module of the SWMM.inp file use this timeseries during the control simulation
% ------------------------------------------------------------------------------------------------------------
add = inp_Precip;
START_DATE = inp_Precip(1,2);
START_TIME = inp_Precip(1,3);
REPORT_START_DATE = inp_Precip(1,2);
REPORT_START_TIME = inp_Precip(1,3);
END_DATE = inp_Precip(end,2);
END_TIME = inp_Precip(end,3);
oldinp = fopen(input,'rt+');% 需要读取的文件
timeseries = fopen('timeseries.txt','wt+');
Title = ["[TIMESERIES]", ";;Name Date Time Value", ";;-------------- ------------------ ------------------"];
fprintf(timeseries,'%s\n',Title);
% save the original information in [TIMESERIES]
%i = 0;
%k1 = 0;
%while ~feof(oldinp)
% tline= fgetl(oldinp);
% if tline == -1
% break;
% end
% %disp(tline)
% i=i+1;
% if contains(tline,'[TIMESERIES]')
% k1 = 1;
%
% elseif contains(tline,'[REPORT]')
% k1 = 0;
% end
%
% if k1 && tline~=""
% fprintf(timeseries,'%s\n',tline);
% end
%end
%fprintf(timeseries,'%s\n',';');
for i = 1 : length(add)
tline = strjoin(add(i,:),'\t');
fprintf(timeseries,'%s\n',tline);
end
fprintf(timeseries,'%s\n',' ');
frewind(oldinp)
frewind(timeseries)
i = 0;
k1 = 0;
while ~feof(oldinp)
tline = fgetl(oldinp);
i = i+1;
if tline == -1
break
elseif contains(tline,'[TIMESERIES]')
k1 = 1;
while ~feof(timeseries)
newData = fgetl(timeseries);
if newData == -1
break
else
newline{i} = newData;
end
i=i+1;
end
elseif contains(tline,'[REPORT]')
k1 = 0;
end
if k1
i = i-1;
else
if contains(tline,'START_DATE') && ~contains(tline,'REPORT')
newline{i} = convertStringsToChars(strcat("START_DATE"," ",START_DATE));
elseif contains(tline,'START_TIME') && ~contains(tline,'REPORT')
newline{i} = convertStringsToChars(strcat("START_TIME"," ",START_TIME));
elseif contains(tline,'REPORT_START_DATE')
newline{i} = convertStringsToChars(strcat("REPORT_START_DATE"," ",REPORT_START_DATE));
elseif contains(tline,'REPORT_START_TIME')
newline{i} = convertStringsToChars(strcat("REPORT_START_TIME"," ",REPORT_START_TIME));
elseif contains(tline,'END_DATE')
newline{i} = convertStringsToChars(strcat("END_DATE"," ",END_DATE));
elseif contains(tline,'END_TIME')
newline{i} = convertStringsToChars(strcat("END_TIME"," ",END_TIME));
else
newline{i} = tline;
end
end
end
fclose(oldinp);
delete(input);
newinp = fopen(input,'wt+');
for k = 1:i-1
fprintf(newinp,'%s\n',newline{k});
end
fclose(newinp);
fclose(timeseries);
delete("timeseries.txt");
end