Loadgrib, a GRIB decoder for Octave
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
Using the loadgrib function
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:
- Centos 5, AMD 64
- Fedora Core 5, AMD 64
- Fedora Core 3, AMD 64
- Cygwin, Windows XP SP2. You will need to install the following cygwin packages:
- gcc-core verion 3.3.3
- gcc-c version 3.3.3
- gcc-g77 version 3.3.3
Note: you have to use the cygwin's old 3.3.3 gcc version and not the default 3.4.4 (see below). You can install all these packages with cygwin's setup.exe.
- Loadgrib doesn't work with the old 2.1.50 version of octave. Consider to upgrade octave.
- No metadata is loaded from the GRIB file.
- Under cygwin, octave is compiled with gcc 3.3.3, due to a bug in the current cygwin default compiler gcc 3.4.4. You need to compile loadgrib also with gcc 3.3.3. Binaries of this version can be downloaded using the cygwin's setup program. (Status: May 31, 2006).
Comments and feedback
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".