气象水文耦合模式WRF-Hydro模型测试(含安装、编译、运行)
文章目录
前言
本文主要介绍安装编译WRF-Hydro模型,并进行测试数据。
本文使用的Linux操作系统是Ubuntu 20.04。
注:由于另外两篇大佬的文章讲解很详细,故本文大致讲解过程,增加了些自己在实现时所遇到的坑,以及解决的方法。(下附大佬文章链接)
WRF-Hydro入门(1):安装、编译、运行
WRF-Hydro环境部署与模型测试
一.编译器的检查
which gcc
which g++
which gfortran
没有安装的话,可以通过sudo apt install build-essential进行安装。
二、安装依赖库
1.创建目录
创建wrf文件夹及两个子目录libraries、src。
mkdir wrf
mkdir /wrf/libraries
mkdir /wrf/src
若显示无法创建目录,则可以试试-p,如下
mkdir -p /wrf/libraries
随后
cd /wrf/libraries
2. 安装依赖库
1.mpich
wget https://files.raymondhqr.top/hpc/mpich-4.1.2.tar.gz#大佬文章里有镜像源,可自行查看
tar zxvf mpich-4.1.2.tar.gz
cd mpich-4.1.2
./configure --prefix=/wrf/libraries/mpich
然后执行make相关指令(时间较长,耐心等待即可):
make
make install
修改环境变量:
vim ~/.bash_profile
增加一行即可(注意路径要符合自身情况,不然后面会报错):
export PATH=wrf/libraries/mpich/bin:$PATH
更新环境变量:
source ~/.bash_profile
2. zlib
返回libraries文件夹,准备并安装zlib(注意路径)
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.7.tar.gz
tar zxvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure --prefix=/wrf/libraries/zlib
make
make install
3.hdf5
与上述步骤类似
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.2/src/hdf5-1.12.2.tar.gz
tar zxvf hdf5-1.12.2.tar.gz
cd hdf5-1.12.2
make
make install
vim ~/.bash_profile
添加环境变量:
export PATH=/wrf/libraries/hdf5/bin:$PATH
export LD_LIBRARY_PATH=/wrf/libraries/hdf5/lib:$LD_LIBRARY_PATH
更新环境变量:
source ~/.bash_profile
4.netcdf_c
wget https://codeload.github.com/Unidata/netcdf-c/tar.gz/refs/tags/v4.9.2
mv v4.9.2 netcdf-c-4.9.2.tar.gz
tar zxvf netcdf-c-4.9.2.tar.gz
cd netcdf-c-4.9.2/
#注意路径
export LD_LIBRARY_PATH=/wrf/libraries/zlib/lib:/wrf/libraries/hdf5/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-Iwrf/libraries/zlib/include -I/wrf/libraries/hdf5/include"
export LDFLAGS="-Lwrf/libraries/zlib/lib -L/wrf/libraries/hdf5/lib"
进行执行:
./configure --prefix=wrf/libraries/netcdf --disable-dap --enable-netcdf-4 --enable-netcdf4 --enable-shared
此时,可能有部分用户报错(比如本人)
configure: error: curl required for byte range support. Install curl or build without --enable-byterange.
如果在尝试了多次安装curl等一系列之后如果还是报错的话,可以选择卸载当前版本,安装更低的版本,这个问题就很容易解决了(下面是4.4.1版本)
wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.4.1.tar.gz
mv v4.4.1 netcdf-c-4.4.1.tar.gz
tar zxvf netcdf-c-4.4.1.tar.gz
cd netcdf-c-4.4.1/
#注意路径
export LD_LIBRARY_PATH=/wrf/libraries/zlib/lib:/wrf/libraries/hdf5/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-I/wrf/libraries/zlib/include -I/wrf/libraries/hdf5/include"
export LDFLAGS="-L/wrf/libraries/zlib/lib -L/wrf/libraries/hdf5/lib"
./configure --prefix=/wrf/libraries/netcdf --disable-dap --enable-netcdf-4 --enable-netcdf4 --enable-shared
make
make install
5.netcdf_fortran
安装高版本的宝们可以下载高版本的netcdf_fortran:
wget https://codeload.github.com/Unidata/netcdf-fortran/tar.gz/refs/tags/v4.6.1
mv v4.6.1 netcdf-fortran-4.6.1.tar.gz
tar zxvf netcdf-fortran-4.6.1.tar.gz
cd netcdf-fortran-4.6.1/
export LD_LIBRARY_PATH=/wrf/libraries/netcdf/lib:/wrf/libraries/zlib/lib:/wrf/libraries/hdf5/lib$LD_LIBRARY_PATH CPPFLAGS="-I/wrf/libraries/netcdf/include" LDFLAGS="-L/wrf/libraries/netcdf/lib"
#执行
./configure --prefix=/wrf/libraries/netcdf
make
make install
vim ~/.bash_profile
添加环境变量:
export NETCDF=/wrf/libraries/netcdf
export PATH=/wrf/libraries/netcdf/bin:$PATH
export LD_LIBRARY_PATH=/wrf/libraries/netcdf/lib:$LD_LIBRARY_PATH
更新环境变量:
source ~/.bash_profile
但若是安装4.4.1版本的宝可以安装下面这个版本:
wget https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.4.4.tar.gz
mv v4.4.4.tar.gz netcdf-fortran-4.4.4.tar.gz
tar zxvf netcdf-fortran-4.4.4.tar.gz
cd netcdf-fortran-4.4.4/
export LD_LIBRARY_PATH=/wrf/libraries/netcdf/lib:/wrf/libraries/zlib/lib:/wrf/libraries/hdf5/lib$LD_LIBRARY_PATH CPPFLAGS="-I/wrf/libraries/netcdf/include" LDFLAGS="-L/wrf/libraries/netcdf/lib"
./configure --prefix=/wrf/libraries/netcdf
make
make install
vim ~/.bash_profile
添加环境变量:
export NETCDF=/wrf/libraries/netcdf
export PATH=/wrf/libraries/netcdf/bin:$PATH
export LD_LIBRARY_PATH=/wrf/libraries/netcdf/lib:$LD_LIBRARY_PATH
更新环境变量:
source ~/.bash_profile
三、安装WRF-Hydro`
返回到wrf文件夹后,进行下载安装
wget https://codeload.github.com/NCAR/wrf_hydro_nwm_public/tar.gz/refs/tags/v5.2.0
mv v5.2.0 WRF-Hydro.tar.gz
tar zxfv wrf_hydro_nwm_public-5.2.0.tar.gz
cd wrf_hydro_nwm_public-5.2.0/trunk/NDHMS
cp template/setEnvar.sh ./
vim setEnvar.sh
在最下面添加一行:
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
更新环境变量:
source ~/.bash_profile
运行第一个脚本:
./configure
选择填2:
运行第二个脚本
./compile_offline_NoahMP.sh setEnvar.sh
编译成功则显示:
查看/wrf-hydro/wrf_hydro_nwm_public-5.2.0/trunk/NDHMS/Run文件夹下生成的exe文件
ls -lah Run/*.exe
四、运行WRF-Hydro
返回到/wrf文件夹后
mkdir example_case && cd example_case
mkdir NWM
mkdir FORCING
mkdir Gridded_no_lakes
mkdir Reach
mkdir supplemental
mkdir Gridded && cd Gridded
mkdir DOMAIN
mkdir RESTART
复制*.TBL文件和wrf_hydro.exe文件至Gridded文件夹
cd /wrf
cp wrf_hydro_nwm_public-5.2.0/trunk/NDHMS/Run/*.TBL example_case/Gridded
cp wrf_hydro_nwm_public-5.2.0/trunk/NDHMS/Run/wrf_hydro.exe example_case/Gridded
下载数据集并解压:
cd ~/wrf/src
wget https://github.com/NCAR/wrf_hydro_nwm_public/releases/download/v5.2.0/croton_NY_training_example_v5.2.tar.gz
如上述步骤出现连接失败的情况,如下图
可通过删除“https://”,进行解决:
wget github.com/NCAR/wrf_hydro_nwm_public/releases/download/v5.2.0/croton_NY_training_example_v5.2.tar.gz
如下图:
解压并运行:
tar zxvf croton_NY_training_example_v5.2.tar.gz
#复制驱动数据到Gridded文件夹
cp -r example_case/FORCING/ /home/huangqirui/wrf/example_case/Gridded
cp -r example_case/NWM/DOMAIN /home/huangqirui/wrf/example_case/Gridded
cp -r example_case/NWM/RESTART /home/huangqirui/wrf/example_case/Gridded
cp -r example_case/NWM/nudgingTimeSliceObs/ /home/huangqirui/wrf/example_case/Gridded
cp -r example_case/NWM/namelist.hrldas /home/huangqirui/wrf/example_case/Gridded
cp -r example_case/NWM/hydro.namelist /home/huangqirui/wrf/example_case/Gridded
#运行
cd ~/wrf/example_case/Gridded
mpirun -np 2 ./wrf_hydro.exe
检查是否成功:
#检查是否成功:
tail -1 diag_hydro.00000
成功即如图所示:
五、总结
以上就是今天要分享的内容,因为作者目前也是小白,如有不当,请多见谅。