Compile and install flexpart 10.4 on ubuntu 18.04 (2023) – the road to building dreams

October 29, 2023

Environmental description

Operating system version: ubuntu 18.04

https://mirrors.aliyun.com/ubuntu-releases/bionic/ubuntu-18.04.6-live-server-amd64.iso

python version: 3.6.9

gcc version: 7.5.0

Compilation installation path:/usr/local

cmake: 3.10.2

I have packaged the required source code packages and put them in my resources.

In January 2021, I have already written a post about Ubuntu compilation and installation. FLEXPART installation and configuration notes (successful case) – The Road to Dreaming_The Blog of Building Dreams-CSDN Blog

I have also encountered a lot of netizens coming to inquire about problems during the compilation and installation process, so today I will sort out the compilation and installation process again, and by the way solve the things that were not very clear in what I wrote before. Welcome everyone to share and make corrections.

Preparing for compilation

# Update software source
sudo apt-get update

#Install compilation tools and dependency packages
sudo apt-get install -y g + + gfortran autoconf libtool automake flex bison cmake python3-dev python3-pip git vim curl unzip build-essential libbz2-dev libssl-dev libreadline-dev libsqlite3-dev tk-dev ruby


#Install python related packages

sudo apt-get install -y python3 python3-eccodes python3-genshi python3-numpy gfortran fftw3-dev libeccodes-dev libemos-dev


# Configure the format displayed by pip

sudo mkdir ~/.pip

sudo cat > ~/.pip/pip.conf << EOF
[list]
format=columns
EOF

# Create soft link

#sudo ln -sf /usr/bin/python3 /usr/bin/python
#sudo ln -sf /usr/bin/pip3 /usr/bin/pip

# examine

#sudo python -V
#sudo pip -V

Prepare python environment

# Install pip package

sudo pip3 install cdsapi ecmwf-api-client eccodes==1.6.1 -i https://pypi.douban.com/simple
 
#Check if the installation is successful

sudo python3 -c "import eccodes; print(eccodes.__version__)"
sudo python3 -c "import genshi; print(genshi.__version__)"
sudo python3 -c "import numpy; print(numpy.__version__)"
sudo pip3 list | grep cdsapi | awk '{print $2}'
sudo python3 -c "import ecmwfapi; print(ecmwfapi.__version__)"

Compile and install

1. Compile and install jasper

# Download source code package

wget -c http://www.ece.uvic.ca/~mdadams/jasper/software/jasper-1.900.1.zip

# Unzip the file to the specified directory

unzip jasper-1.900.1.zip -d /usr/local/

# Create new directory

mkdir -p /usr/local/jasper

# Switch directory

cd /usr/local/jasper-1.900.1

#Configuration

CFLAGS="-fPIC" ./configure --prefix=/usr/local/jasper

# compile
make

# Compilation check
make check

# Install
make install

2. Compile and install grib_api

# Download source code

wget -c https://people.freebsd.org/~sunpoet/sunpoet/grib_api-1.28.0-Source.tar.gz

#Extract to the specified directory

tar -zxvf grib_api-1.28.0-Source.tar.gz -C /usr/local/

# Create a directory

mkdir -p /usr/local/grib_api

# Switch directory

cd /usr/local/grib_api-1.28.0-Source

# Compile the trilogy

./configure --prefix=/usr/local/grib_api --with-jasper=/usr/local/jasper

make

make check

make install

3. Compile and install eccodes

# Download source code

wget -c https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.7.3-Source.tar.gz?api=v2

# Unzip the source code to the specified directory

tar xvzf eccodes-2.7.3-Source.tar.gz -C /usr/local/

# Create a directory

mkdir -p /usr/local/eccodes

# Switch directory

cd /usr/local/eccodes-2.7.3-Source

# Compile the trilogy

mkdir build & amp; & amp; cd build

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/eccodes /usr/local/eccodes-2.7.3-Source -DPYTHON_EXECUTABLE=/usr/bin/python3

make

ctest

make install

# Configure environment variables

cat >> /etc/profile << 'EOF'
export ECCODES_SAMPLES_PATH=$PATH:/usr/local/eccodes/share/eccodes/samples
export ECCODES_DEFINITION_PATH=$PATH:/usr/local/eccodes/share/eccodes/definitions
EOF

source /etc/profile

# Check verification

sudo apt-get install libeccodes-dev
python3 -m eccodes selfcheck

#Normal output is as follows:
Found: ecCodes v2.6.0.
Your system is ready.

4. Compile and install zlib

# Download source code

v=1.2.8

sudo wget http://www.zlib.net/fossils/zlib-${v}.tar.gz

#Extract to the specified directory

sudo tar -xf zlib-${v}.tar.gz -C /usr/local/ & amp; & amp; cd /usr/local/zlib-${v}

# Compile the trilogy

sudo ./configure --prefix=/usr/local

sudo make & amp; & amp; make install

5. Compile and install szlib

# Download source code

v=2.1
wget http://sources.buildroot.net/szip/szip-${v}.tar.gz

#Extract to the specified directory

tar -xf szip-${v}.tar.gz -C /usr/local/

cd /usr/local/szip-${v} & amp; & amp; mkdir -p /usr/local/szip

# Compile the trilogy

./configure --prefix=/usr/local/szip
make
make install

6. Compile and install hdf5

# Download source code

v=1.8.13

wget https://www.gfd-dennou.org/arch/ucar/netcdf/netcdf-4/hdf5-${v}.tar.gz

#Extract to the specified directory

tar -xf hdf5-${v}.tar.gz -C /usr/local/ & amp; & amp; cd /usr/local/hdf5-${v}

# Set variables

prefix="/usr/local/hdf5-$v"
 
echo "Add HDF5_DIR=$prefix to .bashrc"

echo "" >> ~/.bashrc

echo "# HDF5 libraries for python" >> ~/.bashrc

echo export HDF5_DIR=$prefix >> ~/.bashrc

# Compile the trilogy
 
./configure --enable-shared --enable-hl --prefix=$HDF5_DIR

make -j 2 # 2 for number of procs to be used

make install

7. Compile and install netcdf-c

# Download source code

v=4.1.3

wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/netcdf-${v}.tar.gz

#Extract to the specified directory

tar -xf netcdf-${v}.tar.gz -C /usr/local/ & amp; & amp; cd /usr/local/netcdf-${v}

# Set variables

prefix="/usr/local/"
 
echo "Add NETCDF4_DIR=$prefix to .bashrc"
echo "" >> ~/.bashrc
echo "#NETCDF4 libraries for python" >> ~/.bashrc
echo export NETCDF4_DIR=$prefix >> ~/.bashrc

# Compile the trilogy

CPPFLAGS=-I$HDF5_DIR/include LDFLAGS=-L$HDF5_DIR/lib ./configure --enable-netcdf-4 --enable-shared --enable-dap --prefix=$NETCDF4_DIR

make
make install

8. python Netcdf4 installation

# install python's netCDF4

sudo pip3 install cftime==1.3.1 -i https://pypi.douban.com/simple

sudo pip3 install numpy==1.19.4 -i https://pypi.douban.com/simple

sudo pip3 install netCDF4==1.5.5.1 -i https://pypi.douban.com/simple

sudo python3 -c "import netCDF4;print(netCDF4.__version__)"
 

9. Compile and install FLEXPART10.4

# Download source code

wget -c https://www.flexpart.eu/downloads/66

#Extract to the specified directory

tar -xvf 66 -C /usr/local/

# Switch directory

cd /usr/local/flexpart_v10.4_3d7eebf

# Back up src directory

cp -r src src-backup-`date + %F`

cd src

# Modify the makefile

vim makefile

#### Modify the first part

#modified to lines 64-73
        ROOT_DIR = /usr/local
 
        F90 = /usr/bin/gfortran
        MPIF90 = /usr/bin/mpifort
         
        INCPATH1 = ${ROOT_DIR}/grib_api/include
        INCPATH2 = ${ROOT_DIR}/jasper/include
        INCPATH3 = ${ROOT_DIR}/include
        LIBPATH1 = ${ROOT_DIR}/grib_api/lib
        LIBPATH2 = ${ROOT_DIR}/jasper/lib
        LIBPATH3 = ${ROOT_DIR}/lib

#### The second modification

### Enable netCDF output?
ifeq ($(ncf), yes)
        NCOPT = -DUSE_NCF -lnetcdff -lnetcdf
else
        NCOPT = -UUSE_NCF
endif

#### Modify the third part

## LIBRARIES
LIBS = -lgrib_api_f90 -lgrib_api -lm -ljasper $(NCOPT) -lnetcdff
 
FFLAGS = -I$(INCPATH1) -I$(INCPATH2) -I$(INCPATH3) -O$(O_LEV) -g -cpp -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -fmessage -length=0 -flto=jobserver -O$(O_LEV) $(NCOPT) $(FUSER) #-Warray-bounds -fcheck=all # -march=native
 
DBGFLAGS = -I$(INCPATH1) -I$(INCPATH2) -I$(INCPATH3) -O$(O_LEV_DBG) -g3 -ggdb3 -cpp -m64 -mcmodel=medium -fconvert=little-endian -frecord-marker=4 -fmessage-length=0 -flto=jobserver -O$(O_LEV_DBG) $(NCOPT) -fbacktrace -Wall -fdump-core $(FUSER) # -ffpe-trap=invalid,overflow,denormal,underflow,zero -Warray- bounds -fcheck=all
 
LDFLAGS = $(FFLAGS) -L$(LIBPATH1) -Wl,-rpath,$(LIBPATH1) $(LIBS) -L$(LIBPATH2) -L$(LIBPATH3)
LDDEBUG = $(DBGFLAGS) -L$(LIBPATH1) $(LIBS) -L$(LIBPATH2) -L$(LIBPATH3)


# compile

make ncf=yes

# Configure environment variables
cat >> /etc/profile <<'EOF'
export LD_LIBRARY_PATH=/usr/local/grib_api/lib:$LD_LIBRARY_PATH
EOF

source /etc/profile

echo "/usr/local/lib" > /etc/ld.so.conf.d/test.conf

ldconfig 

10. Prepare to install flex_extract

# Pull source code

cd /usr/local

git clone --single-branch --branch master https://www.flexpart.eu/gitmob/flex_extract

1) Compile and install zlib 1.2.9

# Download zlib 1.2.9 source code, compile and install zlib 1.2.9 version

wget https://sourceforge.net/projects/libpng/files/zlib/1.2.9/zlib-1.2.9.tar.gz

#Extract to the specified directory

tar -zxvf zlib-1.2.9.tar.gz -C /usr/local

cd /usr/local/zlib-1.2.9

# Compile the trilogy

./configure; make; make install

#Create soft link

ln -s -f /usr/local/lib/libz.so.1.2.9 /lib/x86_64-linux-gnu/libz.so.1

2) Compile and install emoslib

# Download source code

wget https://confluence.ecmwf.int/download/attachments/3473472/libemos-4.5.9-Source.tar.gz

# Create a directory

mkdir /usr/local/emoslib

#Extract to the specified directory

tar -xzf libemos-4.5.9-Source.tar.gz -C /usr/local/

# Switch directory

cd /usr/local/libemos-4.5.9-Source

#Compile and install

mkdir build; cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/emoslib /usr/local/libemos-4.5.9-Source
make
make install

3) Install ECMWF and ERA5 installation permissions

cat > ~/.ecmwfapirc <<EOF
{
    "url" : "https://api.ecmwf.int/v1",
    "key" : "8fb37b516ba233bde068613a8f08c785",
    "email" : "[email protected]"
}
EOF


cat > ~/.cdsapirc <<EOF
url: {api-url}
key: {uid}:{api-key}
EOF

4) Modify the makefile_local_gfortran file

# Switch directory

cd /usr/local/flex_extract/Source/Fortran/

# Modify files

vim makefile_local_gfortran

# change the original path of ECCODES_INCLUDE_DIR to
ECCODES_INCLUDE_DIR=/usr/include

5) Execute installation flex_extract

# Switch directory

cd /usr/local/flex_extract

# Execute installation

./setup_local.sh

#The successful result output is as follows

WARNING: installdir has not been specified
flex_extract will be installed in here by compiling the Fortran source in /usr/local/flex_extract/Source/Fortran
Install flex_extract_v7.1.2 software at local in directory /usr/local/flex_extract

Using makefile: makefile_local_gfortran
gfortran -O3 -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -lemosR64 -I. -I/usr/include -fdefault-real-8 -fopenmp -fconvert=big-endian -c ./rwgrib2.f90
gfortran -O3 -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -lemosR64 -I. -I/usr/include -fdefault-real-8 -fopenmp -fconvert=big-endian -c ./phgrreal.f90
gfortran -O3 -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -lemosR64 -I. -I/usr/include -fdefault-real-8 -fopenmp -fconvert=big-endian -c ./grphreal.f90
gfortran -O3 -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -lemosR64 -I. -I/usr/include -fdefault-real-8 -fopenmp -fconvert=big-endian -c ./ftrafo.f90
gfortran -O3 -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -lemosR64 -I. -I/usr/include -fdefault-real-8 -fopenmp -fconvert=big-endian -c ./calc_etadot.f90
gfortran -O3 -Bstatic -leccodes_f90 -leccodes -Bdynamic -lm -lemosR64 -I. -I/usr/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 -lemosR64 -fopenmp
ln -sf calc_etadot_fast.out calc_etadot

lrwxrwxrwx 1 root root 20 Oct 29 06:30 ./calc_etadot -> calc_etadot_fast.out

6) Test flex_extract

# Test flex_extract

cd Testing/Installation/Calc_etadot
# execute the Fortran progam without arguments
../../../Source/Fortran/calc_etadot
 
#Successful result display:
STATISTICS: 98842.4598 98709.7359 5120.5385
STOP SUCCESSFULLY FINISHED calc_etadot: CONGRATULATIONS

At this point, all compilation and installation have been completed, and the test has been successful.

The version information of the python package is attached here for your reference:

# pip list
Package Version
----------------------- ------------------
asn1crypto 0.24.0
attrs 17.4.0
Automat 0.6.0
blinker 1.4
cdsapi 0.6.1
certifi 2018.1.18
cffi 1.15.1
cftime 1.3.1
chardet 3.0.4
click 6.7
cloud-init 23.1.2
colorama 0.3.7
command-not-found 0.3
configobj 5.0.6
constantly 15.1.0
cryptography 2.1.4
distro-info 0.18ubuntu0.18.04.1
eccodes 1.6.1
ecmwf-api-client 1.6.3
findlibs 0.0.5
Genshi 0.7
httplib2 0.9.2
hyperlink 17.3.1
idna 2.6
importlib-resources 5.4.0
incremental 16.10.1
Jinja2 2.10
jsonpatch 1.16
jsonpointer 1.10
jsonschema 2.6.0
keyring 10.6.0
keyrings.alt 3.0
language-selector 0.1
MarkupSafe 1.0
netCDF4 1.5.5.1
netifaces 0.10.4
numpy 1.19.5
oauthlib 2.0.6
PAM 0.4.2
pexpect 4.2.1
pip 9.0.1
pyasn1 0.4.2
pyasn1-modules 0.2.1
pycparser 2.21
pycrypto 2.6.1
pygobject 3.26.1
PyJWT 1.5.3
pyOpenSSL 17.5.0
pyserial 3.4
python-apt 1.6.5 + ubuntu0.7
python-debian 0.1.32
pyxdg 0.25
PyYAML 3.12
requests 2.18.4
requests-unixsocket 0.1.5
SecretStorage 2.3.1
service-identity 16.0.0
setuptools 39.0.1
six 1.11.0
sos 4.3
ssh-import-id 5.7
systemd-python 234
tqdm 4.64.1
Twisted 17.9.0
ubuntu-advantage-tools 27.2
ufw 0.36
unattended-upgrades 0.1
urllib3 1.22
wheel 0.30.0
zipp 3.6.0
zope.interface 4.3.2

If you don’t care about the version of flexpart, you can directly use the apt-get command to install it.

apt-get update & amp; & amp; apt-get install flexpart

The relevant source code package can be downloaded from my resources or through the link address in the article.

Note: The address of the source code package in this article will expire over time. If you cannot download it, please search for the relevant version file yourself.

https://v.youku.com/v_show/id_XNjEyOTMyMDc4NA==.html

View the python version in the source code flex_extract:

Check the python version in the flexpart source code:

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Cloud native entry-level skills treeHomepageOverview 16822 people are learning the system