@@ -324,6 +324,29 @@ def _respond_to_istat_state(self, istat):
324324 elif istat > 9 :
325325 # should this be an exception?
326326 raise RuntimeError ("Illegal internal call" )
327+
328+ def _parse_times (self , pathname , startDateStr = None , endDateStr = None ):
329+ '''
330+ parse times based on pathname or startDateStr and endDateStr
331+ start date and end dates may be padded to include a larger interval
332+ '''
333+ interval = self .parse_pathname_epart (pathname )
334+ if startDateStr is None or endDateStr is None :
335+ twstr = pathname .split ("/" )[4 ]
336+ if twstr .find ("-" ) < 0 :
337+ if len (twstr .strip ()) == 0 :
338+ raise Exception (
339+ "No start date or end date and twstr is " + twstr )
340+ sdate = edate = twstr
341+ else :
342+ sdate , edate = twstr .split ("-" )
343+ if startDateStr is None :
344+ startDateStr = sdate .strip ()
345+ if endDateStr is None :
346+ endDateStr = edate .strip ()
347+ endDateStr = self ._pad_to_end_of_block (
348+ endDateStr , interval )
349+ return startDateStr , endDateStr
327350
328351 def read_rts (self , pathname , startDateStr = None , endDateStr = None ):
329352 """
@@ -336,25 +359,9 @@ def read_rts(self, pathname, startDateStr=None, endDateStr=None):
336359 if not opened_already :
337360 self .open ()
338361 interval = self .parse_pathname_epart (pathname )
339- trim_first = False
340- trim_last = False
341- if startDateStr is None or endDateStr is None :
342- twstr = pathname .split ("/" )[4 ]
343- if twstr .find ("-" ) < 0 :
344- if len (twstr .strip ()) == 0 :
345- raise Exception (
346- "No start date or end date and twstr is " + twstr )
347- sdate = edate = twstr
348- else :
349- sdate , edate = twstr .split ("-" )
350- if startDateStr is None :
351- trim_first = True
352- startDateStr = sdate .strip ()
353- if endDateStr is None :
354- trim_last = True
355- endDateStr = edate .strip ()
356- endDateStr = self ._pad_to_end_of_block (
357- endDateStr , interval )
362+ trim_first = startDateStr is None
363+ trim_last = endDateStr is None
364+ startDateStr , endDateStr = self ._parse_times (pathname , startDateStr , endDateStr )
358365 nvals = self .num_values_in_interval (startDateStr , endDateStr , interval )
359366 sdate = parse (startDateStr )
360367 cdate = sdate .date ().strftime ('%d%b%Y' ).upper ()
@@ -426,23 +433,8 @@ def read_its(self, pathname, startDateStr=None, endDateStr=None, guess_vals_per_
426433 from the D-PART of the pathname so make sure to read that from the catalog
427434 before calling this function
428435 """
429- parts = pathname .split ('/' )
430- epart = parts [5 ]
431- if len (parts [4 ].strip ()) == 0 :
432- if startDateStr == None or endDateStr == None :
433- raise Exception (
434- "Either pathname D PART contains timewindow or specify in startDateStr and endDateStr for this call" )
435- nsdate = parse (startDateStr )
436- nsbdate = datetime (nsdate .year ,1 ,1 )
437- nedate = parse (endDateStr )
438- nebdate = datetime (nedate .year ,1 ,1 )
439- startDateStr = nsbdate .strftime (DATE_FMT_STR )
440- endDateStr = nebdate .strftime (DATE_FMT_STR )
441- parts [4 ] = startDateStr + " - " + endDateStr
442- else :
443- tw = list (map (lambda x : x .strip (), parts [4 ].split ('-' )))
444- startDateStr = tw [0 ]
445- endDateStr = self ._pad_to_end_of_block (tw [1 ], epart )
436+ epart = self .parse_pathname_epart (pathname )
437+ startDateStr ,endDateStr = self ._parse_times (pathname , startDateStr , endDateStr )
446438 juls , istat = pyheclib .hec_datjul (startDateStr )
447439 jule , istat = pyheclib .hec_datjul (endDateStr )
448440 ietime = istime = 0
0 commit comments