[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

960125: netCDF perl..



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>