From 4aa319f9dc6209c7d05dfe79299c141aaa8e3e2b Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 07:27:54 -0600 Subject: [PATCH 01/12] adding pre-processor constant NC_MAX_FILENAME to nc_tests.h --- include/nc_tests.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/nc_tests.h b/include/nc_tests.h index 79cc9094c0..b9a35d3f16 100644 --- a/include/nc_tests.h +++ b/include/nc_tests.h @@ -46,6 +46,7 @@ #define BAD_NAME "dd//d/ " #define NUM_CLASSIC_TYPES 6 #define NUM_NETCDF_TYPES 12 +#define NC_MAX_FILENAME 4096 /** \} */ #ifdef USE_PNETCDF From 2bfde9a5ebd88975af9db3c7afaff1d8fa773c19 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 08:55:48 -0600 Subject: [PATCH 02/12] more quantize testing --- nc_test4/tst_quantize.c | 157 +++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 68 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index e8993c61ad..56d1c5a3ff 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -90,8 +90,11 @@ main(int argc, char **argv) #endif #define NUM_MODE_TESTS 2 +#define NUM_QUANTIZE_MODES 3 int mode = NC_NETCDF4|NC_CLOBBER; int m; + int q, quantize_mode[NUM_QUANTIZE_MODES] = {NC_QUANTIZE_BITGROOM, NC_QUANTIZE_GRANULARBR, + NC_QUANTIZE_BITROUND}; printf("\n*** Testing netcdf-4 variable quantization functions.\n"); for (m = 0; m < NUM_MODE_TESTS; m++) @@ -109,87 +112,105 @@ main(int argc, char **argv) int ncid, dimid, varid1, varid2; int quantize_mode_in, nsd_in; + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); #ifndef TESTNCZARR - /* Create a netcdf classic file with one var. Attempt - * quantization. It will not work. */ - if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_3, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3) != NC_ENOTNC4) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in) != NC_ENOTNC4) ERR; - if (nc_close(ncid)) ERR; + /* Create a netcdf classic file with one var. Attempt + * quantization. It will not work. */ + if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_3, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3) != NC_ENOTNC4) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in) != NC_ENOTNC4) ERR; + if (nc_close(ncid)) ERR; #endif - /* Create a netcdf-4 file with two vars. Attempt - * quantization. It will work, eventually... */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_3, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + /* Create a netcdf-4 file with two vars. Attempt + * quantization. It will work, eventually... */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_3, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + + /* Bad varid. */ + if (nc_def_var_quantize(ncid, NC_GLOBAL, quantize_mode[q], NSD_3) != NC_EGLOBAL) ERR; + if (nc_def_var_quantize(ncid, varid2 + 1, quantize_mode[q], NSD_3) != NC_ENOTVAR) ERR; + /* Invalid values. */ + if (nc_def_var_quantize(ncid, varid1, NUM_QUANTIZE_MODES + 1, NSD_3) != NC_EINVAL) ERR; + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], -1) != NC_EINVAL) ERR; + if (quantize_mode[q] == NC_QUANTIZE_BITROUND) + { + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NC_QUANTIZE_MAX_FLOAT_NSB + 1) != NC_EINVAL) ERR; + } + else + { + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NC_QUANTIZE_MAX_FLOAT_NSD + 1) != NC_EINVAL) ERR; + } + if (nc_def_var_quantize(ncid, varid2, NUM_QUANTIZE_MODES + 1, 3) != NC_EINVAL) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], -1) != NC_EINVAL) ERR; + if (quantize_mode[q] == NC_QUANTIZE_BITROUND) + { + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NC_QUANTIZE_MAX_DOUBLE_NSB + 1) != NC_EINVAL) ERR; + } + else + { + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NC_QUANTIZE_MAX_DOUBLE_NSD + 1) != NC_EINVAL) ERR; + } + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], 0) != NC_EINVAL) ERR; - /* Bad varid. */ - if (nc_def_var_quantize(ncid, NC_GLOBAL, NC_QUANTIZE_BITGROOM, NSD_3) != NC_EGLOBAL) ERR; - if (nc_def_var_quantize(ncid, varid2 + 1, NC_QUANTIZE_BITGROOM, NSD_3) != NC_ENOTVAR) ERR; - /* Invalid values. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITROUND + 1, NSD_3) != NC_EINVAL) ERR; - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, -1) != NC_EINVAL) ERR; - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NC_QUANTIZE_MAX_FLOAT_NSD + 1) != NC_EINVAL) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITROUND + 1, 3) != NC_EINVAL) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, -1) != NC_EINVAL) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NC_QUANTIZE_MAX_DOUBLE_NSD + 1) != NC_EINVAL) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, 0) != NC_EINVAL) ERR; - - /* This will work. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM) ERR; - if (nsd_in != NSD_3) ERR; + /* This will work. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q]) ERR; + if (nsd_in != NSD_3) ERR; - /* Wait, I changed my mind! Let's turn off quantization. */ - if (nc_def_var_quantize(ncid, varid1, NC_NOQUANTIZE, 0)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_NOQUANTIZE) ERR; - if (nsd_in != 0) ERR; + /* Wait, I changed my mind! Let's turn off quantization. */ + if (nc_def_var_quantize(ncid, varid1, NC_NOQUANTIZE, 0)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != NC_NOQUANTIZE) ERR; + if (nsd_in != 0) ERR; - /* Changed my mind again, turn it on. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + /* Changed my mind again, turn it on. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; - /* I changed my mind again! Turn it off! */ - if (nc_def_var_quantize(ncid, varid1, NC_NOQUANTIZE, 0)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_NOQUANTIZE) ERR; - if (nsd_in != 0) ERR; + /* I changed my mind again! Turn it off! */ + if (nc_def_var_quantize(ncid, varid1, NC_NOQUANTIZE, 0)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != NC_NOQUANTIZE) ERR; + if (nsd_in != 0) ERR; - /* Changed my mind again, turn it on. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + /* Changed my mind again, turn it on. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; - /* This also will work for double. */ - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_9)) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM) ERR; - if (nsd_in != NSD_9) ERR; + /* This also will work for double. */ + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_9)) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q]) ERR; + if (nsd_in != NSD_9) ERR; - /* End define mode. */ - if (nc_enddef(ncid)) ERR; + /* End define mode. */ + if (nc_enddef(ncid)) ERR; - /* This will not work, it's too late! */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3) != NC_ELATEDEF) ERR; + /* This will not work, it's too late! */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3) != NC_ELATEDEF) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* Close the file. */ + if (nc_close(ncid)) ERR; - /* Open the file and check. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - /* Don't assume the varid !!! */ - if (nc_inq_varid(ncid, VAR_NAME_1, &varid1)) ERR; - if (nc_inq_varid(ncid, VAR_NAME_2, &varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM) ERR; - if (nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM) ERR; - if (nsd_in != NSD_9) ERR; - if (nc_close(ncid)) ERR; + /* Open the file and check. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + /* Don't assume the varid !!! */ + if (nc_inq_varid(ncid, VAR_NAME_1, &varid1)) ERR; + if (nc_inq_varid(ncid, VAR_NAME_2, &varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q]) ERR; + if (nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q]) ERR; + if (nsd_in != NSD_9) ERR; + if (nc_close(ncid)) ERR; + } } SUMMARIZE_ERR; From 6645cce1c99cecdeb6376fd6745498e83d055001 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 09:44:38 -0600 Subject: [PATCH 03/12] more quantize testing --- nc_test4/tst_quantize.c | 78 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 56d1c5a3ff..19e6f8d440 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -224,49 +224,49 @@ main(int argc, char **argv) printf("\t**** testing quantization handling of non-floats..."); { - int ncid; - int dimid[NDIM2]; - int varid; - int nsd_in, quantize_mode; - int nsd_out = 3; -#ifdef TESTNCZARR - char file_name[4096]; -#else - char file_name[NC_MAX_NAME + 1]; -#endif - int xtype[NTYPES] = {NC_CHAR, NC_SHORT, NC_INT, NC_BYTE, NC_UBYTE, - NC_USHORT, NC_UINT, NC_INT64, NC_UINT64}; - int t; - - for (t = 0; t < NTYPES; t++) + for (q = 0; q < NUM_QUANTIZE_MODES; q++) { - sprintf(file_name, "%s_bitgroom_type_%d.nc", TEST, xtype[t]); -#ifdef TESTNCZARR - { - char url[4096]; - snprintf(url,sizeof(url),template,file_name); - strcpy(file_name,url); - } -#endif - /* Create file. */ - if (nc_create(file_name, NC_NETCDF4, &ncid)) ERR; - if (nc_def_dim(ncid, X_NAME, NX_BIG, &dimid[0])) ERR; - if (nc_def_dim(ncid, Y_NAME, NY_BIG, &dimid[1])) ERR; - if (nc_def_var(ncid, VAR_NAME, xtype[t], NDIM2, dimid, &varid)) ERR; - - /* Bitgroom filter returns NC_EINVAL because this is not an - * NC_FLOAT or NC_DOULBE. */ - if (nc_def_var_quantize(ncid, varid, NC_QUANTIZE_BITGROOM, nsd_out) != NC_EINVAL) ERR; - if (nc_close(ncid)) ERR; + int ncid; + int dimid[NDIM2]; + int varid; + int nsd_in, quantize_mode_in; + int nsd_out = 3; + char file_name[NC_MAX_FILENAME + 1]; + int xtype[NTYPES] = {NC_CHAR, NC_SHORT, NC_INT, NC_BYTE, NC_UBYTE, + NC_USHORT, NC_UINT, NC_INT64, NC_UINT64}; + int t; - /* Check file. */ + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); + for (t = 0; t < NTYPES; t++) { - if (nc_open(file_name, NC_NETCDF4, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME,&varid)) ERR; - if (nc_inq_var_quantize(ncid, varid, &quantize_mode, &nsd_in)) - ERR; - if (quantize_mode) ERR; + sprintf(file_name, "%s_quantize_%d_type_%d.nc", TEST, quantize_mode[q], xtype[t]); +#ifdef TESTNCZARR + { + char url[NC_MAX_FILENAME + 1]; + snprintf(url,sizeof(url),template,file_name); + strcpy(file_name,url); + } +#endif + /* Create file. */ + if (nc_create(file_name, NC_NETCDF4, &ncid)) ERR; + if (nc_def_dim(ncid, X_NAME, NX_BIG, &dimid[0])) ERR; + if (nc_def_dim(ncid, Y_NAME, NY_BIG, &dimid[1])) ERR; + if (nc_def_var(ncid, VAR_NAME, xtype[t], NDIM2, dimid, &varid)) ERR; + + /* Quantzie returns NC_EINVAL because this is not + * an NC_FLOAT or NC_DOULBE. */ + if (nc_def_var_quantize(ncid, varid, quantize_mode[q], nsd_out) != NC_EINVAL) ERR; if (nc_close(ncid)) ERR; + + /* Check file. */ + { + if (nc_open(file_name, NC_NETCDF4, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME,&varid)) ERR; + if (nc_inq_var_quantize(ncid, varid, &quantize_mode_in, &nsd_in)) + ERR; + if (quantize_mode_in) ERR; + if (nc_close(ncid)) ERR; + } } } } From 1a13b9ed094848577f6bad79100f93a5f56a8d83 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 10:35:38 -0600 Subject: [PATCH 04/12] more quantize testing --- nc_test4/tst_quantize.c | 153 +++++++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 56 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 19e6f8d440..920f177d9a 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -273,71 +273,112 @@ main(int argc, char **argv) SUMMARIZE_ERR; printf("\t**** testing quantization of scalars..."); { - int ncid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_1] = {1.1111111}; - double double_data[DIM_LEN_1] = {1.111111111111}; - - /* Create a netcdf-4 file with two scalar vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, 0, NULL, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, 0, NULL, &varid2)) ERR; + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + int ncid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_1] = {1.1111111}; + double double_data[DIM_LEN_1] = {1.111111111111}; - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; + /* Create a netcdf-4 file with two scalar vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, 0, NULL, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, 0, NULL, &varid2)) ERR; - /* Write some data. */ - if (nc_put_var_float(ncid, varid1, float_data)) ERR; - if (nc_put_var_double(ncid, varid2, double_data)) ERR; + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; - { - float float_in; - double double_in; - union FU fin; - int nsd_att_in; - /* union FU fout; */ - union DU dfin; - /* union DU dfout; */ + /* Write some data. */ + if (nc_put_var_float(ncid, varid1, float_data)) ERR; + if (nc_put_var_double(ncid, varid2, double_data)) ERR; - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid, VAR_NAME_1, &varid1)) ERR; - if (nc_inq_varid(ncid, VAR_NAME_2, &varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; + /* Close the file. */ + if (nc_close(ncid)) ERR; - /* Each var now has an attribute describing the quantize settings. */ - if (nc_get_att_int(ncid, 0, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; - if (nsd_att_in != NSD_3) ERR; - if (nc_get_att_int(ncid, 1, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; - if (nsd_att_in != NSD_3) ERR; + { + float float_in; + double double_in; + union FU fin; + int nsd_att_in; + union DU dfin; + /* union FU fout; */ + /* union DU dfout; */ + + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid, VAR_NAME_1, &varid1)) ERR; + if (nc_inq_varid(ncid, VAR_NAME_2, &varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + + /* Each var now has an attribute describing the quantize settings. */ + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + if (nc_get_att_int(ncid, 0, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + if (nc_get_att_int(ncid, 1, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + break; + case NC_QUANTIZE_GRANULARBR: + if (nc_get_att_int(ncid, 0, NC_QUANTIZE_GRANULARBR_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + if (nc_get_att_int(ncid, 1, NC_QUANTIZE_GRANULARBR_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + break; + case NC_QUANTIZE_BITROUND: + if (nc_get_att_int(ncid, 0, NC_QUANTIZE_BITROUND_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + if (nc_get_att_int(ncid, 1, NC_QUANTIZE_BITROUND_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + break; + default: + ERR; + } - /* Check the data. */ - if (nc_get_var(ncid, varid1, &float_in)) ERR; - if (nc_get_var(ncid, varid2, &double_in)) ERR; - /* fout.f = float_data[0]; */ - fin.f = float_in; - /* dfout.d = double_data[0]; */ - dfin.d = double_in; - /* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ - /* float_data[0], fout.u, float_data[0], fin.u); */ - if (fin.u != 0x3f8e3000) ERR; - /* printf ("\ndouble_data: %15g : 0x%16llx double_data_in: %15g : 0x%llx\n", */ - /* double_data[0], dfout.u, double_data[0], dfin.u);*/ - if (dfin.u != 0x3ff1c60000000000) ERR; + /* Check the data. */ + if (nc_get_var(ncid, varid1, &float_in)) ERR; + if (nc_get_var(ncid, varid2, &double_in)) ERR; + /* fout.f = float_data[0]; */ + /* dfout.d = double_data[0]; */ + fin.f = float_in; + dfin.d = double_in; + /* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ + /* float_data[0], fout.u, float_data[0], fin.u); */ + /* printf ("\ndouble_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */ + /* double_data[0], dfout.u, double_data[0], dfin.u); */ + + /* Check the results, slightly different for each quantize algorithm. */ + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + if (fin.u != 0x3f8e3000) ERR; + if (dfin.u != 0x3ff1c60000000000) ERR; + break; + case NC_QUANTIZE_GRANULARBR: + if (fin.u != 0x3f8e0000) ERR; + if (dfin.u != 0x3ff1c00000000000) ERR; + break; + case NC_QUANTIZE_BITROUND: + if (fin.u != 0x3f900000) ERR; + if (dfin.u != 0x3ff2000000000000) ERR; + break; + default: + ERR; + } - /* Close the file again. */ - if (nc_close(ncid)) ERR; + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } } } SUMMARIZE_ERR; From 82caba1f12c1b9076dacfecc003f2d169d007222 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 11:44:23 -0600 Subject: [PATCH 05/12] more quantize testing --- nc_test4/tst_quantize.c | 121 +++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 50 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 920f177d9a..700f51b07c 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -384,65 +384,86 @@ main(int argc, char **argv) SUMMARIZE_ERR; printf("\t**** testing quantization of one value..."); { - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_1] = {1.1111111}; - double double_data[DIM_LEN_1] = {1.111111111111}; + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_1] = {1.1111111}; + double double_data[DIM_LEN_1] = {1.111111111111}; - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + /* Create a netcdf-4 file with two vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; - /* Write some data. */ - if (nc_put_var_float(ncid, varid1, float_data)) ERR; - if (nc_put_var_double(ncid, varid2, double_data)) ERR; + /* Write some data. */ + if (nc_put_var_float(ncid, varid1, float_data)) ERR; + if (nc_put_var_double(ncid, varid2, double_data)) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* Close the file. */ + if (nc_close(ncid)) ERR; - { - float float_in; - double double_in; - union FU fin; - /* union FU fout; */ - union DU dfin; - /* union DU dfout; */ + { + float float_in; + double double_in; + union FU fin; + union DU dfin; + /* union FU fout; */ + /* union DU dfout; */ - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; - /* Check the data. */ - if (nc_get_var(ncid, varid1, &float_in)) ERR; - if (nc_get_var(ncid, varid2, &double_in)) ERR; - /* fout.f = float_data[0]; */ - fin.f = float_in; - /* dfout.d = double_data[0]; */ - dfin.d = double_in; - /* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ - /* float_data[0], fout.u, float_data[0], fin.u); */ - if (fin.u != 0x3f8e3000) ERR; - /* printf ("\ndouble_data: %15g : 0x%16llx double_data_in: %15g : 0x%llx\n", */ - /* double_data[0], dfout.u, double_data[0], dfin.u); */ - if (dfin.u != 0x3ff1c60000000000) ERR; + /* Check the data. */ + if (nc_get_var(ncid, varid1, &float_in)) ERR; + if (nc_get_var(ncid, varid2, &double_in)) ERR; + /* fout.f = float_data[0]; */ + /* dfout.d = double_data[0]; */ + fin.f = float_in; + dfin.d = double_in; + /* printf ("\nfloat_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ + /* float_data[0], fout.u, float_data[0], fin.u); */ + /* printf ("\ndouble_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */ + /* double_data[0], dfout.u, double_data[0], dfin.u); */ - /* Close the file again. */ - if (nc_close(ncid)) ERR; + /* Check the results, slightly different for each quantize algorithm. */ + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + if (fin.u != 0x3f8e3000) ERR; + if (dfin.u != 0x3ff1c60000000000) ERR; + break; + case NC_QUANTIZE_GRANULARBR: + if (fin.u != 0x3f8e0000) ERR; + if (dfin.u != 0x3ff1c00000000000) ERR; + break; + case NC_QUANTIZE_BITROUND: + if (fin.u != 0x3f900000) ERR; + if (dfin.u != 0x3ff2000000000000) ERR; + break; + default: + ERR; + } + + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } } } SUMMARIZE_ERR; From d23d90e14880d095e34eb1d5297fcac59e5b13a1 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 12:48:46 -0600 Subject: [PATCH 06/12] more testing of quantize --- nc_test4/tst_quantize.c | 192 ++++++++++++++++++++++++---------------- 1 file changed, 115 insertions(+), 77 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 700f51b07c..2e1372a8c8 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -107,7 +107,7 @@ main(int argc, char **argv) mode |= NC_CLASSIC_MODEL; } - printf("\t**** testing quantization setting and error conditions..."); + printf("\t**** testing quantization setting and error conditions...\n"); { int ncid, dimid, varid1, varid2; int quantize_mode_in, nsd_in; @@ -222,7 +222,7 @@ main(int argc, char **argv) #define Y_NAME "distance_along_canal" #define NDIM2 2 - printf("\t**** testing quantization handling of non-floats..."); + printf("\t**** testing quantization handling of non-floats...\n"); { for (q = 0; q < NUM_QUANTIZE_MODES; q++) { @@ -271,7 +271,7 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; - printf("\t**** testing quantization of scalars..."); + printf("\t**** testing quantization of scalars...\n"); { for (q = 0; q < NUM_QUANTIZE_MODES; q++) { @@ -382,16 +382,17 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; - printf("\t**** testing quantization of one value..."); + printf("\t**** testing quantization of one value...\n"); { for (q = 0; q < NUM_QUANTIZE_MODES; q++) { - printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); int ncid, dimid, varid1, varid2; int quantize_mode_in, nsd_in; float float_data[DIM_LEN_1] = {1.1111111}; double double_data[DIM_LEN_1] = {1.111111111111}; + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); + /* Create a netcdf-4 file with two vars. */ if (nc_create(FILE_NAME, mode, &ncid)) ERR; if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR; @@ -467,89 +468,126 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; - printf("\t**** testing more quantization values..."); + printf("\t**** testing more quantization values...\n"); { - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_5] = {1.11111111, 1.0, 9.99999999, 12345.67, .1234567}; - double double_data[DIM_LEN_5] = {1.1111111, 1.0, 9.999999999, 1234567890.12345, 123456789012345.0}; - int x; + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_5] = {1.11111111, 1.0, 9.99999999, 12345.67, .1234567}; + double double_data[DIM_LEN_5] = {1.1111111, 1.0, 9.999999999, 1234567890.12345, 123456789012345.0}; + int x; - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); + + /* Create a netcdf-4 file with two vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; - /* Write some data. */ - if (nc_put_var_float(ncid, varid1, float_data)) ERR; - if (nc_put_var_double(ncid, varid2, double_data)) ERR; + /* Write some data. */ + if (nc_put_var_float(ncid, varid1, float_data)) ERR; + if (nc_put_var_double(ncid, varid2, double_data)) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* Close the file. */ + if (nc_close(ncid)) ERR; - { - float float_in[DIM_LEN_5]; - double double_in[DIM_LEN_5]; - union FU { - float f; - uint32_t u; - }; + { + float float_in[DIM_LEN_5]; + double double_in[DIM_LEN_5]; + union FU { + float f; + uint32_t u; + }; - union FU fin; - /* union FU fout; */ - union FU xpect[DIM_LEN_5]; - union DU dfin; - /* union DU dfout; */ - union DU double_xpect[DIM_LEN_5]; - xpect[0].u = 0x3f8e3000; - xpect[1].u = 0x3f800fff; - xpect[2].u = 0x41200000; - xpect[3].u = 0x4640efff; - xpect[4].u = 0x3dfcd000; - double_xpect[0].u = 0x3ff1c60000000000; - double_xpect[1].u = 0x3ff001ffffffffff; - double_xpect[2].u = 0x4023fe0000000000; - double_xpect[3].u = 0x41d265ffffffffff; - double_xpect[4].u = 0x42dc120000000000; + union FU fin; + union FU fout; + union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; + union DU dfin; + union DU dfout; + union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + xpect[0][0].u = 0x3f8e3000; + xpect[0][1].u = 0x3f800fff; + xpect[0][2].u = 0x41200000; + xpect[0][3].u = 0x4640efff; + xpect[0][4].u = 0x3dfcd000; + double_xpect[0][0].u = 0x3ff1c60000000000; + double_xpect[0][1].u = 0x3ff001ffffffffff; + double_xpect[0][2].u = 0x4023fe0000000000; + double_xpect[0][3].u = 0x41d265ffffffffff; + double_xpect[0][4].u = 0x42dc120000000000; + break; + case NC_QUANTIZE_GRANULARBR: + xpect[1][0].u = 0x3f8e0000; + xpect[1][1].u = 0x3f800000; + xpect[1][2].u = 0x41200000; + xpect[1][3].u = 0x46410000; + xpect[1][4].u = 0x3dfc0000; + double_xpect[1][0].u = 0x3ff1c00000000000; + double_xpect[1][1].u = 0x3ff0000000000000; + double_xpect[1][2].u = 0x4024000000000000; + double_xpect[1][3].u = 0x41d2600000000000; + double_xpect[1][4].u = 0x42dc200000000000; + break; + case NC_QUANTIZE_BITROUND: + xpect[2][0].u = 0x3f900000; + xpect[2][1].u = 0x3f800000; + xpect[2][2].u = 0x41200000; + xpect[2][3].u = 0x46400000; + xpect[2][4].u = 0x3e000000; + double_xpect[2][0].u = 0x3ff2000000000000; + double_xpect[2][1].u = 0x3ff0000000000000; + double_xpect[2][2].u = 0x4024000000000000; + double_xpect[2][3].u = 0x41d2000000000000; + double_xpect[2][4].u = 0x42dc000000000000; + break; + default: + ERR; + } - /* Check the data. */ - if (nc_get_var(ncid, varid1, float_in)) ERR; - if (nc_get_var(ncid, varid2, double_in)) ERR; - /* printf("\n"); */ - for (x = 0; x < DIM_LEN_5; x++) - { - /* fout.f = float_data[x]; */ - fin.f = float_in[x]; - /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ - /* float_data[x], fout.u, float_data[x], fin.u); */ - if (fin.u != xpect[x].u) ERR; - /* dfout.d = double_data[x]; */ - dfin.d = double_in[x]; - /*printf("double_data: %15g : 0x%16llx double_data_in: %15g : 0x%16llx\n",*/ - /* double_data[x], dfout.u, double_data[x], dfin.u);*/ - if (dfin.u != double_xpect[x].u) ERR; - } + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; - /* Close the file again. */ - if (nc_close(ncid)) ERR; + /* Check the data. */ + if (nc_get_var(ncid, varid1, float_in)) ERR; + if (nc_get_var(ncid, varid2, double_in)) ERR; + /* printf("\n"); */ + for (x = 0; x < DIM_LEN_5; x++) + { + fout.f = float_data[x]; + fin.f = float_in[x]; + /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ + /* float_data[x], fout.u, float_data[x], fin.u); */ + if (fin.u != xpect[q][x].u) ERR; + dfout.d = double_data[x]; + dfin.d = double_in[x]; + /* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */ + /* double_data[x], dfout.u, double_data[x], dfin.u); */ + if (dfin.u != double_xpect[q][x].u) ERR; + } + + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } } } SUMMARIZE_ERR; From cd1aa7b882ca723dc84bbe0f21178339b2c3b13e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 13:15:23 -0600 Subject: [PATCH 07/12] more testing of quantize --- nc_test4/tst_quantize.c | 947 ++++++++++++++++++++++------------------ 1 file changed, 520 insertions(+), 427 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 2e1372a8c8..59d1c33187 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -591,468 +591,561 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; - printf("\t**** testing quantization of one value with type conversion..."); + printf("\t**** testing quantization of one value with type conversion...\n"); { - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_1] = {1.1111111}; - double double_data[DIM_LEN_1] = {1.111111111111}; - - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; - - /* Write some double data to float var. */ - if (nc_put_var_double(ncid, varid1, double_data)) ERR; - - /* Write some float data to double var. */ - if (nc_put_var_float(ncid, varid2, float_data)) ERR; - - /* Close the file. */ - if (nc_close(ncid)) ERR; - + for (q = 0; q < NUM_QUANTIZE_MODES; q++) { - float float_in; - double double_in; - union FU fin; - /* union FU fout; */ - union DU dfin; - /* union DU dfout; */ - int nsd_att_in; - - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - - /* Each var now has an attribute describing the quantize settings. */ - if (nc_get_att_int(ncid, 0, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; - if (nsd_att_in != NSD_3) ERR; - if (nc_get_att_int(ncid, 1, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; - if (nsd_att_in != NSD_3) ERR; - - /* Check the data. */ - if (nc_get_var(ncid, varid1, &float_in)) ERR; - if (nc_get_var(ncid, varid2, &double_in)) ERR; - /* fout.f = (float)double_data[0]; */ - fin.f = float_in; - /* dfout.d = float_data[0]; */ - dfin.d = double_in; - /* printf ("\ndouble_data: %15g : 0x%x float_data_in: %10f : 0x%x\n", */ - /* double_data[0], fout.u, float_in, fin.u); */ - if (fin.u != 0x3f8e3000) ERR; - /* printf ("\nfloat_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */ - /* float_data[0], dfout.u, double_in, dfin.u); */ - if (dfin.u != 0x3ff1c60000000000) ERR; - - /* Close the file again. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("\t**** testing more quantization values with type conversion..."); - { - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_5] = {1.11111111, 1.0, 9.99999999, 12345.67, .1234567}; - double double_data[DIM_LEN_5] = {1.1111111, 1.0, 9.999999999, 1234567890.12345, 123456789012345.0}; - int x; - - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_1] = {1.1111111}; + double double_data[DIM_LEN_1] = {1.111111111111}; - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); + + /* Create a netcdf-4 file with two vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_1, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - /* Write some data. */ - if (nc_put_var_double(ncid, varid1, double_data)) ERR; - if (nc_put_var_float(ncid, varid2, float_data)) ERR; + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; - { - float float_in[DIM_LEN_5]; - double double_in[DIM_LEN_5]; - union FU { - float f; - uint32_t u; - }; - - union FU fin; - /* union FU fout; */ - union FU xpect[DIM_LEN_5]; - union DU dfin; - /* union DU dfout; */ - union DU double_xpect[DIM_LEN_5]; - xpect[0].u = 0x3f8e3000; - xpect[1].u = 0x3f800fff; - xpect[2].u = 0x41200000; - xpect[3].u = 0x4e932fff; - xpect[4].u = 0x56e09000; - double_xpect[0].u = 0x3ff1c60000000000; - double_xpect[1].u = 0x3ff001ffffffffff; - double_xpect[2].u = 0x4024000000000000; - double_xpect[3].u = 0x40c81dffffffffff; - double_xpect[4].u = 0x3fbf9a0000000000; - - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; + /* Write some double data to float var. */ + if (nc_put_var_double(ncid, varid1, double_data)) ERR; - /* Check the data. */ - if (nc_get_var(ncid, varid1, float_in)) ERR; - if (nc_get_var(ncid, varid2, double_in)) ERR; - /* printf("\n"); */ - for (x = 0; x < DIM_LEN_5; x++) - { - /* fout.f = float_data[x]; */ - fin.f = float_in[x]; - /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ - /* float_data[x], fout.u, float_data[x], fin.u); */ - if (fin.u != xpect[x].u) ERR; - /* dfout.d = double_data[x]; */ - dfin.d = double_in[x]; - /* printf("double_data: %15g : 0x%16llx double_data_in: %15g : 0x%16llx\n",*/ - /* double_data[x], dfout.u, double_data[x], dfin.u);*/ - if (dfin.u != double_xpect[x].u) ERR; - } + /* Write some float data to double var. */ + if (nc_put_var_float(ncid, varid2, float_data)) ERR; - /* Close the file again. */ + /* Close the file. */ if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("\t**** testing more quantization values with default fill values..."); - { - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_5] = {1.11111111, NC_FILL_FLOAT, 9.99999999, 12345.67, NC_FILL_FLOAT}; - double double_data[DIM_LEN_5] = {1.1111111, NC_FILL_DOUBLE, 9.999999999, 1234567890.12345, NC_FILL_DOUBLE}; - int x; - - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; - - /* Write some data. */ - if (nc_put_var_float(ncid, varid1, float_data)) ERR; - if (nc_put_var_double(ncid, varid2, double_data)) ERR; - - /* Close the file. */ - if (nc_close(ncid)) ERR; - - { - float float_in[DIM_LEN_5]; - double double_in[DIM_LEN_5]; - union FU { - float f; - uint32_t u; - }; - - union FU fin; - /* union FU fout; */ - union FU xpect[DIM_LEN_5]; - union DU dfin; - /* union DU dfout; */ - union DU double_xpect[DIM_LEN_5]; - xpect[0].u = 0x3f8e3000; - xpect[1].u = 0x7cf00000; - xpect[2].u = 0x41200000; - xpect[3].u = 0x4640efff; - xpect[4].u = 0x7cf00000; - double_xpect[0].u = 0x3ff1c60000000000; - double_xpect[1].u = 0x479e000000000000; - double_xpect[2].u = 0x4023fe0000000000; - double_xpect[3].u = 0x41d265ffffffffff; - double_xpect[4].u = 0x479e000000000000; - - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - - /* Check the data. */ - if (nc_get_var(ncid, varid1, float_in)) ERR; - if (nc_get_var(ncid, varid2, double_in)) ERR; - /* printf("\n"); */ - for (x = 0; x < DIM_LEN_5; x++) { - /* fout.f = float_data[x]; */ - fin.f = float_in[x]; - /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ - /* float_data[x], fout.u, float_data[x], fin.u); */ - if (fin.u != xpect[x].u) ERR; - /* dfout.d = double_data[x]; */ - dfin.d = double_in[x]; - /* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */ - /* double_data[x], dfout.u, double_data[x], dfin.u); */ - if (dfin.u != double_xpect[x].u) ERR; - } - - /* Close the file again. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("\t**** testing more quantization values with custom fill values..."); - { -#define CUSTOM_FILL_FLOAT 99.99999 -#define CUSTOM_FILL_DOUBLE -99999.99999 - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; - float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT}; - double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE}; - float custom_fill_float = CUSTOM_FILL_FLOAT; - double custom_fill_double = CUSTOM_FILL_DOUBLE; - int x; - - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, mode, &ncid)) ERR; - if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; - if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_put_att_float(ncid, varid1, _FillValue, NC_FLOAT, 1, &custom_fill_float)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - if (nc_put_att_double(ncid, varid2, _FillValue, NC_DOUBLE, 1, &custom_fill_double)) ERR; - - /* Turn on quantize for both vars. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; + float float_in; + double double_in; + union FU fin; + union DU dfin; + union FU fout; + union DU dfout; + int nsd_att_in; - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; - /* Write some data. */ - if (nc_put_var_float(ncid, varid1, float_data)) ERR; - if (nc_put_var_double(ncid, varid2, double_data)) ERR; + /* Each var now has an attribute describing the quantize settings. */ + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + if (nc_get_att_int(ncid, 0, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + if (nc_get_att_int(ncid, 1, NC_QUANTIZE_BITGROOM_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + break; + case NC_QUANTIZE_GRANULARBR: + if (nc_get_att_int(ncid, 0, NC_QUANTIZE_GRANULARBR_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + if (nc_get_att_int(ncid, 1, NC_QUANTIZE_GRANULARBR_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + break; + case NC_QUANTIZE_BITROUND: + if (nc_get_att_int(ncid, 0, NC_QUANTIZE_BITROUND_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + if (nc_get_att_int(ncid, 1, NC_QUANTIZE_BITROUND_ATT_NAME, &nsd_att_in)) ERR; + if (nsd_att_in != NSD_3) ERR; + break; + default: + ERR; + } - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* Check the data. */ + if (nc_get_var(ncid, varid1, &float_in)) ERR; + if (nc_get_var(ncid, varid2, &double_in)) ERR; + fout.f = (float)double_data[0]; + fin.f = float_in; + dfout.d = float_data[0]; + dfin.d = double_in; + /* printf ("\ndouble_data: %15g : 0x%x float_data_in: %10f : 0x%x\n", */ + /* double_data[0], fout.u, float_in, fin.u); */ + /* printf ("\nfloat_data: %15g : 0x%16lx double_data_in: %15g : 0x%lx\n", */ + /* float_data[0], dfout.u, double_in, dfin.u); */ - { - float float_in[DIM_LEN_5]; - double double_in[DIM_LEN_5]; - union FU { - float f; - uint32_t u; - }; - - union FU fin; - /* union FU fout; */ - union FU xpect[DIM_LEN_5]; - union DU dfin; - /* union DU dfout; */ - union DU double_xpect[DIM_LEN_5]; - xpect[0].u = 0x3f8e3000; - xpect[1].u = 0x42c7ffff; - xpect[2].u = 0x41200000; - xpect[3].u = 0x4640efff; - xpect[4].u = 0x42c7ffff; - double_xpect[0].u = 0x3ff1c60000000000; - double_xpect[1].u = 0xc0f869fffff583a5; - double_xpect[2].u = 0x4023fe0000000000; - double_xpect[3].u = 0x41d265ffffffffff; - double_xpect[4].u = 0xc0f869fffff583a5; - - /* Open the file and check metadata. */ - if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; - if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; - if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; - if (quantize_mode_in != NC_QUANTIZE_BITGROOM || nsd_in != NSD_3) ERR; + + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + if (fin.u != 0x3f8e3000) ERR; + if (dfin.u != 0x3ff1c60000000000) ERR; + break; + case NC_QUANTIZE_GRANULARBR: + if (fin.u != 0x3f8e0000) ERR; + if (dfin.u != 0x3ff1c00000000000) ERR; + break; + case NC_QUANTIZE_BITROUND: + if (fin.u !=0x3f900000 ) ERR; + if (dfin.u != 0x3ff2000000000000) ERR; + break; + default: + ERR; + } - /* Check the data. */ - if (nc_get_var(ncid, varid1, float_in)) ERR; - if (nc_get_var(ncid, varid2, double_in)) ERR; - /* printf("\n"); */ - for (x = 0; x < DIM_LEN_5; x++) - { - /* fout.f = float_data[x]; */ - fin.f = float_in[x]; - /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ - /* float_data[x], fout.u, float_data[x], fin.u); */ - if (fin.u != xpect[x].u) ERR; - /* dfout.d = double_data[x]; */ - dfin.d = double_in[x]; - /* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */ - /* double_data[x], dfout.u, double_data[x], dfin.u); */ - if (dfin.u != double_xpect[x].u) ERR; + /* Close the file again. */ + if (nc_close(ncid)) ERR; } - - /* Close the file again. */ - if (nc_close(ncid)) ERR; } } SUMMARIZE_ERR; - printf("\t*** Checking BitGroom values with type conversion between ints and floats..."); + printf("\t**** testing more quantization values with type conversion...\n"); { - int ncid; - int dimid; - int varid1, varid2; - unsigned char uc = 99; - signed char sc = -99; - unsigned short us = 9999; - signed short ss = -9999; - unsigned int ui = 9999999; - signed int si = -9999999; - unsigned long long int ull = 999999999; - signed long long int sll = -999999999; - size_t index; - - /* Create file. */ - if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; - - /* Create dims. */ - if (nc_def_dim(ncid, X_NAME, DIM_LEN_8, &dimid)) ERR; - - /* Create the variables. */ - if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - - /* Set up quantization. */ - if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM, NSD_3)) ERR; - - /* For classic mode, we must call enddef. */ - if (m) - if (nc_enddef(ncid)) ERR; + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_5] = {1.11111111, 1.0, 9.99999999, 12345.67, .1234567}; + double double_data[DIM_LEN_5] = {1.1111111, 1.0, 9.999999999, 1234567890.12345, 123456789012345.0}; + int x; - /* Write data. */ - index = 0; - if (nc_put_var1_uchar(ncid, varid1, &index, &uc)) ERR; - if (nc_put_var1_uchar(ncid, varid2, &index, &uc)) ERR; - index = 1; - if (nc_put_var1_schar(ncid, varid1, &index, &sc)) ERR; - if (nc_put_var1_schar(ncid, varid2, &index, &sc)) ERR; - index = 2; - if (nc_put_var1_ushort(ncid, varid1, &index, &us)) ERR; - if (nc_put_var1_ushort(ncid, varid2, &index, &us)) ERR; - index = 3; - if (nc_put_var1_short(ncid, varid1, &index, &ss)) ERR; - if (nc_put_var1_short(ncid, varid2, &index, &ss)) ERR; - index = 4; - if (nc_put_var1_uint(ncid, varid1, &index, &ui)) ERR; - if (nc_put_var1_uint(ncid, varid2, &index, &ui)) ERR; - index = 5; - if (nc_put_var1_int(ncid, varid1, &index, &si)) ERR; - if (nc_put_var1_int(ncid, varid2, &index, &si)) ERR; - index = 6; - if (nc_put_var1_ulonglong(ncid, varid1, &index, &ull)) ERR; - if (nc_put_var1_ulonglong(ncid, varid2, &index, &ull)) ERR; - index = 7; - if (nc_put_var1_longlong(ncid, varid1, &index, &sll)) ERR; - if (nc_put_var1_longlong(ncid, varid2, &index, &sll)) ERR; + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); + + /* Create a netcdf-4 file with two vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; - { - float float_data_in[DIM_LEN_8]; - double double_data_in[DIM_LEN_8]; - int x; + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; - /* Now reopen the file and check. */ - if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR; - if (nc_inq_varid(ncid,VAR_NAME,&varid1)) ERR; - if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + /* Write some data. */ + if (nc_put_var_double(ncid, varid1, double_data)) ERR; + if (nc_put_var_float(ncid, varid2, float_data)) ERR; - /* Read the data. */ - if (nc_get_var_float(ncid, varid1, float_data_in)) ERR; - if (nc_get_var_double(ncid, varid2, double_data_in)) ERR; + /* Close the file. */ + if (nc_close(ncid)) ERR; - union FU xpect[DIM_LEN_8]; - union DU double_xpect[DIM_LEN_8]; - /* This test comes up with different answers to this than - * the corresponding bitgroom filter test, but that's - * OK. In netcdf-c quantization is applied as the data are - * written by the user, but in HDF5 filters, the bitgroom - * filter is applied to all data values as they are - * written to disk. See - * https://github.com/ccr/ccr/issues/194 for a full - * explanation. */ - xpect[0].u = 0x42c60000; - xpect[1].u = 0xc2c60000; - xpect[2].u = 0x461c3000; - xpect[3].u = 0xc61c3000; - xpect[4].u = 0x4b189000; - xpect[5].u = 0xcb189000; - xpect[6].u = 0x4e6e6b28; - xpect[6].u = 0x4e6e6000; - xpect[7].u = 0xce6e6000; - double_xpect[0].u = 0x4058c00000000000; - double_xpect[1].u = 0xc058c00000000000; - double_xpect[2].u = 0x40c3860000000000; - double_xpect[3].u = 0xc0c3860000000000; - double_xpect[4].u = 0x4163120000000000; - double_xpect[5].u = 0xc163120000000000; - double_xpect[6].u = 0x41cdcc0000000000; - double_xpect[7].u = 0xc1cdcc0000000000; - - for (x = 0; x < DIM_LEN_8; x++) { + float float_in[DIM_LEN_5]; + double double_in[DIM_LEN_5]; + union FU { + float f; + uint32_t u; + }; + union FU fin; + union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; union DU dfin; - fin.f = float_data_in[x]; - dfin.d = double_data_in[x]; - /* printf ("%d float_data_in : %08.8f : 0x%x expected %08.8f : 0x%x\n", */ - /* x, float_data_in[x], fin.u, xpect[x].f, xpect[x].u); */ - /* printf ("%d double_data_in : %15g : 0x%llx expected %15g : 0x%llx\n",*/ - /* x, double_data_in[x], dfin.u, double_xpect[x].d, double_xpect[x].u);*/ - if (fin.u != xpect[x].u) - ERR; - if (dfin.u != double_xpect[x].u) + union FU fout; + union DU dfout; + union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; + + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + xpect[0][0].u = 0x3f8e3000; + xpect[0][1].u = 0x3f800fff; + xpect[0][2].u = 0x41200000; + xpect[0][3].u = 0x4e932fff; + xpect[0][4].u = 0x56e09000; + double_xpect[0][0].u = 0x3ff1c60000000000; + double_xpect[0][1].u = 0x3ff001ffffffffff; + double_xpect[0][2].u = 0x4024000000000000; + double_xpect[0][3].u = 0x40c81dffffffffff; + double_xpect[0][4].u = 0x3fbf9a0000000000; + break; + case NC_QUANTIZE_GRANULARBR: + xpect[1][0].u = 0x3f8e0000; + xpect[1][1].u =0x3f800000 ; + xpect[1][2].u = 0x41200000; + xpect[1][3].u = 0x4e930000; + xpect[1][4].u = 0x56e10000; + double_xpect[1][0].u = 0x3ff1c00000000000; + double_xpect[1][1].u = 0x3ff0000000000000; + double_xpect[1][2].u = 0x4024000000000000; + double_xpect[1][3].u = 0x40c8200000000000; + double_xpect[1][4].u = 0x3fbf800000000000; + break; + case NC_QUANTIZE_BITROUND: + xpect[2][0].u = 0x3f900000; + xpect[2][1].u = 0x3f800000; + xpect[2][2].u = 0x41200000; + xpect[2][3].u = 0x4e900000; + xpect[2][4].u = 0x56e00000; + double_xpect[2][0].u = 0x3ff2000000000000; + double_xpect[2][1].u = 0x3ff0000000000000; + double_xpect[2][2].u = 0x4024000000000000; + double_xpect[2][3].u = 0x40c8000000000000; + double_xpect[2][4].u = 0x3fc0000000000000; + break; + default: ERR; - } + } + + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; - /* Close the file. */ - if (nc_close(ncid)) ERR; + /* Check the data. */ + if (nc_get_var(ncid, varid1, float_in)) ERR; + if (nc_get_var(ncid, varid2, double_in)) ERR; + /* printf("\n"); */ + for (x = 0; x < DIM_LEN_5; x++) + { + fout.f = float_data[x]; + fin.f = float_in[x]; + /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ + /* float_data[x], fout.u, float_data[x], fin.u); */ + dfout.d = double_data[x]; + dfin.d = double_in[x]; + /* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */ + /* double_data[x], dfout.u, double_data[x], dfin.u); */ + if (fin.u != xpect[q][x].u) ERR; + if (dfin.u != double_xpect[q][x].u) ERR; + } + + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } } } SUMMARIZE_ERR; +/* /\* printf("\t**** testing more quantization values with default fill values..."); *\/ */ +/* /\* { *\/ */ +/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ +/* /\* { *\/ */ +/* /\* int ncid, dimid, varid1, varid2; *\/ */ +/* /\* int quantize_mode_in, nsd_in; *\/ */ +/* /\* float float_data[DIM_LEN_5] = {1.11111111, NC_FILL_FLOAT, 9.99999999, 12345.67, NC_FILL_FLOAT}; *\/ */ +/* /\* double double_data[DIM_LEN_5] = {1.1111111, NC_FILL_DOUBLE, 9.999999999, 1234567890.12345, NC_FILL_DOUBLE}; *\/ */ +/* /\* int x; *\/ */ + +/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */ + +/* /\* /\\* Create a netcdf-4 file with two vars. *\\/ *\/ */ +/* /\* if (nc_create(FILE_NAME, mode, &ncid)) ERR; *\/ */ +/* /\* if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; *\/ */ +/* /\* if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */ +/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */ + +/* /\* /\\* Turn on quantize for both vars. *\\/ *\/ */ +/* /\* if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; *\/ */ +/* /\* if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; *\/ */ + +/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */ +/* /\* if (m) *\/ */ +/* /\* if (nc_enddef(ncid)) ERR; *\/ */ + +/* /\* /\\* Write some data. *\\/ *\/ */ +/* /\* if (nc_put_var_float(ncid, varid1, float_data)) ERR; *\/ */ +/* /\* if (nc_put_var_double(ncid, varid2, double_data)) ERR; *\/ */ + +/* /\* /\\* Close the file. *\\/ *\/ */ +/* /\* if (nc_close(ncid)) ERR; *\/ */ + +/* /\* { *\/ */ +/* /\* float float_in[DIM_LEN_5]; *\/ */ +/* /\* double double_in[DIM_LEN_5]; *\/ */ +/* /\* union FU { *\/ */ +/* /\* float f; *\/ */ +/* /\* uint32_t u; *\/ */ +/* /\* }; *\/ */ + +/* /\* union FU fin; *\/ */ +/* /\* /\\* union FU fout; *\\/ *\/ */ +/* /\* union FU xpect[DIM_LEN_5]; *\/ */ +/* /\* union DU dfin; *\/ */ +/* /\* /\\* union DU dfout; *\\/ *\/ */ +/* /\* union DU double_xpect[DIM_LEN_5]; *\/ */ +/* /\* xpect[0].u = 0x3f8e3000; *\/ */ +/* /\* xpect[1].u = 0x7cf00000; *\/ */ +/* /\* xpect[2].u = 0x41200000; *\/ */ +/* /\* xpect[3].u = 0x4640efff; *\/ */ +/* /\* xpect[4].u = 0x7cf00000; *\/ */ +/* /\* double_xpect[0].u = 0x3ff1c60000000000; *\/ */ +/* /\* double_xpect[1].u = 0x479e000000000000; *\/ */ +/* /\* double_xpect[2].u = 0x4023fe0000000000; *\/ */ +/* /\* double_xpect[3].u = 0x41d265ffffffffff; *\/ */ +/* /\* double_xpect[4].u = 0x479e000000000000; *\/ */ + +/* /\* /\\* Open the file and check metadata. *\\/ *\/ */ +/* /\* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; *\/ */ +/* /\* if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; *\/ */ +/* /\* if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; *\/ */ +/* /\* if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; *\/ */ +/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ +/* /\* if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; *\/ */ +/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ + +/* /\* /\\* Check the data. *\\/ *\/ */ +/* /\* if (nc_get_var(ncid, varid1, float_in)) ERR; *\/ */ +/* /\* if (nc_get_var(ncid, varid2, double_in)) ERR; *\/ */ +/* /\* /\\* printf("\n"); *\\/ *\/ */ +/* /\* for (x = 0; x < DIM_LEN_5; x++) *\/ */ +/* /\* { *\/ */ +/* /\* /\\* fout.f = float_data[x]; *\\/ *\/ */ +/* /\* fin.f = float_in[x]; *\/ */ +/* /\* /\\* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", *\\/ *\/ */ +/* /\* /\\* float_data[x], fout.u, float_data[x], fin.u); *\\/ *\/ */ +/* /\* if (fin.u != xpect[x].u) ERR; *\/ */ +/* /\* /\\* dfout.d = double_data[x]; *\\/ *\/ */ +/* /\* dfin.d = double_in[x]; *\/ */ +/* /\* /\\* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", *\\/ *\/ */ +/* /\* /\\* double_data[x], dfout.u, double_data[x], dfin.u); *\\/ *\/ */ +/* /\* if (dfin.u != double_xpect[x].u) ERR; *\/ */ +/* /\* } *\/ */ + +/* /\* /\\* Close the file again. *\\/ *\/ */ +/* /\* if (nc_close(ncid)) ERR; *\/ */ +/* /\* } *\/ */ +/* /\* } *\/ */ +/* /\* } *\/ */ +/* /\* SUMMARIZE_ERR; *\/ */ +/* /\* printf("\t**** testing more quantization values with custom fill values..."); *\/ */ +/* /\* { *\/ */ +/* /\* #define CUSTOM_FILL_FLOAT 99.99999 *\/ */ +/* /\* #define CUSTOM_FILL_DOUBLE -99999.99999 *\/ */ +/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ +/* /\* { *\/ */ +/* /\* int ncid, dimid, varid1, varid2; *\/ */ +/* /\* int quantize_mode_in, nsd_in; *\/ */ +/* /\* float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT}; *\/ */ +/* /\* double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE}; *\/ */ +/* /\* float custom_fill_float = CUSTOM_FILL_FLOAT; *\/ */ +/* /\* double custom_fill_double = CUSTOM_FILL_DOUBLE; *\/ */ +/* /\* int x; *\/ */ + +/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */ + +/* /\* /\\* Create a netcdf-4 file with two vars. *\\/ *\/ */ +/* /\* if (nc_create(FILE_NAME, mode, &ncid)) ERR; *\/ */ +/* /\* if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; *\/ */ +/* /\* if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */ +/* /\* if (nc_put_att_float(ncid, varid1, _FillValue, NC_FLOAT, 1, &custom_fill_float)) ERR; *\/ */ +/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */ +/* /\* if (nc_put_att_double(ncid, varid2, _FillValue, NC_DOUBLE, 1, &custom_fill_double)) ERR; *\/ */ + +/* /\* /\\* Turn on quantize for both vars. *\\/ *\/ */ +/* /\* if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; *\/ */ +/* /\* if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; *\/ */ + +/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */ +/* /\* if (m) *\/ */ +/* /\* if (nc_enddef(ncid)) ERR; *\/ */ + +/* /\* /\\* Write some data. *\\/ *\/ */ +/* /\* if (nc_put_var_float(ncid, varid1, float_data)) ERR; *\/ */ +/* /\* if (nc_put_var_double(ncid, varid2, double_data)) ERR; *\/ */ + +/* /\* /\\* Close the file. *\\/ *\/ */ +/* /\* if (nc_close(ncid)) ERR; *\/ */ + +/* /\* { *\/ */ +/* /\* float float_in[DIM_LEN_5]; *\/ */ +/* /\* double double_in[DIM_LEN_5]; *\/ */ +/* /\* union FU { *\/ */ +/* /\* float f; *\/ */ +/* /\* uint32_t u; *\/ */ +/* /\* }; *\/ */ + +/* /\* union FU fin; *\/ */ +/* /\* /\\* union FU fout; *\\/ *\/ */ +/* /\* union FU xpect[DIM_LEN_5]; *\/ */ +/* /\* union DU dfin; *\/ */ +/* /\* /\\* union DU dfout; *\\/ *\/ */ +/* /\* union DU double_xpect[DIM_LEN_5]; *\/ */ +/* /\* xpect[0].u = 0x3f8e3000; *\/ */ +/* /\* xpect[1].u = 0x42c7ffff; *\/ */ +/* /\* xpect[2].u = 0x41200000; *\/ */ +/* /\* xpect[3].u = 0x4640efff; *\/ */ +/* /\* xpect[4].u = 0x42c7ffff; *\/ */ +/* /\* double_xpect[0].u = 0x3ff1c60000000000; *\/ */ +/* /\* double_xpect[1].u = 0xc0f869fffff583a5; *\/ */ +/* /\* double_xpect[2].u = 0x4023fe0000000000; *\/ */ +/* /\* double_xpect[3].u = 0x41d265ffffffffff; *\/ */ +/* /\* double_xpect[4].u = 0xc0f869fffff583a5; *\/ */ + +/* /\* /\\* Open the file and check metadata. *\\/ *\/ */ +/* /\* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; *\/ */ +/* /\* if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; *\/ */ +/* /\* if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; *\/ */ +/* /\* if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; *\/ */ +/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ +/* /\* if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; *\/ */ +/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ + +/* /\* /\\* Check the data. *\\/ *\/ */ +/* /\* if (nc_get_var(ncid, varid1, float_in)) ERR; *\/ */ +/* /\* if (nc_get_var(ncid, varid2, double_in)) ERR; *\/ */ +/* /\* /\\* printf("\n"); *\\/ *\/ */ +/* /\* for (x = 0; x < DIM_LEN_5; x++) *\/ */ +/* /\* { *\/ */ +/* /\* /\\* fout.f = float_data[x]; *\\/ *\/ */ +/* /\* fin.f = float_in[x]; *\/ */ +/* /\* /\\* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", *\\/ *\/ */ +/* /\* /\\* float_data[x], fout.u, float_data[x], fin.u); *\\/ *\/ */ +/* /\* if (fin.u != xpect[x].u) ERR; *\/ */ +/* /\* /\\* dfout.d = double_data[x]; *\\/ *\/ */ +/* /\* dfin.d = double_in[x]; *\/ */ +/* /\* /\\* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", *\\/ *\/ */ +/* /\* /\\* double_data[x], dfout.u, double_data[x], dfin.u); *\\/ *\/ */ +/* /\* if (dfin.u != double_xpect[x].u) ERR; *\/ */ +/* /\* } *\/ */ + +/* /\* /\\* Close the file again. *\\/ *\/ */ +/* /\* if (nc_close(ncid)) ERR; *\/ */ +/* /\* } *\/ */ +/* /\* } *\/ */ +/* /\* } *\/ */ +/* /\* SUMMARIZE_ERR; *\/ */ +/* /\* printf("\t*** Checking BitGroom values with type conversion between ints and floats..."); *\/ */ +/* /\* { *\/ */ +/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ +/* /\* { *\/ */ +/* /\* int ncid; *\/ */ +/* /\* int dimid; *\/ */ +/* /\* int varid1, varid2; *\/ */ +/* /\* unsigned char uc = 99; *\/ */ +/* /\* signed char sc = -99; *\/ */ +/* /\* unsigned short us = 9999; *\/ */ +/* /\* signed short ss = -9999; *\/ */ +/* /\* unsigned int ui = 9999999; *\/ */ +/* /\* signed int si = -9999999; *\/ */ +/* /\* unsigned long long int ull = 999999999; *\/ */ +/* /\* signed long long int sll = -999999999; *\/ */ +/* /\* size_t index; *\/ */ + +/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */ + +/* /\* /\\* Create file. *\\/ *\/ */ +/* /\* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; *\/ */ + +/* /\* /\\* Create dims. *\\/ *\/ */ +/* /\* if (nc_def_dim(ncid, X_NAME, DIM_LEN_8, &dimid)) ERR; *\/ */ + +/* /\* /\\* Create the variables. *\\/ *\/ */ +/* /\* if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */ +/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */ + +/* /\* /\\* Set up quantization. *\\/ *\/ */ +/* /\* if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; *\/ */ +/* /\* if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; *\/ */ + +/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */ +/* /\* if (m) *\/ */ +/* /\* if (nc_enddef(ncid)) ERR; *\/ */ + +/* /\* /\\* Write data. *\\/ *\/ */ +/* /\* index = 0; *\/ */ +/* /\* if (nc_put_var1_uchar(ncid, varid1, &index, &uc)) ERR; *\/ */ +/* /\* if (nc_put_var1_uchar(ncid, varid2, &index, &uc)) ERR; *\/ */ +/* /\* index = 1; *\/ */ +/* /\* if (nc_put_var1_schar(ncid, varid1, &index, &sc)) ERR; *\/ */ +/* /\* if (nc_put_var1_schar(ncid, varid2, &index, &sc)) ERR; *\/ */ +/* /\* index = 2; *\/ */ +/* /\* if (nc_put_var1_ushort(ncid, varid1, &index, &us)) ERR; *\/ */ +/* /\* if (nc_put_var1_ushort(ncid, varid2, &index, &us)) ERR; *\/ */ +/* /\* index = 3; *\/ */ +/* /\* if (nc_put_var1_short(ncid, varid1, &index, &ss)) ERR; *\/ */ +/* /\* if (nc_put_var1_short(ncid, varid2, &index, &ss)) ERR; *\/ */ +/* /\* index = 4; *\/ */ +/* if (nc_put_var1_uint(ncid, varid1, &index, &ui)) ERR; */ +/* if (nc_put_var1_uint(ncid, varid2, &index, &ui)) ERR; */ +/* index = 5; */ +/* if (nc_put_var1_int(ncid, varid1, &index, &si)) ERR; */ +/* if (nc_put_var1_int(ncid, varid2, &index, &si)) ERR; */ +/* index = 6; */ +/* if (nc_put_var1_ulonglong(ncid, varid1, &index, &ull)) ERR; */ +/* if (nc_put_var1_ulonglong(ncid, varid2, &index, &ull)) ERR; */ +/* index = 7; */ +/* if (nc_put_var1_longlong(ncid, varid1, &index, &sll)) ERR; */ +/* if (nc_put_var1_longlong(ncid, varid2, &index, &sll)) ERR; */ + +/* /\\* Close the file. *\\/ */ +/* if (nc_close(ncid)) ERR; */ + +/* { */ +/* float float_data_in[DIM_LEN_8]; */ +/* double double_data_in[DIM_LEN_8]; */ +/* int x; */ + +/* /\\* Now reopen the file and check. *\\/ */ +/* if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */ +/* if (nc_inq_varid(ncid,VAR_NAME,&varid1)) ERR; */ +/* if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; */ + +/* /\\* Read the data. *\\/ */ +/* if (nc_get_var_float(ncid, varid1, float_data_in)) ERR; */ +/* if (nc_get_var_double(ncid, varid2, double_data_in)) ERR; */ + +/* union FU xpect[DIM_LEN_8]; */ +/* union DU double_xpect[DIM_LEN_8]; */ +/* /\\* This test comes up with different answers to this than */ +/* * the corresponding bitgroom filter test, but that's */ +/* * OK. In netcdf-c quantization is applied as the data are */ +/* * written by the user, but in HDF5 filters, the bitgroom */ +/* * filter is applied to all data values as they are */ +/* * written to disk. See */ +/* * https://github.com/ccr/ccr/issues/194 for a full */ +/* * explanation. *\\/ */ +/* xpect[0].u = 0x42c60000; */ +/* xpect[1].u = 0xc2c60000; */ +/* xpect[2].u = 0x461c3000; */ +/* xpect[3].u = 0xc61c3000; */ +/* xpect[4].u = 0x4b189000; */ +/* xpect[5].u = 0xcb189000; */ +/* xpect[6].u = 0x4e6e6b28; */ +/* xpect[6].u = 0x4e6e6000; */ +/* xpect[7].u = 0xce6e6000; */ +/* double_xpect[0].u = 0x4058c00000000000; */ +/* double_xpect[1].u = 0xc058c00000000000; */ +/* double_xpect[2].u = 0x40c3860000000000; */ +/* double_xpect[3].u = 0xc0c3860000000000; */ +/* double_xpect[4].u = 0x4163120000000000; */ +/* double_xpect[5].u = 0xc163120000000000; */ +/* double_xpect[6].u = 0x41cdcc0000000000; */ +/* double_xpect[7].u = 0xc1cdcc0000000000; */ + +/* for (x = 0; x < DIM_LEN_8; x++) */ +/* { */ +/* union FU fin; */ +/* union DU dfin; */ +/* fin.f = float_data_in[x]; */ +/* dfin.d = double_data_in[x]; */ +/* /\\* printf ("%d float_data_in : %08.8f : 0x%x expected %08.8f : 0x%x\n", *\\/ */ +/* /\\* x, float_data_in[x], fin.u, xpect[x].f, xpect[x].u); *\\/ */ +/* /\\* printf ("%d double_data_in : %15g : 0x%llx expected %15g : 0x%llx\n",*\\/ */ +/* /\\* x, double_data_in[x], dfin.u, double_xpect[x].d, double_xpect[x].u);*\\/ */ +/* if (fin.u != xpect[x].u) */ +/* ERR; */ +/* if (dfin.u != double_xpect[x].u) */ +/* ERR; */ +/* } */ + +/* /\\* Close the file. *\\/ */ +/* if (nc_close(ncid)) ERR; */ +/* } */ +/* } */ +/* } */ +/* SUMMARIZE_ERR; */ printf("\t**** Nice, simple example of using BitGroom plus zlib..."); { #define DIM_LEN_SIMPLE 100 From 99dbcad141bd3fdad66223d7ea5cf80b8c777c4b Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 13:21:51 -0600 Subject: [PATCH 08/12] more testing of quantize --- nc_test4/tst_quantize.c | 191 +++++++++++++++++++++++----------------- 1 file changed, 111 insertions(+), 80 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 59d1c33187..235c4b9896 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -828,97 +828,128 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; -/* /\* printf("\t**** testing more quantization values with default fill values..."); *\/ */ -/* /\* { *\/ */ -/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ -/* /\* { *\/ */ -/* /\* int ncid, dimid, varid1, varid2; *\/ */ -/* /\* int quantize_mode_in, nsd_in; *\/ */ -/* /\* float float_data[DIM_LEN_5] = {1.11111111, NC_FILL_FLOAT, 9.99999999, 12345.67, NC_FILL_FLOAT}; *\/ */ -/* /\* double double_data[DIM_LEN_5] = {1.1111111, NC_FILL_DOUBLE, 9.999999999, 1234567890.12345, NC_FILL_DOUBLE}; *\/ */ -/* /\* int x; *\/ */ + printf("\t**** testing more quantization values with default fill values...\n"); + { + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_5] = {1.11111111, NC_FILL_FLOAT, 9.99999999, 12345.67, NC_FILL_FLOAT}; + double double_data[DIM_LEN_5] = {1.1111111, NC_FILL_DOUBLE, 9.999999999, 1234567890.12345, NC_FILL_DOUBLE}; + int x; -/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */ + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); -/* /\* /\\* Create a netcdf-4 file with two vars. *\\/ *\/ */ -/* /\* if (nc_create(FILE_NAME, mode, &ncid)) ERR; *\/ */ -/* /\* if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; *\/ */ -/* /\* if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */ -/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */ + /* Create a netcdf-4 file with two vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; -/* /\* /\\* Turn on quantize for both vars. *\\/ *\/ */ -/* /\* if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; *\/ */ -/* /\* if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; *\/ */ + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; -/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */ -/* /\* if (m) *\/ */ -/* /\* if (nc_enddef(ncid)) ERR; *\/ */ + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; -/* /\* /\\* Write some data. *\\/ *\/ */ -/* /\* if (nc_put_var_float(ncid, varid1, float_data)) ERR; *\/ */ -/* /\* if (nc_put_var_double(ncid, varid2, double_data)) ERR; *\/ */ + /* Write some data. */ + if (nc_put_var_float(ncid, varid1, float_data)) ERR; + if (nc_put_var_double(ncid, varid2, double_data)) ERR; -/* /\* /\\* Close the file. *\\/ *\/ */ -/* /\* if (nc_close(ncid)) ERR; *\/ */ + /* Close the file. */ + if (nc_close(ncid)) ERR; -/* /\* { *\/ */ -/* /\* float float_in[DIM_LEN_5]; *\/ */ -/* /\* double double_in[DIM_LEN_5]; *\/ */ -/* /\* union FU { *\/ */ -/* /\* float f; *\/ */ -/* /\* uint32_t u; *\/ */ -/* /\* }; *\/ */ + { + float float_in[DIM_LEN_5]; + double double_in[DIM_LEN_5]; + union FU { + float f; + uint32_t u; + }; -/* /\* union FU fin; *\/ */ -/* /\* /\\* union FU fout; *\\/ *\/ */ -/* /\* union FU xpect[DIM_LEN_5]; *\/ */ -/* /\* union DU dfin; *\/ */ -/* /\* /\\* union DU dfout; *\\/ *\/ */ -/* /\* union DU double_xpect[DIM_LEN_5]; *\/ */ -/* /\* xpect[0].u = 0x3f8e3000; *\/ */ -/* /\* xpect[1].u = 0x7cf00000; *\/ */ -/* /\* xpect[2].u = 0x41200000; *\/ */ -/* /\* xpect[3].u = 0x4640efff; *\/ */ -/* /\* xpect[4].u = 0x7cf00000; *\/ */ -/* /\* double_xpect[0].u = 0x3ff1c60000000000; *\/ */ -/* /\* double_xpect[1].u = 0x479e000000000000; *\/ */ -/* /\* double_xpect[2].u = 0x4023fe0000000000; *\/ */ -/* /\* double_xpect[3].u = 0x41d265ffffffffff; *\/ */ -/* /\* double_xpect[4].u = 0x479e000000000000; *\/ */ + union FU fin; + union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; + union DU dfin; + union FU fout; + union DU dfout; + union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + xpect[0][0].u = 0x3f8e3000; + xpect[0][1].u = 0x7cf00000; + xpect[0][2].u = 0x41200000; + xpect[0][3].u = 0x4640efff; + xpect[0][4].u = 0x7cf00000; + double_xpect[0][0].u = 0x3ff1c60000000000; + double_xpect[0][1].u = 0x479e000000000000; + double_xpect[0][2].u = 0x4023fe0000000000; + double_xpect[0][3].u = 0x41d265ffffffffff; + double_xpect[0][4].u = 0x479e000000000000; + break; + case NC_QUANTIZE_GRANULARBR: + xpect[1][0].u = ; + xpect[1][1].u = ; + xpect[1][2].u = ; + xpect[1][3].u = ; + xpect[1][4].u = ; + double_xpect[1][0].u = ; + double_xpect[1][1].u = ; + double_xpect[1][2].u = ; + double_xpect[1][3].u = ; + double_xpect[1][4].u = ; + break; + case NC_QUANTIZE_BITROUND: + xpect[2][0].u = ; + xpect[2][1].u = ; + xpect[2][2].u = ; + xpect[2][3].u = ; + xpect[2][4].u = ; + double_xpect[2][0].u = ; + double_xpect[2][1].u = ; + double_xpect[2][2].u = ; + double_xpect[2][3].u = ; + double_xpect[2][4].u = ; + break; + default: + ERR; + } -/* /\* /\\* Open the file and check metadata. *\\/ *\/ */ -/* /\* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; *\/ */ -/* /\* if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; *\/ */ -/* /\* if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; *\/ */ -/* /\* if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; *\/ */ -/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ -/* /\* if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; *\/ */ -/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; -/* /\* /\\* Check the data. *\\/ *\/ */ -/* /\* if (nc_get_var(ncid, varid1, float_in)) ERR; *\/ */ -/* /\* if (nc_get_var(ncid, varid2, double_in)) ERR; *\/ */ -/* /\* /\\* printf("\n"); *\\/ *\/ */ -/* /\* for (x = 0; x < DIM_LEN_5; x++) *\/ */ -/* /\* { *\/ */ -/* /\* /\\* fout.f = float_data[x]; *\\/ *\/ */ -/* /\* fin.f = float_in[x]; *\/ */ -/* /\* /\\* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", *\\/ *\/ */ -/* /\* /\\* float_data[x], fout.u, float_data[x], fin.u); *\\/ *\/ */ -/* /\* if (fin.u != xpect[x].u) ERR; *\/ */ -/* /\* /\\* dfout.d = double_data[x]; *\\/ *\/ */ -/* /\* dfin.d = double_in[x]; *\/ */ -/* /\* /\\* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", *\\/ *\/ */ -/* /\* /\\* double_data[x], dfout.u, double_data[x], dfin.u); *\\/ *\/ */ -/* /\* if (dfin.u != double_xpect[x].u) ERR; *\/ */ -/* /\* } *\/ */ + /* Check the data. */ + if (nc_get_var(ncid, varid1, float_in)) ERR; + if (nc_get_var(ncid, varid2, double_in)) ERR; + printf("\n"); + for (x = 0; x < DIM_LEN_5; x++) + { + fout.f = float_data[x]; + fin.f = float_in[x]; + printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", + float_data[x], fout.u, float_data[x], fin.u); + dfout.d = double_data[x]; + dfin.d = double_in[x]; + printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", + double_data[x], dfout.u, double_data[x], dfin.u); + /* if (fin.u != xpect[x].u) ERR; */ + /* if (dfin.u != double_xpect[x].u) ERR; */ + } -/* /\* /\\* Close the file again. *\\/ *\/ */ -/* /\* if (nc_close(ncid)) ERR; *\/ */ -/* /\* } *\/ */ -/* /\* } *\/ */ -/* /\* } *\/ */ -/* /\* SUMMARIZE_ERR; *\/ */ + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } + } + } + SUMMARIZE_ERR; /* /\* printf("\t**** testing more quantization values with custom fill values..."); *\/ */ /* /\* { *\/ */ /* /\* #define CUSTOM_FILL_FLOAT 99.99999 *\/ */ From 8142189892d05cef6104fb3c00a308335f01c300 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 13:27:18 -0600 Subject: [PATCH 09/12] more testing of quantize --- nc_test4/tst_quantize.c | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 235c4b9896..8e40f94b53 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -890,28 +890,28 @@ main(int argc, char **argv) double_xpect[0][4].u = 0x479e000000000000; break; case NC_QUANTIZE_GRANULARBR: - xpect[1][0].u = ; - xpect[1][1].u = ; - xpect[1][2].u = ; - xpect[1][3].u = ; - xpect[1][4].u = ; - double_xpect[1][0].u = ; - double_xpect[1][1].u = ; - double_xpect[1][2].u = ; - double_xpect[1][3].u = ; - double_xpect[1][4].u = ; + xpect[1][0].u = 0x3f8e0000; + xpect[1][1].u = 0x7cf00000; + xpect[1][2].u = 0x41200000; + xpect[1][3].u = 0x46410000; + xpect[1][4].u = 0x7cf00000; + double_xpect[1][0].u = 0x3ff1c00000000000; + double_xpect[1][1].u = 0x479e000000000000; + double_xpect[1][2].u = 0x4024000000000000; + double_xpect[1][3].u = 0x41d2600000000000; + double_xpect[1][4].u = 0x479e000000000000; break; case NC_QUANTIZE_BITROUND: - xpect[2][0].u = ; - xpect[2][1].u = ; - xpect[2][2].u = ; - xpect[2][3].u = ; - xpect[2][4].u = ; - double_xpect[2][0].u = ; - double_xpect[2][1].u = ; - double_xpect[2][2].u = ; - double_xpect[2][3].u = ; - double_xpect[2][4].u = ; + xpect[2][0].u = 0x3f900000; + xpect[2][1].u = 0x7cf00000; + xpect[2][2].u = 0x41200000; + xpect[2][3].u = 0x46400000; + xpect[2][4].u = 0x7cf00000; + double_xpect[2][0].u = 0x3ff2000000000000; + double_xpect[2][1].u = 0x479e000000000000; + double_xpect[2][2].u = 0x4024000000000000; + double_xpect[2][3].u = 0x41d2000000000000; + double_xpect[2][4].u = 0x479e000000000000; break; default: ERR; @@ -929,19 +929,19 @@ main(int argc, char **argv) /* Check the data. */ if (nc_get_var(ncid, varid1, float_in)) ERR; if (nc_get_var(ncid, varid2, double_in)) ERR; - printf("\n"); + /* printf("\n"); */ for (x = 0; x < DIM_LEN_5; x++) { fout.f = float_data[x]; fin.f = float_in[x]; - printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", - float_data[x], fout.u, float_data[x], fin.u); dfout.d = double_data[x]; dfin.d = double_in[x]; - printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", - double_data[x], dfout.u, double_data[x], dfin.u); - /* if (fin.u != xpect[x].u) ERR; */ - /* if (dfin.u != double_xpect[x].u) ERR; */ + /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ + /* float_data[x], fout.u, float_data[x], fin.u); */ + /* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */ + /* double_data[x], dfout.u, double_data[x], dfin.u); */ + if (fin.u != xpect[q][x].u) ERR; + if (dfin.u != double_xpect[q][x].u) ERR; } /* Close the file again. */ From 31dfc1ce15c3ad08ed42e405bc5a9bf22ec2783c Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 13:29:56 -0600 Subject: [PATCH 10/12] more testing of quantize --- nc_test4/tst_quantize.c | 215 +++++++++++++++++++++++----------------- 1 file changed, 123 insertions(+), 92 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 8e40f94b53..0a45d89e20 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -950,103 +950,134 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; -/* /\* printf("\t**** testing more quantization values with custom fill values..."); *\/ */ -/* /\* { *\/ */ -/* /\* #define CUSTOM_FILL_FLOAT 99.99999 *\/ */ -/* /\* #define CUSTOM_FILL_DOUBLE -99999.99999 *\/ */ -/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ -/* /\* { *\/ */ -/* /\* int ncid, dimid, varid1, varid2; *\/ */ -/* /\* int quantize_mode_in, nsd_in; *\/ */ -/* /\* float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT}; *\/ */ -/* /\* double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE}; *\/ */ -/* /\* float custom_fill_float = CUSTOM_FILL_FLOAT; *\/ */ -/* /\* double custom_fill_double = CUSTOM_FILL_DOUBLE; *\/ */ -/* /\* int x; *\/ */ + printf("\t**** testing more quantization values with custom fill values..."); + { +#define CUSTOM_FILL_FLOAT 99.99999 +#define CUSTOM_FILL_DOUBLE -99999.99999 + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; + float float_data[DIM_LEN_5] = {1.11111111, CUSTOM_FILL_FLOAT, 9.99999999, 12345.67, CUSTOM_FILL_FLOAT}; + double double_data[DIM_LEN_5] = {1.1111111, CUSTOM_FILL_DOUBLE, 9.999999999, 1234567890.12345, CUSTOM_FILL_DOUBLE}; + float custom_fill_float = CUSTOM_FILL_FLOAT; + double custom_fill_double = CUSTOM_FILL_DOUBLE; + int x; -/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */ + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); -/* /\* /\\* Create a netcdf-4 file with two vars. *\\/ *\/ */ -/* /\* if (nc_create(FILE_NAME, mode, &ncid)) ERR; *\/ */ -/* /\* if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; *\/ */ -/* /\* if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */ -/* /\* if (nc_put_att_float(ncid, varid1, _FillValue, NC_FLOAT, 1, &custom_fill_float)) ERR; *\/ */ -/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */ -/* /\* if (nc_put_att_double(ncid, varid2, _FillValue, NC_DOUBLE, 1, &custom_fill_double)) ERR; *\/ */ + /* Create a netcdf-4 file with two vars. */ + if (nc_create(FILE_NAME, mode, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME_1, DIM_LEN_5, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_1, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_put_att_float(ncid, varid1, _FillValue, NC_FLOAT, 1, &custom_fill_float)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + if (nc_put_att_double(ncid, varid2, _FillValue, NC_DOUBLE, 1, &custom_fill_double)) ERR; -/* /\* /\\* Turn on quantize for both vars. *\\/ *\/ */ -/* /\* if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; *\/ */ -/* /\* if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; *\/ */ + /* Turn on quantize for both vars. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; -/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */ -/* /\* if (m) *\/ */ -/* /\* if (nc_enddef(ncid)) ERR; *\/ */ + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; -/* /\* /\\* Write some data. *\\/ *\/ */ -/* /\* if (nc_put_var_float(ncid, varid1, float_data)) ERR; *\/ */ -/* /\* if (nc_put_var_double(ncid, varid2, double_data)) ERR; *\/ */ - -/* /\* /\\* Close the file. *\\/ *\/ */ -/* /\* if (nc_close(ncid)) ERR; *\/ */ - -/* /\* { *\/ */ -/* /\* float float_in[DIM_LEN_5]; *\/ */ -/* /\* double double_in[DIM_LEN_5]; *\/ */ -/* /\* union FU { *\/ */ -/* /\* float f; *\/ */ -/* /\* uint32_t u; *\/ */ -/* /\* }; *\/ */ - -/* /\* union FU fin; *\/ */ -/* /\* /\\* union FU fout; *\\/ *\/ */ -/* /\* union FU xpect[DIM_LEN_5]; *\/ */ -/* /\* union DU dfin; *\/ */ -/* /\* /\\* union DU dfout; *\\/ *\/ */ -/* /\* union DU double_xpect[DIM_LEN_5]; *\/ */ -/* /\* xpect[0].u = 0x3f8e3000; *\/ */ -/* /\* xpect[1].u = 0x42c7ffff; *\/ */ -/* /\* xpect[2].u = 0x41200000; *\/ */ -/* /\* xpect[3].u = 0x4640efff; *\/ */ -/* /\* xpect[4].u = 0x42c7ffff; *\/ */ -/* /\* double_xpect[0].u = 0x3ff1c60000000000; *\/ */ -/* /\* double_xpect[1].u = 0xc0f869fffff583a5; *\/ */ -/* /\* double_xpect[2].u = 0x4023fe0000000000; *\/ */ -/* /\* double_xpect[3].u = 0x41d265ffffffffff; *\/ */ -/* /\* double_xpect[4].u = 0xc0f869fffff583a5; *\/ */ - -/* /\* /\\* Open the file and check metadata. *\\/ *\/ */ -/* /\* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; *\/ */ -/* /\* if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; *\/ */ -/* /\* if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; *\/ */ -/* /\* if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; *\/ */ -/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ -/* /\* if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; *\/ */ -/* /\* if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; *\/ */ - -/* /\* /\\* Check the data. *\\/ *\/ */ -/* /\* if (nc_get_var(ncid, varid1, float_in)) ERR; *\/ */ -/* /\* if (nc_get_var(ncid, varid2, double_in)) ERR; *\/ */ -/* /\* /\\* printf("\n"); *\\/ *\/ */ -/* /\* for (x = 0; x < DIM_LEN_5; x++) *\/ */ -/* /\* { *\/ */ -/* /\* /\\* fout.f = float_data[x]; *\\/ *\/ */ -/* /\* fin.f = float_in[x]; *\/ */ -/* /\* /\\* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", *\\/ *\/ */ -/* /\* /\\* float_data[x], fout.u, float_data[x], fin.u); *\\/ *\/ */ -/* /\* if (fin.u != xpect[x].u) ERR; *\/ */ -/* /\* /\\* dfout.d = double_data[x]; *\\/ *\/ */ -/* /\* dfin.d = double_in[x]; *\/ */ -/* /\* /\\* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", *\\/ *\/ */ -/* /\* /\\* double_data[x], dfout.u, double_data[x], dfin.u); *\\/ *\/ */ -/* /\* if (dfin.u != double_xpect[x].u) ERR; *\/ */ -/* /\* } *\/ */ - -/* /\* /\\* Close the file again. *\\/ *\/ */ -/* /\* if (nc_close(ncid)) ERR; *\/ */ -/* /\* } *\/ */ -/* /\* } *\/ */ -/* /\* } *\/ */ -/* /\* SUMMARIZE_ERR; *\/ */ + /* Write some data. */ + if (nc_put_var_float(ncid, varid1, float_data)) ERR; + if (nc_put_var_double(ncid, varid2, double_data)) ERR; + + /* Close the file. */ + if (nc_close(ncid)) ERR; + + { + float float_in[DIM_LEN_5]; + double double_in[DIM_LEN_5]; + union FU { + float f; + uint32_t u; + }; + + union FU fin; + /* union FU fout; */ + union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; + union DU dfin; + /* union DU dfout; */ + union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + xpect[0][0].u = 0x3f8e3000; + xpect[0][1].u = 0x42c7ffff; + xpect[0][2].u = 0x41200000; + xpect[0][3].u = 0x4640efff; + xpect[0][4].u = 0x42c7ffff; + double_xpect[0][0].u = 0x3ff1c60000000000; + double_xpect[0][1].u = 0xc0f869fffff583a5; + double_xpect[0][2].u = 0x4023fe0000000000; + double_xpect[0][3].u = 0x41d265ffffffffff; + double_xpect[0][4].u = 0xc0f869fffff583a5; + break; + case NC_QUANTIZE_GRANULARBR: + xpect[1][0].u = 0x3f8e0000; + xpect[1][1].u = 0x7cf00000; + xpect[1][2].u = 0x41200000; + xpect[1][3].u = 0x46410000; + xpect[1][4].u = 0x7cf00000; + double_xpect[1][0].u = 0x3ff1c00000000000; + double_xpect[1][1].u = 0x479e000000000000; + double_xpect[1][2].u = 0x4024000000000000; + double_xpect[1][3].u = 0x41d2600000000000; + double_xpect[1][4].u = 0x479e000000000000; + break; + case NC_QUANTIZE_BITROUND: + xpect[2][0].u = 0x3f900000; + xpect[2][1].u = 0x7cf00000; + xpect[2][2].u = 0x41200000; + xpect[2][3].u = 0x46400000; + xpect[2][4].u = 0x7cf00000; + double_xpect[2][0].u = 0x3ff2000000000000; + double_xpect[2][1].u = 0x479e000000000000; + double_xpect[2][2].u = 0x4024000000000000; + double_xpect[2][3].u = 0x41d2000000000000; + double_xpect[2][4].u = 0x479e000000000000; + break; + default: + ERR; + } + + /* Open the file and check metadata. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_1,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + if (nc_inq_var_quantize(ncid, varid1, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + if (nc_inq_var_quantize(ncid, varid2, &quantize_mode_in, &nsd_in)) ERR; + if (quantize_mode_in != quantize_mode[q] || nsd_in != NSD_3) ERR; + + /* Check the data. */ + if (nc_get_var(ncid, varid1, float_in)) ERR; + if (nc_get_var(ncid, varid2, double_in)) ERR; + printf("\n"); + for (x = 0; x < DIM_LEN_5; x++) + { + fout.f = float_data[x]; + fin.f = float_in[x]; + printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", + float_data[x], fout.u, float_data[x], fin.u); + dfout.d = double_data[x]; + dfin.d = double_in[x]; + printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", + double_data[x], dfout.u, double_data[x], dfin.u); + /* if (fin.u != xpect[q][x].u) ERR; */ + /* if (dfin.u != double_xpect[q][x].u) ERR; */ + } + + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } + } + } + SUMMARIZE_ERR; /* /\* printf("\t*** Checking BitGroom values with type conversion between ints and floats..."); *\/ */ /* /\* { *\/ */ /* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ From a621ed4224a0c7eb9d822762ef4926005d1f125a Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 13:33:23 -0600 Subject: [PATCH 11/12] more testing of quantize --- nc_test4/tst_quantize.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index 0a45d89e20..c5d31b6870 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -998,10 +998,10 @@ main(int argc, char **argv) }; union FU fin; - /* union FU fout; */ union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; union DU dfin; - /* union DU dfout; */ + union FU fout; + union DU dfout; union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_5]; switch (quantize_mode[q]) { @@ -1019,27 +1019,27 @@ main(int argc, char **argv) break; case NC_QUANTIZE_GRANULARBR: xpect[1][0].u = 0x3f8e0000; - xpect[1][1].u = 0x7cf00000; + xpect[1][1].u = 0x42c7ffff; xpect[1][2].u = 0x41200000; xpect[1][3].u = 0x46410000; - xpect[1][4].u = 0x7cf00000; + xpect[1][4].u = 0x42c7ffff; double_xpect[1][0].u = 0x3ff1c00000000000; - double_xpect[1][1].u = 0x479e000000000000; + double_xpect[1][1].u = 0xc0f869fffff583a5; double_xpect[1][2].u = 0x4024000000000000; double_xpect[1][3].u = 0x41d2600000000000; - double_xpect[1][4].u = 0x479e000000000000; + double_xpect[1][4].u = 0xc0f869fffff583a5; break; case NC_QUANTIZE_BITROUND: xpect[2][0].u = 0x3f900000; - xpect[2][1].u = 0x7cf00000; + xpect[2][1].u = 0x42c7ffff; xpect[2][2].u = 0x41200000; xpect[2][3].u = 0x46400000; - xpect[2][4].u = 0x7cf00000; + xpect[2][4].u = 0x42c7ffff; double_xpect[2][0].u = 0x3ff2000000000000; - double_xpect[2][1].u = 0x479e000000000000; + double_xpect[2][1].u = 0xc0f869fffff583a5; double_xpect[2][2].u = 0x4024000000000000; double_xpect[2][3].u = 0x41d2000000000000; - double_xpect[2][4].u = 0x479e000000000000; + double_xpect[2][4].u = 0xc0f869fffff583a5; break; default: ERR; @@ -1068,8 +1068,8 @@ main(int argc, char **argv) dfin.d = double_in[x]; printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", double_data[x], dfout.u, double_data[x], dfin.u); - /* if (fin.u != xpect[q][x].u) ERR; */ - /* if (dfin.u != double_xpect[q][x].u) ERR; */ + if (fin.u != xpect[q][x].u) ERR; + if (dfin.u != double_xpect[q][x].u) ERR; } /* Close the file again. */ From f32890e1be2688b75102bd857519014b177cb638 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Fri, 8 Jul 2022 14:58:52 -0600 Subject: [PATCH 12/12] more testing of quantize --- nc_test4/tst_quantize.c | 311 +++++++++++++++++++++++----------------- 1 file changed, 176 insertions(+), 135 deletions(-) diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index c5d31b6870..2619577d81 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -950,7 +950,7 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; - printf("\t**** testing more quantization values with custom fill values..."); + printf("\t**** testing more quantization values with custom fill values...\n"); { #define CUSTOM_FILL_FLOAT 99.99999 #define CUSTOM_FILL_DOUBLE -99999.99999 @@ -1057,17 +1057,17 @@ main(int argc, char **argv) /* Check the data. */ if (nc_get_var(ncid, varid1, float_in)) ERR; if (nc_get_var(ncid, varid2, double_in)) ERR; - printf("\n"); + /* printf("\n"); */ for (x = 0; x < DIM_LEN_5; x++) { fout.f = float_data[x]; fin.f = float_in[x]; - printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", - float_data[x], fout.u, float_data[x], fin.u); dfout.d = double_data[x]; dfin.d = double_in[x]; - printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", - double_data[x], dfout.u, double_data[x], dfin.u); + /* printf ("float_data: %10f : 0x%x float_data_in: %10f : 0x%x\n", */ + /* float_data[x], fout.u, float_data[x], fin.u); */ + /* printf("double_data: %15g : 0x%16lx double_data_in: %15g : 0x%16lx\n", */ + /* double_data[x], dfout.u, double_data[x], dfin.u); */ if (fin.u != xpect[q][x].u) ERR; if (dfin.u != double_xpect[q][x].u) ERR; } @@ -1078,136 +1078,177 @@ main(int argc, char **argv) } } SUMMARIZE_ERR; -/* /\* printf("\t*** Checking BitGroom values with type conversion between ints and floats..."); *\/ */ -/* /\* { *\/ */ -/* /\* for (q = 0; q < NUM_QUANTIZE_MODES; q++) *\/ */ -/* /\* { *\/ */ -/* /\* int ncid; *\/ */ -/* /\* int dimid; *\/ */ -/* /\* int varid1, varid2; *\/ */ -/* /\* unsigned char uc = 99; *\/ */ -/* /\* signed char sc = -99; *\/ */ -/* /\* unsigned short us = 9999; *\/ */ -/* /\* signed short ss = -9999; *\/ */ -/* /\* unsigned int ui = 9999999; *\/ */ -/* /\* signed int si = -9999999; *\/ */ -/* /\* unsigned long long int ull = 999999999; *\/ */ -/* /\* signed long long int sll = -999999999; *\/ */ -/* /\* size_t index; *\/ */ - -/* /\* printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); *\/ */ + printf("\t*** Checking BitGroom values with type conversion between ints and floats...\n"); + { + for (q = 0; q < NUM_QUANTIZE_MODES; q++) + { + int ncid; + int dimid; + int varid1, varid2; + unsigned char uc = 99; + signed char sc = -99; + unsigned short us = 9999; + signed short ss = -9999; + unsigned int ui = 9999999; + signed int si = -9999999; + unsigned long long int ull = 999999999; + signed long long int sll = -999999999; + size_t index; + + printf("\t\t**** testing quantize algorithm %d...\n", quantize_mode[q]); -/* /\* /\\* Create file. *\\/ *\/ */ -/* /\* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; *\/ */ - -/* /\* /\\* Create dims. *\\/ *\/ */ -/* /\* if (nc_def_dim(ncid, X_NAME, DIM_LEN_8, &dimid)) ERR; *\/ */ - -/* /\* /\\* Create the variables. *\\/ *\/ */ -/* /\* if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; *\/ */ -/* /\* if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; *\/ */ - -/* /\* /\\* Set up quantization. *\\/ *\/ */ -/* /\* if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; *\/ */ -/* /\* if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; *\/ */ - -/* /\* /\\* For classic mode, we must call enddef. *\\/ *\/ */ -/* /\* if (m) *\/ */ -/* /\* if (nc_enddef(ncid)) ERR; *\/ */ - -/* /\* /\\* Write data. *\\/ *\/ */ -/* /\* index = 0; *\/ */ -/* /\* if (nc_put_var1_uchar(ncid, varid1, &index, &uc)) ERR; *\/ */ -/* /\* if (nc_put_var1_uchar(ncid, varid2, &index, &uc)) ERR; *\/ */ -/* /\* index = 1; *\/ */ -/* /\* if (nc_put_var1_schar(ncid, varid1, &index, &sc)) ERR; *\/ */ -/* /\* if (nc_put_var1_schar(ncid, varid2, &index, &sc)) ERR; *\/ */ -/* /\* index = 2; *\/ */ -/* /\* if (nc_put_var1_ushort(ncid, varid1, &index, &us)) ERR; *\/ */ -/* /\* if (nc_put_var1_ushort(ncid, varid2, &index, &us)) ERR; *\/ */ -/* /\* index = 3; *\/ */ -/* /\* if (nc_put_var1_short(ncid, varid1, &index, &ss)) ERR; *\/ */ -/* /\* if (nc_put_var1_short(ncid, varid2, &index, &ss)) ERR; *\/ */ -/* /\* index = 4; *\/ */ -/* if (nc_put_var1_uint(ncid, varid1, &index, &ui)) ERR; */ -/* if (nc_put_var1_uint(ncid, varid2, &index, &ui)) ERR; */ -/* index = 5; */ -/* if (nc_put_var1_int(ncid, varid1, &index, &si)) ERR; */ -/* if (nc_put_var1_int(ncid, varid2, &index, &si)) ERR; */ -/* index = 6; */ -/* if (nc_put_var1_ulonglong(ncid, varid1, &index, &ull)) ERR; */ -/* if (nc_put_var1_ulonglong(ncid, varid2, &index, &ull)) ERR; */ -/* index = 7; */ -/* if (nc_put_var1_longlong(ncid, varid1, &index, &sll)) ERR; */ -/* if (nc_put_var1_longlong(ncid, varid2, &index, &sll)) ERR; */ - -/* /\\* Close the file. *\\/ */ -/* if (nc_close(ncid)) ERR; */ - -/* { */ -/* float float_data_in[DIM_LEN_8]; */ -/* double double_data_in[DIM_LEN_8]; */ -/* int x; */ - -/* /\\* Now reopen the file and check. *\\/ */ -/* if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */ -/* if (nc_inq_varid(ncid,VAR_NAME,&varid1)) ERR; */ -/* if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; */ - -/* /\\* Read the data. *\\/ */ -/* if (nc_get_var_float(ncid, varid1, float_data_in)) ERR; */ -/* if (nc_get_var_double(ncid, varid2, double_data_in)) ERR; */ - -/* union FU xpect[DIM_LEN_8]; */ -/* union DU double_xpect[DIM_LEN_8]; */ -/* /\\* This test comes up with different answers to this than */ -/* * the corresponding bitgroom filter test, but that's */ -/* * OK. In netcdf-c quantization is applied as the data are */ -/* * written by the user, but in HDF5 filters, the bitgroom */ -/* * filter is applied to all data values as they are */ -/* * written to disk. See */ -/* * https://github.com/ccr/ccr/issues/194 for a full */ -/* * explanation. *\\/ */ -/* xpect[0].u = 0x42c60000; */ -/* xpect[1].u = 0xc2c60000; */ -/* xpect[2].u = 0x461c3000; */ -/* xpect[3].u = 0xc61c3000; */ -/* xpect[4].u = 0x4b189000; */ -/* xpect[5].u = 0xcb189000; */ -/* xpect[6].u = 0x4e6e6b28; */ -/* xpect[6].u = 0x4e6e6000; */ -/* xpect[7].u = 0xce6e6000; */ -/* double_xpect[0].u = 0x4058c00000000000; */ -/* double_xpect[1].u = 0xc058c00000000000; */ -/* double_xpect[2].u = 0x40c3860000000000; */ -/* double_xpect[3].u = 0xc0c3860000000000; */ -/* double_xpect[4].u = 0x4163120000000000; */ -/* double_xpect[5].u = 0xc163120000000000; */ -/* double_xpect[6].u = 0x41cdcc0000000000; */ -/* double_xpect[7].u = 0xc1cdcc0000000000; */ - -/* for (x = 0; x < DIM_LEN_8; x++) */ -/* { */ -/* union FU fin; */ -/* union DU dfin; */ -/* fin.f = float_data_in[x]; */ -/* dfin.d = double_data_in[x]; */ -/* /\\* printf ("%d float_data_in : %08.8f : 0x%x expected %08.8f : 0x%x\n", *\\/ */ -/* /\\* x, float_data_in[x], fin.u, xpect[x].f, xpect[x].u); *\\/ */ -/* /\\* printf ("%d double_data_in : %15g : 0x%llx expected %15g : 0x%llx\n",*\\/ */ -/* /\\* x, double_data_in[x], dfin.u, double_xpect[x].d, double_xpect[x].u);*\\/ */ -/* if (fin.u != xpect[x].u) */ -/* ERR; */ -/* if (dfin.u != double_xpect[x].u) */ -/* ERR; */ -/* } */ - -/* /\\* Close the file. *\\/ */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* } */ -/* } */ -/* SUMMARIZE_ERR; */ + /* Create file. */ + if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + + /* Create dims. */ + if (nc_def_dim(ncid, X_NAME, DIM_LEN_8, &dimid)) ERR; + + /* Create the variables. */ + if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + + /* Set up quantization. */ + if (nc_def_var_quantize(ncid, varid1, quantize_mode[q], NSD_3)) ERR; + if (nc_def_var_quantize(ncid, varid2, quantize_mode[q], NSD_3)) ERR; + + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; + + /* Write data. */ + index = 0; + if (nc_put_var1_uchar(ncid, varid1, &index, &uc)) ERR; + if (nc_put_var1_uchar(ncid, varid2, &index, &uc)) ERR; + index = 1; + if (nc_put_var1_schar(ncid, varid1, &index, &sc)) ERR; + if (nc_put_var1_schar(ncid, varid2, &index, &sc)) ERR; + index = 2; + if (nc_put_var1_ushort(ncid, varid1, &index, &us)) ERR; + if (nc_put_var1_ushort(ncid, varid2, &index, &us)) ERR; + index = 3; + if (nc_put_var1_short(ncid, varid1, &index, &ss)) ERR; + if (nc_put_var1_short(ncid, varid2, &index, &ss)) ERR; + index = 4; + if (nc_put_var1_uint(ncid, varid1, &index, &ui)) ERR; + if (nc_put_var1_uint(ncid, varid2, &index, &ui)) ERR; + index = 5; + if (nc_put_var1_int(ncid, varid1, &index, &si)) ERR; + if (nc_put_var1_int(ncid, varid2, &index, &si)) ERR; + index = 6; + if (nc_put_var1_ulonglong(ncid, varid1, &index, &ull)) ERR; + if (nc_put_var1_ulonglong(ncid, varid2, &index, &ull)) ERR; + index = 7; + if (nc_put_var1_longlong(ncid, varid1, &index, &sll)) ERR; + if (nc_put_var1_longlong(ncid, varid2, &index, &sll)) ERR; + + /* Close the file. */ + if (nc_close(ncid)) ERR; + + { + float float_data_in[DIM_LEN_8]; + double double_data_in[DIM_LEN_8]; + int x; + + /* Now reopen the file and check. */ + if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + if (nc_inq_varid(ncid,VAR_NAME,&varid1)) ERR; + if (nc_inq_varid(ncid,VAR_NAME_2,&varid2)) ERR; + + /* Read the data. */ + if (nc_get_var_float(ncid, varid1, float_data_in)) ERR; + if (nc_get_var_double(ncid, varid2, double_data_in)) ERR; + + union FU xpect[NUM_QUANTIZE_MODES][DIM_LEN_8]; + union DU double_xpect[NUM_QUANTIZE_MODES][DIM_LEN_8]; + + /* This test comes up with different answers to this than + * the corresponding bitgroom filter test, but that's + * OK. In netcdf-c quantization is applied as the data are + * written by the user, but in HDF5 filters, the bitgroom + * filter is applied to all data values as they are + * written to disk. See + * https://github.com/ccr/ccr/issues/194 for a full + * explanation. */ + switch (quantize_mode[q]) + { + case NC_QUANTIZE_BITGROOM: + xpect[0][0].u = 0x42c60000; + xpect[0][1].u = 0xc2c60000; + xpect[0][2].u = 0x461c3000; + xpect[0][3].u = 0xc61c3000; + xpect[0][4].u = 0x4b189000; + xpect[0][5].u = 0xcb189000; + xpect[0][6].u = 0x4e6e6000; + xpect[0][7].u = 0xce6e6000; + double_xpect[0][0].u = 0x4058c00000000000; + double_xpect[0][1].u = 0xc058c00000000000; + double_xpect[0][2].u = 0x40c3860000000000; + double_xpect[0][3].u = 0xc0c3860000000000; + double_xpect[0][4].u = 0x4163120000000000; + double_xpect[0][5].u = 0xc163120000000000; + double_xpect[0][6].u = 0x41cdcc0000000000; + double_xpect[0][7].u = 0xc1cdcc0000000000; + break; + case NC_QUANTIZE_GRANULARBR: + xpect[1][0].u = 0x42c60000; + xpect[1][1].u = 0xc2c60000; + xpect[1][2].u = 0x461c4000; + xpect[1][3].u = 0xc61c4000; + xpect[1][4].u = 0x4b18a000; + xpect[1][5].u = 0xcb18a000; + xpect[1][6].u = 0x4e6e6000; + xpect[1][7].u = 0xce6e6000; + double_xpect[1][0].u = 0x4058c00000000000; + double_xpect[1][1].u = 0xc058c00000000000; + double_xpect[1][2].u = 0x40c3880000000000; + double_xpect[1][3].u = 0xc0c3880000000000; + double_xpect[1][4].u = 0x4163140000000000; + double_xpect[1][5].u = 0xc163140000000000; + double_xpect[1][6].u = 0x41cdcc0000000000; + double_xpect[1][7].u = 0xc1cdcc0000000000; + break; + case NC_QUANTIZE_BITROUND: + xpect[2][0].u = 0x42c00000; + xpect[2][1].u = 0xc2c00000; + xpect[2][2].u = 0x46200000; + xpect[2][3].u = 0xc6200000; + xpect[2][4].u = 0x4b200000; + xpect[2][5].u = 0xcb200000; + xpect[2][6].u = 0x4e700000; + xpect[2][7].u = 0xce700000; + double_xpect[2][0].u = 0x4058000000000000; + double_xpect[2][1].u = 0xc058000000000000; + double_xpect[2][2].u = 0x40c4000000000000; + double_xpect[2][3].u = 0xc0c4000000000000; + double_xpect[2][4].u = 0x4164000000000000; + double_xpect[2][5].u = 0xc164000000000000; + double_xpect[2][6].u = 0x41ce000000000000; + double_xpect[2][7].u = 0xc1ce000000000000; + break; + default: + ERR; + } + + for (x = 0; x < DIM_LEN_8; x++) + { + union FU fin; + union DU dfin; + fin.f = float_data_in[x]; + dfin.d = double_data_in[x]; + /* printf ("%d float_data_in : %08.8f : 0x%x expected %08.8f : 0x%x\n", */ + /* x, float_data_in[x], fin.u, xpect[q][x].f, xpect[q][x].u); */ + /* printf ("%d double_data_in : %15g : 0x%lx expected %15g : 0x%lx\n", */ + /* x, double_data_in[x], dfin.u, double_xpect[q][x].d, double_xpect[q][x].u); */ + if (fin.u != xpect[q][x].u) ERR; + if (dfin.u != double_xpect[q][x].u) ERR; + } + + /* Close the file. */ + if (nc_close(ncid)) ERR; + } + } + } + SUMMARIZE_ERR; printf("\t**** Nice, simple example of using BitGroom plus zlib..."); { #define DIM_LEN_SIMPLE 100