FLEXPART安装笔记,ubantu,grib_api,eccodes,NetCDF

FLEXPART安装配置笔记
2021.09.06 
参考:https://blog.csdn.net/qq_34777982/article/details/112222088
#重中之重,一定要用18.04版的,我用20.04装了一个星期掉坑无数(旧包不能配最新的版本),安装ubuntu 18.04系统#使用完整的向导安装,参考 :https://www.cnblogs.com/liuqun/p/12655156.html,不能使用快捷方法,否则安装几个包后系统就无法启动,掉坑无数
遇到安装选择[Y/n]输入Y/,后面装包过程中遇到yes/no输入yes,遇到选择路径直接回车就行。
1.安装前准备
说明:
编译安装都安装到/usr/local
python3
pip3
ubantu18.04     
'''非常实用的技巧'''
一、使用sudo -s直接用root帐号编写,可以少写sudo
二、可以使用复制粘过去,避免输错,节省时间,ubantu系统用使用复制粘贴为ctr+shift+c和ctr+shift+v
 
系统配置
sudo apt-get update
sudo apt-get install g++ gfortran autoconf libtool automake flex bison cmake python3-dev python3-pip git vim curl build-essential libbz2-dev libssl-dev libreadline-dev libsqlite3-dev tk-dev ruby
 
安装依赖
apt-get install python3 (usually already available on GNU/Linux systems)
 apt-get install python3-eccodes
 apt-get install python3-genshi
 apt-get install python3-numpy
 apt-get install gfortran
 apt-get install fftw3-dev
 apt-get install libeccodes-dev
 apt-get install libemos-dev
 
pip3 install cdsapi
pip3 install ecmwf-api-client
 
#python3
# check in python3 console
import eccodes
import genshi
import numpy
import cdsapi
import ecmwfapi
 
2.安装jasper
 
cd /usr/local
wget http://www.ece.uvic.ca/~mdadams/jasper/software/jasper-1.900.1.zip
unzip jasper-1.900.1.zip
mkdir jasper
cd jasper-1.900.1
CFLAGS="-fPIC" ./configure --prefix=/usr/local/jasper
make
make check
make install
 
3.安装grib_api   #check段可能下载时间过长,有部分数据无法下载没有关系
https://links.jianshu.com/go?to=https%3A%2F%2Fpeople.freebsd.org%2F%7Esunpoet%2Fsunpoet%2Fgrib_api-1.28.0-Source.tar.gz
 
cd /usr/local
wget https://people.freebsd.org/~sunpoet/sunpoet/grib_api-1.28.0-Source.tar.gz
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
make check
make install
 
4.安装eccodes  #后面如出现 python3 -m eccodes selfcheck不能使用,没有关系。
 
wget https://software.ecmwf.int/wiki/download/attachments/45757960/eccodes-2.7.3-Source.tar.gz
tar xvzf eccodes-2.7.3-Source.tar.gz
mkdir eccodes
cd eccodes-2.7.3-Source
mkdir build && 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
export ECCODES_SAMPLES_PATH=$PATH:/usr/local/eccodes/share/eccodes/samples
export ECCODES_DEFINITION_PATH=$PATH:/usr/local/eccodes/share/eccodes/definitions
sudo apt-get install libeccodes-dev
python3 -m eccodes selfcheck
Found: ecCodes v2.6.0.
Your system is ready.
 
5.安装 NetCDF
 
sudo apt-get install libnetcdf-dev libnetcdff-dev
 
安装 zlib
v=1.2.8  
sudo wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/zlib-${v}.tar.gz
sudo tar -xf zlib-${v}.tar.gz && cd zlib-${v}
sudo ./configure --prefix=/usr/local
sudo make install
cd ..
 
安装 szlib
v=2.1
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/szip-${v}.tar.gz
tar -xf szip-${v}.tar.gz && cd szip-${v}
./configure --prefix=/usr/local/szip
make
make install
 
安装hdf5
v=1.8.13
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/hdf5-${v}.tar.gz
tar -xf hdf5-${v}.tar.gz && cd hdf5-${v}
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
 
./configure --enable-shared --enable-hl --prefix=$HDF5_DIR
make -j 2 # 2 for number of procs to be used
make install
cd ..
 
安装 netcdf-c
v=4.1.3
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-${v}.tar.gz
tar -xf netcdf-${v}.tar.gz && cd 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_DIR
make 
make install
cd ..
 
python Netcdf4 安装
# install python's netCDF4
pip3 install netcdf4 --upgrade
 
 
6.安装FLEXPART10.4
 
cd /usr/local
wget https://www.flexpart.eu/downloads/66
tar xvf 66
cd flexpart_v10.4_3d7eebf
 
cp -r src src2
cd src2
'''修改文件,直接复制覆盖原段'''
vi makefile
#modified to 
        ROOT_DIR = /usr/local
 
        F90       = /usr/bin/gfortran
        MPIF90    = /usr/bin/mpifort
         
        INCPATH1  = ${ROOT_DIR}/grib_api/include
        INCPATH2  = ${ROOT_DIR}/jasper/include
        INCPATH3 = /include
        LIBPATH1 = ${ROOT_DIR}/grib_api/lib
        LIBPATH2 = ${ROOT_DIR}/jasper/lib
        LIBPATH3 = /lib
### Enable netCDF output?
ifeq ($(ncf), yes)
        NCOPT = -DUSE_NCF -lnetcdff -lnetcdf
else
        NCOPT = -UUSE_NCF
endif
## 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)
 
make ncf=yes
export LD_LIBRARY_PATH=/usr/local/grib_api/lib:$LD_LIBRARY_PATH
 
 
7.安装flex_extract
 
cd /usr/local
git clone --single-branch --branch master https://www.flexpart.eu/gitmob/flex_extract
 
 
8.import eccodes 报错处理-安装zlib1.2.9
 
wget https://sourceforge.net/projects/libpng/files/zlib/1.2.9/zlib-1.2.9.tar.gz
tar -xvf zlib-1.2.9.tar.gz
cd zlib-1.2.9
sudo -s
./configure; make; make install
cd /lib/x86_64-linux-gnu
ln -s -f /usr/local/lib/libz.so.1.2.9/lib libz.so.1
cd ~
rm -rf zlib-1.2.9
 
9.install emoslib
 
cd /usr/local
mkdir emoslib
wget https://confluence.ecmwf.int/download/attachments/3473472/libemos-4.5.9-Source.tar.gz
tar -xzf libemos-4.5.9-Source.tar.gz
cd 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
 
10.安装ECMWFERA5安装权限
 
cd 
vim .ecmwfapirc
{
    "url"   : "https://api.ecmwf.int/v1",
    "key"   : "8fb37b516ba233bde068613a8f08c785",
    "email" : "791653827@qq.com"
}
vim .cdsapirc
url: {api-url}
key: {uid}:{api-key}
 
11.修改makefile_local_gfortran文件
 
cd /usr/local/flex_extract/Source/Fortran/makefile_local_gfortran
vi makefile_local_gfortran
# change the original path of ECCODES_INCLUDE_DIR to 
ECCODES_INCLUDE_DIR=/usr/include
 
12.修改makefile_local_gfortran文件
 
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_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 Nov 13 20:19 ./calc_etadot -> calc_etadot_fast.out
 
13.测试flex_extract
 
cd 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
 
 
 经过上面的安装flexpart的运行应该是没问题了
 但在flex_extract的下载上可能有问题,flex_extract可以下载并准备ECEI数据可用,经过研究要通过几个办法来解决。
 1.通过运行flex_extract里面的Run文件夹下的run_local.sh,发现eccode和gribapi这两个包版本不对,这两个包的代码是python2版的,确装在python3下,要替换一下。
 2.替换一下可以解决python代码下eccodes和gribapi运行的问题。但仍可能有缺少cffi的问题。
 3.pip3 install cffi。安装后看一下cffi的版本,可能是1.15.0版,这要和numpy的版本要对应上,numpy版本太高,这两又不兼容了,就要再降低numpy的版本.
 4.pip3 install findlibs
 5.安装fftw-3.3.10这个包,为什么装我忘了。解压后,新建一个fftw文件夹
 .configure --prefix=/usr/local/fftw
 make
 make install

 
参考:能看懂下面第一个比较重要
https://gmd.copernicus.org/articles/12/4955/2019/#section10
https://www.jianshu.com/p/6bc7cee6c9bf
https://www.jianshu.com/p/314f2a001aa8

<think>好的,我现在需要帮助用户找到FlexPart安装的方法或教程。首先,用户提到参考了两个引用,其中引用[1]是关于各种软件应用教程,可能包含FlexPart安装指南,但用户没有直接找到。引用[2]是关于PMF源解析技术的专家信息,可能与FlexPart无关。用户明确需要FlexPart安装步骤,可能需要从其他可靠来源获取信息。 FlexPart是用于大气传输和扩散模拟的软件,常用于气象和环境研究。安装步骤可能涉及依赖库的安装、源码编译等。通常,这类软件的官方文档或GitHub仓库会有详细指南。需要检查用户是否访问过FlexPart的官方网站或GitHub页面。例如,官方文档可能要求安装ECMWF的库、GRIB API、Jasper等依赖项。用户可能需要使用wget或git下载源码,并按照步骤配置和编译。 另外,用户可能需要安装Fortran编译器和MPI库,如gfortran和OpenMPI。安装步骤可能包括设置环境变量,运行make命令等。常见问题可能包括依赖项缺失或路径配置错误,需指导用户检查错误信息,安装缺失的包,并确保所有路径正确。 考虑到用户可能需要具体步骤,应分步说明,并提醒注意事项,如权限问题、依赖版本兼容性等。同时,建议用户参考官方资源或社区支持,如GitHub的issue页面或相关论坛,以解决安装中的问题。 最后,生成的相关问题应涵盖依赖项、配置编译、测试安装、常见错误和替代方案,帮助用户全面了解安装过程及后续使用。</think>### FlexPart安装指南 FlexPart是用于大气传输模拟的开源软件,常用于污染物扩散或粒子轨迹追踪研究。以下是安装步骤及注意事项: --- #### **1. 安装依赖库** FlexPart依赖多个科学计算库,需提前配置: - **ECMWF Libraries**:包括`eccodes`和`emoslib`,用于处理气象数据格式 ```bash # 示例安装eccodes wget https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.30.0-Source.tar.gz tar -xzf eccodes-2.30.0-Source.tar.gz cd eccodes-2.30.0-Source mkdir build && cd build cmake .. make sudo make install ``` - **NetCDF库**:用于数据存储 - **Jasper**:处理GRIB2格式图像压缩 - **Fortran编译器**:如`gfortran`或`Intel Fortran` --- #### **2. 获取FlexPart源码** 从官方GitHub仓库克隆代码: ```bash git clone https://github.com/Flexpart/flexpart.git cd flexpart/src ``` --- #### **3. 配置与编译** - **修改Makefile**:根据系统环境设置编译器路径和库路径 ```makefile F90 = gfortran LIB_PATH = -L/usr/local/eccodes/lib INC_PATH = -I/usr/local/eccodes/include ``` - **执行编译**: ```bash make clean make all ``` 成功后会生成可执行文件`flexpart`[^1]。 --- #### **4. 测试安装** 运行示例案例验证安装: ```bash cd ../examples ./run_test_case.sh ``` 若输出轨迹文件且无报错,则安装成功[^2]。 --- #### **常见问题** 1. **依赖库缺失**:编译时报错`undefined reference`,需检查`eccodes`或`netcdf`路径 2. **权限问题**:安装系统级库时使用`sudo` 3. **版本冲突**:确保`gfortran`版本≥9.0 ---
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值