title: How to take a subset from a netCDF file using latitude/longitude boundaries in R
body: <p>I have a netCDF file that I wish to extract a subset from defined by latitude/longitude boundaries (i.e. a lat/long defined box), using the ‘ncdf’ package in R. </p>
  
  <p>A summary of my netCDF file is below. It has two dimensions (latitude and longitude) and 1 variable (10U_GDS4_SFC). It is essentially a lat/long grid containing wind values:</p>
  
  <pre><code>[1] "file example.nc has 2 dimensions:"
  [1] "lat_0   Size: 1280"
  [1] "lon_1   Size: 2560"
  [1] "------------------------"
  [1] "file example.nc has 1 variables:"
  [1] "float 10U_GDS4_SFC[lon_1,lat_0]  Longname:10 metre U wind component Missval:1e+30"
  </code></pre>
  
  <p>The latitude variable runs from +90 to -90 and the longitude variable runs form 0 to 360.</p>
  
  <p>I wish to extract a subset of the overall grid using the following geographical corner boundaries: </p>
  
  <p>bottom left corner: Lat: 34.5˚, Long: 355˚,
  top left corner: Lat: 44.5˚, Long: 355˚, 
  top right corner: Lat: 44.5˚, Long: 12˚, 
  bottom right corner: Lat: 34.5˚ , Long: 12˚ </p>
  
  <p>I am aware that parts of a variable can be extracted using the <code>get.var.ncdf()</code> command (example below):</p>
  
  <pre><code>z1 = get.var.ncdf(example.nc, "10U_GDS4_SFC", start=c(11,26), count=c(5,5))
  </code></pre>
  
  <p>However, I can’t work out how lat/long can be incorporated so that I end up with a subsetted spatial grid containing variable values. I am new to working with netCDF values in R, and any advice would be greatly appreciated. Many thanks!</p>