WGRIB interface to MATLAB
This is a very small collection of MATLAB script that enable to read GRIB files. The scripts were originally developed to load the output of the Regional Spectral Model (RSM).
Download the toolbox : rsm_wgrib.tar
Installation instructions:
1) Untar the file and add this directory to your MATLAb path (e.g. >> addpath /mypath/rsm_wgrib ).
2) Compile the wgrib.c file using "gcc -o wgrib wgrib.c" and place the executable in the same directory of the toolbox. Alternatively you can run MATLAB and execute >> rsm_compile_wgrib
3) Run MATLAB and type >> rsm_example
Additional documentation:
There are two main functions
function [INV] = rsm_get_inv (gribfile);
Loads the invertory of the GRIBFILE into
a structure array.
function [FIELD, S] = rsm_extract_record (gribfile, record);
Extract field corresponding to record number RECORD
from GRIBFILE into variable FIELD. S returns the inventory of
the selected record. To get a full inventory of the GRIBFILE
use INV = rsm_get_inv(GRIBFILE).
An example of INV for a landmask file:
gribfile=which('lsmsk00.grib')
inv = rsm_get_inv(gribfile)
inv =
string: {'1:0:d=00010100:LAND:sfc:0-1mon ave:NAve=744'}
recnum: 1
datestr: {'d=00010100'}
year: 0
month: 1
day: 1
hour: 0
varname: {'LAND'}LAND=rsm_extract_record(gribfile, 1)
NOTE: if the GRIB file contains multiple records just indicate the record number that you want. To figure out which record number you want to load check the INV. :)
Any question ask Emanuele Di Lorenzo (email: wgrib@ocean3d.org)