Skip to content

Commit

Permalink
Rename GranularBitGroom to GranularBitRound
Browse files Browse the repository at this point in the history
As per Charlie Zender's request (#2197 (comment)), the GranularBitGroom name is changed to GranularBitRound
with attendant code changes.
  • Loading branch information
DennisHeimbigner committed Jan 28, 2022
1 parent 4e167d0 commit 89cc20a
Show file tree
Hide file tree
Showing 18 changed files with 2,990 additions and 2,390 deletions.
4 changes: 2 additions & 2 deletions include/netcdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ there. */

#define NC_NOQUANTIZE 0 /**< No quantization in use. */
#define NC_QUANTIZE_BITGROOM 1 /**< Use BitGroom quantization. */
#define NC_QUANTIZE_GRANULARBG 2 /**< Use Granular BitGroom quantization. */
#define NC_QUANTIZE_GRANULARBR 2 /**< Use Granular BitRound quantization. */

/** When quantization is used for a variable, an attribute of the
* appropriate name is added. */
#define NC_QUANTIZE_BITGROOM_ATT_NAME "_QuantizeBitgroomNumberOfSignificantDigits"
#define NC_QUANTIZE_GRANULARBG_ATT_NAME "_QuantizeGranularBitGroomNumberOfSignificantDigits"
#define NC_QUANTIZE_GRANULARBR_ATT_NAME "_QuantizeGranularBitRoundNumberOfSignificantDigits"

/** For quantization, the allowed value of number of significant
* digits for float. */
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/dvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_le
The data are quantized by setting unneeded bits to zeros or ones
so that they may compress well. BitGroom sets bits alternately to 1/0,
while Granular BitGroom (GBG) sets (more) bits to zeros.
while Granular BitRound (GBR) sets (more) bits to zeros.
Quantization is lossy (data are irretrievably altered), and it
improves the compression ratio provided by a subsequent lossless
compression filter. Quantization alone will not reduce the data size.
Expand Down Expand Up @@ -529,7 +529,7 @@ nc_def_var_deflate(int ncid, int varid, int shuffle, int deflate, int deflate_le
@param ncid File ID.
@param varid Variable ID. ::NC_GLOBAL may not be used.
@param quantize_mode Quantization mode. May be ::NC_NOQUANTIZE or
::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBG.
::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBR.
@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
Expand Down
4 changes: 2 additions & 2 deletions libhdf5/hdf5open.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,10 +1219,10 @@ static int get_quantize_info(NC_VAR_INFO_T *var)
}
else
{
attid = H5Aopen_by_name(datasetid, ".", NC_QUANTIZE_GRANULARBG_ATT_NAME,
attid = H5Aopen_by_name(datasetid, ".", NC_QUANTIZE_GRANULARBR_ATT_NAME,
H5P_DEFAULT, H5P_DEFAULT);
if (attid > 0)
var->quantize_mode = NC_QUANTIZE_GRANULARBG;
var->quantize_mode = NC_QUANTIZE_GRANULARBR;
}

/* If there is an attribute, read it for the nsd. */
Expand Down
8 changes: 4 additions & 4 deletions libhdf5/hdf5var.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *unused1,
/* Only two valid mode settings. */
if (*quantize_mode != NC_NOQUANTIZE &&
*quantize_mode != NC_QUANTIZE_BITGROOM &&
*quantize_mode != NC_QUANTIZE_GRANULARBG)
*quantize_mode != NC_QUANTIZE_GRANULARBR)
return NC_EINVAL;

if (*quantize_mode == NC_QUANTIZE_BITGROOM || *quantize_mode == NC_QUANTIZE_GRANULARBG)
if (*quantize_mode == NC_QUANTIZE_BITGROOM || *quantize_mode == NC_QUANTIZE_GRANULARBR)
{
/* Only float and double types can have quantization. */
if (var->type_info->hdr.id != NC_FLOAT &&
Expand Down Expand Up @@ -816,7 +816,7 @@ NC4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
* has been specified, then the netCDF library will quantize according
* to the selected algorithm. BitGroom will apply all zeros or
* all ones (alternating) to bits which are not needed to specify the
* value to the number of significant digits. GranularBG will zero
* value to the number of significant digits. GranularBR will zero
* more bits than BG, and thus be more compressible and less accurate.
* Both will change the value of the data, and will make it more compressible.
*
Expand Down Expand Up @@ -848,7 +848,7 @@ NC4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
* @param ncid File ID.
* @param varid Variable ID. NC_GLOBAL may not be used.
* @param quantize_mode Quantization mode. May be ::NC_NOQUANTIZE or
* ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBG.
* ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBR.
* @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).
Expand Down
4 changes: 2 additions & 2 deletions libhdf5/nc4hdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,8 @@ var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid
&var->nsd, NC_INT, 0)))
BAIL(retval);

if (var->quantize_mode == NC_QUANTIZE_GRANULARBG)
if ((retval = nc4_put_att(var->container, var->hdr.id, NC_QUANTIZE_GRANULARBG_ATT_NAME, NC_INT, 1,
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);

Expand Down
4 changes: 2 additions & 2 deletions libnczarr/zsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ ncz_sync_atts(NC_FILE_INFO_T* file, NC_OBJ* container, NCindex* attlist, int isc
if((stat = NCJinsert(jatts,NC_QUANTIZE_BITGROOM_ATT_NAME,jint))) goto done;
jint = NULL;
break;
case NC_QUANTIZE_GRANULARBG:
if((stat = NCJinsert(jatts,NC_QUANTIZE_GRANULARBG_ATT_NAME,jint))) goto done;
case NC_QUANTIZE_GRANULARBR:
if((stat = NCJinsert(jatts,NC_QUANTIZE_GRANULARBR_ATT_NAME,jint))) goto done;
jint = NULL;
break;
default: break;
Expand Down
8 changes: 4 additions & 4 deletions libnczarr/zvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ NCZ_def_var_endian(int ncid, int varid, int endianness)
* size.
*
* Variables which use quantize will have added an attribute with either the name
* ::NC_QUANTIZE_BITGROOM_ATT_NAME or ::NC_QUANTIZE_GRANULARBG, but in either case
* ::NC_QUANTIZE_BITGROOM_ATT_NAME or ::NC_QUANTIZE_GRANULARBR, but in either case
* will contain the number of significant digits.
* Users should not delete or change this
* attribute. This is the only record that quantize has been applied
Expand All @@ -1054,7 +1054,7 @@ NCZ_def_var_endian(int ncid, int varid, int endianness)
* @param ncid File ID.
* @param varid Variable ID. NC_GLOBAL may not be used.
* @param quantize_mode Quantization mode. May be ::NC_NOQUANTIZE or
* ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBG.
* ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBR.
* @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).
Expand Down Expand Up @@ -1091,8 +1091,8 @@ NCZ_ensure_quantizer(int ncid, NC_VAR_INFO_T* var)
if(NCZ_get_att(ncid,var->hdr.id,NC_QUANTIZE_BITGROOM_ATT_NAME,&nsd,NC_INT)==NC_NOERR) {
var->quantize_mode = NC_QUANTIZE_BITGROOM;
var->nsd = nsd;
} else if(NCZ_get_att(ncid,var->hdr.id,NC_QUANTIZE_GRANULARBG_ATT_NAME,&nsd,NC_INT)==NC_NOERR) {
var->quantize_mode = NC_QUANTIZE_GRANULARBG;
} else if(NCZ_get_att(ncid,var->hdr.id,NC_QUANTIZE_GRANULARBR_ATT_NAME,&nsd,NC_INT)==NC_NOERR) {
var->quantize_mode = NC_QUANTIZE_GRANULARBR;
var->nsd = nsd;
} else {
var->quantize_mode = NC_NOQUANTIZE;
Expand Down
14 changes: 7 additions & 7 deletions libsrc4/nc4var.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,10 @@ NC4_var_par_access(int ncid, int varid, int par_access)
* @param fill_value The fill value.
* @param strict_nc3 Non-zero if strict model in effect.
* @param quantize_mode May be ::NC_NOQUANTIZE or
* ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBG.
* ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBR.
* @param nsd Number of significant diggits for quantizize. Ignored
* unless quantize_mode is ::NC_QUANTIZE_BITGROOM or
* ::NC_QUANTIZE_GRANULARBG.
* ::NC_QUANTIZE_GRANULARBR.
*
* @returns ::NC_NOERR No error.
* @returns ::NC_EBADTYPE Type not found.
Expand Down Expand Up @@ -574,7 +574,7 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type,
{
assert(dest_type == NC_FLOAT || dest_type == NC_DOUBLE);

/* Parameters shared by both BitGroom and GranularBG */
/* Parameters shared by both BitGroom and GranularBR */
if (dest_type == NC_FLOAT)
{
/* Determine the fill value. */
Expand Down Expand Up @@ -1433,11 +1433,11 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type,
}
} /* endif BitGroom */

if (quantize_mode == NC_QUANTIZE_GRANULARBG)
if (quantize_mode == NC_QUANTIZE_GRANULARBR)
{
if (dest_type == NC_FLOAT)
{
/* Granular BitGroom */
/* Granular BitRound */
op1.fp = (float *)dest;
u32_ptr = op1.ui32p;
for (idx = 0L; idx < len; idx++)
Expand Down Expand Up @@ -1471,7 +1471,7 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type,
}
else
{
/* Granular BitGroom */
/* Granular BitRound */
op1.dp = (double *)dest;
u64_ptr = op1.ui64p;
for (idx = 0L; idx < len; idx++)
Expand Down Expand Up @@ -1503,7 +1503,7 @@ nc4_convert_type(const void *src, void *dest, const nc_type src_type,

}
}
} /* endif GranularBG */
} /* endif GranularBR */

return NC_NOERR;
}
Expand Down
4 changes: 2 additions & 2 deletions nc_test4/tst_quantize.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ main(int argc, char **argv)
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_GRANULARBG + 1, NSD_3) != NC_EINVAL) ERR;
if (nc_def_var_quantize(ncid, varid1, NC_QUANTIZE_GRANULARBR + 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_GRANULARBG + 1, 3) != NC_EINVAL) ERR;
if (nc_def_var_quantize(ncid, varid2, NC_QUANTIZE_GRANULARBR + 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;
Expand Down
4 changes: 2 additions & 2 deletions nc_test4/tst_vlenstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string.h>
#include "netcdf.h"

#define DEBUG
#undef DEBUG

#ifdef DEBUG
static char* buf = NULL;
Expand Down Expand Up @@ -123,7 +123,7 @@ writeAttribute(int len, int ncid, nc_type vlen_typeID)
stringIndex += sixth_size;

#ifdef DEBUG
if(buf) free(buf); buf = NULL;
if(buf) {free(buf); buf = NULL;}
nc_dump_data(ncid,vlen_typeID,data,len,&buf);
fprintf(stderr,">>> attribute = %s\n",buf);
#endif
Expand Down
2 changes: 1 addition & 1 deletion ncgen/genbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ genbin_definespecialattributes(Symbol* var)
}
CHECK_ERR(stat);
}
if(special->flags & _QUANTIZE_FLAG) {
if(special->flags & (_QUANTIZEBG_FLAG | _QUANTIZEBR_FLAG)) {
stat = nc_def_var_quantize(var->container->nc_id,
var->nc_id, special->_Quantizer, special->_NSD);
CHECK_ERR(stat);
Expand Down
6 changes: 3 additions & 3 deletions ncgen/genc.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,11 @@ genc_definespecialattributes(Symbol* vsym)
codelined(1,"CHECK_ERR(stat);");
}
}
if(special->flags & _QUANTIZE_FLAG) {
const char* alg = NULL;
if(special->flags & (_QUANTIZEBG_FLAG | _QUANTIZEBR_FLAG)) {
const char* alg = NULL;
switch(special->_Quantizer) {
case NC_QUANTIZE_BITGROOM: alg = "NC_QUANTIZE_BITGROOM";
case NC_QUANTIZE_GRANULARBG: alg = "NC_QUANTIZE_GRANULARBG";
case NC_QUANTIZE_GRANULARBR: alg = "NC_QUANTIZE_GRANULARBR";
default: alg = "NC_NOQUANTIZE";
}
bbprintf0(stmt,
Expand Down
3 changes: 2 additions & 1 deletion ncgen/ncgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ various C global variables
#define _FORMAT_FLAG 0x800
#define _FILTER_FLAG 0x1000
#define _CODECS_FLAG 0x2000
#define _QUANTIZE_FLAG 0x4000
#define _QUANTIZEBG_FLAG 0x4000
#define _QUANTIZEBR_FLAG 0x8000

extern struct Specialtoken {
char* name;
Expand Down
5 changes: 3 additions & 2 deletions ncgen/ncgen.l
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ struct Specialtoken specials[] = {
{"_SuperblockVersion",_SUPERBLOCK,_SUPERBLOCK_FLAG},
{"_Filter",_FILTER,_FILTER_FLAG},
{"_Codecs",_CODECS,_CODECS_FLAG},
{"_QuantizeBitgroomNumberOfSignificantDigits",_QUANTIZE,_QUANTIZE_FLAG},
{"_QuantizeBitGroomNumberOfSignificantDigits",_QUANTIZEBG,_QUANTIZEBG_FLAG},
{"_QuantizeBitRoundNumberOfSignificantDigits",_QUANTIZEBR,_QUANTIZEBR_FLAG},
{NULL,0} /* null terminate */
};

Expand Down Expand Up @@ -217,7 +218,7 @@ NUMBER [+-]?[0-9][0-9]*[Uu]?([BbSs]|[Ll]|[Ll][Ll])?
DBLNUMBER [+-]?[0-9]*\.[0-9]*{exp}?[LlDd]?|[+-]?[0-9]*{exp}[LlDd]?
FLTNUMBER [+-]?[0-9]*\.[0-9]*{exp}?[Ff]|[+-]?[0-9]*{exp}[Ff]

SPECIAL "_FillValue"|"_Format"|"_Storage"|"_ChunkSizes"|"_Fletcher32"|"_DeflateLevel"|"_Shuffle"|"_Endianness"|"_NoFill"|"_NCProperties"|"_IsNetcdf4"|"_SuperblockVersion"|"_Filter"|"_Codecs"|"_QuantizeBitgroomNumberOfSignificantDIgits"|"_QuantizeGranularBitGroomNumberOfSignificantDigits"
SPECIAL "_FillValue"|"_Format"|"_Storage"|"_ChunkSizes"|"_Fletcher32"|"_DeflateLevel"|"_Shuffle"|"_Endianness"|"_NoFill"|"_NCProperties"|"_IsNetcdf4"|"_SuperblockVersion"|"_Filter"|"_Codecs"|"_QuantizeBitgroomNumberOfSignificantDIgits"|"_QuantizeGranularBitRoundNumberOfSignificantDigits"

USASCII [\x01-\x7F]

Expand Down
21 changes: 15 additions & 6 deletions ncgen/ncgen.y
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ NCConstant* constant;
_SUPERBLOCK
_FILTER
_CODECS
_QUANTIZE
_QUANTIZEBG
_QUANTIZEBR
DATASETID

%type <sym> ident typename primtype dimd varspec
Expand Down Expand Up @@ -773,8 +774,10 @@ attrdecl:
{$$ = makespecial(_FILTER_FLAG,$1,NULL,(void*)$5,ISCONST);}
| ambiguous_ref ':' _CODECS '=' conststring
{$$ = makespecial(_CODECS_FLAG,$1,NULL,(void*)$5,ISCONST);}
| ambiguous_ref ':' _QUANTIZE '=' constint
{$$ = makespecial(_QUANTIZE_FLAG,$1,NULL,(void*)$5,ISCONST);}
| ambiguous_ref ':' _QUANTIZEBG '=' constint
{$$ = makespecial(_QUANTIZEBG_FLAG,$1,NULL,(void*)$5,ISCONST);}
| ambiguous_ref ':' _QUANTIZEBR '=' constint
{$$ = makespecial(_QUANTIZEBR_FLAG,$1,NULL,(void*)$5,ISCONST);}
| ambiguous_ref ':' _NOFILL '=' constbool
{$$ = makespecial(_NOFILL_FLAG,$1,NULL,(void*)$5,ISCONST);}
| ':' _FORMAT '=' conststring
Expand Down Expand Up @@ -1243,7 +1246,8 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst)
break;
case _SUPERBLOCK_FLAG:
case _DEFLATE_FLAG:
case _QUANTIZE_FLAG:
case _QUANTIZEBG_FLAG:
case _QUANTIZEBR_FLAG:
tmp = nullconst();
tmp->nctype = NC_INT;
convert1(con,tmp);
Expand Down Expand Up @@ -1340,10 +1344,15 @@ makespecial(int tag, Symbol* vsym, Symbol* tsym, void* data, int isconst)
special->_DeflateLevel = idata;
special->flags |= _DEFLATE_FLAG;
break;
case _QUANTIZE_FLAG:
case _QUANTIZEBG_FLAG:
special->_Quantizer = NC_QUANTIZE_BITGROOM;
special->_NSD = idata;
special->flags |= _QUANTIZE_FLAG;
special->flags |= _QUANTIZEBG_FLAG;
break;
case _QUANTIZEBR_FLAG:
special->_Quantizer = NC_QUANTIZE_GRANULARBR;
special->_NSD = idata;
special->flags |= _QUANTIZEBR_FLAG;
break;
case _SHUFFLE_FLAG:
special->_Shuffle = tf;
Expand Down
Loading

0 comments on commit 89cc20a

Please sign in to comment.