now nsd of 0 is NC_EINVAL for nc_def_var_quantize()

This commit is contained in:
Edward Hartnett 2021-09-10 06:10:20 -06:00
parent 7806ded5f2
commit 5200477de1
3 changed files with 8 additions and 22 deletions

View File

@ -523,12 +523,13 @@ nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_le
https://www.researchgate.net/publication/301575383_Bit_Grooming_Statistically_accurate_precision-preserving_quantization_with_compression_evaluated_in_the_netCDF_Operators_NCO_v448.
@param ncid File ID.
@param varid Variable ID. NC_GLOBAL may not be used.
@param varid Variable ID. ::NC_GLOBAL may not be used.
@param quantize_mode Quantization mode. May be ::NC_NOQUANTIZE or
::NC_QUANTIZE_BITGROOM.
@param nsd Number of significant digits. May be any integer from 1
to ::NC_QUANTIZE_MAX_FLOAT_NSD (for variables of type ::NC_FLOAT) or
::NC_QUANTIZE_MAX_DOUBLE_NSD (for variables of type ::NC_DOUBLE).
to ::NC_QUANTIZE_MAX_FLOAT_NSD (for variables of type ::NC_FLOAT)
or ::NC_QUANTIZE_MAX_DOUBLE_NSD (for variables of type
::NC_DOUBLE). Ignored if quantize_mode = NC_NOQUANTIZE.
@return ::NC_NOERR No error.
@return ::NC_EGLOBAL Can't use ::NC_GLOBAL with this function.
@ -539,7 +540,7 @@ nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_le
@return ::NC_ESTRICTNC3 Attempting netcdf-4 operation on strict nc3
netcdf-4 file.
@return ::NC_ELATEDEF Too late to change settings for this variable.
@return ::NC_EINVAL Invalid input
@return ::NC_EINVAL Invalid input.
@author Charlie Zender, Ed Hartnett
*/
int

View File

@ -730,7 +730,7 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *unused1,
return NC_EINVAL;
/* NSD must be in range. */
if (*nsd < 0)
if (*nsd <= 0)
return NC_EINVAL;
if (var->type_info->hdr.id == NC_FLOAT &&
*nsd > NC_QUANTIZE_MAX_FLOAT_NSD)
@ -744,27 +744,11 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *unused1,
var->quantize_mode = *quantize_mode;
/* If nsd was zero, turn quantization off. */
if (*nsd == 0)
var->quantize_mode = NC_NOQUANTIZE;
/* If quantization is turned off, then set nsd to 0. */
if (*quantize_mode == NC_NOQUANTIZE)
var->nsd = 0;
}
/* Setting nsd to 0 turns off quantization. */
if (nsd && !quantize_mode)
{
if (*nsd == 0)
{
var->quantize_mode = NC_NOQUANTIZE;
var->nsd = *nsd;
}
else
return NC_EINVAL;
}
return NC_NOERR;
}

View File

@ -104,6 +104,7 @@ main(int argc, char **argv)
if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_BITGROOM + 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;
@ -121,7 +122,7 @@ main(int argc, char **argv)
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_QUANTIZE_BITGROOM, 0)) ERR;
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;