一、检查所需编译器是否完备
本项目需要在编译器gcc,g++,gfortran下进行,可以使用which命令进行查找,若未安装,可运行以下代码:
sudo apt-get install gcc sudo apt-get install g++ sudo apt-get install gfortran
检查编译器
二、安装wrf-hydro
(应该后面安装,我操作的时候上来就把这个装了)
三、安装依赖库
此处安装可以选择windows下安装再finalshell传输,后面两个我选择直接在虚拟机中打开网页再直接extract解压,感觉更省事。
1.mpich依赖库安装 下载链接:https://www.mpich.org/downloads/
(也可以wget命令下载)这里我选择的版本是4.2.2
利用finalshell传输压缩文件
解压缩进入对应文件目录
检查环境
make编译
make install安装
利用vim添加环境变量
source 更新环境变量
tar zxvf mpich-4.2.2.tar.gz cd ./mpich-4.2.2 ./configure --prefix=/home/downloads/wrf-hydro/libraries/mpich make make install vim ~/.bash_profile export PATH=/home/downloads/wrf-hydro/libraries/mpich/bin:$PATH source ~/.bash_profile
2.zlib安装 下载链接: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=/home/downloads/wrf-hydro/libraries/zlib make make install
3.hdf5安装
下载链接:https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/
编译安装并更新环境变量。
tar zxvf hdf5-1.12.2.tar.gz cd ./hdf5-1.12.2 ./configure --prefix=/home/downloads/wrf-hydro/libraries/hdf5 --with-zlib=/home/downloads/wrf-hydro/libraries/zlib --enable-fortran --enable-cxx make make install vim ~/.bash_profile export PATH=/home/downloads/wrf-hydro/libraries/hdf5/bin:$PATH export LD_LIBRARY_PATH=/home/downloads/wrf-hydro/libraries/hdf5/lib:$LD_LIBRARY_PATH
4.netcdf-c依赖库安装
下载链接:https://downloads.unidata.ucar.edu/netcdf/
这里我就直接虚拟机内下载了,设置一组临时变量,检查环境,make编译,make install安装
tar zxvf netcdf-c-4.9.2.tar.gz cd ./netcdf-c-4.9.2 export LD_LIBRARY_PATH=/home/downloads/wrf-hydro/libraries/zlib/lib:/home/downloads/wrf-hydro/libraries/hdf5/lib:$LD_LIBRARY_PATH export CPPFLAGS="-I/home/downloads/wrf-hydro/libraries/zlib/include -I/home/downloads/wrf-hydro/libraries/hdf5/include" export LDFLAGS="-L/home/downloads/wrf-hydro/libraries/zlib/lib -L/home/downloads/wrf-hydro/libraries/hdf5/lib" ./configure --prefix=/home/downloads/wrf-hydro/libraries/netcdf --disable-dap --enable-netcdf-4 --enable-netcdf4 --enable-shared make make install
5.netcdf-fortran安装
下载链接:https://github.com/Unidata/netcdf-fortran/releases/tag/v4.4.4
tar zxvf netcdf-fortran-4.4.4.tar.gz cd ./netcdf-fortran-4.4.4 export LD_LIBRARY_PATH=/home/downloads/wrf-hydro/libraries/netcdf/lib:/home/downloads/wrf-hydro/libraries/zlib/lib:/home/downloads/wrf-hydro/libraries/hdf5/lib$LD_LIBRARY_PATH CPPFLAGS="-I/home/downloads/wrf-hydro/libraries/netcdf/include" LDFLAGS="-L/home/downloads/wrf-hydro/libraries/netcdf/lib" ./configure --prefix=/home/downloads/wrf-hydro/libraries/netcdf make make install
利用vim添加环境变量,再source 更新环境变量
vim ~/.bash_profile export NETCDF=/home/downloads/wrf-hydro/libraries/netcdf export PATH=/home/downloads/wrf-hydro/libraries/netcdf/bin:$PATH export LD_LIBRARY_PATH=/home/downloads/wrf-hydro/libraries/netcdf/lib:$LD_LIBRARY_PATH source ~/.bash_profile
这里就是怪啊,我一开始编译那步卡了一个中午,也不是卡,就是编译了一中午,也确实一直在编译,一会儿蹦一行,后来我果断重新弄了。查了一下有个博主说:
如果在netcdf-fortran编译过程中出现了type mismatch的问题
就把netcdf都升级到最新版本,再次编译,可以解决;或者将编译器版本,原gcc,gfortran-11版本太高,降为-9版本,也可解决问题。
这里附个链接:http://t.csdnimg.cn/6yL5S可以参考
三、编译wrf-hydro
在 Linux 环境中,配置环境变量时通常会创建一个新的变量文件(例如 .bashrc
, .bash_profile
, .profile
, .zshrc
等),而不是直接修改系统文件或原始文件,是出于安全稳定的考虑,并且可以根据用户需要进行特定的配置。
复制环境变量文件 cp template/setEnvar.sh ./
编辑环境变量文件vim setEnvar.sh
加入 export WRFIO_NCD_LARGE_FILE_SUPPORT=1
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
更新检查后进行编译:
source setEnvar.sh ./configure ./compile_offline_NoahMP.sh setEnvar.sh
编译成功如下
四、下载数据并测试
下载链接:https://github.com/NCAR/wrf_hydro_nwm_public/releases/download/v5.2.0/croton_NY_training_example_v5.2.tar.gz
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
复制到相应目录:
cp -r example_case/FORCING/ /home/downloads/wrf-hydro/example_case/Gridded cp -r example_case/NWM/DOMAIN /home/downloads/wrf-hydro/example_case/Gridded cp -r example_case/NWM/RESTART /home/downloads/wrf-hydro/example_case/Gridded cp -r example_case/NWM/nudgingTimeSliceObs/ /home/downloads/wrf-hydro/example_case/Gridded cp -r example_case/NWM/namelist.hrldas /home/downloads/wrf-hydro/example_case/Gridded cp -r example_case/NWM/hydro.namelist /home/downloads/wrf-hydro/example_case/Gridded
运行并查看成功与否
cd ~/wrf/example_case/Gridded mpirun -np 2 ./wrf_hydro.exe tail -1 diag_hydro.00000