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.
The nc_get_var1 set of functions can be confusing because it takes a single index no matter how many dimensions a variable has. Let me suggest the following as perhaps more clear. Suppose you want to read the value at position X,Y. then define that position using: > size_t start[2]; > start[0] = X; > start[1] = Y; Then ask for a single element using: > size_t count[2]; > count[0] = 1; > count[1] = 1; Then do this: > int zvalue; > nc_get_vara_int(ncid,zid,start,count,&zvalue) where zid is the variable identifier for z that you obtained using nc_inq_varid(). > > Recently, I tried to use 'netcdf.h', 'netcdf.dll' and 'netcdf.lib' to decode > the netcdf format file: the global topography data file > 'ETOPO1_Ice_g_gmt4.grd'(please see website: > https://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/ice_surface/grid_registered/netcdf/). > There are three variables in the file: latitude named 'y', longitude named > 'x', and the topography data named 'z'. I used the function in 'netcdf.h' to > get the varid and vartype of 'z', which are 2 and 4(=NC_INT). And I tried to > use the function 'nc_get_var1_int' to get one value in 'z' with two > dimensions, however the function return -40. I don't know what happened. > Could you help me how to decode 'z' in the topography file > 'ETOPO1_Ice_g_gmt4.grd' using the functions in 'netcdf.h'. > > > Best regards. > > Qu > =Dennis Heimbigner Unidata Ticket Details =================== Ticket ID: RYL-581729 Department: Support netCDF Priority: Critical Status: Open =================== 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.