Before downloading data check if your processing software supports the GRIB and/or NetCDF formats. If your software supports both, use GRIB as first choice. If your software supports only NetCDF or if you run into problems with GRIB, use the NetCDF format.

Introduction

The GRIB file format is designed for storing and distributing weather data. GRIB files are widely used in meteorological applications (Wikipedia article, including a list of software to read GRIB files).

GRIB stands for "General Regularly distributed Information in Binary form" and is a WMO (World Meteorological Organisation) standard format for archiving and exchanging gridded data. GRIB is a binary format, and the data is packed to increase storage efficiency. GRIB messages are often concatenated together to form a GRIB file. GRIB files usually have the extension .grib, .grb or .gb.

Currently there are two different coding standards: GRIB edition 1 (commonly referred to as GRIB1) and GRIB edition 2 (GRIB2). The major differences are in the structure of the messages; in GRIB2, several variables are defined with more precision (e.g. in GRIB1, latitudes and longitudes are in milli-degrees while in GRIB2, they are in micro-degrees). Also in GRIB2, longitude values must lie between 0 and 360 degrees), the encoding of the parameter is very different, and in GRIB2 the description of the data is template/table based. Note that a GRIB file can contain a mix of GRIB1 and GRIB2 messages.

Please see the WMO "Introduction to GRIB Edition 1 and GRIB Edition 2" documentation for further details. 

The ECMWF model (the Integrated Forecasting System, IFS) currently outputs model-level fields in GRIB2 while pressure and surface level outputs are produced in GRIB1. For example,ERA-Interim (a climate reanalysis dataset provided by ECMWF) is produced in the GRIB edition 1 format. The ERA-Interim data is then made available for download in its native GRIB format.

GRIB conversion to netCDF

In some cases, data is also available in NetCDF format as the result of the conversion of the GRIB file to NetCDF. Note that due to this conversion, not all the information in the GRIB file will be included in the NetCDF version, and his is particularly true for the GRIB file metadata. As a result, care should be taken when using these files. At this time, the NetCDF format is not formally supported by ECMWF.

How to read GRIB files

ECMWF provides and supports ecCodes. This software package has an Application Program Interface which makes ECMWF GRIB1 and GRIB2 files accessible from C, FORTRAN and Python programmes. ecCodes also provides a useful set of command line tools to give quick access to GRIB messages within the files.

Metview is a software tool from ECMWF which allows users to read, process and visualise GRIB 1 and GRIB 2 data (see Metview documentation).

Please be aware that when reading GRIB files where the range of valid data values includes '9999' that some software may incorrectly indicate that these data points are missing. This is because 9999 is the default missing value indicator. 

Common GUI tools for reading and visualising GRIB files are:

For users comfortable with command line tools:

  • ecCodes by ECMWF
    • Supports GRIB to NetCDF conversion (grib_to_netcdf -o netcdf_file grib_file)
    • Supports GRIB to JSON (grib_dump -j <gribfile>)
    • See tools and code examples for Fortran, Python and C
  • CDO info operators (info, infon, sinfo, sinfon)
  • NCO
  • GrADS
  • wgrib2, only for GRIB edition 2, wgrib2 cannot decode GRIB edition 1 files
  • IDL
  • the GDAL library, with limited support for coordinate systems, georeferencing and metadata. In particular irregular (non-cartesian) coordinate systems might not be decoded correctly.

More tools are listed in this Wikipedia article.

How to extract data from GRIB to text

This example shows how to extract data from a GRIB file to generic text using ecCodes.

Preparation:

  1. Get a computer running Linux
  2. On your Linux computer install ECMWF's ecCodes software
  3. Get some data in GRIB format (for example from the CAMS or C3S Service). For this use case, we assume the file contains forecast data, and surface data (ie. a single layer, no atmospheric layers above the surface)

Example 1: List data from GRIB

grib_get_data -p dataDate,dataTime,validityDate,validityTime my_file.grib

... giving this output:

output
Latitude, Longitude, Value, dataDate, dataTime, validityDate, validityTime
   69.950  -24.950 6.7796034626e-08 20160117 0 20160117 0
   69.950  -24.850 6.8240265944e-08 20160117 0 20160117 0
   69.950  -24.750 6.8275508864e-08 20160117 0 20160117 0
   69.950  -24.650 6.8133954540e-08 20160117 0 20160117 0
...


Note that the keys dataDate, dataTime, validityDate, validityTime are available in CAMS/C3S
forecast data. Analysis data has different keys.dataDate and dataTime indicate the date/time we forecast from. validityDate and validityTime indicate the date/time we forecast for.

For further options please see the documentation of the ecCodes command line GRIB tools

Example 2: List data for closest point(s)

For a given coordinate, for example (lat=46.87 / lon=8.73), list data of the closest model point:

grib_ls -l 46.87,8.73,1 -p dataDate,dataTime,validityDate,validityTime my_file.grib

... giving this output:

output
my_file.grib
dataDate      dataTime      validityDate  validityTime   value 
20160117      0             20160117      0             3.37724e-08   
20160117      0             20160117      100           3.24475e-08   
20160117      0             20160117      200           3.3837e-08     
...
20160117      0             20160117      2200          3.2791e-08    
20160117      0             20160117      2300          3.61387e-08   
20160117      0             20160118      0             3.96635e-08   
25 of 25 messages in my_grib_file.grib
 
25 of 25 total messages in 1 files
Input Point: latitude=46.87  longitude=8.73
Grid Point chosen #1 index=162037 latitude=46.85 longitude=8.75 distance=2.69 (Km)
Other grid Points
- 1 - index=162037 latitude=46.85 longitude=8.75 distance=2.69 (Km)
- 2 - index=162036 latitude=46.85 longitude=8.65 distance=6.47 (Km)
- 3 - index=161337 latitude=46.95 longitude=8.75 distance=9.02 (Km)
- 4 - index=161336 latitude=46.95 longitude=8.65 distance=10.77 (Km)


Tips 

For further options please see the documentation of the ecCodes command line GRIB tools

-F option to format values as decimals instead of scientific:

grib_ls -F %f my_file.grib

Redirect the output to a text file:

grib_get_data my_file.grib > my_file.txt

List only the first or last 10 lines of an output (aka pipe):

grib_get_data my_file.grib | head -n10
grib_get_data my_file.grib | tail -n10

This document has been produced in the context of the Copernicus Atmosphere Monitoring Service (CAMS) and Copernicus Climate Change Service (C3S).

The activities leading to these results have been contracted by the European Centre for Medium-Range Weather Forecasts, operator of CAMS and C3S on behalf of the European Union (Delegation Agreement signed on 11/11/2014 and Contribution Agreement signed on 22/07/2021). All information in this document is provided "as is" and no guarantee or warranty is given that the information is fit for any particular purpose.

The users thereof use the information at their sole risk and liability. For the avoidance of all doubt , the European Commission and the European Centre for Medium - Range Weather Forecasts have no liability in respect of this document, which is merely representing the author's view.