Recipe: Matlab program as OPeNDAP client

From GEOS-5
Jump to: navigation, search

Back to G5NR Data Access Guide.

Problem

By accessing the collection inst01hr_3d_T_Cv via the OPeNDAP server

http://opendap.nccs.nasa.gov/dods/OSSE/G5NR/Ganymed/7km

we want to read the surface temperature data inside the box bound by latitudes 25oN, 50oN and longitudes -130oW, -65oW for 2006/Sep/18, 9z and compute its min/max.

Solution

MATLAB version 2012a and later has native openDAP support. The following code has been tested with MATLAB version 2014a.

The metadata for the collection inst01hr_3d_T_Cv is available at

http://opendap.nccs.nasa.gov/dods/OSSE/G5NR/Ganymed/7km/0.5000_deg/inst/inst01hr_3d_T_Cv.info

Code

This code accesses the collection inst01hr_3d_T_Cv from the OPeNDAP server and reads a subset of the temperature data (all levels inside the bounding box specified above) and computes its max/min. It then computes the max/min of the above data at the surface (level=72).

NOTE:

  1. Instead of reading a downloaded NetCDF-4 file, we read an OPeNDAP URL.
  2. While in the downloaded file, the temperature variable appears in the uppercase (T), on the OPeNDAP server, this variable is in lowercase.
  3. Via the OPeNDAP URL, we now have access to all times for which data exists. The hourly inst files are available starting at 2005/15/15, 2200z. Our desired time, 2006/09/18, 0900z is then the 11772th step.
 1 % opendap url
 2 opdurl = 'http://opendap.nccs.nasa.gov:9090/dods/OSSE/G5NR/Ganymed/7km/0.5000_deg/inst/inst01hr_3d_T_Cv'
 3 
 4 % bounding box
 5 %   lons = -130:0.5:-65
 6 %   lats =   25:0.5:50
 7 imin = round((-130. + 180.)/0.5);
 8 imax = round(( -65. + 180.)/0.5);
 9 jmin = round((  25 +  90.)/0.5);
10 jmax = round((  50 +  90.)/0.5);
11 % corresponding array sizes
12 im = imax-imin+1;
13 jm = jmax-jmin+1;
14 lm = 72; % read all 72 levels
15 
16 % read temperature inside the bounding box
17 % time 11772 corresponds to 2006/09/18, 9z
18 start = [imin, jmin, 1, 11772];
19 count = [im, jm, lm, 1];
20 fprintf('Reading Tsub (subset of T)...');
21 Tsub = ncread(opdurl, 't', start, count);
22 fprintf('done.\n')
23 
24 % compute max/min of Tsub
25 fprintf('max(Tsub): %f\n', max(Tsub(:)));
26 fprintf('min(Tsub): %f\n', min(Tsub(:)));
27 
28 % compute max/min of Tsub at surface
29 level = 72; % surface
30 Tsub_surface = Tsub(:,:,72);
31 fprintf('max(Tsub at surface): %f\n', max(Tsub_surface(:)));
32 fprintf('min(Tsub at surface): %f\n', min(Tsub_surface(:)));

Output

Running this MATLAB script, we get the output

>> g5nr_reader

opdurl =

http://opendap.nccs.nasa.gov:9090/dods/OSSE/G5NR/Ganymed/7km/0.5000_deg/inst/inst01hr_3d_T_Cv

Reading Tsub (subset of T)...done.
max(Tsub): 305.604828
min(Tsub): 191.695648
max(Tsub at surface): 305.604828
min(Tsub at surface): 276.292328

Discussion

See Also

  1. File Spec: File:G5NR-Ganymed-7km FileSpec-ON6-V1.0.pdf
  2. Recipe: Fortran program to read data from downloaded file

No Warranty

Copyright