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

20040812: NetCDF: Reading undimensioned variable in netcdf-perl?



Stephen,

> To: address@hidden
> From: Stephen Leroy <address@hidden>
> Subject: NetCDF: Reading undimensioned variable in netcdf-perl?
> Organization: Harvard University
> Keywords: 200408121755.i7CHtSaW002379 netCDF Perl

The above message contained the following:

> I'm having all sorts of trouble reading in an undimensioned variable 
> (scalar) in a perl script using netcdf-perl. I'm trying something like
> 
> @index = ();
> $value = 0;
> 
> $ncid = NetCDF::open( $file, NetCDF::WRITE );
> $varid = NetCDF::varid( $ncid, "scalarvar" );
> $stat = NetCDF::varget1( $ncid, $varid, \@index, \$value );
> 
> I've tried the same with @index = ( 0 ), but the result is always the 
> same. A value of zero is returned.
> 
> Any quick advice?

Because the netCDF variable is a scalar, use NetCDF::varget() instead of
NetCDF::varget1(), e.g.,

    @coords = ();
    @counts = ();
    @values = ();
    NetCDF::varget($ncid, $scalarvarid, \@coords, \@counts, \@values) == 0 ||
        die "Couldn't get value of scalar variable\n";
    print "Scalar value is $values[0]\n";

Thanks for showing me that the testing script needed a "scalar" test.

> Thanks,
> Stephen Leroy

Regards,
Steve Emmerson

> NOTE: All email exchanges with Unidata User Support are recorded in the
> Unidata inquiry tracking system and then made publically available
> through the web.  If you do not want to have your interactions made
> available in this way, you must let us know in each email you send to us.