GRIB is the file format used by most weather forecasting centers to store their model forecasts. It is standardized by the World Meteorological Organization. The function loadgrib allows to decode a GRIB file and to import a variable in Octave. This function is based on the wgrib tool of Wesley Ebisuzaki which he placed into the public domain.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You will need (obviously) octave (version 2.1.70 or higher). The wgrib tool is included in the package. Download the sources from http://ocgmod1.marine.usf.edu/loadgrib/loadgrib-0.1.1.tar.gz and decompress the tar file. In the newly created directory, type "make" to compile:
wget -O - http://ocgmod1.marine.usf.edu/loadgrib/loadgrib-0.1.1.tar.gz | tar xvfz - cd loadgrib make
VAR = loadgrib(FILENAME,INDEX)
The variable specified by INDEX is loaded from a GRIB file named FILENAME. You can use the shell command wgrib to list the content of a GRIB file and to identify the variable index.
The file example_wgrib.m downloads a forecast of NCEP Global Forecast System (about 41 MB in size) and extracts the air temperature forecast for your location. The example requires the shell command 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%H',gmtime(t)); % current date in UTC % load about 41 MB from NCEP GFS system(['wget -O gfs.grib ftp://ftpprd.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.' 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')
On the following platforms, loadgrib is known to work:
Any suggestions, comments, bug fixes, ... are of course very appreciated. Send them to: abarth at marine dot usf dot edu.
If you experience a problem under cygwin, please send me also the list of installed packaged by running the command:
cygcheck -c > all_packages.txt
and sent me the file "all_packages.txt".
Alexander Barth, last update May 31, 2006.