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.
Hi Venkat, > I have a netcdf which has 33 global attributes. The program I wrote in > Fortran 90 showed the variable Nglobalatts as 33. > > But I am having difficulties to get the names and values of these > attributes. I am able to handle dimensions and variables but not > attributes. > > The only way I can get values for the global attributes is that I have > to know the attribute name before I get the values. For now, I ran some > other program ncbrowse to get the attribute names. I searched the f90 > interface userguide. I could not find the right routine to use. Can you > please look into this problem? To get the names of global attributes, you have to use NF90_GLOBAL as a variable pseudo-ID. It's mentioned in the F90 documentation in the Attributes Introduction section: http://www.unidata.ucar.edu/netcdf/docs/netcdf-f90.html#Attributes To find out how many global attributes there are, you can use nf90_inquire(ncid, nDimensions, nVariables, nAttributes, unlimitedDimId, formatNum) where the "nAttributes" parameter returns the number of global attributes. Then to find out the name of the Nth global attribute, use: nf90_inq_attname(ncid, varid, attnum, name) where varid is NF90_GLOBAL, attnum is N, and the name is returned in the last parameter. Once you have the name, you can find the type and length of the attribute by calling nf90_inquire_attribute(ncid, varid, name, xtype, len, attnum) again using NF90_GLOBAL as the varid. Finally to get the value(s) of the attribute, use nf90_get_att(ncid, varid, name, values) Please let us know if this isn't clear. --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: DQA-136247 Department: Support netCDF Priority: Normal Status: Closed