两年前我刚接触WRF-Chem,被各种环境配置所扰,通过各种查阅资料才顺利配置WRF-Chem的环境并运行,中间走了很多弯路,所以写这篇博客的目的主要是希望刚入门WRF-Chem的同学不要被环境配置以及安装等流程所扰,后续也会推出WRF-Chem运行等具体步骤。
PS:若大家采用的是gfortran,环境配置以及WRF安装可参考我的另两篇博客《环境配置与SMOKE安装》以及基于gfortran的WRF安装,本博客主要是基于ifort编译器的环境配置以及WRF-Chem安装
Linux:RedHat
fortran编译器:ifort
WRFV4
WPSV4
CHEMV4
WRF-Chem需要的依赖库如下:
链接:https://pan.baidu.com/s/13PtUj0V5ttzdN9dbau3opA?pwd=0vmp
提取码:0vmp
–来自百度网盘超级会员V6的分享
vim ~/.bashrc
# env
#####
export CC=icc
export FC=ifort
export CXX=icpc
export CPPFLAGS='-fPIC'
export FCFLAGS='-fPIC'
export CXXFLAGS='-fPIC'
export NETCDF=/home/gonghaixing/netcdf
export PATH=$NETCDF/bin:$PATH
export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH
export CPPFLAGS='-I/home/gonghaixing/netcdf/include'
export LDFLAGS='-L/home/gonghaixing/netcdf/lib'
export NETCDF_ROOT=/home/gonghaixing/netcdf
export NCARG_ROOT=/home/gonghaixing/netcdf
export JASPERLIB=/home/gonghaixing/netcdf/lib
export JASPERINC=/home/gonghaixing/netcdf/include
#####
source ~/.bashrc
首先在home目录下创建一个LIBRARIES文件夹用来存放安装包软件
cd ~
mkdir LIBRARIES
cd LIBRARIES
cd /home/gonghaixing/LIBRARIES
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure --prefix=/home/gonghaixing/netcdf
make
make check
make install
cd ..
tar -zxvf szip-2.1.1.tar.gz
cd szip-2.1.1/
./configure --enable-shared --prefix=/home/gonghaixing/netcdf
make
make check
make install
cd ..
tar -zxvf hdf5-1.8.13.tar.gz
cd hdf5-1.8.13/
./configure --prefix=/home/gonghaixing/netcdf --with-zlib=/home/gonghaixing/netcdf
make # 这个时间会很长
make check
make install
cd ..
tar -zxvf netcdf-4.3.2.tar.gz
cd netcdf-4.3.2/
./configure --prefix=/home/gonghaixing/netcdf --disable-dap
make
make check
make install
cd ..
tar -zxvf netcdf-cxx4-4.3.0.tar.gz
cd netcdf-cxx4-4.3.0/
./configure --enable-shared --prefix=/home/gonghaixing/netcdf
make
make check
make install
cd ..
tar -zxvf netcdf-fortran-4.4.0.tar.gz
cd netcdf-fortran-4.4.0/
./configure --prefix=/home/gonghaixing/netcdf
make
make check
make install
nc-config --all
nf-config --all
cd ..
tar -zxvf jasper-1.900.1.tar.gz
cd jasper-1.900.1
./configure --enable-shared --prefix=/home/gonghaixing/netcdf
make
make install
cd ..
tar -zxvf libpng-1.2.50.tar.gz
cd libpng-1.2.50
./configure --enable-shared --prefix=/home/gonghaixing/netcdf
make
make install
cd /home/gonghaixing/TESTS/
wget http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_NETCDF_MPI_tests.tar
tar -xvf Fortran_C_NETCDF_MPI_tests.tar
# Test 1: Fortran + C + NetCDF
cp ${NETCDF}/include/netcdf.inc .
ifort -c 01_fortran+c+netcdf_f.f
icc -c 01_fortran+c+netcdf_c.c
ifort 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o -L${NETCDF}/lib -lnetcdff -lnetcdf
./a.out
# Test 2: Fortran + C + NetCDF + MPI
cp ${NETCDF}/include/netcdf.inc .
mpif90 -c 02_fortran+c+netcdf+mpi_f.f
mpicc -c 02_fortran+c+netcdf+mpi_c.c
mpif90 02_fortran+c+netcdf+mpi_f.o 02_fortran+c+netcdf+mpi_c.o -L/home/gonghaixing/netcdf/lib -lnetcdff -lnetcdf
mpirun -np 2 ./a.out
# WRF-Chem
export EM_CORE=1
export NMM_CORE=0
export WRF_CHEM=1
export WRF_KPP=1
export WRF_DA_CORE=0
cd /home/gonghaixing/WRF-Chem
tar -zxvf WPS.tar.gz
tar -zxvf WRF.tar.gz
# 将解压后的文件改名为WRF,去除后缀
cd WRF/
# 选择编译器
./configure
Enter selection [1-75] :15
Compile for nesting? (1=basic, 2=preset moves, 3=vortex following) [default 1]:1
# 修改文件
vi configure.wrf
154 DM_FC = mpiifort
155 DM_CC = mpiicc
./compile em_real > compile.log 2>&1 &
# 要命sos,这个跑了一个半小时
./compile emi_conv >& convert.log &
cd /home/gonghaixing/WRF-Chem/WPS-4.1
./configure
Enter selection [1-40] : 17
./compile >& compile.log &
ls *.exe
至此,WRF-ChemV4编译成功
参考:
[1] WRF官网
[2] 气象家园博客