Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: getatt in netcdf-perl

Rorik,

I think this is what you want to know.

You can use pack, so it would be

$unit = pack("C*",@var_att);
print $unit;

Hopefully, I got the syntax right,

Jessica


On Friday, April 5, 2002, at 10:04 PM, 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



 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690