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.
> Organization:Department of Rangeland Ecology and Management, Texas A&M > University > Keywords: 199410111337.AA20941 C++ interface, NcDim Hi Dan, > > > Bugs: > > > NcFile::add_var(NcToken, NcType, int, const NcDim*) > > > changed to be > > > NcFile::add_var(NcToken, NcType, int, const NcDim**) > > > (I could not make a program pass a list of dims > > > in that it created.) ... > I had trouble building an array of dims, > because you can only get a single NcDim* from the file. > Here is what I wanted to do: > > NcDim* dimlist[curVar->num_dims()]; > NcDim* tempDim; > for (int j = 0; j < curVar->num_dims(); j++) { > tempDim = curVar->get_dim(j); > dimlist[j] = outFile->get_dim(tempDim->name()); > // try to use existing dim, if not add it > if (!dimlist[j]) { > if (!outFile->add_dim(tempDim->name(),tempDim->size())) { > exit 1; > } > } > > Is there a way to make a const NcDim* that holds 2 elements? > (because NcDim() is private "NcDim foo[12];" fails, the closest > I came was NcDim* foo[12]) I got also changed line 166 of > netcdf.cc from: > > for (int i=0; i < ndims; i++) > dimids[i] = dims[i].id(); > > to: > > for (int i=0; i < ndims; i++) > dimids[i] = dims[i]->id(); After looking at it, I concluded that you're exactly right about this bug and how to fix it. I've incorporated your change. It looks like if I had a test for this version of the NcFile::add_var() member function, I would have seen the problem. Thanks for the fix. > > > Enhancements for NcVar: > > > > > > get_rec/put_rec/set_rec member functions that use > > > the unlimited dimension to step through records, includes > > > changes to NcVal to allow a size parameter so you get > > > just a record rather than an NcVal of the entire > > > variable. > > > > > > get_index(TYPE *key), a slow linear search that > > > finds the record number of the first variable that matches > > > some key > > > > These both seem worthwhile. Can you make the changes available to me? > > > > I will, but right now they are interspersed with the New/Old file > stuff (that I need to test/fix a bit.) It will be a easier to send both. > If you haven't heard from me by Friday, hassle me. I guess I could hassle you, but I'm in no great hurry to get these changes since I won't be able to work on them until after next week anyway. But I would appreciate getting them when they're ready. Thanks again for using this stuff and giving us such valuable feedback. --Russ