Hi Mike, > I am converting some code from the old C++ API to the new one. > > I notice that there is no NcGroup::addVar() method specifically for scalars. > > Therefore I need to use the following call: > > NcVar NcGroup::addVar(const string& name, const NcType& ncType, const > vector<NcDim>& ncDimVector) > > and pass in an ncDimVector of 0 length. > > I notice that in the code, the following call is made: > > ncCheck(nc_def_var(myId,name.c_str(),tmpType.getId(),dimIds.size(),&dimIds[0],&varId),__FILE__,__LINE__); > > and this specifically takes the address: > > &dimIds[0] > > So I have 2 questions: > > (1) Am I correct in using this method to add a scalar variable? Yes. but I think it would also work OK if you just gave a 0 argument (a null pointer) instead of &dimIds[0]. > (b) Is &dimIds[0] guaranteed to be safe if the length of dimIds is 0, > i.e. dimIds[0] does not exist? I have done some tests and it seems that > this operation returns 0 for a zero-length vector, but this may just be > luck. Yes that's the way it's supposed to work in the C API, as documented here: http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-c.html#nc_005fdef_005fvar where it says dimids Vector of ndims dimension IDs corresponding to the variable dimensions. For classic model netCDF files, if the ID of the unlimited dimension is included, it must be first. This argument is ignored if ndims is 0. For expanded model netCDF4/HDF5 files, there may be any number of unlimited dimensions, and they may be used in any element of the dimids array. --Russ > > Thanks for any advice. > > Mike Dixon, EOL > > Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: ROZ-206338 Department: Support netCDF Priority: Normal Status: Closed
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.