mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
now nsd of 0 is NC_EINVAL for nc_def_var_quantize()
This commit is contained in:
parent
7806ded5f2
commit
5200477de1
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user