Skip to content

Commit

Permalink
some fixes, return warnflag and errcode in getComputedTime*
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariosmsk committed Apr 17, 2024
1 parent 3c91160 commit a9e3226
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions epyt/epanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ class epanet:

def __init__(self, *argv, version=2.2, ph=False, loadfile=False, msx=False, customlib=None):
# Constants
# Demand model types. DDA #0 Demand driven analysis,
warnings.simplefilter('always')
# Demand model types. DDA #0 Demand driven analysis,
# PDA #1 Pressure driven analysis.
self.msxname = None
self.DEMANDMODEL = ['DDA', 'PDA']
Expand Down Expand Up @@ -2362,6 +2363,12 @@ def getComputedTimeSeries(self):
value_final = self.getComputedTimeSeries_ENepanet()
return value_final
value = self.__readEpanetBin(fid, binfile, 0)
value.WarnFlag = False
if self.errcode:
value.WarnFlag = True
value.ErrCode = self.errcode
self.api.ENgeterror(self.errcode)

value.StatusStr = {}
for i in range(1, len(value.Status) + 1):
value.StatusStr[i] = []
Expand Down Expand Up @@ -2393,6 +2400,10 @@ def getComputedTimeSeries_ENepanet(self):
self.api.ENepanet(self.TempInpFile, rptfile, binfile)
fid = open(binfile, "rb")
value = self.__readEpanetBin(fid, binfile, 0)
value.WarnFlag = False
if self.errcode:
value.ErrCode = self.errcode
value.WarnFlag = True
value.StatusStr = {}
for i in range(1, len(value.Status) + 1):
value.StatusStr[i] = []
Expand Down Expand Up @@ -10923,7 +10934,7 @@ def __readEpanetBin(self, f, binfile, *argv):
value.IDLabelEachLink = []
for i in range(value.NumberLinks):
value.IDLabelEachLink.append(f.read(32).replace(b'\x00', b'').decode())
while (True):
while True:
binval = list(f.read(1))[0]
if binval != 0:
break
Expand Down Expand Up @@ -11001,8 +11012,13 @@ def __readEpanetBin(self, f, binfile, *argv):
value.AverageTankReactionRate = struct.unpack('f', f.read(4))
value.AverageSourceInflowRate = struct.unpack('f', f.read(4))
value.NumberReportingPeriods2 = list(f.read(1))[0]
f.read(1)
f.read(1)
f.read(1)
value.WarningFlag = list(f.read(1))[0]
value.MagicNumber = f.read(10)
self.errcode = value.WarningFlag
# check here - error
value.MagicNumber = struct.unpack('b', f.read(1))

if len(argv) > 0:
v = EpytValues()
Expand Down Expand Up @@ -13728,13 +13744,15 @@ def ENgetelseaction(self, ruleIndex, actionIndex):
self.ENgeterror()
return [linkIndex.value, status.value, setting.value]

def ENgeterror(self):
def ENgeterror(self, errcode=0):
""" Returns the text of an error message generated by an error code, as warning.

ENgeterror()

"""
if self.errcode:
if self.errcode or errcode:
if errcode:
self.errcode = errcode
errmssg = create_string_buffer(150)
self._lib.ENgeterror(self.errcode, byref(errmssg), 150)
warnings.warn(errmssg.value.decode())
Expand Down

0 comments on commit a9e3226

Please sign in to comment.