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

970128: netcdf 3 double--float conversion



Robert,

> To: address@hidden
> From: Robert Fischer <address@hidden>
> Subject: netcdf 3 wish: double--float conversion
> Organization: Harvard University
> Keywords: 199701281524.IAA17332

In the above message you wrote:

> here's a wish i have for netcdf v3: an ability to easily convert between
> floating point formats when reading & writing data.  calculations are done
> in double precision for a variety of reasons; however, the answers are
> often only correct to a few decimal places.  i'd like to be able to read
> and write whole arrays, converting them to single precision (or even
> sometimes a custom 2-byte format) when writing to disk.  this could be
> accomplished by providing an optional format-conversion routine to
> ncvarput, which gets called on every data element (i know, this could be
> slow; maybe just build in automatic double<->float conversion, and that
> would be very nice).

Your wish has already been granted.  The netCDF-3 package supports
automatic conversion between arithmetic types.  Thus, it is possible
to read an array of netCDF floats with an input netCDF call into an
internal array of doubles, perform some calculations, and then write the
resulting internal array of doubles into a netCDF array of shorts (or
bytes!) with an output netCDF call.  The full matrix of conversions is
supported, i.e. any external type (byte, short, int, float, double) can
be automatically converted between any internal type (char, short, int,
long, float, double).

--------
Steve Emmerson   <address@hidden>