Posts

GRIB command line tools from ECMWF

6 Jun 2017

ECMWF supplies some useful command line tools for handling GRIB files: grib_get, grib_ls and grib_dump and several others. The tools are supplied as part of the latest version of the GRIB API.

To use the tools, you have to install the GRIB API from ECMWF: https://software.ecmwf.int/wiki/display/GRIB/GRIB+API+CMake+installation

Recent versions weren’t available from any of the remote repositories in my system’s default list. Therefore I had to download the installation package of a recent version of the grib-api (v. 1.14.0 or later) manually and then install it from a local repository using the Synaptic package manager in Ubuntu. See here for details of how to do this. Also, make sure you know whether your system is 32-bit or 64-bit and download the appropriate package. For my 32-bit Ubuntu system I used the 32-bit Debian package from the ECMWF GRIB-API Releases list.

With the API installed I was able to examine the contents of the files using grib_dump. After figuring out what was inside the files, I then extracted a time series for a specific location (specified as a latitude,longitude pair) using :

#!/bin/sh # u component, all validity times grib_ls -w shortName:s="u",stepRange=3 -l 51.8483,-8.483543 -p dataDate,dataTime,validityDate,validityTime MERA_PRODYEAR_2015_06_33_105_10_0_FC3hr.grb > test33.txt # v component, all validity times grib_ls -l 51.8483,-8.483543 -p dataDate,dataTime,validityDate,validityTime -w shortName:s="v" MERA_PRODYEAR_2015_06_34_105_10_0_FC3hr.grb > test34.txt

This extracted values for the four nearest grid cells to the specified location, for all forecast validity times (1h, 2h, 3h). There is a ‘grib_filter’ tool also provided which looks very useful as it can be used to match data based on a set of rules specified in a separate file. This looks better than the approach I took, but for now was just happy to get some data out of the GRIB files.

Electricity and Environment Laboratory

Renewable energy and land-atmosphere interactions research

Top