Exemple #1
0
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
import pkgutil

import cffi

__version__ = "1.4.0"

LOG = logging.getLogger(__name__)

try:
    import ecmwflibs as findlibs
except ImportError:
    import findlibs

library_path = findlibs.find("eccodes")
if library_path is None:
    raise RuntimeError("Cannot find the ecCodes library")

# default encoding for ecCodes strings
ENC = "ascii"

ffi = cffi.FFI()
CDEF = pkgutil.get_data(__name__, "grib_api.h")
CDEF += pkgutil.get_data(__name__, "eccodes.h")
ffi.cdef(CDEF.decode("utf-8").replace("\r", "\n"))


lib = ffi.dlopen(library_path)
import json

#
#  This Python interface needs to find the Magics library
#
#  We first search LD_LIBRARY_PATH. If you have strange behaviours,
#  check your $LD_LIBRARY_PATH.
#  This is only required on Linux! Therefore we do not have to check
#  on MacOS the DYLD_LIBRARY_PATH or for *.dylib.
#
lib = None

try:
    import ecmwflibs

    lib = ecmwflibs.find("MagPlus")
except Exception:
    pass

if sys.platform == "darwin":
    for directory in os.environ.get("DYLD_LIBRARY_PATH", "").split(":"):
        fullname = os.path.join(directory, "libMagPlus.dylib")
        if os.path.exists(fullname):
            lib = fullname
            break

    if lib is None:
        fullname = os.path.join(
            os.environ.get("MAGPLUS_HOME", ""), "lib/libMagPlus.dylib"
        )
        if os.path.exists(fullname):
Exemple #3
0
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
#

import ctypes
import ctypes.util
import sys
import os

import numpy as np
from functools import partial

try:
    import ecmwflibs

    lib = ecmwflibs.find("eccodes")

except ModuleNotFoundError:
    lib = ctypes.util.find_library("eccodes")

ecmwf_lib = os.path.join(os.environ.get("ECCODES_LIB_DIR", ""),
                         "libeccodes.so")
ecmwf_lib_mac = os.path.join(os.environ.get("ECCODES_LIB_DIR", ""),
                             "libeccodes.dylib")

if lib is None:
    for lib in (
            "/opt/ecmwf/eccodes/lib/libeccodes.so",
            "/usr/local/lib/libeccodes.dylib",
            ecmwf_lib,
            ecmwf_lib_mac,
Exemple #4
0
#

import ctypes
import ctypes.util
import json
import sys

import numpy as np
from numpy.ctypeslib import ndpointer

try:
    import ecmwflibs as findlibs
except ImportError:
    import findlibs

lib = findlibs.find("MagPlus")
if lib is None:
    raise RuntimeError("Cannot find MagPlus library")

dll = ctypes.CDLL(lib)


class FILE(ctypes.Structure):
    pass


FILE_p = ctypes.POINTER(FILE)

####################################################################

Exemple #5
0
import cffi

LOG = logging.getLogger(__name__)

ffi = cffi.FFI()
CDEF_H = pkgutil.get_data(__name__, "grib_api.h") + pkgutil.get_data(__name__, "eccodes.h")
# on Windows the decoded string has '\r' characters not present in the original file
ffi.cdef(CDEF_H.decode("utf-8").replace("\r", "\n"))


LIBNAMES = ["eccodes", "libeccodes.so", "libeccodes"]

try:
    import ecmwflibs

    LIBNAMES.insert(0, ecmwflibs.find("eccodes"))
except Exception:
    pass

if os.environ.get("ECCODES_DIR"):
    eccdir = os.environ["ECCODES_DIR"]
    LIBNAMES.insert(0, os.path.join(eccdir, "lib/libeccodes.so"))
    LIBNAMES.insert(0, os.path.join(eccdir, "lib64/libeccodes.so"))

for libname in LIBNAMES:
    try:
        lib = ffi.dlopen(libname)
        LOG.debug("ecCodes library found using name '%s'.", libname)
        break
    except OSError:
        raise RuntimeError(f"ecCodes library not found using {LIBNAMES}")