@@ -715,36 +715,54 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *unused1,
715715 }
716716
717717 /* Remember quantization settings. They will be used when data are
718- * written. */
718+ * written.
719+ * Code block is identical to one in zvar.c---consider functionalizing */
719720 if (quantize_mode )
720721 {
721- /* Only two valid mode settings. */
722+ /* Only four valid mode settings. */
722723 if (* quantize_mode != NC_NOQUANTIZE &&
723724 * quantize_mode != NC_QUANTIZE_BITGROOM &&
724- * quantize_mode != NC_QUANTIZE_GRANULARBR )
725+ * quantize_mode != NC_QUANTIZE_GRANULARBR &&
726+ * quantize_mode != NC_QUANTIZE_BITROUND )
725727 return NC_EINVAL ;
726728
727- if (* quantize_mode == NC_QUANTIZE_BITGROOM || * quantize_mode == NC_QUANTIZE_GRANULARBR )
729+ if (* quantize_mode == NC_QUANTIZE_BITGROOM ||
730+ * quantize_mode == NC_QUANTIZE_GRANULARBR ||
731+ * quantize_mode == NC_QUANTIZE_BITROUND )
728732 {
729733 /* Only float and double types can have quantization. */
730734 if (var -> type_info -> hdr .id != NC_FLOAT &&
731735 var -> type_info -> hdr .id != NC_DOUBLE )
732736 return NC_EINVAL ;
733737
734- /* For bitgroom, number of significant digits is required. */
738+
739+ /* All quantization codecs require number of significant digits */
735740 if (!nsd )
736741 return NC_EINVAL ;
737742
738743 /* NSD must be in range. */
739744 if (* nsd <= 0 )
740745 return NC_EINVAL ;
741- if (var -> type_info -> hdr .id == NC_FLOAT &&
742- * nsd > NC_QUANTIZE_MAX_FLOAT_NSD )
743- return NC_EINVAL ;
744- if (var -> type_info -> hdr .id == NC_DOUBLE &&
745- * nsd > NC_QUANTIZE_MAX_DOUBLE_NSD )
746- return NC_EINVAL ;
747746
747+ if (* quantize_mode == NC_QUANTIZE_BITGROOM ||
748+ * quantize_mode == NC_QUANTIZE_GRANULARBR )
749+ {
750+ if (var -> type_info -> hdr .id == NC_FLOAT &&
751+ * nsd > NC_QUANTIZE_MAX_FLOAT_NSD )
752+ return NC_EINVAL ;
753+ if (var -> type_info -> hdr .id == NC_DOUBLE &&
754+ * nsd > NC_QUANTIZE_MAX_DOUBLE_NSD )
755+ return NC_EINVAL ;
756+ }
757+ else if (* quantize_mode == NC_QUANTIZE_BITROUND )
758+ {
759+ if (var -> type_info -> hdr .id == NC_FLOAT &&
760+ * nsd > NC_QUANTIZE_MAX_FLOAT_NSB )
761+ return NC_EINVAL ;
762+ if (var -> type_info -> hdr .id == NC_DOUBLE &&
763+ * nsd > NC_QUANTIZE_MAX_DOUBLE_NSB )
764+ return NC_EINVAL ;
765+ }
748766 var -> nsd = * nsd ;
749767 }
750768
@@ -812,12 +830,25 @@ NC4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
812830 * error.)
813831 *
814832 * When quantize is turned on, and the number of significant digits
815- * has been specified, then the netCDF library will quantize according
816- * to the selected algorithm. BitGroom will apply all zeros or
817- * all ones (alternating) to bits which are not needed to specify the
818- * value to the number of significant digits. GranularBR will zero
819- * more bits than BG, and thus be more compressible and less accurate.
820- * Both will change the value of the data, and will make it more compressible.
833+ * (NSD) has been specified, then the netCDF library will quantize according
834+ * to the selected algorithm. BitGroom interprets NSD as decimal digits
835+ * will apply all zeros or all ones (alternating) to bits which are not
836+ * needed to specify the value to the number of significant decimal digits.
837+ * BitGroom retain the same number of bits for all values of a variable.
838+ * BitRound (BR) interprets NSD as binary digits (i.e., bits) and keeps the
839+ * the user-specified number of significant bits then rounds the result
840+ * to the nearest representable number according to IEEE rounding rules.
841+ * BG and BR both retain a uniform number of significant bits for all
842+ * values of a variable. Granular BitRound interprest NSD as decimal
843+ * digits. GranularBR determines the number of bits to necessary to
844+ * retain the user-specified number of significant digits individually
845+ * for every value of the variable. GranularBR then applies the BR
846+ * quantization algorithm on a granular, value-by-value, rather than
847+ * uniformly for the entire variable. GranularBR quantizes more bits
848+ * than BG, and is thus more compressive and less accurate than BG.
849+ * BR knows bits and makes no guarantees about decimal precision.
850+ * All quantization algorithms change the values of the data, and make
851+ * it more compressible.
821852 *
822853 * Quantizing the data does not reduce the size of the data on disk,
823854 * but combining quantize with compression will allow for better
@@ -829,10 +860,10 @@ NC4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
829860 * size.
830861 *
831862 * Variables which use quantize will have added an attribute with name
832- * ::NC_QUANTIZE_[ALG_NAME]_ATT_NAME, which will contain the number of
833- * significant digits. Users should not delete or change this
834- * attribute. This is the only record that quantize has been applied
835- * to the data.
863+ * ::NC_QUANTIZE_BITGROOM_ATT_NAME, ::NC_QUANTIZE_GRANULARBR_ATT_NAME,
864+ * or ::NC_QUANTIZE_BITROUND_ATT_NAME that contains the number of
865+ * significant digits. Users should not delete or change this attribute.
866+ * This is the only record that quantize has been applied to the data.
836867 *
837868 * As with the deflate settings, quantize settings may only be
838869 * modified before the first call to nc_enddef(). Once nc_enddef() is
@@ -847,10 +878,15 @@ NC4_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
847878 * @param ncid File ID.
848879 * @param varid Variable ID. NC_GLOBAL may not be used.
849880 * @param quantize_mode Quantization mode. May be ::NC_NOQUANTIZE or
850- * ::NC_QUANTIZE_BITGROOM or ::NC_QUANTIZE_GRANULARBR.
851- * @param nsd Number of significant digits. May be any integer from 1
852- * to ::NC_QUANTIZE_MAX_FLOAT_NSD (for variables of type ::NC_FLOAT) or
853- * ::NC_QUANTIZE_MAX_DOUBLE_NSD (for variables of type ::NC_DOUBLE).
881+ * ::NC_QUANTIZE_BITGROOM, ::NC_QUANTIZE_BITROUND or ::NC_QUANTIZE_GRANULARBR.
882+ * @param nsd Number of significant digits (either decimal or binary).
883+ * May be any integer from 1 to ::NC_QUANTIZE_MAX_FLOAT_NSD (for variables
884+ * of type ::NC_FLOAT) or ::NC_QUANTIZE_MAX_DOUBLE_NSD (for variables
885+ * of type ::NC_DOUBLE) for mode ::NC_QUANTIZE_BITGROOM and mode
886+ * ::NC_QUANTIZE_GRANULARBR. May be any integer from 1 to
887+ * ::NC_QUANTIZE_MAX_FLOAT_NSB (for variables of type ::NC_FLOAT) or
888+ * ::NC_QUANTIZE_MAX_DOUBLE_NSB (for variables of type ::NC_DOUBLE)
889+ * for mode ::NC_QUANTIZE_BITROUND.
854890 *
855891 * @returns ::NC_NOERR No error.
856892 * @returns ::NC_EBADID Bad ncid.
0 commit comments