当前位置: 首页 > 工具软件 > Hydro > 使用案例 >

WRF-Hydro入门(1):安装、编译、运行

袁安志
2023-12-01


前言

安装编译WRF-Hydro模型,并用官网测试数据集运行模型。


一、安装所需

系统:Linux—CentOS 7
编译器:GCC(gcc、g++、gfortran)
依赖库:mpich-3.0.4zlib-1.2.7hdf5-1.12netcdf_c-4.4.1.1netcdf_fortran-4.4.4
软件: WRF-Hydro-5.2.0

二、安装依赖库

1.检查编译器

[bamboonion@wrf-hydro ~]$ which gcc
/usr/bin/gcc
[bamboonion@wrf-hydro ~]$ which g++
/usr/bin/g++
[bamboonion@wrf-hydro ~]$ which gfortran
/usr/bin/gfortran
[bamboonion@wrf-hydro ~]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)

如果没安装则: yum -y install gcc gcc-c++ gcc-gfortran

2.复制依赖库安装包

创建wrf-hydro文件夹及两个子目录libraries、src,并将共享文件夹下的安装包复制到src目录下
libraries为依赖库安装目录,src为依赖库安装包解压目录

[bamboonion@wrf-hydro ~]$ mkdir -p /home/bamboonion/wrf-hydro/libraries
[bamboonion@wrf-hydro ~]$ mkdir -p /home/bamboonion/wrf-hydro/src
[bamboonion@wrf-hydro ~]$ cd  /home/bamboonion/wrf-hydro/src
[bamboonion@wrf-hydro src]$ cp /mnt/hgfs/Data_Shared/mpich-3.0.4.tar.gz ./
[bamboonion@wrf-hydro src]$ cp /mnt/hgfs/Data_Shared/zlib-1.2.7.tar.gz ./
[bamboonion@wrf-hydro src]$ cp /mnt/hgfs/Data_Shared/hdf5-1.12.2.tar.gz ./
[bamboonion@wrf-hydro src]$ cp /mnt/hgfs/Data_Shared/netcdf-c-4.4.1.1.tar.gz ./
[bamboonion@wrf-hydro src]$ cp /mnt/hgfs/Data_Shared/netcdf-fortran-4.4.4.tar.gz ./

3.安装mpich

[bamboonion@wrf-hydro src]$ tar zxvf mpich-3.0.4.tar.gz
[bamboonion@wrf-hydro src]$ cd mpich-3.0.4
[bamboonion@wrf-hydro mpich-3.0.4]$ ./configure --prefix=/home/bamboonion/wrf-hydro/libraries/mpich
[bamboonion@wrf-hydro mpich-3.0.4]$ make
[bamboonion@wrf-hydro mpich-3.0.4]$ make install
[bamboonion@wrf-hydro mpich-3.0.4]$ vim ~/.bash_profile #添加环境变量
###mpich
export PATH=/home/bamboonion/wrf-hydro/libraries/mpich/bin:$PATH
[bamboonion@wrf-hydro mpich-3.0.4]$ source ~/.bash_profile #更新环境变量

4.安装zlib

[bamboonion@wrf-hydro src]$ tar zxvf zlib-1.2.7.tar.gz
[bamboonion@wrf-hyfro src]$ cd zlib-1.2.7
[bamboonion@wrf-hyfro zlib-1.2.7]$ ./configure --prefix=/home/bamboonion/wrf-hydro/libraries/zlib
[bamboonion@wrf-hyfro zlib-1.2.7]$ make
[bamboonion@wrf-hyfro zlib-1.2.7]$ make install

5.安装hdf5

[bamboonion@wrf-hyfro src]$ tar zxvf hdf5-1.12.2.tar.gz
[bamboonion@wrf-hyfro src]$ cd hdf5-1.12.2
[bamboonion@wrf-hyfro hdf5-1.12.2]$ ./configure --prefix=/home/bamboonion/wrf-hydro/libraries/hdf5 --with-zlib=/home/bamboonion/wrf-hydro/libraries/zlib --enable-fortran --enable-cxx
[bamboonion@wrf-hyfro hdf5-1.12.2]$ make
[bamboonion@wrf-hyfro hdf5-1.12.2]$ make install
[bamboonion@wrf-hyfro hdf5-1.12.2]$ vim ~/.bash_profile #添加环境变量
### hdf5
export PATH=/home/bamboonion/wrf-hydro/libraries/hdf5/bin:$PATH
export LD_LIBRARY_PATH=/home/bamboonion/wrf-hydro/libraries/hdf5/lib:$LD_LIBRARY_PATH
[bamboonion@wrf-hyfro hdf5-1.12.2]$ source ~/.bash_profile #更新环境变量

6.安装netcdf_c

[bamboonion@wrf-hyfro src]$ tar zxvf netcdf-c-4.4.1.1.tar.gz
[bamboonion@wrf-hyfro src]$ cd netcdf-c-4.4.1.1
[bamboonion@wrf-hyfro netcdf-c-4.4.1.1]$ export LD_LIBRARY_PATH=/home/bamboonion/wrf-hydro/libraries/zlib/lib:/home/bamboonion/wrf-hydro/libraries/hdf5/lib:$LD_LIBRARY_PATH
[bamboonion@wrf-hyfro netcdf-c-4.4.1.1]$ CPPFLAGS="-I/home/bamboonion/wrf-hydro/libraries/zlib/include -I/home/bamboonion/wrf-hydro/libraries/hdf5/include" LDFLAGS="-L/home/bamboonion/wrf-hydro/libraries/zlib/lib -L/home/bamboonion/wrf-hydro/libraries/hdf5/lib" ./configure --prefix=/home/bamboonion/wrf-hydro/libraries/netcdf --disable-dap --enable-netcdf-4 --enable-netcdf4 --enable-shared 
[bamboonion@wrf-hyfro netcdf-c-4.4.1.1]$ make
[bamboonion@wrf-hyfro netcdf-c-4.4.1.1]$ make install

7.安装netcdf_fortran

[bamboonion@wrf-hyfro src]$ tar zxvf netcdf-fortran-4.4.4.tar.gz
[bamboonion@wrf-hyfro src]$ cd netcdf-fortran-4.4.4
[bamboonion@wrf-hyfro netcdf-fortran-4.4.4]$ export LD_LIBRARY_PATH=/home/bamboonion/wrf-hydro/libraries/netcdf/lib:/home/bamboonion/wrf-hydro/libraries/zlib/lib:/home/bamboonion/wrf-hydro/libraries/hdf5/lib$LD_LIBRARY_PATH
[bamboonion@wrf-hyfro netcdf-fortran-4.4.4]$ CPPFLAGS="-I/home/bamboonion/wrf-hydro/libraries/netcdf/include" LDFLAGS="-L/home/bamboonion/wrf-hydro/libraries/netcdf/lib" ./configure --prefix=/home/bamboonion/wrf-hydro/libraries/netcdf
[bamboonion@wrf-hyfro netcdf-fortran-4.4.4]$ make
[bamboonion@wrf-hyfro netcdf-fortran-4.4.4]$ make install
[bamboonion@wrf-hyfro netcdf-fortran-4.4.4]$ vim ~/.bash_profile #添加环境变量
###netcdf
export NETCDF=/home/bamboonion/wrf-hydro/libraries/netcdf
export PATH=/home/bamboonion/wrf-hydro/libraries/netcdf/bin:$PATH
export LD_LIBRARY_PATH=/home/bamboonion/wrf-hydro/libraries/netcdf/lib:$LD_LIBRARY_PATH
[bamboonion@wrf-hyfro netcdf-fortran-4.4.4]$ source ~/.bash_profile #更新环境变量

三、安装WRF-Hydro

[bamboonion@wrf-hyfro wrf-hydro]$ cp /mnt/hgfs/Data_Shared/wrf_hydro_nwm_public-5.2.0.tar.gz ./
[bamboonion@wrf-hyfro wrf-hydro]$ tar zxfv wrf_hydro_nwm_public-5.2.0.tar.gz 
[bamboonion@wrf-hyfro wrf-hydro]$ cd wrf_hydro_nwm_public-5.2.0/trunk/NDHMS
[bamboonion@wrf-hyfro NDHMS]$ cp template/setEnvar.sh ./ #复制环境变量文件
[bamboonion@wrf-hyfro NDHMS]$ vi setEnvar.sh #编辑环境变量文件

编辑环境变量,新添加:export WRFIO_NCD_LARGE_FILE_SUPPORT=1

#!/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
#这允许NoahMP使用空间分布的参数作为土地表面模型,而不是基于土壤类别和土地使用类别查找表的参数。

# RAPID model: 0=Off, 1=On.
export WRF_HYDRO_RAPID=0
#与RAPID routing模型耦合。目前不支持此选项。

# WCOSS file units: 0=Off, 1=On.
export NCEP_WCOSS=0
#除非在WCOSS机器上工作,否则请勿使用。

# NWM output metadata: 0=Off, 1=On.
export NWM_META=0

# Streamflow nudging: 0=Off, 1=On.
export WRF_HYDRO_NUDGING=0
#让模型结果逼近真实的河流观测数据。

#Large netcdf file support: 0=Off,1=On.
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
#允许大于2GIB的NetCDF输入输出文件。

编辑完毕后更新环境变量并运行配置脚本

[bamboonion@wrf-hyfro NDHMS]$ source setEnvar.sh
[bamboonion@wrf-hyfro NDHMS]$ ./configure 
#Enter slection选择:2 (gfort)
[bamboonion@wrf-hyfro NDHMS]$ ./compile_offline_NoahMP.sh setEnvar.sh

出现下列语句即为编译成功

*****************************************************************
Make was successful

*****************************************************************
The environment variables used in the compile:
HYDRO_D=1
NCEP_WCOSS=0
NETCDF=/home/bamboonion/wrf-hydro/libraries/netcdf
SPATIAL_SOIL=1
WRF_HYDRO=1
WRF_HYDRO_NUDGING=0
WRF_HYDRO_RAPID=0

查看/home/bamboonion/wrf-hydro/wrf_hydro_nwm_public-5.2.0/trunk/NDHMS/Run文件夹下生成的exe文件

[bamboonion@wrf-hyfro NDHMS]$ ls -lah Run/*.exe

四、运行WRF-Hydro

下载测试数据集:https://ral.ucar.edu/projects/wrf_hydro/testcases

创建测试数据集文件夹

[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/NWM
[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/FORCING
[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/Gridded_no_lakes
[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/Reach
[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/supplemental
[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/Gridded/DOMAIN
[bamboonion@wrf-hyfro wrf-hydro]$ mkdir -p /home/bamboonion/wrf-hydro/example_case/Gridded/RESTART

复制*.TBL文件和wrf_hydro.exe文件至Gridded文件夹下

[bamboonion@wrf-hyfro wrf-hydro]$ cp wrf_hydro_nwm_public*/trunk/NDHMS/Run/*.TBL example_case/Gridded
[bamboonion@wrf-hyfro wrf-hydro]$ cp wrf_hydro_nwm_public*/trunk/NDHMS/Run/wrf_hydro.exe example_case/Gridded

解压测试数据集

[bamboonion@wrf-hyfro wrf-hydro]$ cd /home/bamboonion/wrf-hydro/src
[bamboonion@wrf-hyfro src]$ cp /mnt/hgfs/Data_Shared/croton_NY_training_example_v5.2.tar.gz ./
[bamboonion@wrf-hyfro src]$ tar zxvf croton_NY_training_example_v5.2.tar.gz

复制驱动数据至Gridded文件夹下

[bamboonion@wrf-hyfro src]$ cp -r example_case/FORCING /home/bamboonion/wrf-hydro/example_case/Gridded
[bamboonion@wrf-hyfro src]$ cp -r example_case/NWM/DOMAIN /home/bamboonion/wrf-hydro/example_case/Gridded
[bamboonion@wrf-hyfro src]$ cp -r example_case/NWM/RESTART /home/bamboonion/wrf-hydro/example_case/Gridded
[bamboonion@wrf-hyfro src]$ cp -r example_case/NWM/nudgingTimeSliceObs /home/bamboonion/wrf-hydro/example_case/Gridded
[bamboonion@wrf-hyfro src]$ cp -r example_case/NWM/namelist.hrldas /home/bamboonion/wrf-hydro/example_case/Gridded
[bamboonion@wrf-hyfro src]$ cp -r example_case/NWM/hydro.namelist /home/bamboonion/wrf-hydro/example_case/Gridded

运行模型

[bamboonion@wrf-hyfro src]$ cd /home/bamboonion/wrf-hydro/example_case/Gridded
[bamboonion@wrf-hyfro Gridded]$ mpirun -np 2 ./wrf_hydro.exe

测试模型是否运行成功

[bamboonion@wrf-hyfro Gridded]$ tail -1 diag_hydro.00000
 The model finished successfully.......

五、下一步

可视化输出文件

 类似资料: