[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 980109: netcdf3 interface (bug?)
- Subject: Re: 980109: netcdf3 interface (bug?)
- Date: Fri, 09 Jan 1998 13:07:09 -0700
> Date: Fri, 9 Jan 1998 12:59:29 -0700
> From: Jim Edwards <address@hidden>
> To: address@hidden
> Subject: Re: 980109: netcdf3 interface (bug?)
Hi Jim,
> I have been working for a few months in converting some of our code
> from the netcdf 2 to the netcdf 3 interface. One of the reasons for
> doing this is that the solaris compiler (SunOS 5.6 f90: WorkShop
> Compilers 4.2 ) automatically converts integer*2 and integer*1 to
> integer in code and so using the netcdf 2 interface will for example
> cause you to read a short field into half of your array - it doesn't
> produce an error but it doesn't produce the expected result either.
>
> Converting to netcdf 3 and changing our internal types to integer has
> solved most of the problem. However, I've just run into something
> that i believe may be a bug in the netcdf 3 interface.
>
> A data field is stored as byte in the netcdf file, i read it in as
> real and get a signed value. I would expect byte to be converted as
> unsigned, obviously this is open to interpratation, what do you think?
It's not a bug, but it's apparently not documented very well either. In
the Appendix D, "NetCDF 2 C Transition Guide" of the netCDF User's
Guide, it says:
The _uchar and _schar functions were introduced in netCDF-3 to
eliminate an ambiguity, and support both signed and unsigned byte
data. In netCDF-2, whether the external NC_BYTE type represented
signed or unsigned values was left up to the user. In netcdf-3, we
treat NC_BYTE as signed for the purposes of conversion to short,
int, long, float, or double. (Of course, no conversion takes place
when the internal type is signed char.) In the _uchar functions, we
treat NC_BYTE as if it were unsigned. Thus, no NC_ERANGE error can
occur converting between NC_BYTE and unsigned char.
Hence you can use unsigned or signed bytes, but external byte arrays are
always treated as signed for conversion to other types. This is similar
to Java, where the byte type is always signed.
--Russ
_____________________________________________________________________
Russ Rew UCAR Unidata Program
address@hidden http://www.unidata.ucar.edu