diff --git a/ChangeLog b/ChangeLog index 73b5180b7edefda7180fefecc4dbd8dcb50a3c85..90012f86777a88f0611550441f9b7d2053c80b78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-06-28 Uwe Schulzweida + + * Added check for NetCDF4.8 function ncaux_h5filterspec_parselist() + 2024-06-21 Uwe Schulzweida * using CGRIBEX library version 2.3.0 diff --git a/app/cdi.c b/app/cdi.c index 3b66e3d3e72c5cfc6f12987f0ca6a8a364fddb3e..4aea731eb68c106c8772a1e0d398e2d5e5ef0f56 100644 --- a/app/cdi.c +++ b/app/cdi.c @@ -729,7 +729,7 @@ define_compress(const char *arg) } else if (strncmp(arg, "zstd", 4) == 0) { - if (filterSpec == NULL) + if (filterSpec[0] == 0) { int filterid = 32015; int level = (len >= 6 && len <= 7 && arg[4] == '_' && isdigit(arg[5])) ? atoi(&arg[5]) : 1; @@ -938,10 +938,7 @@ main(int argc, char *argv[]) if (DefaultByteorder != CDI_UNDEFID) streamDefByteorder(streamID2, DefaultByteorder); - if (filterSpec) - { - streamDefFilter(streamID2, filterSpec); - } + if (filterSpec[0]) streamDefFilter(streamID2, filterSpec); if (comptype != CDI_COMPRESS_NONE) { diff --git a/m4/acx_options.m4 b/m4/acx_options.m4 index a869f477ebb12f6d27c7cbec99e8d5eeaaa1aa61..95b499cf4dc6d4d8b37ad1ae334de048251f24d1 100644 --- a/m4/acx_options.m4 +++ b/m4/acx_options.m4 @@ -202,6 +202,10 @@ AS_VAR_IF([ENABLE_NETCDF], [yes], [AC_DEFINE([HAVE_NC4SZLIB],[1],[Define to 1 for NetCDF4/szlib support]) ENABLE_NC4SZLIB=yes])]) +AS_IF([test "x$ENABLE_NC4" = "xyes"], + [AC_SEARCH_LIBS([ncaux_h5filterspec_parselist], [netcdf], + [AC_DEFINE([HAVE_NCAUX_H5FILTERSPEC_PARSELIST],[1],[Define to 1 for NetCDF4 ncaux_h5filterspec_parselist support])],,)]) + AS_IF([test "x$ENABLE_NC4SZLIB" = "xyes"], [AC_SEARCH_LIBS([nc_def_var_szip], [netcdf], [AC_DEFINE([HAVE_NC_DEF_VAR_SZIP],[1],[Define to 1 for NetCDF4 nc_def_var_szip support])],,)]) diff --git a/src/cdf_write.c b/src/cdf_write.c index ad2d634148c2ba24ad99289bf31ffb1b620c3246..42c5ee1d7049eb3f3270942846bbac8d8a92eb9c 100644 --- a/src/cdf_write.c +++ b/src/cdf_write.c @@ -3,7 +3,6 @@ #endif #ifdef HAVE_LIBNETCDF - #include "dmemory.h" #include "cdi.h" #include "cdi_int.h" @@ -12,8 +11,8 @@ #include "cdf_int.h" #include "vlist.h" #include "vlist_var.h" +#endif -// #include <netcdf_filter.h> #ifdef HAVE_NETCDF4 #include "netcdf_aux.h" #endif @@ -21,9 +20,9 @@ void cdf_def_var_filter(int ncid, int ncvarID, const char *filterSpec) { -#ifdef HAVE_NETCDF4 if (filterSpec) { +#ifdef HAVE_NCAUX_H5FILTERSPEC_PARSELIST size_t nfilters = 0; NC_H5_Filterspec **filters = NULL; int status = ncaux_h5filterspec_parselist(filterSpec, NULL, &nfilters, &filters); @@ -51,17 +50,19 @@ cdf_def_var_filter(int ncid, int ncvarID, const char *filterSpec) for (size_t i = 0; i < nfilters; i++) ncaux_h5filterspec_free(filters[i]); free(filters); } - } #else - static bool lwarn = true; - if (lwarn) - { - lwarn = false; - Warning("Filter failed, NetCDF4 not available!"); - } + static bool lwarn = true; + if (lwarn) + { + lwarn = false; + Warning("Filter failed, NetCDF4 function ncaux_h5filterspec_parselist() not available!"); + } #endif + } } +#ifdef HAVE_LIBNETCDF + void cdfDefVarDeflate(int ncid, int ncvarID, int shuffle, int compLevel) { @@ -501,7 +502,7 @@ cdfDefVarFilter(int fileID, int fileType, int ncvarID, const char *filterSpec) if (lwarn) { lwarn = false; - Warning("Filter is only available for NetCDF4!"); + Warning("Filter is only available with NetCDF4!"); } } } @@ -1056,9 +1057,13 @@ cdfDefVar(stream_t *streamptr, int varID) char filterSpec[CDI_MAX_NAME]; length = CDI_MAX_NAME; if (cdiInqKeyString(vlistID, varID, CDI_KEY_FILTERSPEC, filterSpec, &length) == CDI_NOERR) - cdfDefVarFilter(fileID, fileType, ncvarID, filterSpec); + { + cdfDefVarFilter(fileID, fileType, ncvarID, filterSpec); + } else if (streamptr->filterSpec) - cdfDefVarFilter(fileID, fileType, ncvarID, streamptr->filterSpec); + { + cdfDefVarFilter(fileID, fileType, ncvarID, streamptr->filterSpec); + } } if (*stdname) cdf_put_att_text(fileID, ncvarID, "standard_name", strlen(stdname), stdname); diff --git a/src/stream.c b/src/stream.c index a28de9b032a6a902632f7bb16c8e330c03a3a031..5a1ce3b1286e759bb36adf8cb67b388d4868dcbe 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1245,6 +1245,8 @@ streamDestroy(stream_t *streamptr) streamptr->filename = NULL; } + if (streamptr->filterSpec) free(streamptr->filterSpec); + if (streamptr->vars) { for (int index = 0; index < streamptr->nvars; index++)