[GIS] Extract single datapoint from netCDF file in R using ndcf

netcdfr

I'm trying to extract a single variable from a 3-dimensional netCDF file.

[1] "file blah.nc has 3 dimensions:"
[1] "longitude   Size: 200"
[1] "latitude   Size: 100"
[1] "time   Size: 2000"
[1] "------------------------"
[1] "file blah.nc has 1 variables:"
[1] "short temp[longitude,latitude,time]  Longname:temperature Missval:-9999"

Time's units are "days". I just want to get a single day in the middle of the dataset at time=t1 say. The manual seems to indicate that I should temp1 = get.var.ncdf(blah.nc, "temp", start=c(long1, lat1, t1)), but this gets all temperatures for all longs and lats until the ends of the arrays. I don't want to read the entire variable and then extract the desired value in R, I want the ncdf library to do it. get.var.ncdf doesn't take a end=c(long1+1, lat1+1, t1+1) argument as far as I can tell? So, how can I do this using ncdf?

Best Answer

You need the count argument:

temp1 = get.var.ncdf(blah.nc, "temp", start=c(long1, lat1, t1), count=c(2,2,2))
Related Question