From 88650e34df70cc298fceaf636aefa55eaaed5a9d Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 19 Oct 2023 11:53:57 +0100 Subject: [PATCH 1/3] Remove duplicated try-catch in filter test This was hiding printing the error message --- cxx4/test_filter.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/cxx4/test_filter.cpp b/cxx4/test_filter.cpp index 879ba71..abcd367 100644 --- a/cxx4/test_filter.cpp +++ b/cxx4/test_filter.cpp @@ -51,22 +51,12 @@ int main() latVar.setChunking(NcVar::nc_CHUNKED,chunks); cout<<"Setting Filter...."; - try{ - latVar.setFilter(BZIP2_ID,BZIP2_NPARAMS,&level); - cout<<"Success."< Date: Thu, 19 Oct 2023 11:57:03 +0100 Subject: [PATCH 2/3] Use deflate filter in test, which is always present Fixes #134 BZIP2 filter might not be available depending on how HDF5 was compiled --- cxx4/test_filter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cxx4/test_filter.cpp b/cxx4/test_filter.cpp index abcd367..db4c17c 100644 --- a/cxx4/test_filter.cpp +++ b/cxx4/test_filter.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include "test_utilities.h" @@ -51,7 +52,7 @@ int main() latVar.setChunking(NcVar::nc_CHUNKED,chunks); cout<<"Setting Filter...."; - latVar.setFilter(BZIP2_ID,BZIP2_NPARAMS,&level); + latVar.setFilter(H5Z_FILTER_DEFLATE, BZIP2_NPARAMS, &level); cout<<"Success\n"; cout<<"Getting filter..."; From b45aa199de00d9fce111bc88ad5363bd0b511bf4 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 19 Oct 2023 12:04:44 +0100 Subject: [PATCH 3/3] Tidy filter test, check return values --- cxx4/test_filter.cpp | 47 +++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/cxx4/test_filter.cpp b/cxx4/test_filter.cpp index db4c17c..a420eab 100644 --- a/cxx4/test_filter.cpp +++ b/cxx4/test_filter.cpp @@ -1,6 +1,7 @@ // Purpose: Converts ida3 format xma data to netcdf4 // Usage: xma2netcdf +#include #include #include #include @@ -17,14 +18,8 @@ using namespace netCDF::exceptions; #define NDIMS 4 #define NLAT 6 #define LAT_NAME "latitude" -#define BZIP2_ID 307 -#define BZIP2_LEVEL 9 -#define BZIP2_NPARAMS 1 string UNITS = "units"; string DEGREES_NORTH = "degrees_north"; -unsigned int level = BZIP2_LEVEL; -unsigned int idp = BZIP2_ID; -size_t nparamsp = BZIP2_NPARAMS; int main() { @@ -51,13 +46,43 @@ int main() latVar.setChunking(NcVar::nc_CHUNKED,chunks); - cout<<"Setting Filter...."; - latVar.setFilter(H5Z_FILTER_DEFLATE, BZIP2_NPARAMS, &level); - cout<<"Success\n"; + constexpr unsigned int set_filter_id = H5Z_FILTER_DEFLATE; + constexpr unsigned int set_filter_nparams = 1; + constexpr unsigned int set_filter_level = 9; - cout<<"Getting filter..."; - latVar.getFilter(&idp,&nparamsp, &level); + cout<<"Setting Filter... "; + latVar.setFilter(set_filter_id, set_filter_nparams, &set_filter_level); cout<<"Success\n"; + + cout<<"Getting filter... "; + unsigned int level {}; + unsigned int idp {}; + size_t nparamsp {}; + latVar.getFilter(&idp, &nparamsp, &level); + + bool success = true; + if (idp != set_filter_id) { + cout << "got wrong filter ID (got " << set_filter_id + << ", expected " << set_filter_id << ")\n"; + success &= false; + } + if (nparamsp != set_filter_nparams) { + cout << "got wrong number of filter parameters (got " << nparamsp + << ", expected " << set_filter_nparams << ")\n"; + success &= false; + } + if (level != set_filter_level) { + cout << "got wrong filter level (got " << level + << ", expected " << set_filter_level << ")\n"; + success &= false; + } + + if (success) { + cout<<"Success\n"; + } else { + cout << "Failure\n"; + return EXIT_FAILURE; + } } catch (NcException& e) {