getatt in netcdf-perl

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

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