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.
Susan, > From: address@hidden (Susan Norman) > Subject: netCDF perl.. > Organization: NCAR/ATD > Keywords: 199601241830.AA10647 netCDF perl In the above message you wrote: > Hopefully, this will be a very simple question for you.. > > I'm trying to write a perl script that reads a netCDF file. > I can't seem to get it to read the global attributes however. > > The code I'm using is: > $test=NetCDF::attname($ncid,NC_GLOBAL,0,$name); > > The value returned is the name of the first attribute of the > first variable (not the global variable). To get the name of global attribute $i, use the following function: NetCDF::attname($ncid, NetCDF::GLOBAL, $i, $name); To inquire about the global attribute named $name, use the following function: NetCDF::attinq($ncid, NetCDF::GLOBAL, $name, $type, $len); If ($type == NetCDF::CHAR || $len == 1) then the attribute is a scalar; otherwise, it's a vector. To get the value of a scalar global attribute named $name, use the following function: NetCDF::attget($ncid, NetCDF::GLOBAL, $name, \$attval); To get the value of a vector global attribute named $name, use the following function: NetCDF::attget($ncid, NetCDF::GLOBAL, $name, \@attval); Please let me know if this helps. -------- Steve Emmerson <address@hidden>