Skip Navigation Links 
NOAA logo - Click to go to the NOAA homepage National Weather Service   NWS logo - Click to go to the NWS homepage
Environmental Modeling Center
Local forecast by
"City, St" or
Zip Code


Marine Modeling and Analysis Branch Logo
Click here to go to the MMAB homepage

Data Analysis using MATLAB and NCTOOLBOX

Home Compare with Obs* Data Assim* Monitor* RTOFS & WOCE* Graphics Viewer* Data Access About the Model
* -- MMAB internal use only

The following examples use MATLAB® to extract and visualize the sea surface height from RTOFS Atlantic model data from the NOMADS data server and a downloaded GRiB file.


The examples make use of two free toolboxes,

  1. NCTOOLBOX: A MATLAB toolbox for working with common data model datasets
  2. M_MAP: A mapping package for MATLAB.
These toolboxes can be installed in your home directory, they do not need to be installed into the system-wide folders.

Example 1: Plot data from the NOMADS Data Server

First set up the URL to access the data server. See the RTOFS directory on NOMADS for the list of available model run dates.


The contents of the OpenDAP dataset can be explored by clicking on the "Info" button in the RTOFS directory for the day or by using this command in MATLAB:


Note that the NOMADS data server interpolates and delivers the data on a regular lat/lon field, not the native model grid. To analyze the model output on the native grid you will have to work from a downloaded GRiB file (see Example 2).

Extract the sea surface height field from NOMADS.

The indexing into the data set is standard MATLAB array indexing. In this case we want the first forecast step, but note that the first time step in the RTOFS OpenDAP link is all NaN values. So we start with the second timestep.

We need to convert the data from single to double precision and remove any singleton dimensions, as the NCTOOLBOX routines return the numbers as they are stored in the netCDF file, in this case single precision.

Plot the field using M_MAP. Start with setting the map projection using the limits of the lat/lon data itself:
m_proj('miller','lat',[min(lat(:)) max(lat(:))],...
'lon',[min(lon(:)) max(lon(:))])
Next, plot the field using the M_MAP version of pcolor.
shading flat;
Add a coastline and axis values.
m_coast('patch',[.7 .7 .7])
Add a colorbar and title.
title('Example 1: RTOFS Sea Surface Height from NOMADS');
You should see this image in your figure window: figure for example 1

Example 2: Plot data from an RTOFS GRiB file

This example requires that you download a GRiB file from either our NOMADS data server or the Production FTP Server (see our Data Access page for more information. For this exercise, I used the nowcast file for 20111004: ofs_atl.t00z.N000.grb.grib2 retrieved from NOMADS. This example assumes that the GRiB file is in the current working directory.

Note that the file variables have different names when you access it locally instead of through the OpenDAP interface. Specifically, "sshgsfc" becomes "Sea_Surface_Height_Relative_to_Geoid", "lat" is "Latitude_of_Presure_Point_surface" and "lon" is "Longitude_of_Presure_Point_surface". Once you've defined the ncgeodataset (in this case called nco), you can examine the variable names by printing out the values of nco.variables. Note that since we are working with the model's native grid (Arakawa C-Grid) the lat/lon positions for some values (ssh, temperature, mixed layer depth, others) is different from the lat/lon points for the horizontal velocity components.
And now we extract the SSH field using the parameter names from nj_info:
Note that because each GRiB file has only a single time step I access the first time point, not the second as was the case in Example 1.

From this point on the code is identical to the previous example:
m_proj('miller','lat',[min(lat(:)) max(lat(:))],...
  'lon',[min(lon(:)) max(lon(:))])
shading flat;
m_coast('patch',[.7 .7 .7]);
title('Example 2: RTOFS Sea Surface Height from GRiB');
You should see this image in your figure window: figure for example 2

MATLAB® is a registered trademark of The Mathworks. Inc.
EMC/MMAB Information Topics:
All Products, About Us, Contact Us
NOAA/ National Weather Service
National Centers for Environmental Prediction
Environmental Modeling Center
Marine Modeling and Analysis Branch
5830 University Research Court
College Park, MD 20740
About Us
Career Opportunities
Privacy Policy
Page last modified: Tuesday, 28-Jan-2014 17:11:55 UTC