[R] Inconsistent results from var.get.nc in RNetCDF

C. Susannah Tysor susannah.tysor at nau.edu
Sat Jun 18 00:21:40 CEST 2011


Hello -

I am having trouble extracting data from NetCDF data files using
RNetCDF. The data files each have 3 dimensions (longitude, latitude,
and a date) and 3 variables (latitude, longitude, and a climate
variable).

Here is some of the output from print.nc for clarity:

-----
dimensions:
      month = UNLIMITED ; // (1368 currently)
      lat = 3105 ;
      lon = 7025 ;
variables:
      float lat(lat) ;
              lat:long_name = "latitude" ;
              lat:standard_name = "latitude" ;
              lat:units = "degrees_north" ;
      float lon(lon) ;
              lon:long_name = "longitude" ;
              lon:standard_name = "longitude" ;
              lon:units = "degrees_east" ;
      short tmax(lon, lat, month) ;
              tmax:missing_value = -9999 ;
              tmax:_FillValue = -9999 ;
              tmax:units = "degree_celsius" ;
              tmax:scale_factor = 0.01 ;
              tmax:valid_min = -5000 ;
              tmax:valid_max = 6000 ;
-----

I am getting behavior I don't understand when I use the var.get.nc
function from the RNetCDF package.

For example, when I attempt to extract 82 values beginning at stval
from the maximum temperature data with
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,82))
I get
   Error: Invalid argument


But after successfully running
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,80))
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,81))
the command with 82 works:
   > var.get.nc(p8m.tmax,'tmax', start=c(lon_val, lat_val, stval),
count=c(1,1,82))
    [1]  444  866 1063 1496 1905 2625 2662 2515 2016 1282  862  270
850  560 1002 1069 1900 2394 2721 2352 2192 1843  656  483  350  384
1532 1219 1929 2428
   [31] 2517 2288 2038 1209  527  489  407  505  899 1252 1885 2193
2707 2220 2040 1498 1040  689  594  941  729 1374 2016 2556 2475 2193
1841 1316 1010  476
   [61]  202  646 1266 1357 1860 2451 2530 2355 2010 1519 1210  228
173  600 1037 1316 1530 2389 2358 2303 2052 1583

The same occurs in the identically structured tmin file, but at 36
instead of 82:
  > var.get.nc(p8m.tmin,'tmin', start=c(lon_val, lat_val, stval),
count=c(1,1,36))
produces
   Error: Invalid argument

But after repeating the command with 30, 31, etc
   >var.get.nc(p8m.tmin,'tmin', start=c(lon_val, lat_val, stval),
count=c(1,1,36)) works.

Does anyone know what causes the initial failure to extract the
variable? And how I might prevent it?

Thanks!
Susannah

---
C. Susannah Tysor
Research Assistant
Pinyon Ecology Research Group
Northern Arizona University



More information about the R-help mailing list