Re: getatt in netcdf-perl

Rorik:  You might also be interested in the PDL::NetCDF interface.  This
requires the installation of PDL (the perl data language) and the
PDL::NetCDF package.  Once this hassle is over, one has more flexible
access to attributes.

See:

http://www.cpan.org/modules/by-module/PDL/PDL-2.3.2.tar.gz 
http://www.cpan.org/modules/by-authors/Douglas_Hunt/PDL-NetCDF-0.80.tar.gz 

Regards, 

  Doug Hunt

Rorik Peterson wrote:
> 
> I am new to the perl interface for netCDF and I'm using the test.pl
> script in the distribution to learn from.  I want to get a variable's
> attribute that is a string.  I only see a way to get it as an ASCII
> array.  Currently I loop through the array with perl's chr to fix it,
> but there must be a better way.  What am I missing? Transcript follow.
> 
> rorik@stickley$ ncdump sample.nc
> netcdf sample {
> dimensions:
>      x = 2 ;
> variables:
>      int x(x) ;
>              x:units = "meters" ;
> data:
> 
>  x = 1, 2 ;
>  }
> 
> rorik@stickley$ cat test.pl
> #!/usr/bin/perl -w
> 
> use NetCDF;
> 
> my $ncid = NetCDF::open("sample.nc", NOWRITE);
> my $varid = NetCDF::varid($ncid, "x");
> NetCDF::attget($ncid, $varid, "units", \@var_att) == 0 or die;
> print "@var_att\n";
> foreach(@var_att) { print chr $_; }
> print "\n";
> rorik@stickley$ ./test.pl
> 109 101 116 101 114 115
> meters
> 
> --
> Rorik Peterson
> Research Engineer

-- 
dhunt@xxxxxxxx
Software Engineer III
UCAR - COSMIC
Tel. (303) 497-2611

  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: