Index: vardata.c =================================================================== RCS file: /upc/share/CVS/netcdf/ncdump/vardata.c,v retrieving revision 1.43 diff -c -r1.43 vardata.c *** 1.43 1996/06/07 14:46:14 --- vardata.c 1996/10/04 17:16:34 *************** *** 8,13 **** --- 8,16 ---- #include #include #include + #ifndef NO_FINITE + #include /* for finite() */ + #endif #ifndef NO_FLOAT_H #include /* for FLT_EPSILON, DBL_EPSILON */ #endif /* NO_FLOAT_H */ *************** *** 113,118 **** --- 116,127 ---- double_eps = double_epsilon(); } + #ifndef NO_FINITE + #define IS_FINITE(x) (finite(x)) + #else + #define IS_FINITE(x) (((x)-(x))==((x)-(x))) + #endif + /* * Output a single value of a variable, except if there is a fill value for *************** *** 128,190 **** struct ncvar *varp; /* variable */ void *valp; /* value, interpreted using varp->type */ { ! union { ! char *cp; ! short *sp; ! nclong *lp; ! float *fp; ! double *dp; ! } vp, fillp; ! switch (varp->type) { case NC_BYTE: ! fillp.cp = &varp->fillval.charv; ! vp.cp = (char *)valp; ! if (varp->has_fillval && *fillp.cp == *vp.cp) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, *vp.cp); } break; case NC_SHORT: ! fillp.sp = &varp->fillval.shortv; ! vp.sp = (short *)valp; ! if (varp->has_fillval && *fillp.sp == *vp.sp) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, *vp.sp); } break; case NC_LONG: ! fillp.lp = &varp->fillval.longv; ! vp.lp = (nclong *)valp; ! if (varp->has_fillval && *fillp.lp == *vp.lp) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, *vp.lp); } break; case NC_FLOAT: ! fillp.fp = &varp->fillval.floatv; ! vp.fp = (float *)valp; ! #define absval(x) ( (x) < 0 ? -(x) : (x) ) if(varp->has_fillval && ! (*vp.fp > 0) == (*fillp.fp > 0) && /* prevents potential overflow */ ! (absval(*vp.fp - *fillp.fp) <= absval(float_eps * *fillp.fp))) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, *vp.fp); } break; case NC_DOUBLE: ! fillp.dp = &varp->fillval.doublev; ! vp.dp = (double *)valp; if(varp->has_fillval && ! (*vp.dp > 0) == (*fillp.dp > 0) && /* prevents potential overflow */ ! (absval(*vp.dp - *fillp.dp) <= absval(double_eps * *fillp.dp))) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, *vp.dp); } break; default: --- 137,206 ---- struct ncvar *varp; /* variable */ void *valp; /* value, interpreted using varp->type */ { ! char cval, cfill; ! short sval, sfill; ! long lval, lfill; ! float fval, ffill; ! double dval, dfill; ! switch (varp->type) { case NC_BYTE: ! cfill = varp->fillval.charv; ! cval = *(char *)valp; ! if (varp->has_fillval && cfill == cval) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, cval); } break; case NC_SHORT: ! sfill = varp->fillval.shortv; ! sval = *(short *)valp; ! if (varp->has_fillval && sfill == sval) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, sval); } break; case NC_LONG: ! lfill = varp->fillval.longv; ! lval = *(nclong *)valp; ! if (varp->has_fillval && lfill == lval) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, lval); } break; case NC_FLOAT: ! ffill = varp->fillval.floatv; ! fval = *(float *)valp; if(varp->has_fillval && ! IS_FINITE(ffill) && /* needed, because IEEE infinity actually ! * passes the next two tests with any ! * value! */ ! (fval > 0) == (ffill > 0) && /* prevents potential overflow */ ! (fabs(fval - ffill) <= fabs(float_eps * ffill))) { ! (void) sprintf(sout, FILL_STRING); ! } else if (!IS_FINITE(ffill) && !IS_FINITE(fval)) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, fval); } break; case NC_DOUBLE: ! dfill = varp->fillval.doublev; ! dval = *(double *)valp; if(varp->has_fillval && ! IS_FINITE(dfill) && /* needed, because IEEE infinity actually ! * passes the next two tests with finite ! * values! */ ! (dval > 0) == (dfill > 0) && /* prevents potential overflow */ ! (fabs(dval - dfill) <= fabs(double_eps * dfill))) { ! (void) sprintf(sout, FILL_STRING); ! } else if (!IS_FINITE(dfill) && !IS_FINITE(dval)) { (void) sprintf(sout, FILL_STRING); } else { ! (void) sprintf(sout, fmt, dval); } break; default: