(libdirs)
return None
Get the version string for the first netcdf lib found in libdirs.
    (major.minor.release). If nothing found, return None.
Get the version string for the first netcdf lib found in libdirs.
    (major.minor.release). If nothing found, return None.
Get the version string for the first netcdf lib found in libdirs . ( major . minor . release ) . If nothing found return None .
def getnetcdfvers(libdirs):
    """
    Get the version string for the first netcdf lib found in libdirs.
    (major.minor.release). If nothing found, return None.
    """

    import os, re, sys, ctypes

    if sys.platform.startswith('win'):
        regexp = re.compile('^netcdf.dll$')
    elif sys.platform.startswith('cygwin'):
        bindirs = []
        for d in libdirs:
            bindirs.append(os.path.dirname(d) + '/bin')
        regexp = re.compile(r'^cygnetcdf-\d.dll')
    elif sys.platform.startswith('darwin'):
        regexp = re.compile(r'^libnetcdf.dylib')
    else:
        regexp = re.compile(r'^libnetcdf.so')

    if sys.platform.startswith('cygwin'):
        dirs = bindirs
    else:
        dirs = libdirs
    for d in dirs:
        try:
            candidates = [x for x in os.listdir(d) if regexp.match(x)]
            if len(candidates) != 0:
                candidates.sort(
                    key=lambda x: len(x))  # Prefer libfoo.so to libfoo.so.X.Y.Z
                path = os.path.abspath(os.path.join(d, candidates[0]))
            lib = ctypes.cdll.LoadLibrary(path)
            inq_libvers = lib.nc_inq_libvers
            inq_libvers.restype = ctypes.c_char_p
            vers = lib.nc_inq_libvers()
            return vers.split()[0]
        except Exception:
            pass  # We skip invalid entries, because that's what the C compiler does

    return None
def getnetcdfvers ( libdirs ) : import os , re , sys , ctypes if sys . platform . startswith ( 'win' ) : regexp = re . compile ( '^netcdf.dll$' ) elif sys . platform . startswith ( 'cygwin' ) : bindirs = [ ] for d in libdirs : bindirs . append ( os . path . dirname ( d ) + '/bin' ) regexp = re . compile ( r'^cygnetcdf-\d.dll' ) elif sys . platform . startswith ( 'darwin' ) : regexp = re . compile ( r'^libnetcdf.dylib' ) else : regexp = re . compile ( r'^libnetcdf.so' ) if sys . platform . startswith ( 'cygwin' ) : dirs = bindirs else : dirs = libdirs for d in dirs : try : candidates = [ x for x in os . listdir ( d ) if regexp . match ( x ) ] if len ( candidates ) != 0 : candidates . sort ( key = lambda x : len ( x ) ) # Prefer libfoo.so to libfoo.so.X.Y.Z path = os . path . abspath ( os . path . join ( d , candidates [ 0 ] ) ) lib = ctypes . cdll . LoadLibrary ( path ) inq_libvers = lib . nc_inq_libvers inq_libvers . restype = ctypes . c_char_p vers = lib . nc_inq_libvers ( ) return vers . split ( ) [ 0 ] except Exception : pass # We skip invalid entries, because that's what the C compiler does return None