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.
Marston, > Thanks for your response. I've made the adjustment to the scale factor > and add offset as suggested and I have written packing routines in my > script. > Yes, the shape of swd->t has the shape swd->t[nlev][nlat][nlon]. In your example code, you used "levlen", "latlen", and "lonlen" to set the sizes of the netCDF dimensions and hence the shape of the netCDF variable. Are nlev, nlat, and nlon the same as levlen, latlen, and lonlen? > When I print the data just prior to writing it all the levels return a > consistent max and min data value. > But when I read the data from the NETCDF file the levels are all > screwed up. After reading the data, do you apply the unpacking formula to the values before looking at them? The library does not apply the unpacking formula for you. If you're looking at the max and min of the packed values, those would not be the max and min of the data values you expect. > I've been using the examples given in the netcdf installation and have > experimenting with nc_put_vara and nc_put_var since I have 1D, 2D, and > 3D arrays to store. > It's a little confusing which function to use for the 2D and 3D arrays. If you have all the values you want to write in a memory array, then you can write them all at once with a single call to nc_put_var_TYPE(). You would typically use nc_put_vara_TYPE() or nc_put_varm_TYPE() if you only have a slice of the variable in memory and thus have to write it with multiple calls as the data is generated. The simplest nc_put_var_TYPE() call assumes all the data you want to write are contiguous in memory, in the order in which they will be stored on disk (last index varying fastest for C). > I don't think I understand the multiple call to these functions in > order to write the array correctly. In one example this multiple call > is used when there is a time step. > I have none. > > Can you expand on for me please - if this is the solution to the > problem? You can write data of any dimensionality if you have it all in memory. Often netCDF is used when all the data won't fit into memory at once or is generated a slice at a time, as in models output for multiple time steps. So you should be able to write 1D, 2D, or 3D data with a single call from in-memory arrays. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: ZPJ-875297 Department: Support netCDF Priority: Normal Status: Closed