FLEXPART installation guide

This post shares my experience installing the FLEXPART software.

What’s FLEXPART and about this guide

FLEXPART (“FLEXible PARTicle dispersion model”) is a Lagrangian
transport and dispersion model suitable for the simulation of a large
range of atmospheric transport processes.

I am currently learning to use this tool to facilitate researches on atmospheric moisture transports. So this guide is by no means comprehensive, nor guaranteed to work 100% of the time in a different setup. Rather, it is my working notes recording the procedures I took to get it installed on my 2 Linux desktop machines (both running Manjaro Linux). Hopefully it would be of any help to others.


System requirements

OS: Linux, it is said to work also on Mac.

Basic build tools (probably already installed in one’s Linux distro):

  • g++
  • gfortran
  • autoconf
  • libtool
  • automake
  • flex
  • bison
  • git
  • python3

Things I installed manually on desktop (Manjaro Linux):

  • cmake
  • gcc-fortran
  • netcdf-fortran
  • netcdf-fortran-openmpi (necessary?)
  • hdf5

These things should be readily available in the Linux distro’s software repository.

Dependency libraries

GRIB library

Note that FLEXPART used GRIB_API from ECMWF for reading GRIB formatted data. Version >= 1.6.1 of GRIB_API is needed for reading GRIB2 format.

However, GRIB_API has been deprecated and ECMWF now uses eccodes for I/O of GRIB formatted data.

Older versions of FLEXPART can use either GRIB_API or eccodes, the source code of the model doesn’t need change, but the makefile does.

Jasper library

"Nowadays, the jasper lib is not required separately, grib_api or eccodes will handle it."

I didn’t install this.

Install eccodes

Source code of eccodes: https://confluence.ecmwf.int/display/ECC/Releases

Installation guide: https://confluence.ecmwf.int/display/ECC/ecCodes+installation

Installation steps:

  1. download tarbar eccodes-x.y.z-Source.tar.gz from above link.
  2. in shell:
> tar -xzf  eccodes-x.y.z-Source.tar.gz
> mkdir build ; cd build

> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ ../eccodes-x.y.z-Source

> make
> ctest
> make install

cmake options:

  • DCMAKE_INSTALL_PREFIX: default to /usr/local/

NOTE that the default /usr/local/ location is causing me a bit trouble, the eccodes python module cannot find it. I had to symlink these files:

  • libeccodes_f90.so and libeccodes.so from /usr/local/lib to /usr/lib/
  • eccodes_config.h eccodes_ecbuild_config.h eccodes.h eccodes.mod eccodes_version.h eccodes_windef.h grib_api.h grib_api.mod from /usr/local/include/ to /usr/include
  1. install eccodes python module:

After make install, install the Python package using

pip install eccodes

Tried conda install -c conda-forge eccodes, didn’t work.

After installation, execute the following to test:

$ python -m eccodes selfcheck
Found: ecCodes v2.21.0.
Your system is ready.

Install GRIB_API

Didn’t do this step. See this excerpt:

Please note that GRIB-API is no longer maintained. The primary GRIB
encoding–decoding package used at the ECMWF is currently ecCodes. Any
new features for the handling of GRIB files will only be developed in
ecCodes. However, for FLEXPART v10.4 grib_api is sufficient. We
keep the grib_api instructions for backward consistency.
For future versions, ensure that the path *usr/local/lib* is in the
environment variable $PATH; otherwise, ecCodes may not find it.

Install GRIB_API if needed:

tar xvzf grib_api-1.28.0-Source.tar.gz
mkdir grib_api
cd grib_api-1.28.0-Source
./configure --prefix=/usr/local/grib_api --with-jasper=/usr/local/jasper
make check
make install


  1. download source from: https://www.flexpart.eu/wiki/FpRoadmap

  2. unpack the tarbar:

    tar -xvf flexpart_v10.4.tar

    the output files are in {flexpart_root}.

  3. edit the {flexpart_root}/src/makefile:

    changes I made:

#ROOT_DIR = /homevip/flexpart/
ROOT_DIR = /usr/local

F90	  = /usr/bin/gfortran
MPIF90    = /usr/bin/mpifort

#INCPATH1  = ${ROOT_DIR}/gcc-5.4.0/include
INCPATH1  = /usr/include
INCPATH2  = /usr/local/include
#LIBPATH1 = ${ROOT_DIR}/gcc-5.4.0/lib
LIBPATH1 = /usr/lib
LIBPATH2 = /usr/local/lib


#LIBS = -lgrib_api_f90 -lgrib_api -lm -ljasper -lnetcdff
#LIBS = -lgrib_api_f90 -lgrib_api -lm -ljasper $(NCOPT)
LIBS = -leccodes_f90 -leccodes -lm -ljasper $(NCOPT)
**NOTE** that the last line is telling the compiler to use
`eccodes` instead of `GRIB_API`.
  1. set LD_LIBRARY_PATH (not sure necessary):

    export LD_LIBRARY_PATH="/usr/lib/:$LD_LIBRARY_PATH"
  2. make with netcdf output support:

    make ncf=yes

    To see if everything goes ok, try:


    The output:

Welcome to FLEXPART Version 10.4 (2019-11-12)
FLEXPART is free software released under the GNU General Public License.
#### TRAJECTORY MODEL ERROR! FILE "pathnames"#### 
#### DIRECTORY.                              ####

Install flex_extract

flex_extract is for:

  1. obtaining meteorological data from ECMWF (ERA40, ERA-I, ERA5, 20C reanalyses or operational), in GRIB format.
  2. pre-process obtained data for usage as FLEXPART input.


  • Documentation webpage: https://www.flexpart.eu/flex_extract/index.html
  • Software Installation Plan (SIP): <file:///home/guangzhi/Documents/MeiTingTrunk/climate/_collections/Unknown_unknown_flex_extract software installation plan (SIP).pdf>
  • Software User Tutorial (SUT): <file:///home/guangzhi/Documents/MeiTingTrunk/climate/_collections/Unknown_unknown_flex_extract software user tutorial.pdf>

ECMWF accounts

One needs to register at ECMWF for data retrieval.

Major modes

  • Remote (member-state users only)
  • Gateway (member-state users only)
  • Local, member-state user
  • Local, public user

Will focus on local, public only.

System environment


  • Python 3
  • numpy
  • genshi
  • eccodes
  • ecmwf-api-client (for everything except ERA5)
  • cdsapi (for ERA5 and member user)

These can be installed in conda, or using pip. Check installation using:

import eccodes
import genshi
import numpy
import ecmwfapi
import cdsapi


  • gfortran
  • eccodes (see above)
  • emoslib (Fortran interpolation lib)
  • fftw3 (required by emoslib)

LD_LIBRARY_PATH is recommended to set to include installed libs.

Install the emoslib (optional) dependency

NOTE that this is only needed for those data sets which don’t contain vertical velocity as etadot.

NOTE emoslib has been deprecated by ECMWF.


> tar -xzf libemos-4.0.0-Source.tar.gz
> cd libemos-4.0.0-Source
> mkdir build ; cd build 
> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/emos -DECCODES_PATH=/usr/local/eccodes -DCMAKE_Fortran_FLAGS="-fallow-argument-mismatch" ../libemos-4.5.9-Source


> make
> make test
> make install

Trouble shooting 1

Trouble shooting 2

  • more undefined references to `grib_get_error_message':
/usr/bin/ld: ../lib/libemosR64.a(describe_input_field.c.o):/home/guangzhi/Downloads/emos_source/libemos-4.5.9-Source/interpolation/describe_input_field.c:527: more undefined references to `grib_get_error_message' follow
collect2: error: ld returned 1 exit status
make[2]: *** [sandbox/CMakeFiles/emos_tool.dir/build.make:106: bin/emos_tool] Error 1
make[1]: *** [CMakeFiles/Makefile2:1474: sandbox/CMakeFiles/emos_tool.dir/all] Error 2
make: *** [Makefile:182: all] Error 2

See this: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=239438.

The proposed solution is to set environment variable before cmake (NOT make):

export LDFLAGS="-leccodes"

Install flex_extract

  1. Get the repository:
git clone --single-branch --branch master https://www.flexpart.eu/gitmob/flex_extract
  1. Setup a Python environment, see above.

  2. Edit flex_extract/Source/Fortran/makefile_local_gfortran:


    • ECCODES_INCLUDE_DIR to /usr/local/include, because eccodes is installed in /usr/local

    • EMOSLIB to -L/usr/local/emos/lib -lemosR64, because Emoslib is installed there.

  3. run setup_local.sh to install

    Installation is successful if the below is shown:

(eccodes):flex_extract$ ./setup_local.sh 
WARNING: installdir has not been specified
flex_extract will be installed in here by compiling the Fortran source in /home/guangzhi/Downloads/flex_extract/Source/Fortran
Install flex_extract_v7.1.2 software at local in directory /home/guangzhi/Downloads/flex_extract

Using makefile: makefile_local_gfortran
/home/guangzhi/.local/anaconda3/envs/eccodes/lib/python3.9/subprocess.py:935: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
self.stdin = io.open(p2cwrite, 'wb', bufsize)
/home/guangzhi/.local/anaconda3/envs/eccodes/lib/python3.9/subprocess.py:941: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
self.stdout = io.open(c2pread, 'rb', bufsize)
/home/guangzhi/.local/anaconda3/envs/eccodes/lib/python3.9/subprocess.py:946: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
self.stderr = io.open(errread, 'rb', bufsize)
gfortran  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -I. -I/usr/local/include -fdefault-real-8 -fopenmp -fconvert=big-endian  -c	./rwgrib2.f90
gfortran  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -I. -I/usr/local/include -fdefault-real-8 -fopenmp -fconvert=big-endian  -c	./phgrreal.f90
gfortran  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -I. -I/usr/local/include -fdefault-real-8 -fopenmp -fconvert=big-endian  -c	./grphreal.f90
gfortran  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -I. -I/usr/local/include -fdefault-real-8 -fopenmp -fconvert=big-endian  -c	./ftrafo.f90
gfortran  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -I. -I/usr/local/include -fdefault-real-8 -fopenmp -fconvert=big-endian  -c	./calc_etadot.f90
gfortran  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -I. -I/usr/local/include -fdefault-real-8 -fopenmp -fconvert=big-endian  -c	./posnam.f90
gfortran rwgrib2.o calc_etadot.o ftrafo.o grphreal.o posnam.o phgrreal.o -o calc_etadot_fast.out  -O3  -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -L/usr/local/emos/lib -lemosR64 -fopenmp
ln -sf calc_etadot_fast.out calc_etadot

lrwxrwxrwx 1 guangzhi guangzhi 20 Mar 31 11:51 ./calc_etadot -> calc_etadot_fast.out

NOTE that this is different from installation guides in the documentation paper (Pisso et al. 2019). This version is likely more up-to-date because the Pisso et al. 2019 instructions use a install.py script which is still Python2.

The CONVERT2 executable is also not compiled using the new method. The makefile doesn’t specify such an EXE.

  1. test flex_extract
> cd Testing/Installation/Calc_etadot
# execute the Fortran progam without arguments
> ../../../Source/Fortran/calc_etadot
Installation is successful if the below is shown:

    STATISTICS:          98842.4598  98709.7359   5120.5385


  1. Hi GUANGZHI, your post has been really helpful as i have been having problems with FLEXPART installation for quite awhile. Can I ask for clarification on Trouble shooting 2 session for emoslib? I am not sure what was done to overcome the error “grib_get_error_message”
    Thank you so much!

    • Hi JIA HAO,

      In case you have not solved the issue, consider trying the following and see if it works.

      1. clear the build directory.
      2. set the LDFLAGS variable like so: export LDFLAGS="-leccodes" (if you are using bash shell).
      2b. (alternative to step 2, I’m not sure which is better but worth a try if step 2 doesn’t work): LDFLAGS="-L${ECCODES}/lib -leccodes", where ${ECCODES} is the eccodes installation location.
      3. (not sure this is necessary but for good measure just set it): export LD_LIBRARY_PATH="${ECCODES}/lib:$LD_LIBRARY_PATH". Again, ${ECCODES} is the eccodes installation location.
      4. run that long cmake command again.
      5. Hopefully it works.

Leave a Reply