Chapter 4. NC_VARGET

In the prior example, we saw a dataset with three variables, lon, lat, and elevation. Let's retrieve the longitude, using nc_varget.m. The m-file is most simply used to get an entire variable as follows.

>> url = 'http://tashtego.marine.rutgers.edu:8080/thredds/dodsC/roms/nena/SRTM/w100w20s10n90.nc';
>> lon = nc_varget ( url, 'lon' );
>> size(lon)

ans =

        9600           1

>> lon(1:5)

ans =

  -99.9958
  -99.9875
  -99.9792
  -99.9708
  -99.9625

    

Now let's retrieve the elevation map that corresponds to the northeastern United States. Rather than retrieve all of it (it's a big dataset and doing so would take a long time), we'll just retrieve the part that we need. This will mean supplying start and extent parameters to nc_varget If we look at the metadata for the longitude and latitude and do the math, we can figure out that we need to start around index 5850 for the latitude and 2900 for the longitude. Retrieving a 1200x1200 section is equivalent to a 10x10 degree block. After that, we'll mask out the water and make a figure of the results.

>> e = nc_varget ( url, 'elevation', [5850 2900], [1200 1200] );
>> water = find(e < 0 );
>> e(water) = NaN;
>> pcolor ( e ); shading flat; colormap(summer);
>> set ( gca, 'clim', [0 600] );      % this brings out a bit more contrast
>> colorbar
>> daspect ( [1 cos(42*pi/180) 1] )
    

Please, please do not go nuts with nc_varget.m and try to limit your opendap data retrievals to what you need. Trying to retrieve 50 GB of data will only earn you a heaping of scorn from the maintainers of the remote opendap data site.