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: NOAA/FSL > Keywords: 199401061837.AA19023, C++ interface, bug Hi Tom, > I've bumped into another problem that I would like you to look at. If > you remember, I'm using the C++ interface to netCDF. My problem > occurs when I attempt to get a variable attribute that does not exist. > According to the documentation, "If no such attribute has been attached > to the variable, zero is returned." However in my case a non-zero > value is returned when I attempt to get an attribute that does not > exist. I have attached a piece of code with the corresponding CDL that > demonstrates this problem. As always, thanks for you time. Thank you for providing another good bug report. I think the fix is adding a few lines to the NcVar::get_att(NcToken) member. Please let me know if the appended patch doesn't work, or if you find any more bugs. --Russ =================================================================== RCS file: RCS/netcdf.cc,v retrieving revision 1.44 diff -c -r1.44 netcdf.cc *** 1.44 1993/12/07 16:17:48 --- netcdf.cc 1994/01/06 21:42:44 *************** *** 491,496 **** --- 491,500 ---- NcAtt * NcVar::get_att( NcToken aname ) const { NcAtt* att = new NcAtt(the_file, this, aname); + if (! att->is_valid()) { + delete att; + return 0; + } return att; }