decoding GRIB files in Octave

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

decoding GRIB files in Octave

Alexander Barth
Hi all,

With those poor people (like me) who need to decode a cryptic GRIB file,
I want to share loadgrib (, a
octave function to import variables from a GRIB file. GRIB is the file
format used by most weather forecasting centers to store their model
forecasts. It is standardized by the World Meteorological Organization.
This function is based on the wgrib tool of Wesley Ebisuzaki which he
placed into the public domain.

To install and compile this function, type:

wget -O - | tar  xvfz -
cd loadgrib

The example below shows the usage of loadgrib. It gives the air
temperature forecast in your home town  (based on forecast of the NCEP
Global Forecast System). You will need wget and octave-forge.


my_lon = 278; % your longitude in degrees East [0:360]
my_lat = 28;  % your latitude in degrees North [-90:90]

t = floor(time/86400) * 86400; % epoch time of last midnight
my_date = strftime('%Y%m%d',gmtime(t));  % current date in UTC
% load about 41 MB from NCEP GFS
system(['wget -O gfs.grib' my_date '/gfs.t00z.sfluxgrbf24']);

airtemp = loadgrib('gfs.grib',38);
lon = linspace(0,359.687,1152);
lat = linspace(-89.761,89.761,576);
my_airtemp = interp2(lon,lat,airtemp(:,end:-1:1)',my_lon,my_lat);
my_airtemp = my_airtemp - 273.15;
disp(['Forcasted temp. for ' strftime('%d-%b-%y %H:%M:%S CUT',gmtime(t+86400)) ': ' num2str(my_airtemp) ' deg C']);
%colormap(hsv); imagesc(airtemp')

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information: