This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
>To: address@hidden >From: address@hidden >Subject: unsigned datatypes >Organization: UCAR/Unidata >Keywords: 200104182010.f3IKAgL10773 Hi Steven, > does netcdf support unsigned datatypes (int, short, char) No, int and short values are interpreted as signed qualities in netCDF. For char or byte values, there is some support for unsigned data. Whatever 8-bit byte you store in an NC_BYTE type netCDF variable, you will get the exact same 8 bits back when you read data from that netCDF variable into a byte memory location. If that memory location is for a variable that's declared "unsigned char", it should be interpreted as unsigned. On the other hand, netCDF includes functions that let you read 8-bit data as other numeric types. For example, the function int nc_get_var_int (int ncid, int varid, int *ip); will let you retrieve a variable as an int, whether it's stored as a byte, a short, an int, a long, a float, or a double. In that case, 8-bit values are interpreted as signed for the purpose of any numeric conversions that the library does. But you can still retrieve the data as unsigned bytes by using the function: int nc_get_vara_uchar (int ncid, int varid, unsigned char *ip); --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu