Re: reading netcdf-4 ubyte datatype [message #74679 is a reply to message #74678] |
Fri, 28 January 2011 11:08   |
alison
Messages: 7 Registered: October 2004
|
Junior Member |
|
|
David,
I don't see a way off-hand to attach a file to this post, so here is
the content of a "test_read.cdl" file which can be used to create a
netcdf4 file with "ncgen -k 3 test_read.cdl".
netcdf test_read {
variables:
ubyte myvar;
data:
myvar = 255;
}
This creates a little netcdf4 file containing a single variable of
type ubyte (unsigned byte) whose value is 255. Trying to read this
file in IDL I get this:
IDL> ncid = ncdf_open('test_read.nc')
% Loaded DLM: NCDF.
IDL> varid = ncdf_varid(ncid,'myvar')
IDL> ncdf_varget, ncid, varid, x
% NCDF_VARGET: File format error. Varid 0 has a unknown type
% Execution halted at: $MAIN$
IDL>
Conversely, if I try to create a netcdf4 file from within IDL and
store an unsigned byte into it, there is not a "ubyte" option
available to the ncdf_vardef command, and if I use the "byte" option,
like this:
x = 255b
ncid = ncdf_create('test_write.nc',/netcdf4_format,/clobber)
varid = ncdf_vardef(ncid,'myvar',/byte)
ncdf_varput, ncid, varid, x
Then, "ncdump test_write.nc" shows that the resulting netcdf4 file
contains this:
netcdf test_write {
variables:
byte myvar ;
data:
myvar = -1 ;
}
This is not the desired result, as the 255 has become -1. It seems
that IDL just doesn't support unsigned bytes in netcdf. Can you
verify this? or am I missing something here?
Alison
On Jan 28, 10:44 am, David Fanning <n...@dfanning.com> wrote:
> Alison writes:
>> I am using IDL 8.0 for Linux. I also notice that if I write an IDL
>> "byte" variable (which is unsigned) to a netcdf file, it is written as
>> a netcdf "byte" type (signed), when it should be "ubyte" (unsigned).
>> There doesn't appear to be any way to control the datatype which IDL
>> is automatically choosing when reading/writing from netcdf file. Is
>> there a way to represent my 8-bit unsigned data so that it is handled
>> properly in both IDL and netcdf-4?
>
> Do you have an example of such a file we can test with?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|