diff --git a/src/cdf_write.c b/src/cdf_write.c index 2b54a1e7db355d90abd98e1573f80b4f0d3b39cb..5bac6a3d9098042fdf9b7333720290a5d3ddba8f 100644 --- a/src/cdf_write.c +++ b/src/cdf_write.c @@ -1137,7 +1137,7 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarID, int dtype, s for (size_t i = 0; i < nvals; ++i) { double temp = mdata_sp[i]; - if (!DBL_IS_EQUAL(temp, missval)) + if (!DBL_IS_EQUAL(temp, (float) missval)) { if (haveAddoffset) temp -= addoffset; if (haveScalefactor) temp /= scalefactor; @@ -1184,7 +1184,8 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarID, int dtype, s } } - if (dtype == CDI_DATATYPE_UINT8 || dtype == CDI_DATATYPE_INT8 || dtype == CDI_DATATYPE_INT16 || dtype == CDI_DATATYPE_INT32) + if (dtype == CDI_DATATYPE_UINT8 || dtype == CDI_DATATYPE_INT8 || dtype == CDI_DATATYPE_UINT16 || dtype == CDI_DATATYPE_INT16 + || dtype == CDI_DATATYPE_UINT32 || dtype == CDI_DATATYPE_INT32) { if (memtype == MEMTYPE_FLOAT) { @@ -1232,18 +1233,33 @@ cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarID, int dtype, s } } - if (CDF_Debug && memtype != MEMTYPE_FLOAT) + if (CDF_Debug) { double fmin = 1.0e200; double fmax = -1.0e200; - for (size_t i = 0; i < nvals; ++i) + if (memtype == MEMTYPE_FLOAT) { - if (!DBL_IS_EQUAL(pdata_dp[i], missval)) + for (size_t i = 0; i < nvals; ++i) { - if (pdata_dp[i] < fmin) fmin = pdata_dp[i]; - if (pdata_dp[i] > fmax) fmax = pdata_dp[i]; + if (!DBL_IS_EQUAL(pdata_sp[i], (float) missval)) + { + if (pdata_sp[i] < fmin) fmin = pdata_sp[i]; + if (pdata_sp[i] > fmax) fmax = pdata_sp[i]; + } } } + else + { + for (size_t i = 0; i < nvals; ++i) + { + if (!DBL_IS_EQUAL(pdata_dp[i], missval)) + { + if (pdata_dp[i] < fmin) fmin = pdata_dp[i]; + if (pdata_dp[i] > fmax) fmax = pdata_dp[i]; + } + } + } + Message("nvals = %zu, nmiss = %d, missval = %g, minval = %g, maxval = %g", nvals, nmiss, missval, fmin, fmax); } } diff --git a/src/vlist_var.c b/src/vlist_var.c index d8785445a50bf58a30ac3d2b3634bd02bd52948b..d99e787712117b8d012575d2ad2692951dad82df 100644 --- a/src/vlist_var.c +++ b/src/vlist_var.c @@ -741,12 +741,12 @@ vlistDefVarDatatype(int vlistID, int varID, int datatype) switch (datatype) { case CDI_DATATYPE_INT8: varptr->missval = check_range(missval, -SCHAR_MAX, SCHAR_MAX) ? missval : -SCHAR_MAX; break; - case CDI_DATATYPE_UINT8: varptr->missval = check_range(missval, 0, UCHAR_MAX) ? missval : UCHAR_MAX; break; - case CDI_DATATYPE_INT16: varptr->missval = check_range(missval, -SHRT_MAX, SHRT_MAX) ? missval : -SHRT_MAX; break; - case CDI_DATATYPE_UINT16: varptr->missval = check_range(missval, 0, USHRT_MAX) ? missval : USHRT_MAX; break; - case CDI_DATATYPE_INT32: varptr->missval = check_range(missval, -INT_MAX, INT_MAX) ? missval : -INT_MAX; break; - case CDI_DATATYPE_UINT32: varptr->missval = check_range(missval, 0, UINT_MAX) ? missval : UINT_MAX; break; - case CDI_DATATYPE_FLT32: varptr->missval = check_range(missval, -FLT_MAX, FLT_MAX) ? missval : CDI_Default_Missval; break; + case CDI_DATATYPE_UINT8: varptr->missval = check_range(missval, 0, UCHAR_MAX) ? missval : UCHAR_MAX; break; + case CDI_DATATYPE_INT16: varptr->missval = check_range(missval, -SHRT_MAX, SHRT_MAX) ? missval : -SHRT_MAX; break; + case CDI_DATATYPE_UINT16: varptr->missval = check_range(missval, 0, USHRT_MAX) ? missval : USHRT_MAX; break; + case CDI_DATATYPE_INT32: varptr->missval = check_range(missval, -INT_MAX, INT_MAX) ? missval : -INT_MAX; break; + case CDI_DATATYPE_UINT32: varptr->missval = check_range(missval, 0, UINT_MAX) ? missval : UINT_MAX; break; + case CDI_DATATYPE_FLT32: varptr->missval = check_range(missval, -FLT_MAX, FLT_MAX) ? missval : CDI_Default_Missval; break; } // clang-format on }