Skip to content

Commit 8ad370a

Browse files
committed
fix for issue #1209
1 parent 55d19c1 commit 8ad370a

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

include/netCDF4.pxi

+3-5
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ cdef extern from "netcdf.h":
368368
int nc_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier) nogil
369369

370370

371+
371372
IF HAS_QUANTIZATION_SUPPORT:
372373
cdef extern from "netcdf.h":
373374
cdef enum:
@@ -377,6 +378,8 @@ IF HAS_QUANTIZATION_SUPPORT:
377378
NC_QUANTIZE_BITROUND
378379
int nc_def_var_quantize(int ncid, int varid, int quantize_mode, int nsd) nogil
379380
int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp) nogil
381+
382+
IF HAS_NCFILTER:
380383
cdef extern from "netcdf_filter.h":
381384
int nc_inq_filter_avail(int ncid, unsigned filterid) nogil
382385

@@ -388,32 +391,27 @@ IF HAS_SZIP_SUPPORT:
388391
int nc_inq_var_quantize(int ncid, int varid, int *quantize_modep, int *nsdp) nogil
389392
int nc_def_var_szip(int ncid, int varid, int options_mask, int pixels_per_bloc) nogil
390393
int nc_inq_var_szip(int ncid, int varid, int *options_maskp, int *pixels_per_blockp) nogil
391-
cdef extern from "netcdf_filter.h":
392-
int nc_inq_filter_avail(int ncid, unsigned filterid) nogil
393394

394395
IF HAS_ZSTANDARD_SUPPORT:
395396
cdef extern from "netcdf_filter.h":
396397
cdef enum:
397398
H5Z_FILTER_ZSTD
398399
int nc_def_var_zstandard(int ncid, int varid, int level) nogil
399400
int nc_inq_var_zstandard(int ncid, int varid, int* hasfilterp, int *levelp) nogil
400-
int nc_inq_filter_avail(int ncid, unsigned id) nogil
401401

402402
IF HAS_BZIP2_SUPPORT:
403403
cdef extern from "netcdf_filter.h":
404404
cdef enum:
405405
H5Z_FILTER_BZIP2
406406
int nc_def_var_bzip2(int ncid, int varid, int level) nogil
407407
int nc_inq_var_bzip2(int ncid, int varid, int* hasfilterp, int *levelp) nogil
408-
int nc_inq_filter_avail(int ncid, unsigned filterid) nogil
409408

410409
IF HAS_BLOSC_SUPPORT:
411410
cdef extern from "netcdf_filter.h":
412411
cdef enum:
413412
H5Z_FILTER_BLOSC
414413
int nc_def_var_blosc(int ncid, int varid, unsigned subcompressor, unsigned level, unsigned blocksize, unsigned addshuffle) nogil
415414
int nc_inq_var_blosc(int ncid, int varid, int* hasfilterp, unsigned* subcompressorp, unsigned* levelp, unsigned* blocksizep, unsigned* addshufflep) nogil
416-
int nc_inq_filter_avail(int ncid, unsigned filterid) nogil
417415

418416
IF HAS_NC_OPEN_MEM:
419417
cdef extern from "netcdf_mem.h":

setup.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def check_api(inc_dirs,netcdf_lib_version):
7070
has_zstandard = False
7171
has_bzip2 = False
7272
has_blosc = False
73+
has_ncfilter = False
7374
has_set_alignment = False
7475

7576
for d in inc_dirs:
@@ -116,6 +117,8 @@ def check_api(inc_dirs,netcdf_lib_version):
116117
has_bzip2 = True
117118
if line.startswith('EXTERNL int nc_def_var_blosc'):
118119
has_blosc = True
120+
if line.startswith('EXTERNL int nc_inq_filter_avail'):
121+
has_ncfilter = True
119122

120123
ncmetapath = os.path.join(d,'netcdf_meta.h')
121124
if os.path.exists(ncmetapath):
@@ -143,7 +146,7 @@ def check_api(inc_dirs,netcdf_lib_version):
143146
return has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \
144147
has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \
145148
has_parallel4_support, has_pnetcdf_support, has_szip_support, has_quantize, \
146-
has_zstandard, has_bzip2, has_blosc, has_set_alignment
149+
has_zstandard, has_bzip2, has_blosc, has_set_alignment, has_ncfilter
147150

148151

149152
def getnetcdfvers(libdirs):
@@ -557,7 +560,7 @@ def _populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs):
557560
has_rename_grp, has_nc_inq_path, has_nc_inq_format_extended, \
558561
has_cdf5_format, has_nc_open_mem, has_nc_create_mem, \
559562
has_parallel4_support, has_pnetcdf_support, has_szip_support, has_quantize, \
560-
has_zstandard, has_bzip2, has_blosc, has_set_alignment = \
563+
has_zstandard, has_bzip2, has_blosc, has_set_alignment, has_ncfilter = \
561564
check_api(inc_dirs,netcdf_lib_version)
562565
# for netcdf 4.4.x CDF5 format is always enabled.
563566
if netcdf_lib_version is not None and\
@@ -671,6 +674,13 @@ def _populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs):
671674
sys.stdout.write('netcdf lib does not have nc_set_alignment function\n')
672675
f.write('DEF HAS_SET_ALIGNMENT = 0\n')
673676

677+
if has_blosc:
678+
sys.stdout.write('netcdf lib has nc_inq_filter_avail function\n')
679+
f.write('DEF HAS_NCFILTER = 1\n')
680+
else:
681+
sys.stdout.write('netcdf lib does not have nc_inq_filter_avail function\n')
682+
f.write('DEF HAS_NCFILTER = 0\n')
683+
674684
f.close()
675685

676686
if has_parallel4_support or has_pnetcdf_support:

src/netCDF4/_netCDF4.pyx

+13-7
Original file line numberDiff line numberDiff line change
@@ -3543,15 +3543,21 @@ returns True if bzip2 compression filter is available"""
35433543
**`has_szip_filter(self)`**
35443544
returns True if szip compression filter is available"""
35453545
cdef int ierr
3546-
IF HAS_SZIP_SUPPORT:
3547-
with nogil:
3548-
ierr = nc_inq_filter_avail(self._grpid, H5Z_FILTER_SZIP)
3549-
if ierr:
3546+
IF HAS_NCFILTER:
3547+
IF HAS_SZIP_SUPPORT:
3548+
with nogil:
3549+
ierr = nc_inq_filter_avail(self._grpid, H5Z_FILTER_SZIP)
3550+
if ierr:
3551+
return False
3552+
else:
3553+
return True
3554+
ELSE:
35503555
return False
3551-
else:
3556+
ELSE:
3557+
IF HAS_SZIP_SUPPORT:
35523558
return True
3553-
ELSE:
3554-
return False
3559+
ELSE:
3560+
return False
35553561

35563562
cdef class Group(Dataset):
35573563
"""

0 commit comments

Comments
 (0)