Skip to content

Commit

Permalink
Fix python part to work with both sequential and parallel libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
AWehrhahn committed Jul 14, 2021
1 parent 8be7a23 commit 31e9da5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions test/cwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,12 @@ def call(self, name, *args, raise_error=True, raise_warning=False, **kwargs):
"{name} (call external): {error}".format(name=name, error=error)
)
return error

def new_state(self):
try:
return idl_call_external("NewState", lib=self.lib, restype="state")
except AttributeError:
return None

def free_state(self, state):
return idl_call_external("FreeState", state=state)
12 changes: 8 additions & 4 deletions test/sme_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, libfile=None, datadir=None):
self.ion = None

self.lib = IDL_DLL(libfile)
self.parallel = False
self.state = self.NewState()

if datadir is not None:
Expand Down Expand Up @@ -94,14 +95,17 @@ def check_data_files_exist(self):
def NewState(self, delete_old=True):
if delete_old and hasattr(self, "state") and self.state is not None:
self.FreeState()
self.state = self.lib.call(
"NewState", restype="state", raise_error=False, raise_warning=False
)
self.state = self.lib.new_state()
if self.state is None:
self.parallel = False
else:
self.parallel = True

return self.state

def FreeState(self):
if self.state is not None:
self.lib.call("FreeState", raise_error=False, raise_warning=False, state=self.state)
self.lib.free_state(self.state)
self.state = None

def SMELibraryVersion(self):
Expand Down

0 comments on commit 31e9da5

Please sign in to comment.