Due to the current gap in continued funding from the U.S. National Science Foundation (NSF), the NSF Unidata Program Center has temporarily paused most operations. See NSF Unidata Pause in Most Operations for details.

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



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