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.
>From: address@hidden (Matthew H. Savoie) >Organization: NOAA/FSL >Keywords: 199706092015.OAA03230 netCDF Hi Matt, > Got a question, I'm trying to get the number of global attributes from > an existing netcdf file. > > > status = nc_inq_varnatts(oldID, NC_GLOBAL, &nattsp) > > The documentation about attributes says that you can use NC_GLOBAL as > a psuedo-variable id, but I can't get the above statement to return > anything except -49 (variable not found). > > Is there a way to get the number of global attributes? If not should > there be? Sorry to take so long to answer this, it "slipped through the cracks". The documented way to find the number of global attributes in the netcdf-3 interface is status = nc_inq_natts(oldID, &nattsp); I've just checked and this works as intended. I was surprised that the way you tried, using NC_GLOBAL, did not also work, but the documentation appears to be correct also in this case. It appears that the only use for the NC_GLOBAL attribute is to put and get values of a global attribute. I think I'll treat this as a documentation bug; the User's Guide should be more explicit about the uses for NC_GLOBAL and should have a cross-reference to nc_inq_atts under nc_inq_varnatts. But we'll also look at whether we should extend the functionality of nc_inq_varnatts() so it does what you expect when NC_GLOBAL is the variable ID, just because that's the way the netcdf-2 interface worked and other users may trip on the same problem. --Russ _____________________________________________________________________ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu