From 536cdd28f935a62a13e069813df101663c8c1c67 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 2 Jul 2022 06:14:32 -0600 Subject: [PATCH 1/4] fix and test quantize mode for NC_CLASSIC_MODEL --- libhdf5/hdf5file.c | 5 +- libhdf5/nc4hdf.c | 53 +- nc_test4/tst_quantize.c | 1731 ++++++++++++++++++++------------------- 3 files changed, 941 insertions(+), 848 deletions(-) diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index 29f44fd5b0..1b7888f7ab 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -132,8 +132,8 @@ sync_netcdf4_file(NC_FILE_INFO_T *h5) * otherwise, end define mode. */ if (h5->flags & NC_INDEF) { - if (h5->cmode & NC_CLASSIC_MODEL) - return NC_EINDEFINE; + /* if (h5->cmode & NC_CLASSIC_MODEL) */ + /* return NC_EINDEFINE; */ /* Turn define mode off. */ h5->flags ^= NC_INDEF; @@ -740,5 +740,6 @@ nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5) /* Redef mode needs to be tracked separately for nc_abort. */ h5->redef = NC_FALSE; + /* Sync all metadata to storage. */ return sync_netcdf4_file(h5); } diff --git a/libhdf5/nc4hdf.c b/libhdf5/nc4hdf.c index 66f2c3927d..fca0b012d9 100644 --- a/libhdf5/nc4hdf.c +++ b/libhdf5/nc4hdf.c @@ -680,6 +680,50 @@ write_coord_dimids(NC_VAR_INFO_T *var) return retval; } +/** + * @internal When nc_def_var_quantize() is used, a new attribute is + * added to the var, containing the quantize information. + * + * @param var Pointer to var info struct. + * + * @returns NC_NOERR No error. + * @returns NC_EHDFERR HDF5 returned an error. + * @author Ed Hartnett + */ +static int +write_quantize_att(NC_VAR_INFO_T *var, char *att_name, int nsd) +{ + NC_HDF5_VAR_INFO_T *hdf5_var; + hsize_t len = 1; + hid_t c_spaceid = -1, c_attid = -1; + int retval = NC_NOERR; + + assert(var && var->format_var_info); + + /* Get HDF5-specific var info. */ + hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info; + + /* Set up space for attribute. */ + if ((c_spaceid = H5Screate_simple(1, &len, &len)) < 0) + BAIL(NC_EHDFERR); + + /* Create the attribute. */ + if ((c_attid = H5Acreate1(hdf5_var->hdf_datasetid, att_name, + H5T_NATIVE_INT, c_spaceid, H5P_DEFAULT)) < 0) + BAIL(NC_EHDFERR); + + /* Write our attribute. */ + if (H5Awrite(c_attid, H5T_NATIVE_INT, &nsd) < 0) + BAIL(NC_EHDFERR); + +exit: + if (c_spaceid >= 0 && H5Sclose(c_spaceid) < 0) + BAIL2(NC_EHDFERR); + if (c_attid >= 0 && H5Aclose(c_attid) < 0) + BAIL2(NC_EHDFERR); + return retval; +} + /** * @internal Write a special attribute for the netCDF-4 dimension ID. * @@ -1016,18 +1060,15 @@ var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid * (NSD, for BitGroom and Granular BitRound) or number of significant bits * (NSB, for BitRound). */ if (var->quantize_mode == NC_QUANTIZE_BITGROOM) - if ((retval = nc4_put_att(var->container, var->hdr.id, NC_QUANTIZE_BITGROOM_ATT_NAME, NC_INT, 1, - &var->nsd, NC_INT, 0))) + if ((retval = write_quantize_att(var, NC_QUANTIZE_BITGROOM_ATT_NAME, var->nsd))) BAIL(retval); if (var->quantize_mode == NC_QUANTIZE_GRANULARBR) - if ((retval = nc4_put_att(var->container, var->hdr.id, NC_QUANTIZE_GRANULARBR_ATT_NAME, NC_INT, 1, - &var->nsd, NC_INT, 0))) + if ((retval = write_quantize_att(var, NC_QUANTIZE_GRANULARBR_ATT_NAME, var->nsd))) BAIL(retval); if (var->quantize_mode == NC_QUANTIZE_BITROUND) - if ((retval = nc4_put_att(var->container, var->hdr.id, NC_QUANTIZE_BITROUND_ATT_NAME, NC_INT, 1, - &var->nsd, NC_INT, 0))) + if ((retval = write_quantize_att(var, NC_QUANTIZE_BITROUND_ATT_NAME, var->nsd))) BAIL(retval); /* Write attributes for this var. */ diff --git a/nc_test4/tst_quantize.c b/nc_test4/tst_quantize.c index bb515b0c86..e8993c61ad 100644 --- a/nc_test4/tst_quantize.c +++ b/nc_test4/tst_quantize.c @@ -89,95 +89,109 @@ main(int argc, char **argv) #define FILE_NAME file_url #endif +#define NUM_MODE_TESTS 2 + int mode = NC_NETCDF4|NC_CLOBBER; + int m; + printf("\n*** Testing netcdf-4 variable quantization functions.\n"); - printf("**** testing quantization setting and error conditions..."); + for (m = 0; m < NUM_MODE_TESTS; m++) { - int ncid, dimid, varid1, varid2; - int quantize_mode_in, nsd_in; + if (!m) + printf("**** testing with NC_NETCDF4...\n"); + else + { + printf("**** testing with NC_NETCDF4|NC_CLASSIC_MODEL...\n"); + mode |= NC_CLASSIC_MODEL; + } + + printf("\t**** testing quantization setting and error conditions..."); + { + int ncid, dimid, varid1, varid2; + int quantize_mode_in, nsd_in; #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, 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; #endif - /* Create a netcdf-4 file with two vars. Attempt - * quantization. It will work, eventually... */ - if (nc_create(FILE_NAME, NC_NETCDF4|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(ncid, VAR_NAME_2, NC_DOUBLE, NDIM1, &dimid, &varid2)) 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; - - /* 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; - - /* 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; - - /* 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; - - /* 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; - - /* 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; - } - SUMMARIZE_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, 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; + + /* 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; + + /* 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; + + /* 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; + + /* 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; + + /* 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; + } + SUMMARIZE_ERR; #define NX_BIG 100 #define NY_BIG 100 @@ -187,790 +201,827 @@ main(int argc, char **argv) #define Y_NAME "distance_along_canal" #define NDIM2 2 - printf("**** testing quantization handling of non-floats..."); - { - int ncid; - int dimid[NDIM2]; - int varid; - int nsd_in, quantize_mode; - int nsd_out = 3; + 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]; + char file_name[4096]; #else - char file_name[NC_MAX_NAME + 1]; + 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; + 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++) - { - sprintf(file_name, "%s_bitgroom_type_%d.nc", TEST, xtype[t]); + for (t = 0; t < NTYPES; t++) + { + 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; + + /* 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, &nsd_in)) + ERR; + if (quantize_mode) ERR; + if (nc_close(ncid)) ERR; + } + } + } + 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; + + /* 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; + { - char url[4096]; - snprintf(url,sizeof(url),template,file_name); - strcpy(file_name,url); + float float_in; + double double_in; + union FU fin; + int nsd_att_in; + /* union FU fout; */ + union DU dfin; + /* 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; + + /* 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_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; + + /* Close the file again. */ + if (nc_close(ncid)) ERR; } -#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; - - /* 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, &nsd_in)) - ERR; - if (quantize_mode) ERR; - if (nc_close(ncid)) ERR; - } - } - } - SUMMARIZE_ERR; - printf("**** 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, NC_NETCDF4|NC_CLOBBER, &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; - - /* 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; - - /* 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; - double double_in; - union FU fin; - int nsd_att_in; - /* union FU fout; */ - union DU dfin; - /* 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; - - /* 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_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; - - /* Close the file again. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("**** 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}; - - /* Create a netcdf-4 file with two vars. */ - if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &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; - - /* 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; - double double_in; - union FU fin; - /* union FU fout; */ - union DU dfin; - /* 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; - - /* 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; - - /* Close the file again. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("**** testing more quantization values..."); - { - 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, NC_NETCDF4|NC_CLOBBER, &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; - - /* 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 = 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; - - /* 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%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; - } - - /* Close the file again. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("**** testing quantization of one value with type conversion..."); - { - 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, NC_NETCDF4|NC_CLOBBER, &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; - - /* 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; - - { - 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("**** 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, NC_NETCDF4|NC_CLOBBER, &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; - - /* Write some data. */ - if (nc_put_var_double(ncid, varid1, double_data)) ERR; - if (nc_put_var_float(ncid, varid2, float_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 = 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; - - /* 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; - } - - /* Close the file again. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("**** 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, NC_NETCDF4|NC_CLOBBER, &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; - - /* 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("**** 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, NC_NETCDF4|NC_CLOBBER, &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; - - /* 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 != 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("*** Checking BitGroom values with type conversion between ints and floats..."); - { - 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; - - /* 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]; + } + 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}; + + /* 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 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; + double double_in; + union FU fin; + /* union FU fout; */ + union DU dfin; + /* 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; + + /* 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; + + /* Close the file again. */ + if (nc_close(ncid)) ERR; + } + } + SUMMARIZE_ERR; + printf("\t**** testing more quantization values..."); + { + 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; - /* 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++) + /* 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; - 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; + /* 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; + + /* 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%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; + } + + /* Close the file again. */ + if (nc_close(ncid)) ERR; } + } + SUMMARIZE_ERR; + printf("\t**** testing quantization of one value with type conversion..."); + { + 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; - /* Close the file. */ - if (nc_close(ncid)) ERR; - } - } - SUMMARIZE_ERR; - printf("*** Nice, simple example of using BitGroom plus zlib..."); - { + { + 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; + + /* For classic mode, we must call enddef. */ + if (m) + if (nc_enddef(ncid)) ERR; + + /* Write some data. */ + if (nc_put_var_double(ncid, varid1, double_data)) ERR; + if (nc_put_var_float(ncid, varid2, float_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 = 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; + + /* 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; + } + + /* Close the file again. */ + 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; + + /* 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 != 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*** Checking BitGroom values with type conversion between ints and floats..."); + { + 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; + + /* 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 #define EPSILON .1 - int ncid; - int dimid; - int varid1, varid2; - float *float_data; - double *double_data; - int i; - - /* Set up some data to write. */ - if (!(float_data = malloc(DIM_LEN_SIMPLE * sizeof(float)))) - ERR; - if (!(double_data = malloc(DIM_LEN_SIMPLE * sizeof(double)))) - ERR; - for (i = 0; i < DIM_LEN_SIMPLE; i++) - { - float_data[i] = 1.5 * i; - double_data[i] = 1.5 * i; - } - - /* Create the file. */ - if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; - - /* Add one dimension. */ - if (nc_def_dim(ncid, "dim1", DIM_LEN_SIMPLE, &dimid)) ERR; - - /* Create two variables, one float, one double. Quantization - * may only be applied to floating point data. */ - if (nc_def_var(ncid, "var1", NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; - if (nc_def_var(ncid, "var2", NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; - - /* Set up quantization. This will not make the data any - * smaller, unless compression is also turned on. In this - * case, we will set 3 significant digits. */ - 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; + int dimid; + int varid1, varid2; + float *float_data; + double *double_data; + int i; + + /* Set up some data to write. */ + if (!(float_data = malloc(DIM_LEN_SIMPLE * sizeof(float)))) + ERR; + if (!(double_data = malloc(DIM_LEN_SIMPLE * sizeof(double)))) + ERR; + for (i = 0; i < DIM_LEN_SIMPLE; i++) + { + float_data[i] = 1.5 * i; + double_data[i] = 1.5 * i; + } + + /* Create the file. */ + if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + + /* Add one dimension. */ + if (nc_def_dim(ncid, "dim1", DIM_LEN_SIMPLE, &dimid)) ERR; + + /* Create two variables, one float, one double. Quantization + * may only be applied to floating point data. */ + if (nc_def_var(ncid, "var1", NC_FLOAT, NDIM1, &dimid, &varid1)) ERR; + if (nc_def_var(ncid, "var2", NC_DOUBLE, NDIM1, &dimid, &varid2)) ERR; + + /* Set up quantization. This will not make the data any + * smaller, unless compression is also turned on. In this + * case, we will set 3 significant digits. */ + 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; #ifdef TESTNCZARR #ifdef ENABLE_NCZARR_FILTERS - /* Set up zlib compression. This will work better because the - * data are quantized, yielding a smaller output file. We will - * set compression level to 1, which is usually the best - * choice. */ - if (nc_def_var_deflate(ncid, varid1, 0, 1, 1)) ERR; + /* Set up zlib compression. This will work better because the + * data are quantized, yielding a smaller output file. We will + * set compression level to 1, which is usually the best + * choice. */ + if (nc_def_var_deflate(ncid, varid1, 0, 1, 1)) ERR; #endif #endif - /* Write the 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; - - /* Check the resulting file for correctness. */ - { - float float_data_in[DIM_LEN_SIMPLE]; - double double_data_in[DIM_LEN_SIMPLE]; + /* 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,"var1",&varid1)) ERR; - if (nc_inq_varid(ncid,"var2",&varid2)) ERR; + /* Write the data. */ + if (nc_put_var_float(ncid, varid1, float_data)) ERR; + if (nc_put_var_double(ncid, varid2, double_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; - for (i = 0; i < DIM_LEN_SIMPLE; i++) + /* Check the resulting file for correctness. */ { - if (fabs(float_data_in[i] - float_data[i]) > EPSILON) - ERR; - if (fabs(double_data_in[i] - double_data[i]) > EPSILON) - ERR; + float float_data_in[DIM_LEN_SIMPLE]; + double double_data_in[DIM_LEN_SIMPLE]; + + /* Now reopen the file and check. */ + if (nc_open(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + if (nc_inq_varid(ncid,"var1",&varid1)) ERR; + if (nc_inq_varid(ncid,"var2",&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; + + for (i = 0; i < DIM_LEN_SIMPLE; i++) + { + if (fabs(float_data_in[i] - float_data[i]) > EPSILON) + ERR; + if (fabs(double_data_in[i] - double_data[i]) > EPSILON) + ERR; + } + + /* Close the file. */ + if (nc_close(ncid)) ERR; } - /* Close the file. */ - if (nc_close(ncid)) ERR; - } - - /* Free resources. */ - free(float_data); - free(double_data); + /* Free resources. */ + free(float_data); + free(double_data); + } + SUMMARIZE_ERR; } - SUMMARIZE_ERR; FINAL_RESULTS; } From a2aeec89365b2f10256f3914e696c37e6f7b8ca7 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 2 Jul 2022 06:19:52 -0600 Subject: [PATCH 2/4] documentation --- RELEASE_NOTES.md | 1 + libhdf5/hdf5file.c | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a28e135e29..5ec3d3cb8e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -8,6 +8,7 @@ This file contains a high-level description of this package's evolution. Release ## 4.9.1 - T.B.D. +* [Bug Fix] Fix quantize with CLASSIC_MODEL files. See [Github #2405](https://github.com/Unidata/netcdf-c/pull/2445). * [Enhancement] Add `--disable-quantize` option to `configure`. * [Enhancement] Provide a simple API to allow user access to the internal .rc file table: supports get/set/overwrite of entries of the form "key=value". See [Github #2408](https://github.com/Unidata/netcdf-c/pull/2408). * [Bug Fix] Use env variable USERPROFILE instead of HOME for windows and mingw. See [Github #2405](https://github.com/Unidata/netcdf-c/pull/2405). diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index 1b7888f7ab..1c00b88be7 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -128,13 +128,10 @@ sync_netcdf4_file(NC_FILE_INFO_T *h5) assert(h5 && h5->format_file_info); LOG((3, "%s", __func__)); - /* If we're in define mode, that's an error, for strict nc3 rules, - * otherwise, end define mode. */ + /* End depend mode if needed. (Error checking for classic mode has + * already happened). */ if (h5->flags & NC_INDEF) { - /* if (h5->cmode & NC_CLASSIC_MODEL) */ - /* return NC_EINDEFINE; */ - /* Turn define mode off. */ h5->flags ^= NC_INDEF; From 309d4bec35b3234805548ab2f82b8953ec9ce508 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 2 Jul 2022 07:51:33 -0600 Subject: [PATCH 3/4] code and documentation cleanup --- libhdf5/hdf5file.c | 2 +- libhdf5/nc4hdf.c | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/libhdf5/hdf5file.c b/libhdf5/hdf5file.c index 1c00b88be7..3542e3f386 100644 --- a/libhdf5/hdf5file.c +++ b/libhdf5/hdf5file.c @@ -737,6 +737,6 @@ nc4_enddef_netcdf4_file(NC_FILE_INFO_T *h5) /* Redef mode needs to be tracked separately for nc_abort. */ h5->redef = NC_FALSE; - /* Sync all metadata to storage. */ + /* Sync all metadata and data to storage. */ return sync_netcdf4_file(h5); } diff --git a/libhdf5/nc4hdf.c b/libhdf5/nc4hdf.c index fca0b012d9..a235ea451e 100644 --- a/libhdf5/nc4hdf.c +++ b/libhdf5/nc4hdf.c @@ -685,17 +685,20 @@ write_coord_dimids(NC_VAR_INFO_T *var) * added to the var, containing the quantize information. * * @param var Pointer to var info struct. + * @param att_name Name of the qunatize attribute. + * @param nsd Number of significant digits. * * @returns NC_NOERR No error. * @returns NC_EHDFERR HDF5 returned an error. * @author Ed Hartnett */ static int -write_quantize_att(NC_VAR_INFO_T *var, char *att_name, int nsd) +write_quantize_att(NC_VAR_INFO_T *var) { NC_HDF5_VAR_INFO_T *hdf5_var; hsize_t len = 1; hid_t c_spaceid = -1, c_attid = -1; + char att_name[NC_MAX_NAME + 1]; int retval = NC_NOERR; assert(var && var->format_var_info); @@ -703,6 +706,22 @@ write_quantize_att(NC_VAR_INFO_T *var, char *att_name, int nsd) /* Get HDF5-specific var info. */ hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info; + /* Different quantize algorithms get different attribute names. */ + switch var->quantize_mode + { + case NC_QUANTIZE_BITGROOM: + sprintf(att_name, "%s", NC_QUANTIZE_BITGROOM_ATT_NAME); + break; + case NC_QUANTIZE_GRANULARBR: + sprintf(att_name, "%s", NC_QUANTIZE_GRANULARBR_ATT_NAME); + break; + case NC_QUANTIZE_BITROUND: + sprintf(att_name, "%s", NC_QUANTIZE_BITROUND_ATT_NAME); + break; + default: + return NC_EINVAL; + } + /* Set up space for attribute. */ if ((c_spaceid = H5Screate_simple(1, &len, &len)) < 0) BAIL(NC_EHDFERR); @@ -713,7 +732,7 @@ write_quantize_att(NC_VAR_INFO_T *var, char *att_name, int nsd) BAIL(NC_EHDFERR); /* Write our attribute. */ - if (H5Awrite(c_attid, H5T_NATIVE_INT, &nsd) < 0) + if (H5Awrite(c_attid, H5T_NATIVE_INT, &var->nsd) < 0) BAIL(NC_EHDFERR); exit: @@ -1059,16 +1078,8 @@ var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid * single integer which is the number of significant digits * (NSD, for BitGroom and Granular BitRound) or number of significant bits * (NSB, for BitRound). */ - if (var->quantize_mode == NC_QUANTIZE_BITGROOM) - if ((retval = write_quantize_att(var, NC_QUANTIZE_BITGROOM_ATT_NAME, var->nsd))) - BAIL(retval); - - if (var->quantize_mode == NC_QUANTIZE_GRANULARBR) - if ((retval = write_quantize_att(var, NC_QUANTIZE_GRANULARBR_ATT_NAME, var->nsd))) - BAIL(retval); - - if (var->quantize_mode == NC_QUANTIZE_BITROUND) - if ((retval = write_quantize_att(var, NC_QUANTIZE_BITROUND_ATT_NAME, var->nsd))) + if (var->quantize_mode) + if ((retval = write_quantize_att(var))) BAIL(retval); /* Write attributes for this var. */ From 4e4209b6f0019e60343dcd282914b51c65c8d8ce Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 2 Jul 2022 08:13:13 -0600 Subject: [PATCH 4/4] code and documentation cleanup --- libhdf5/nc4hdf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libhdf5/nc4hdf.c b/libhdf5/nc4hdf.c index a235ea451e..b81e9c146f 100644 --- a/libhdf5/nc4hdf.c +++ b/libhdf5/nc4hdf.c @@ -707,7 +707,7 @@ write_quantize_att(NC_VAR_INFO_T *var) hdf5_var = (NC_HDF5_VAR_INFO_T *)var->format_var_info; /* Different quantize algorithms get different attribute names. */ - switch var->quantize_mode + switch (var->quantize_mode) { case NC_QUANTIZE_BITGROOM: sprintf(att_name, "%s", NC_QUANTIZE_BITGROOM_ATT_NAME);