Decoding ECMWF/ERA grib

Use their code...

ECMWF supply a grib decoder called gribex. If this is not what you want, then maybe you'll be interested in my perl decoder. Why should you prefer mine? Well, gribex is huge and unwieldy, my perl is only 400 lines and readily customisable. Theirs (apparently) does not run on alphas.

I also recommend you look at the "wgrib" package (wesley.wwb.noaa.gov/wgrib.html).

Further reading:
The ECMWF web site is www.ecmwf.int.
The BADC site is www.badc.rl.ac.uk and their ERA-pages are there too.

Or use mine...

The basic translation of ECMWF-grib to text or binary format is done by wmc_grib1.pl. This is fine if your grib described a lat-long or gaussian grid. But maybe you have grib describing the data as spherical harmonics. Then, things become complicated. You need to move on to:

Phase 2: harmonics to grid values

This phase is done in Fortran, because (a) its CPU-intensive and (b) I didn't want to write my own fft-legendre transform routines. Actually, I did write some in IDL... but I didn't do it very efficiently. May be interesting as a stand-alone, who knows? harm2ll.pro.

My code relies on sources from http://www.atmos.washington.edu/misc/PBL_LIB.html which I found from an altavista search on +harmonic +grid. You need only the routines sphere2grid.f and fft99f.f from their package, to do it my way. You can do it all their way, but I fould that their interface was heavily wrapped up in their own way of doing things.

Having decided that the interface they use to their prog was not what I wanted, I decided that a direct interface to their routine "trggen" was needed... so I wrote t1062ll.f and the associated script t1062ll.pl. This converts ECMWF T106 grib output into lat-long values, and all you have to do now is work out which way is up!

Note that the output is on a regular-longitude (starts at 0 and goes upwards) by gaussian-latitue grid. The BADC file about gaussian grids may help, or you may just prefer the gaussian latitudes file (note: this is n80 specific). A question sometimes asked is: "Is the first gridbox centered at 0E, or is 0E the longitude of the boxes western edge?". The answer is, I think, that the values are not gridbox values but point values, since they have been converted from the spectral representation. Therefore each value is a point, existing therefore at the given longitude-latitude.

Phase 3: [optional] grid values to PP-fields

If you understand the UKMO/Hadley Centre PP-format, and understand IDL or PV-WAVE, you may care to look at some routines I have for further processing. Even if you don't want to do the processing, they might be a useful example of how to read in the data.

So: if you have "reduced resolution" (ie 2.5 x 2.5 degree) files, you want badc2pp.pro. If you have T106 data, you want n802pp.pro. There are some support procedures: readfromfile.pro read in data from a binary/text file, and gofilename2header.pro reads data (year, month, etc) from the filename and puts it into a header block.

Use and Warranty

The code is freely available for non-commercial use. I would appreciate feedback if you use it (and perhaps "why not" if you didn't!).

There is, of course, absolutely not warranty as to the accuracy of the code. I guarantee that there are some bugs still in it, but I don't know what they are...

Support: users of the code are expected to work things out for themselves. I'm not going to answer your Perl questions for you. But I may be prepared to offer some limited advice if you have problems.


If you likeed this, you might like some of my other Perl scripts

William M. Connolley