Re: Output to Netcdf signed bytes

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon, 1 Jun 2009 15:17:13 -0600

Hi Dave,

It is true that the NCL byte type was from the beginning defined as
an unsigned 8-bit quantity. This was an unfortunate departure from
the general effort to be compatible with NetCDF, which has always
treated the byte type as signed. Any thoughts of changing NCL's
behavior subsequently have been derailed by the concern for backwards
compatibility. Our next release, after the bug-fix 5.1.1 release,
will contain unsigned versions of all the integer types as well as a
64-bit integer type. It would be good if we could figure out a way to
have both unsigned and signed byte types. It comes down to a question
of a naming scheme. The logical names "byte" for signed 8-bit and
"ubyte" for unsigned 8-bit would break backwards compatibility. So we
are still thinking about it.

In the meantime, I think you are correct that the way to write your
signed byte quantities to NetCDF is to add 256 to the values that are
less than 0. Once in NetCDF format they will have the correct signed
values. Sorry but I don't know of a better way right now.
  -dave

On May 31, 2009, at 9:52 PM, Dave Allured wrote:

> I have an array of signed integers in range -128 to +127. I would
> like to output this to a Netcdf file as signed bytes in the same
> range -128 to +127.
>
> However the inttobyte function interprets bytes as unsigned in range
> 0 to +255. It seems that I need an extra step to add 256 to all
> negative integers to map them to +128 to +255, before writing to
> Netcdf.
>
> Is this the most straightforward way to output Netcdf signed bytes,
> or am I missing something? Thank you for any advice.
>
> Dave Allured
> CU/CIRES Climate Diagnostics Center (CDC)
> http://cires.colorado.edu/science/centers/cdc/
> NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
> http://www.cdc.noaa.gov/psd1/
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jun 01 2009 - 15:17:13 MDT

This archive was generated by hypermail 2.2.0 : Wed Jun 03 2009 - 12:52:48 MDT