Eccodes is an open source library made by ECMWF for reading and writing grib files, which is the most common file format for meteorological und oceanographic data in operational use (while in research, Netcdf is mainly used). If one wants to work with grib files seriously, one will have to install it earlier or later. On top of that, one will also have to make sure C and Python code is able to import the library's functionality.
First of all, I would highly recommend not to use anything else than Linux, preferably Ubuntu, for working with meteorological data, especially grib files. If you do not want to migrate to Linux completely, consider either a dual boot or a virtual machine.
I just show you the commands with minimal explanation.
It is also possible to install an older version of Eccodes with apt:
sudo apt-get install libeccodes-dev
Install this package if you want to use command line tools:
sudo apt-get install libeccodes-tools
In case you want the latest version, you have to install manually from source. You have to install some libraries first:
sudo apt-get install libnetcdff-dev libopenjp2-7-dev gfortran make unzip git cmake wget
If you don't already have, create a directory for source builds:
cd && mkdir source_builds
Now, cd into this directory, create a subfolder for the eccodes build and download the source code of eccodes. Replace 2.27.0 with the latest version:
cd source_builds && mkdir eccodes && cd eccodes && wget https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.27.0-Source.tar.gz?api=v2
Now, untar the code:
tar -xzf eccodes-2.27.0-Source.tar.gz?api=v2
mkdir build && cd build
I have my source builds installed into /usr/src, however this is up to you and maybe not according to conventions or not the best choice for another reason. If you choose something else, remember to adapt the environment variables later on as well.
sudo mkdir /usr/src/eccodes
cmake -DCMAKE_INSTALL_PREFIX=/usr/src/eccodes -DENABLE_JPG=ON ../eccodes-2.27.0-Source
make -j
ctest
All tests need to be passed.
sudo make install
The following commands are needed for being able to use the applications in the bin folder (grib_dump, grib_ls, ...) from the command line.
sudo cp -r /usr/src/eccodes/bin/* /usr/bin
This is only required if you install eccodes for the first time.
echo 'export ECCODES_DIR=/usr/src/eccodes' >> ~/.bashrc
echo 'export ECCODES_DEFINITION_PATH=/usr/src/eccodes/share/eccodes/definitions' >> ~/.bashrc
source ~/.bashrc
sudo cp $ECCODES_DIR/lib/libeccodes.so /usr/lib
sudo cp /usr/src/eccodes/include/* /usr/include/
sudo apt-get install python3-pip
pip3 install eccodes-python
python3 -m eccodes selfcheck
Response should be:
Found: ecCodes v2.27.0.
Your system is ready.
For usage in C code, use
-leccodes
as a GCC option. In the source files in which you use eccodes type
#include "eccodes.h"
at the beginning. In Python, just do
import eccodes as ec;
Feel free to ask.
Lovey guide. An absolute gem.