2023年10月29日
环境说明
操作系统版本:ubuntu 18.04
python版本:3.6.9
gcc版本:7.5.0
编译安装路径:/usr/local
cmake: 3.10.2
所需要的源码包我已经打包放到我的资源。
2021年1月份已经写过一篇Ubuntu 编译安装的帖子FLEXPART安装配置笔记(成功案例)——筑梦之路_筑梦之路的博客-CSDN博客
也遇到比较多的网友来咨询在编译安装过程中的问题,因此今天再次整理一下编译安装的过程,顺便解决之前写的不是很明确的地方,欢迎大家交流指正。
准备编译工作
# 更新软件源
sudo apt-get update# 安装编译工具和依赖包
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# 安装python相关包sudo apt-get install -y python3 python3-eccodes python3-genshi python3-numpy gfortran fftw3-dev libeccodes-dev libemos-dev# 配置pip显示的格式sudo mkdir ~/.pipsudo cat > ~/.pip/pip.conf << EOF
[list]
format=columns
EOF# 建立软链接sudo ln -sf /usr/bin/python3 /usr/bin/python
sudo ln -sf /usr/bin/pip3 /usr/bin/pip# 检查sudo python -V
sudo pip -V
准备python环境
# 安装pip的包sudo pip3 install cdsapi ecmwf-api-client eccodes==1.6.1 -i https://pypi.douban.com/simple#检查是否安装成功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__)"
编译安装
1. 编译安装jasper
# 下载源码包wget -c http://www.ece.uvic.ca/~mdadams/jasper/software/jasper-1.900.1.zip# 解压文件到指定目录unzip jasper-1.900.1.zip -d /usr/local/# 新建目录mkdir -p /usr/local/jasper# 切换目录cd /usr/local/jasper-1.900.1# 配置CFLAGS="-fPIC" ./configure --prefix=/usr/local/jasper# 编译
make# 编译检查
make check# 安装
make install
2. 编译安装grib_api
# 下载源码wget -c https://people.freebsd.org/~sunpoet/sunpoet/grib_api-1.28.0-Source.tar.gz# 解压到指定目录tar -zxvf grib_api-1.28.0-Source.tar.gz -C /usr/local/# 创建目录mkdir -p /usr/local/grib_api# 切换目录cd /usr/local/grib_api-1.28.0-Source# 编译三部曲./configure --prefix=/usr/local/grib_api --with-jasper=/usr/local/jaspermakemake checkmake install
3. 编译安装eccodes
# 下载源码wget -c https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.7.3-Source.tar.gz?api=v2# 解压源码到指定目录tar xvzf eccodes-2.7.3-Source.tar.gz -C /usr/local/# 创建目录mkdir -p /usr/local/eccodes# 切换目录cd /usr/local/eccodes-2.7.3-Source# 编译三部曲mkdir build && cd buildcmake -DCMAKE_INSTALL_PREFIX=/usr/local/eccodes /usr/local/eccodes-2.7.3-Source -DPYTHON_EXECUTABLE=/usr/bin/python3makectestmake install# 配置环境变量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
EOFsource /etc/profile# 检查验证sudo apt-get install libeccodes-dev
python3 -m eccodes selfcheck# 正常输出如下:
Found: ecCodes v2.6.0.
Your system is ready.
4. 编译安装zlib
# 下载源码v=1.2.8 sudo wget http://www.zlib.net/fossils/zlib-${v}.tar.gz# 解压到指定目录sudo tar -xf zlib-${v}.tar.gz -C /usr/local/ && cd /usr/local/zlib-${v}# 编译三部曲sudo ./configure --prefix=/usr/localsudo make && make install
5. 编译安装 szlib
# 下载源码v=2.1
wget http://sources.buildroot.net/szip/szip-${v}.tar.gz# 解压到指定目录tar -xf szip-${v}.tar.gz -C /usr/local/cd /usr/local/szip-${v} && mkdir -p /usr/local/szip# 编译三部曲./configure --prefix=/usr/local/szip
make
make install
6. 编译安装hdf5
# 下载源码v=1.8.13wget https://www.gfd-dennou.org/arch/ucar/netcdf/netcdf-4/hdf5-${v}.tar.gz# 解压到指定目录tar -xf hdf5-${v}.tar.gz -C /usr/local/ && cd /usr/local/hdf5-${v}# 设置变量prefix="/usr/local/hdf5-$v"echo "Add HDF5_DIR=$prefix to .bashrc"echo "" >> ~/.bashrcecho "# HDF5 libraries for python" >> ~/.bashrcecho export HDF5_DIR=$prefix >> ~/.bashrc# 编译三部曲./configure --enable-shared --enable-hl --prefix=$HDF5_DIRmake -j 2 # 2 for number of procs to be usedmake install
7. 编译安装netcdf-c
# 下载源码v=4.1.3wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/netcdf-${v}.tar.gz# 解压到指定目录tar -xf netcdf-${v}.tar.gz -C /usr/local/ && cd /usr/local/netcdf-${v}# 设置变量prefix="/usr/local/"echo "Add NETCDF4_DIR=$prefix to .bashrc"
echo "" >> ~/.bashrc
echo "# NETCDF4 libraries for python" >> ~/.bashrc
echo export NETCDF4_DIR=$prefix >> ~/.bashrc# 编译三部曲CPPFLAGS=-I$HDF5_DIR/include LDFLAGS=-L$HDF5_DIR/lib ./configure --enable-netcdf-4 --enable-shared --enable-dap --prefix=$NETCDF4_DIRmake
make install
8. python Netcdf4 安装
# install python's netCDF4sudo pip3 install cftime==1.3.1 -i https://pypi.douban.com/simplesudo pip3 install numpy==1.19.4 -i https://pypi.douban.com/simplesudo pip3 install netCDF4==1.5.5.1 -i https://pypi.douban.com/simplesudo python3 -c "import netCDF4;print(netCDF4.__version__)"
9. 编译安装FLEXPART10.4
# 下载源码wget -c https://www.flexpart.eu/downloads/66# 解压到指定目录tar -xvf 66 -C /usr/local/ # 切换目录cd /usr/local/flexpart_v10.4_3d7eebf# 备份src目录cp -r src src-backup-`date +%F`# 修改makefile文件vim makefile#### 修改第一处#modified to 64-73行ROOT_DIR = /usr/localF90 = /usr/bin/gfortranMPIF90 = /usr/bin/mpifortINCPATH1 = ${ROOT_DIR}/grib_api/includeINCPATH2 = ${ROOT_DIR}/jasper/includeINCPATH3 = /includeLIBPATH1 = ${ROOT_DIR}/grib_api/libLIBPATH2 = ${ROOT_DIR}/jasper/libLIBPATH3 = /lib#### 修改第二处### Enable netCDF output?
ifeq ($(ncf), yes)NCOPT = -DUSE_NCF -lnetcdff -lnetcdf
elseNCOPT = -UUSE_NCF
endif#### 修改第三处## LIBRARIES
LIBS = -lgrib_api_f90 -lgrib_api -lm -ljasper $(NCOPT) -lnetcdffFFLAGS = -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=nativeDBGFLAGS = -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=allLDFLAGS = $(FFLAGS) -L$(LIBPATH1) -Wl,-rpath,$(LIBPATH1) $(LIBS) -L$(LIBPATH2) -L$(LIBPATH3)
LDDEBUG = $(DBGFLAGS) -L$(LIBPATH1) $(LIBS) -L$(LIBPATH2) -L$(LIBPATH3)# 编译make ncf=yes# 配置环境变量
cat >> /etc/profile <<'EOF'
export LD_LIBRARY_PATH=/usr/local/grib_api/lib:$LD_LIBRARY_PATH
EOFsource /etc/profile
10. 准备安装flex_extract
# 拉取源码cd /usr/localgit clone --single-branch --branch master https://www.flexpart.eu/gitmob/flex_extract
1)编译安装zlib 1.2.9
# 下载zlib 1.2.9源码,编译安装zlib 1.2.9版本wget https://sourceforge.net/projects/libpng/files/zlib/1.2.9/zlib-1.2.9.tar.gz# 解压到指定目录tar -zxvf zlib-1.2.9.tar.gz -C /usr/localcd /usr/local/zlib-1.2.9# 编译三部曲./configure; make; make install# 创建软链接ln -s -f /usr/local/lib/libz.so.1.2.9 /lib/x86_64-linux-gnu/libz.so.1
2) 编译安装emoslib
# 下载源码wget https://confluence.ecmwf.int/download/attachments/3473472/libemos-4.5.9-Source.tar.gz# 创建目录mkdir /usr/local/emoslib# 解压到指定目录tar -xzf libemos-4.5.9-Source.tar.gz -C /usr/local/# 切换目录cd /usr/local/libemos-4.5.9-Source# 编译安装mkdir build ; cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/emoslib /usr/local/libemos-4.5.9-Source
make
make install
3)安装ECMWF 与ERA5安装权限
cat > ~/.ecmwfapirc <<EOF
{"url" : "https://api.ecmwf.int/v1","key" : "8fb37b516ba233bde068613a8f08c785","email" : "791653827@qq.com"
}
EOFcat > ~/.cdsapirc <<EOF
url: {api-url}
key: {uid}:{api-key}
EOF
4) 修改makefile_local_gfortran文件
# 切换目录cd /usr/local/flex_extract/Source/Fortran/# 修改文件vim makefile_local_gfortran# change the original path of ECCODES_INCLUDE_DIR to
ECCODES_INCLUDE_DIR=/usr/include
5) 执行安装flex_extract
# 切换目录cd /usr/local/flex_extract# 执行安装./setup_local.sh#成功结果输出如下内容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_extractUsing 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_etadotlrwxrwxrwx 1 root root 20 Oct 29 06:30 ./calc_etadot -> calc_etadot_fast.out
6)测试flex_extract
# 测试flex_extractcd Testing/Installation/Calc_etadot
# execute the Fortran progam without arguments
../../../Source/Fortran/calc_etadot#成功结果展示:
STATISTICS: 98842.4598 98709.7359 5120.5385
STOP SUCCESSFULLY FINISHED calc_etadot: CONGRATULATIONS
至此,已经全部编译安装完成,并测试成功。
这里附上python包的版本信息,以供各位参考:
# 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
如果不关心flexpart的版本,可以直接使用apt-get命令安装
apt-get update && apt-get install flexpart
相关源码包在我的资源或者通过文中链接地址下载。
注意事项:文中源码包的地址会随着时间过期,若不能下载请自行搜索相关版本文件。