This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
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.