Skip to content

Commit

Permalink
Allow package to be imported without ext C library
Browse files Browse the repository at this point in the history
Signed-off-by: Conor MacBride <conor@macbride.me>
  • Loading branch information
ConorMacBride committed Sep 1, 2020
1 parent 51fd817 commit c2b2f0e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/mcalf/profiles/voigt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
# gcc -Wall -fPIC -c voigt.c
# gcc -shared -o libvoigt.so voigt.o
dllabspath = "{0}{1}".format(os.path.dirname(os.path.abspath(__file__)), os.path.sep) # Path to libraries directory
libfile = glob.glob('{}ext_voigtlib.*.so'.format(dllabspath))[0] # Select first (and only) library in this directory
lib = ctypes.CDLL(libfile) # Load the library
lib.func.restype = ctypes.c_double # Specify the expected result type
lib.func.argtypes = (ctypes.c_int, ctypes.c_double) # Specify the type of the input parameters
cvoigt = lib.func # Create alias for the specific function used in functions below
try:
libfile = glob.glob('{}ext_voigtlib.*.so'.format(dllabspath))[0] # Select first (and only) library in this directory
lib = ctypes.CDLL(libfile) # Load the library
lib.func.restype = ctypes.c_double # Specify the expected result type
lib.func.argtypes = (ctypes.c_int, ctypes.c_double) # Specify the type of the input parameters
cvoigt = lib.func # Create alias for the specific function used in functions below
except IndexError: # File does not exist
warnings.warn("Could not locate the external C library. Further use of `clib` will fail!")


# Parameters for `voigt_approx_nobg` and other approx. Voigt functions
Expand Down

0 comments on commit c2b2f0e

Please sign in to comment.