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

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

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



Stephen,

> To: support@xxxxxxxxxxxxxxxx
> From: Stephen Leroy <leroy@xxxxxxxxxxxxxxxxx>
> 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.


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of 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