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.
Tom, > To: address@hidden > From: tom cook <address@hidden> > Subject: varinq not reporting correct varid? > Organization: U Miami/RSMAS The above message contained the following: > Hi, I'm trying to read in some NCEP reanalysis data which is in netcdf > format. The data consists of 4 variables, 3 1-d arrays and 1 3-d array. > Here is the curtailed info from ncdump: > ------------------------------------------- > ~>ncdump uwnd.10m.gauss.2000.nc |more > netcdf uwnd.10m.gauss.2000 { > dimensions: > lon = 192 ; > lat = 94 ; > time = UNLIMITED ; // (1464 currently) > variables: > float lat(lat) ; > lat:units = "degrees_north" ; > lat:actual_range = 88.542f, -88.542f ; > lat:long_name = "Latitude" ; > float lon(lon) ; > lon:units = "degrees_east" ; > lon:long_name = "Longitude" ; > lon:actual_range = 0.f, 358.125f ; > double time(time) ; > time:units = "hours since 1-1-1 00:00:0.0" ; > time:long_name = "Time" ; > time:actual_range = 17522904., 17531682. ; > time:delta_t = "0000-00-00 06:00:00" ; > short uwnd(time, lat, lon) ; > uwnd:long_name = "4xDaily u-wind at 10 m" ; > uwnd:valid_range = -102.2f, 102.2f ; > uwnd:actual_range = -26.7f, 32.5f ; > uwnd:units = "m/s" ; > uwnd:add_offset = 225.45f ; > uwnd:scale_factor = 0.01f ; > uwnd:missing_value = 32766s ; > uwnd:precision = 2s ; > uwnd:least_significant_digit = 1s ; > uwnd:GRIB_id = 33s ; > uwnd:GRIB_name = "U GRD" ; > uwnd:var_desc = "u-wind\n", > "U" ; > uwnd:dataset = "NMC Reanalysis\n", > "L" ; > uwnd:level_desc = "10 m\n", > "P" ; > uwnd:statistic = "Individual Obs\n", > "I" ; > uwnd:parent_stat = "Other\n", > "-" ; > > // global attributes: > :Conventions = "COARDS" ; > :title = "4x daily NMC reanalysis (2000)" ; > :base_date = 2000s, 1s, 1s ; > :history = "created 00/01/30 by Hoop (netCDF2.3)" ; > :description = "Data is from NMC initialized > reanalysis\n", > "(4x/day). It consists of T62 variables interpolated to\n", > "pressure surfaces from model (sigma) surfaces." ; > :platform = "Model" ; > data: > etc... > -------------------------------- > > I'm using the following to read the data: > > ------------ > #!/usr/bin/perl > use NetCDF; > $ncid=NetCDF::open("uwnd.10m.gauss.2000.nc", NetCDF::READ); > NetCDF::inquire($ncid, $ndims, $nvars, $natts, $recdir); > for ($i=0;$i<=$nvars-1;$i++){ > NetCDF::varinq($ncid,$i, $name, $datatype, $ndims, \@dimids, $natts); > NetCDF::varget($ncid,$i,0,2,\@data); The "start" and "count" arguments in the "varget()" call above are incorrect. They must be references to arrays. An example of reading a multi-dimensional netCDF variable can be found in the perl script "perl/test.pl" of the netcdf-perl distribution. Search for the string "Vet fixed variable values". Let me know if you don't have access to this perl script. Please let me know if this helps. > etc ... > } > ---------- > > Anyway, when I run this variable 0-2 read ok with varget, but when it gets > to variable 3 ($i=3) I get the following error message: > > ncvarget: ncid 3: Index exceeds dimension bound > > So I'm thinking, either this isn't the correct way to read a 3-dim > variable, or the varid is somehow off. Any thoughts or help would be very > appreciated. > > Thanks, > Tom Regards, Steve Emmerson