Hi Tong Wei, > My name is Tong Wei from Harris Corp.. Right now, I am trying to create > a n= etcdf4 file by using Matlab. However, I have a issue about values > saved in = .nc file. > > Here is our issue: > Try to save one 8-bit unsigned integer array into a .nc file. Please see > below for a piece of codes that we are using now. > > Here is our problem: > some data could not be saved as we have expected. For example, data > (91344,1 ) shows 222 under Matlab command window; but this value shows > "-34" if using ncdump. > > So, I am wondering do you have any solutions/suggestions for this? For the classic version of the netCDF file format, the interpretation of 8-bit byte data was left up to the application. As it says in the section of the documentation of the file format: http://www.unidata.ucar.edu/software/netcdf/docs/classic_format_spec.html Note on byte data: It is possible to interpret byte data as either signed (-128 to 127) or unsigned (0 to 255). When reading byte data through an interface that converts it into another numeric type, the default interpretation is signed. There are various attribute conventions for specifying whether bytes represent signed or unsigned data, but no standard convention has been established. The variable attribute â_Unsignedâ is reserved for this purpose in future implementations. The netCDF-Java software interprets the "_Unsigned" attribute as indicating the values are to be treated as unsigned. NetCDF-4 has support for an unsigned byte type NC_UBYTE. The same bits are stored in the file, whether the bytes are intended to be signed or unsigned. If you want the values to be interpreted as unsigned for classic format data, you can simply add 256 to the signed byte values that are negative, to get the corresponding values between 0 and 255 instead of -128 to 127. If you wanted 222 instead of -34, it looks like adding 256 would put the value in the intended range. --Russ > The version of Matlab: 7.10 > The version of Mapping Toolbox: 3.1 > > %%%% --1 initialize file > ncid=netcdf.create('/pg/OPZ_data/Imagery/Raw_Binary_Data/temp/L2ServicesSharedLibrary_Parameters.nc','NC_WRITE'); > > %%%% --2 define dimensions > Xdimid=netcdf.defDim(ncid,'X_tongWei',dim(1,1)); > > %%%% --3 define new variables > Xvarid=netcdf.defVar(ncid,'SemiStatic_X_tongWei','byte',Xdimid); > > %%%% --4 Leave define mode and enter data mode to write data > netcdf.endDef(ncid); > > %%%% -- 5 Write data to variable > data=uint8(data); > netcdf.putVar(ncid,Xvarid,data(1:dim(1,1),:)); > netcdf.close(ncid); > > > > Tong Wei > Harris Corp., GOES-R > 240 206 7095 > > > > > Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: NVN-733440 Department: Support netCDF Priority: Normal Status: Closed
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.