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.
Bill, > -> > 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 > > I'm confused because I see an ARRAY of STRUCTURES of type "struct datum" > being written (i.e. the "value" argument to ncvarputg()) NOT an array of > type DOUBLE. I was confused, because you referred to the example on page *95* of the User's Guide, which is a FORTRAN example using NCVPTG. That's why I used all the references to the FORTRAN interfaces in my previous reply. Apparently you want to know about the C example on page *93*. I should have figured this out, because your question asked about ncvarputg() instead of NCVPTG. Sorry, I'm in context now. > Yes. I gather that one needs to pass the appropriate type of data. > And that's why I am confused as I don't see, in the example, that the > variable is of any netCDF data type. The example in the printed copy is garbled, and was corrected in a later update. It should be right in your on-line version, and in the on-line NetCDF User's Guide at http://www.unidata.ucar.edu/packages/netcdf/guide.txn_9.html#SEC90 The corrected version looks like this: /* write generalized hyperslab of values into netCDF variable */ ncvarputg(ncid, rh_id, start, count, stride, imap, (void*)&data[0][0][0].rh_val); so the type of the data is supposed to be "double". If you have further questions about this example, you should ask its author, Steve Emmerson (address@hidden). I've CC:ed him on this response, in case he has corrections to any of this. > ... Perhaps if I > describe what I'm trying to do you can give me a short answer: YES, NO, > or MAYBE... ;-) > I have an array of what I call HYPERSLAB structures defined as: > > struct HYPERSLB { > struct GlobalObs glbobs; > struct GlobalCalc glbclc; > struct dsrc Data[lat][lon]; > } AMIE[Ntotal]; > > where: > > struct GlobalObs { > int Plck; > float IMF, AE, DST; > } > > struct GlobalCalc { > float PPP, HemPwr, PhiMax; > float PhiMin, PhiDelta; > } > > struct data_src { > char *name; > int IPC; > float angc, Ped, Hall; > } > > I would like to be able to write a generalized hyperslab for each element > of the AMIE array. > Am I trying to do the impossible or can netCDF support this level of > abstraction? I'll have a look at the ncputrec, etc routines. Maybe. ncvarputg() is only capable of writing a block of data values of a single type, so you will either have to make multiple calls or use ncrecput(). I believe you can only use ncrecput() for this if Ntotal is the unlimited dimension in your netCDF file. --Russ ______________________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden P.O. Box 3000 http://www.unidata.ucar.edu/ Boulder, CO 80307-3000 ______________________________________________________________________________