Hi Aseem:

I will try to keep this as short as possible, because a lot of the issue here 
is more with understanding netcdf file structure than with R, because once you 
understand the former using ncdf4 is pretty straightforward..  So if you want a 
more detailed response we should probably take it off line.

Netcdf gridded field are comprised of dimensions or coordinate variables  
(which are booth index values and variables that hold the values of the 
dimensions), and of parameters defined on those dimensions.

>From what you send me I see:

>  $ ndims     : num 3

which means your file has three dimensions, "lon", "lat" and "time", dimension 
as lon(1068), lat(510) and time(22280).

The file says you have 6 variables:

>  nvars: int 6

but 3 of those are the variables holding the lon,lat and time values, the 
others  (with their dimensions):
pr(lon,lat,time)
tasmax(lon,lat,time)
lasmin(lon,lat,time)

When you called nc_open, you actually already have the coordinate values in the 
structure, for example  (and I hope I don't skip a leveling the structure), 
the longitude are at ncold$dim$lon$vals, and similar for the others.  So say we 
have set lon,lat and time as these values, the steps to subset the data would 
be:

1.  Find the indexes of the variable lon that fall in the subset you want  
(lets say for samples 10:19
2. Find the indexes of the variable lat that fall int subset you want  (let's 
say 20:29)
3. FInd the indexes of the times that fall int subset you want  (let's say 1:5)

than to subset the variable "pr" you would make a call like:

pr<-ncvar_get(ncold,'pr',start=c(10,20,1), count=c(10,10,5))

Note the values of "start" are the same as the first values of the indices 
given above for the three dimensions, and the count values are the number of 
elements to read in each dimensions  (i.e. 19-10+1, 29-20+1, 5-1+1).  pr will 
then contain the subset of the data.

Be certain to close the file:

nc_close(ncold)

Hope this gives you some idea of how to proceed.

-Roy

On Aug 27, 2014, at 3:29 PM, Aseem Sharma <nature.as...@gmail.com> wrote:


**********************
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to