fix and test quantize mode for NC_CLASSIC_MODEL

This commit is contained in:
Edward Hartnett 2022-07-02 06:14:32 -06:00
parent a00bb62167
commit 536cdd28f9
3 changed files with 926 additions and 833 deletions

View File

@ -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);
}

View File

@ -680,6 +680,50 @@ exit:
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. */

File diff suppressed because it is too large Load Diff