diff options
-rw-r--r-- | interp.py | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -1,4 +1,5 @@ import ctypes +from errno import ENOENT import numpy as np @@ -75,6 +76,14 @@ def interp2d(src_start, src_step, src_val, dst_coords, stencil): _doubleptr = ctypes.POINTER(ctypes.c_double) +class LibError(Exception): + _errmsg = """ + Cannot load the interpolation library. Make sure you've built it (run 'make') + and the dynamic loader can locate it (e.g. add the directory to LD_LIBRARY_PATH). + """ + def __init__(self): + super().__init__(self._errmsg) + class Interp2D_C: _lib = None _interp_func = None @@ -93,8 +102,10 @@ class Interp2D_C: _ret_c = None def __init__(self, src_start, src_step, src_val, stencil): - self._lib = ctypes.CDLL('lib_interp_c.so') - + try: + self._lib = ctypes.CDLL('lib_interp_c.so') + except OSError as e: + raise LibError func = getattr(self._lib, 'interp2d_%d' % stencil) func.argtypes = [_doubleptr, _doubleptr, _doubleptr, |