[netcdf-java] Writing unsigned data to attributes


I'm trying to write unsigned data to attributes, but I can't quite get it 
working. I've seen the mailing list threads on reading from unsigned 
attributes, but I haven't seen much discussion about writing.

Suppose I have an unsigned byte variable, and I want to set its `valid_range` 
attribute. I tried using `Array.setUnsigned`, but the values are still written 
as signed. In this case the valid range is 0..255, which comes out as 0..-1. 
This causes ToolsUI to read the variable as being empty.

I would just use shorts instead of bytes, but this approach does not seem to be 
reliable for all attributes: it fails for the `_FillValue` attribute which the 
nc4 IOSP says must be the same type as the variable.

I asked a question on StackOverflow; it has some simplified code in it:


 - NetCDF-Java 4.3.16
 - libnetcdf 4.2.1
 - ToolsUI 4.3

Let me know if you need more information.


Alex Fraser
Software Engineer

  • 2013 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: