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

Re: 971120: Unsigned 2-byte data



>From: address@hidden
>Subject: Unsigned 2-byte data
>Organization: ?
>Keywords: 199711202100.OAA29252 netCDF unsigned 2-byte

Hi,

>      I am using netCDF 2.4 to store unsigned 16-bit data from a digital 
>      camera. Currently I am using the external data type "NC_SHORT".  The 
>      problem is, other programs and utilities like 'ncdump' treat my data 
>      as signed data.  This means values > 0x7FFF "wrap-around" and are 
>      represented as negative numbers.
>      
>      Is there an alternative to using NC_SHORT for storing unsigned 2-byte 
>      data?  Using NC_INT or NC_FLOAT was considered, but this costs me 
>      twice the storage space.
>      
>      Any suggestions you may have would be appreciated.

Sorry, but we can't help very much here.  The only 16-bit data type
currently supported by netCDF is 16-bit signed integers.  The reason for
this is that netCDF must support both Fortran and C, and Fortran 77 had
no notion of unsigned integer types.  (I'm not sure whether Fortran 90
supports any unsigned types.)  Fortran is not the only language with no
support for unsigned types; Java also treats all primitive integer types
as signed.

You can always interpret the data as unsigned in your own applications,
and you could provide an "add_offset" attribute for variables that store
16-bit unsigned data, in order to indicate that the actual value should
be obtained by adding the "add_offset" value (2^15) to the signed 16-bit
integer value.  Unfortunately, most netCDF applications like ncdump
don't pay attention to the "add_offset" attribute, since it's just a
suggested attribute convention and is not mandated.

Our plans call for eventually supporting packed data in netCDF-4, in
which types of all sizes will be supported, e.g. 11-bit data.  But I
can't say when netCDF-4 will be available, and it will require a new
file format (the old file format will still be supported, but not for
the new types).

--Russ

_____________________________________________________________________

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