NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
Hi, Here is a question about data-type conversion done by the netcdf-c library.I have a file with short data, but I am trying to read the data as float using nc_get_vara_float. This will make it easier for me to apply scale and offset factors later on.
I noticed that the short value of -1 is changed to 65535 when reading it with the nc_get_vara_float function, while for attributes the value stays -1, when using the nc_get_att_float function.
Is this expected behaviour? Below a small test program which illustrates this: #include <stdio.h> #include <netcdf.h> int main(){ int status; int ncid; int varid; static size_t start[] = {0, 0, 0}; static size_t count[] = {1, 1, 1}; float varData[1]; float attrData[1];status = nc_open("http://opendap.nmdc.eu/knmi/thredds/dodsC/radarprecipclim/RAD_NL21_RAC_MFBS_01H_NC.nc", 0, &ncid);
if (status != NC_NOERR) {return 1;} status = nc_inq_varid (ncid, "image1_image_data", &varid); if (status != NC_NOERR) {return 2;} status = nc_get_vara_float(ncid, varid, start, count, varData); if (status != NC_NOERR) {return 3;} status = nc_get_att_float(ncid,varid,"_FillValue",attrData); if (status != NC_NOERR) {return 4;} nc_close(ncid); printf("Vardata : %f\t\nAttrdata: %f\n",varData[0],attrData[0]); return 0; } it returns: Vardata : 65535.000000 Attrdata: -1.000000 I would expect that both values are -1? Best regards, Maarten Plieger -- Maarten Plieger KNMI, R&D Information and Observation Technology, De Bilt (t) +31 30 2206330
netcdfgroup
archives: