WRF 的安装其实没有什么难点,主要是依赖库比较繁琐,还有两个用的比较多的 chem 和 hydro,我在安装的时候在网上找的教程都不尽如人意,所以在这里总结一下
#安装依赖库 Zlib netCDF HDF5 Libpng Jasper
#例如在local文件夹下
$ mkdir Zlib netCDF HDF5 Libpng Jasper
# 安装Zlib
$ tar zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure --prefix=/local/Zlib
$ make && make install
#安装HDF5
$ tar zxvf hdf5-1.10.5.tar.gz
$ cd hdf5-1.10.5
$ ./configure --prefix=/local/HDF5 --enable-fortran --enable-fortran2003
#不过根据官方文档的说法,似乎两个选项同时存在的时候,只有--enable-fortran2003生效
$ make
$ make install
#安装netCDF
$ tar zxvf netcdf-4.1.3.tar.gz
$ cd netcdf-4.1.3
$ ./configure --prefix=/local/netCDF --disable-netcdf-4 --disable-shared --disable-dap CC=icc CXX=icpc FC=ifort F77=ifort
$ make
$ make install
#安装Libpng
$ tar -zxvf libpng-1.2.12.tar.gz
$ cd libpng-1.2.12
$ ./configure --prefix=/local/Libpng CC=icc CXX=icpc F77=ifort
$ make
$ make install
#安装Jasper
$ tar -zxvf jasper-1.701.0.tar.gz
$ cd jasper-1.701.0
$ ./configure --prefix=/local/Jasper CC=icc CXX=icpc F77=ifort
$ make
$ make install
$ vim ~/.bashrc #添加以下内容
#for netcdf
export NETCDF=/local/netCDF
export PATH=$NETCDF/bin:$PATH
export LD_LIBRARY=$NETCDF/lib:$LD_LIBRARY_PATH
export INCLUDE=${NETCDF}/include:$INCLUDE
#for hdf5
export HDF5=/local/HDF5
export PATH=$PATH:$HDF5/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HDF5/lib
#for zlib
export ZLIB_HOME=/local/Zlib
export LD_LIBRARY_PATH=$ZLIB_HOME/lib:$LD_LIBRARY_PATH
#for libpng
export LIBPNG_HOME=/local/Libpng
export PATH=/local/Libpng/bin:$PATH
export LD_LIBRARY_PATH=${LIBPNG_HOME}/lib:$LD_LIBRARY_PATH
export MANPATH=${LIBPNG_HOME}/share/man:$MANPATH
export LIBPNGLIB=${LIBPNG_HOME}/lib
export LIBPNGINC=${LIBPNG_HOME}/include
#for Jasper
export JASPER_HOME=/local/Jasper
export PATH=${JASPER_HOME}/bin:$PATH
export LD_LIBRARY_PATH=${JASPER_HOME}/lib:$LD_LIBRARY_PATH
export MANPATH=${JASPER_HOME}/share/man:$MANPATH
export JASPERLIB=${JASPER_HOME}/lib
export JASPERINC=${JASPER_HOME}/include
#确保安装时文件使用无限制
export WRF_EM_CORE=1
ulimit -s unlimited
#重新载入
$ source ~/.bashrc
下面编译的 WRF 是普通版本,如果你想直接安装带有 chem 或 hydro 模块可以直接看最下面的教程
#安装 WRF
$ export PATH=${NETCDF}/bin:$PATH
$ export WRFIO_NCD_LARGE_FILE_SUPPORT=1
$ tar zxvf WRFV3.8.1.TAR.gz
$ cd WRFV3
$ ./configure
15
1
$ vim configure.wrf #修改以下内容
DM_FC=mpiifort
DM_CC=mpiicc
$ ./compile em_real -j 24
$ ./compile wrf -j 24 # 24是代表你的机器cpu核心数
等待编译完成,在最后如出现 Executables successfully built,以及查看 main 文件夹下出现 4 个可执行 exe 文件就是安装成功
如果出现其他问题,可以自行上网搜索解决
$ cd WPS
$ ./configure
19
$ vim configure.wps #修改以下内容
COMPRESSION_LIBS = -L/path/to/jasper/1.900.1/0/lib -L/path/to/other/lib -ljasper -lpng -lz
COMPRESSION_INC = -I/path/to/jasper/1.900.1/0/include
DM_FC=mpiifort
DM_CC=mpiicc
$ ./compile
看到有三个可执行文件 geogrid.exe metgrid.exe ungrib.exe 即可
将 wrf-chem 解压到 WRFV3 文件夹中
export WRF_CHEM=1
export WRF_KPP=1
./compile -j 12 emi_conv
测试 wrf 3.9.1 使用 hydro 5.1.2 可以成功安装
tar zxf wrf_hydro_nwm_public-5.1.2.tar.gz
# 保存一下原文件夹
mv hydro hydro_bak
# 将下载好的复制出来
cp -r wrf_hydro_nwm_public-5.1.2/trunk/NDHMS/ ./hydro
touch setEnvar.sh
vim setEnvar.sh
写入下面的内容,并保存
#!/bin/bash
# WRF-Hydro compile time options
# This is a WRF environment variable. Always set to 1=On for compiling WRF-Hydro.
export WRF_HYDRO=1
# Enhanced diagnostic output for debugging: 0=Off, 1=On.
export HYDRO_D=1
# Spatially distributed parameters for NoahMP: 0=Off, 1=On.
export SPATIAL_SOIL=1
# RAPID model: 0=Off, 1=On.
export WRF_HYDRO_RAPID=0
# Large netcdf file support: 0=Off, 1=On.
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
# WCOSS file units: 0=Off, 1=On.
export NCEP_WCOSS=0
# Streamflow nudging: 0=Off, 1=On.
export WRF_HYDRO_NUDGING=0
source 上面的文件,加载环境变量
source setEnvar.sh
cd hydro
./configure
# 选择 intel parallel
3
vim macros
# 修改编译器
COMPILER90=mpiifort
# 返回 WRFV3 文件夹重新编译主程序
cd ..
./clean
./compile wrf -j 24
./compile em_real -j 24
安装成功后会在 hydro/Run 文件夹下会出现 wrf_hydro.exe,以及最后编译 wrf.exe 时会在最后一句编译命令处看到 -lHYDRO