def __init__(self, output_file_name): """ Open the named file and maintain an internal pointer to be used to access contents of the file. Read header information from the file including units, times, and lists of nodes and links. Args output_file_name (str): full path and file name of EPANET binary output file to open """ self._call_int_return = c_int( ) # Private variable used only inside call_int self._call_double_return = c_double( ) # Private variable used only inside call_double self.output_file_name = str(output_file_name) self.ptrapi = _lib.ENR_init() ret = _lib.ENR_open(self.ptrapi, self.output_file_name) if ret != 0: self._raise_error(ret) file_version = self._call_int(_lib.ENR_getVersion) print("ENR opened {} Version {}".format(output_file_name, str(file_version))) self._measure_new_out_value_series() self._get_units() self.dates = [] self.times = [] self._get_times() self.nodes = ENR_node_type.read_all(self) self.links = ENR_link_type.read_all(self) self.all_items = (self.nodes, self.links)
def __init__(self, binfile): """ 1) Initializes the opaque pointer to enrapi struct. 2) Opens the output file. """ self.enrapi = c_void_p() ret = _lib.ENR_open(byref(self.enrapi), str(binfile)) if ret != 0: self.RaiseError(ret) self._get_Units() self._get_NetSize() self._get_Times() self._cache_node_ids() self._cache_link_ids()
def open(filename): addr=ctypes.c_void_p() errcheck(_lib.ENR_open(ctypes.byref(addr), filename) ) return addr
"""example: direct call thougt ctypesgen generated module """ import ctypes from Externals.epanet.outputapi import outputapi as _lib label = _lib.String( (_lib.MAXID+1)*'\0') errmsg = _lib.String( (_lib.MAXMSG+1)*'\0') k=ctypes.c_int() x= ctypes.c_float() addr=ctypes.c_void_p() filename= "Net1.bin" if _lib.ENR_open(ctypes.byref(addr), filename) ==0 : print "\nfile {0} successfuly opened\n".format(filename) else: exit() if _lib.ENR_getNetSize(addr, _lib.ENR_nodeCount, ctypes.byref(k)) ==0 : print "nodes: {0}".format(k.value) if _lib.ENR_getNetSize(addr, _lib.ENR_tankCount, ctypes.byref(k)) ==0 : print "tanks: {0}".format(k.value) if _lib.ENR_getNetSize(addr, _lib.ENR_linkCount, ctypes.byref(k)) ==0 : print "links: {0}".format(k.value) if _lib.ENR_getNetSize(addr, _lib.ENR_pumpCount, ctypes.byref(k)) ==0 : print "pumps: {0}".format(k.value)