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.
>To: address@hidden >From: John Zbesko <address@hidden> >Subject: nc_inq functions in C++ interface? >Organization: UCAR/Unidata >Keywords: 200306242006.h5OK6kLd022253 Hi John, > Thank you so much for suggesting the C++ beta version > of the NetCDF API. > > Are there analogs for the nc_inq group of C functions? > For example, I have code to open a NetCDF database and > determine the number of variables, but how do I find > the name of the 5th variable? In netcdfcpp.h or the C++ documentation, you can find the NcFile::get_var method: NcVar* get_var( int ) const; // n-th variable with which you can get the 5th variable, by using the argument 5. Then with that variable you can get the name, using the NcVar::name() function. See the example in the src/cxx/nctst.cpp file, which includes the function void DumpableNcFile::dumpvars( void ) that outputs all the variable names, similar to ncdump, using just the C++ interface. > NcFile nc (filename,NcFile::ReadOnly); > int number_of_variables=nc.num_vars(); > QString variable5= ?????????? > > Or should I be using the C nc_inq functions and use > the "id", as in nc.id()? No, you should not have to use anything from the C interface. The C++ interface is intended to be an independent interface from which you can do anything the C interface supports. > Thank you for your help- or perhaps this is a question > more appropriate to the mailing list? The question is exactly appropriate for address@hidden, and probably not ideal for the netcdfgroup mailing list, which is intended more for announcements and discussion than questions about use. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://my.unidata.ucar.edu