55##
66
77from .base_io import *
8+ import copy
89
910# Some constants
1011ELEVATION = 0
@@ -94,6 +95,14 @@ def properties(self):
9495 def properties (self , value ):
9596 self ._properties = value
9697
98+ @property
99+ def property_names (self ):
100+ return self ._property_names
101+
102+ @property_names .setter
103+ def property_names (self , value ):
104+ self ._property_names = value
105+
97106 @property
98107 def use_timeseries (self ):
99108 return self ._timeseries
@@ -123,7 +132,7 @@ def __init__(self, input):
123132
124133 def read (self , fname ):
125134 """Read in 'hydraulics.in' file."""
126- print ("Reading in" + fname + "..." )
135+ print ("Reading in " + fname + "..." )
127136 f = open (fname , "r" )
128137 # # of blocks
129138 tokens , ok = self ._read_and_parse_line (f , 1 )
@@ -133,6 +142,7 @@ def read(self, fname):
133142 nudging = float (tokens [0 ])
134143 # Loof for structure
135144 for struct_i in range (n_structures ):
145+ struct2 = False
136146 struct = SchismStructure ()
137147 # index and name
138148 tokens , ok = self ._read_and_parse_line (f , 2 )
@@ -168,6 +178,13 @@ def read(self, fname):
168178 op_down = float (tokens [1 ])
169179 op_up = float (tokens [2 ])
170180 struct .properties = [elevation , width , coeff , op_down , op_up ]
181+ struct .property_names = [
182+ "elevation" ,
183+ "width" ,
184+ "coeff" ,
185+ "op_down" ,
186+ "op_up" ,
187+ ]
171188 elif struct_type == "radial" or struct_type == "orifice" :
172189 tokens , ok = self ._read_and_parse_line (f , 3 )
173190 elevation = float (tokens [0 ])
@@ -178,19 +195,89 @@ def read(self, fname):
178195 op_down = float (tokens [1 ])
179196 op_up = float (tokens [2 ])
180197 struct .properties = [elevation , width , height , coeff , op_down , op_up ]
198+ struct .property_names = [
199+ "elevation" ,
200+ "width" ,
201+ "height" ,
202+ "coeff" ,
203+ "op_down" ,
204+ "op_up" ,
205+ ]
181206 elif struct_type == "transfer" :
182207 tokens , ok = self ._read_and_parse_line (f , 1 )
183208 flow = float (tokens [0 ])
184209 struct .properties = [flow ]
210+ struct .property_names = ["flow" ]
211+ elif struct_type == "radial_relheight" :
212+ tokens , ok = self ._read_and_parse_line (f , 3 )
213+ elevation = float (tokens [0 ])
214+ width = float (tokens [1 ])
215+ height = float (tokens [2 ])
216+ tokens , ok = self ._read_and_parse_line (f , 2 )
217+ coeff = float (tokens [0 ])
218+ coef_height = float (tokens [1 ])
219+ tokens , ok = self ._read_and_parse_line (f , 2 )
220+ op_down = float (tokens [0 ])
221+ op_up = float (tokens [1 ])
222+ struct .properties = [elevation , width , height , coeff , op_down , op_up ]
223+ struct .property_names = [
224+ "elevation" ,
225+ "width" ,
226+ "height" ,
227+ "coeff" ,
228+ "op_down" ,
229+ "op_up" ,
230+ ]
231+ elif struct_type == "weir_culvert" :
232+ # get weir data first
233+ tokens , ok = self ._read_and_parse_line (f , 2 )
234+ elevation = float (tokens [0 ])
235+ width = float (tokens [1 ])
236+ tokens , ok = self ._read_and_parse_line (f , 3 )
237+ coeff = float (tokens [0 ])
238+ op_down = float (tokens [1 ])
239+ op_up = float (tokens [2 ])
240+ struct .properties = [elevation , width , height , coeff , op_down , op_up ]
241+ struct .property_names = [
242+ "elevation" ,
243+ "width" ,
244+ "height" ,
245+ "coeff" ,
246+ "op_down" ,
247+ "op_up" ,
248+ ]
249+ struct2 = copy .deepcopy (struct )
250+ struct2 .n_duplicate = n_duplicate
251+ # n_duplicates for culvert
252+ tokens , ok = self ._read_and_parse_line (f , 1 )
253+ cn_duplicate = int (tokens [0 ])
254+ tokens , ok = self ._read_and_parse_line (f , 2 )
255+ elevation = float (tokens [0 ])
256+ width = float (tokens [1 ])
257+ tokens , ok = self ._read_and_parse_line (f , 3 )
258+ coeff = float (tokens [0 ])
259+ op_down = float (tokens [1 ])
260+ op_up = float (tokens [2 ])
261+ struct2 .properties = [elevation , width , coeff , op_down , op_up ]
262+ struct2 .property_names = [
263+ "elevation" ,
264+ "width" ,
265+ "coeff" ,
266+ "op_down" ,
267+ "op_up" ,
268+ ]
185269 else :
186- raise Exception ("Not supported structure type" )
270+ raise Exception (f "Not supported structure type { struct_type } " )
187271
188272 # Time series
189273 tokens , ok = self ._read_and_parse_line (f , 1 )
190274 timeseries = int (tokens [0 ])
191275 struct .use_timeseries = timeseries
192276 # Add the structure
193277 self ._input .add_structure (struct )
278+ if struct2 :
279+ struct2 .use_timeseries = timeseries
280+ self ._input .add_structure (struct2 )
194281
195282 f .close ()
196283 print ("Done reading a structure file." )
@@ -295,7 +382,7 @@ def write(self, fname="hydraulics.in"):
295382 struct .properties ["culvert_n_duplicates" ]
296383 )
297384 f .write (buf )
298- buf = "%f %f\n " % (
385+ buf = "%f %f! elevation and width for culverts \n " % (
299386 struct .properties ["culvert_elevation" ],
300387 struct .properties ["culvert_radius" ],
301388 )
0 commit comments