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.
Hi Bill, Glenn forwarded your netCDF question to me for a reply. (If you want to be sure to get an answer even if one or both of us are away from our email, send your questions to address@hidden.) > Can you tell me the data type of the netCDF variable "rh" > referenced in the example on page 95 of the "NetCDF User's > Guide", Vers. 2.3, February 1993? > I'd like to write an array of structures into a netCDF file > but don't understand what data type to use for the value argument > to ncvarputg(). The example opens a previously created netCDF file, so the original NCVDEF call that defined the RH variable was presumably in a previously run program. However from the example it can be inferred that RH was defined as type NCDOUBLE, corresponding to double precision, since an array of data of type DOUBLE is being used to overwrite every other value of RH in the example. In using NCVPTG, you must use data of the type corresponding to the netCDF variable (DOUBLE for type NCDOUBLE, REAL for type NCFLOAT, INTEGER for type NCLONG, etc.). You can find out what the type of the variable is with a call to NCVINQ. Neither the compiler nor the library can detect the error if you try to write the wrong type of data into a netCDF variable (only the C++ interface permits the detection of such errors). If by "structures" you mean something like C structs or Pascal records (I don't remember what the Fortran 90 equivalent is called, modules?), netCDF doesn't support that abstraction directly, since Fortran 77 had nothing into which you could read such an object. So, if you are trying to use NCVPTG to intersperse writing data of different types in the space allocated for variable elements of a single type, it won't work. The C interface has some interfaces for supporting something like structures (ncrecput, ncrecget, ncrecinq) but they are really just wrappers around multiple calls, each reading or writing arrays of data of a single type. --Russ ______________________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden P.O. Box 3000 http://www.unidata.ucar.edu/ Boulder, CO 80307-3000 ______________________________________________________________________________