Skip to content

Commit

Permalink
changes in epanet class - input arg msxfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariosmsk committed Mar 24, 2024
1 parent 46e0f14 commit bc501db
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions epyt/epanet.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def isList(var):
class epanet:
""" EPyt main functions class """

def __init__(self, *argv, version=2.2, loadfile=False, msx=False):
def __init__(self, *argv, version=2.2, loadfile=False, msxfile=None):
# Constants
# Demand model types. DDA #0 Demand driven analysis,
# PDA #1 Pressure driven analysis.
Expand Down Expand Up @@ -563,6 +563,7 @@ def __init__(self, *argv, version=2.2, loadfile=False, msx=False):

# Initial attributes
self.classversion = __version__
msx = True if msxfile is not None else False
self.api = epanetapi(version, msx=msx)
print(f'EPANET version {self.getVersion()} '
f'loaded (EPyT version {self.classversion}).')
Expand Down Expand Up @@ -633,8 +634,8 @@ def __init__(self, *argv, version=2.2, loadfile=False, msx=False):
plt.rcParams['figure.constrained_layout.use'] = True
plt.rcParams['figure.max_open_warning'] = 30

if msx:
self.msx = epanetmsxapi()
if msxfile is not None:
self.msx = epanetmsxapi(msxfile)

def addControls(self, control, *argv):
""" Adds a new simple control.
Expand Down Expand Up @@ -12836,10 +12837,8 @@ def __init__(self, version=2.2, msx=False):
self._lib = cdll.LoadLibrary(self.LibEPANET)
self.LibEPANETpath = os.path.dirname(self.LibEPANET)

if float(version) >= 2.2 and '64' in str(platform.architecture()) and not msx:
if float(version) >= 2.2 and 'win' in str(platform.architecture()) and not msx:
self._ph = c_uint64()
elif float(version) >= 2.2 and not msx:
self._ph = c_uint32()
else:
self._ph = None

Expand Down Expand Up @@ -15654,7 +15653,7 @@ def ENwriteline(self, line):
class epanetmsxapi:
"""example msx = epanetmsxapi()"""

def __init__(self, filename=''):
def __init__(self, msxfile=''):
ops = platform.system().lower()
if ops in ["windows"]:
self.MSXLibEPANET = resource_filename("epyt", os.path.join("libraries", "win", "epanetmsx.dll"))
Expand All @@ -15669,11 +15668,11 @@ def __init__(self, filename=''):
self.msx_error = self.msx_lib.MSXgeterror
self.msx_error.argtypes = [c_int, c_char_p, c_int]

if not os.path.exists(filename):
raise FileNotFoundError(f"File not found: {filename}")
if not os.path.exists(msxfile):
raise FileNotFoundError(f"File not found: {msxfile}")

print("Opening MSX file:", filename)
filename = c_char_p(filename.encode('utf-8'))
print("Opening MSX file:", msxfile)
filename = c_char_p(msxfile.encode('utf-8'))
err = self.msx_lib.MSXopen(filename)
if err != 0:
self.MSXerror(err)
Expand All @@ -15682,7 +15681,7 @@ def __init__(self, filename=''):
else:
print("MSX file opened successfully.")

def MSXopen(self, filename):
def MSXopen(self, msxfile):
"""
Open MSX file
filename - Arsenite.msx or use full path
Expand All @@ -15691,12 +15690,12 @@ def MSXopen(self, filename):
msx.MSXopen(filename)
msx.MSXopen(Arsenite.msx)
"""
print("Opening MSX file:", filename)
if not os.path.exists(filename):
raise FileNotFoundError(f"File not found: {filename}")
print("Opening MSX file:", msxfile)
if not os.path.exists(msxfile):
raise FileNotFoundError(f"File not found: {msxfile}")

filename = c_char_p(filename.encode('utf-8'))
err = self.msx_lib.MSXopen(filename)
msxfile = c_char_p(msxfile.encode('utf-8'))
err = self.msx_lib.MSXopen(msxfile)
if err != 0:
self.MSXerror(err)
if err == 503:
Expand Down

0 comments on commit bc501db

Please sign in to comment.