-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcfms.py
More file actions
65 lines (48 loc) · 1.56 KB
/
cfms.py
File metadata and controls
65 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import ctypes
import os
import pyfms
_libpath = None
_lib = None
def init(libpath: str = None):
"""
Initializes the pyfms package by
setting the cFMS library in all modules
and initializing all constants in each
module. pyFMS will use the library
compiled during installation. Users can override
this default library by specifying a cFMS library path
"""
global _libpath, _lib
if libpath is None:
_libpath = os.path.dirname(__file__) + "/lib/cFMS/lib/libcFMS.so"
try:
_lib = ctypes.cdll.LoadLibrary(_libpath)
except OSError:
print(
f"{_libpath} does not exist. Please compile cFMS with ./compile.py\
or provide a path to cFMS with pyfms.cfms.init(libpath=path_to_cfms"
)
return
else:
_libpath = libpath
_lib = ctypes.cdll.LoadLibrary(_libpath)
pyfms.utils.constants._init(_libpath, _lib)
pyfms.utils.grid_utils._init(_libpath, _lib)
pyfms.py_data_override.data_override._init(_libpath, _lib)
pyfms.py_fms.fms._init(_libpath, _lib)
pyfms.py_diag_manager.diag_manager._init(_libpath, _lib)
pyfms.py_horiz_interp.horiz_interp._init(_libpath, _lib)
pyfms.py_mpp.mpp._init(_libpath, _lib)
pyfms.py_mpp.mpp_domains._init(_libpath, _lib)
def lib() -> type[ctypes.CDLL]:
"""
returns the currently used ctypes.CDLL
cFMS object
"""
return _lib
def libpath() -> str:
"""
returns the library path of the currently
used cFMS object
"""
return _libpath