Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions cdm/core/src/main/java/ucar/nc2/filter/ConvertMissing.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,22 @@ public static ConvertMissing createFromVariable(VariableDS var) {
}
}

boolean unsignedBecauseCdmAttr = var.attributes().findAttributeString(CDM.UNSIGNED, "false").equals("true");
// skip unscaling if signedness is UNSIGNED and the CDM _Unsigned attribute is true
boolean skipUnscale = signedness.equals(Signedness.UNSIGNED) && unsignedBecauseCdmAttr;
if (validRangeDifferentDataType && !skipUnscale) {
// Signal that valid range (or min/max) was specified in unpacked values, so we
// need to repack those values. Only applies when the DataTypes do not match because
// the variable is unsigned.
double scale = var.attributes().findAttributeDouble(CDM.SCALE_FACTOR, 1);
double offset = var.attributes().findAttributeDouble(CDM.ADD_OFFSET, 0);
validMin = (validMin - offset) / scale;
validMax = (validMax - offset) / scale;
// only check if we found valid_range, valid_min, or valid_max
if (validType != null) {
boolean unsignedBecauseCdmAttr = var.attributes().findAttributeString(CDM.UNSIGNED, "false").equals("true");
// skip unscaling if signedness is UNSIGNED and the CDM _Unsigned attribute is true or if
// the valid_* type and the variable type are both integral
boolean skipUnscale = (signedness.equals(Signedness.UNSIGNED) && unsignedBecauseCdmAttr)
|| (validType.isIntegral() && var.getOriginalDataType().isIntegral());
if (validRangeDifferentDataType && !skipUnscale) {
// Signal that valid range (or min/max) was specified in unpacked values, so we
// need to repack those values. Only applies when the DataTypes do not match because
// the variable is unsigned.
double scale = var.attributes().findAttributeDouble(CDM.SCALE_FACTOR, 1);
double offset = var.attributes().findAttributeDouble(CDM.ADD_OFFSET, 0);
validMin = (validMin - offset) / scale;
validMax = (validMax - offset) / scale;
}
}

if (validMin > validMax) {
Expand Down
Loading