[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 960417: netCDF and nans



> >From: David Osburn <address@hidden>
> >Subject: netCDF and nans
> >Organization: NOAA/FSL
> >Keywords: 199604172058.AA29676

Hi Dave,

>   Hi.  I'd like some information on handling of NaNs (Not a Number) in
>   netCDF.  Do the netCDF libraries do anything special in dealing with
>   NaNs?  That is, do netCDF library functions do any checking whatsoever
>   to determine whether a value is a NaN, either in writing to, or reading
>   from a netCDF file?  Is your handling of NaNs (or non-handling of NaNs)
>   consistent for both C and Fortran netCDF versions?

The C and Fortran libraries are consistent in not handling NaNs in any
special way.  They never test for NaNs or try to deal with them as other
than floating-point numbers.  We expect netCDF to be used on non-IEEE
platforms such as Cray YMP, so we can't assume there is such a thing as a
NaN.

>   Also, I see that 'ncdump' shows a value of "NaN", rather than a numeric
>   value, when encountering NaNs in a netCDF file.  Does this non-numeric
>   representation of NaNs come from netCDF library code, or a lower level?
>   Example of 'ncdump' output with "NaN":
> 
>   altimeter = FloatInf, 1007.112 , 1007.112 , NaN , 1009.483 , FloatInf, 
>     1010.837 , 1010.837  ;

It's lower-level, from whatever the C library function sprintf() does when
asked to print a NaN using a standard %f or %g format.  On some platforms,
this will print "NaN".  The latest X/Open specifications for Unix-like
systems say:

  "The fprintf family of functions may make available character string
   representations for infinity and NaN."

but does not dictate that conforming systems are required to do this, nor
say what the character string representation should be.

Incidentally, I think the current release (2.4) of netCDF has an ncdump that
no longer prints "FloatInf" for default floating-point fill values, but
instead displays such values as "_".  Hence the current ncdump output for
the above would now be:

   altimeter = _, 1007.112 , 1007.112 , NaN , 1009.483 , _, 
     1010.837 , 1010.837  ;

--Russ

______________________________________________________________________________

Russ Rew                                           UCAR Unidata Program
address@hidden                              http://www.unidata.ucar.edu