Skip to content

Commit

Permalink
Merge pull request #2445 from edwardhartnett/ejh_fix_quantize
Browse files Browse the repository at this point in the history
fix and test quantize mode for NC_CLASSIC_MODEL
  • Loading branch information
WardF authored Jul 7, 2022
2 parents ee5e159 + 4b0f337 commit 26c5582
Show file tree
Hide file tree
Showing 4 changed files with 961 additions and 858 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ 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`.
* [Bug Fix] Fix CMakeLists.txt to handle all acceptable boolean values for -DPLUGIN_INSTALL_DIR. See [Github #2430](https://github.com/Unidata/netcdf-c/pull/2430).
* [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).
Expand Down
8 changes: 3 additions & 5 deletions libhdf5/hdf5file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -740,5 +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 and data to storage. */
return sync_netcdf4_file(h5);
}
78 changes: 65 additions & 13 deletions libhdf5/nc4hdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,69 @@ 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.
* @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)
{
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);

/* 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);

/* 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, &var->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.
*
Expand Down Expand Up @@ -1015,19 +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 = nc4_put_att(var->container, var->hdr.id, NC_QUANTIZE_BITGROOM_ATT_NAME, NC_INT, 1,
&var->nsd, NC_INT, 0)))
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)))
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 (var->quantize_mode)
if ((retval = write_quantize_att(var)))
BAIL(retval);

/* Write attributes for this var. */
Expand Down
Loading

0 comments on commit 26c5582

Please sign in to comment.