WRF安装

由于本人安装过多次、多个版本的WRF程序,走了许多弯路,不忍心大家再像我一样浪费时间,所以整理一些可用经验。参考自:Compiling WRF (ucar.edu)https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php

  • 系统环境配置 

1、首先确保有没有安装好编译语言gfortran、gcc、g++以及cpp。

2、创建WRF工作文件及其后续可能用得上的子文件。之所以选择在~/目录下直接建立WRF工作站,主要是方便所有人访问,不需要host/sudo权限。

which gfortran
which cpp
which gcc
sudo apt install gfortran gcc cpp g++ make
gcc --version
gfortran --version
cpp --version


mkdir ~/WRF_WorkStation
mkdir ~/WRF_WorkStation/Libraries
mkdir ~/WRF_WorkStation/netcdf
mkdir ~/WRF_WorkStation/grib2
mkdir ~/WRF_WorkStation/mpich
mkdir ~/WRF_WorkStation/test

3、进入~/WRF_WorkStation/test文件中,将下载好的Fortran and C Tests Tar File 解压。具体的测试成功与否请参照Compiling WRF (ucar.edu)

tar -xf Fortran_C_tests.tar
gfortran TEST_1_fortran_only_fixed.f
./a.out
gfortran TEST_2_fortran_only_free.f90
./a.out
gcc TEST_3_c_only.c
./a.out
gcc -c -m64 TEST_4_fortran+c_c.c
gfortran -c -m64 TEST_4_fortran+c_f.f90
gfortran -m64 TEST_4_fortran+c_f.o TEST_4_fortran+c_c.o
./a.out
./TEST_csh.csh
./TEST_perl.pl
./TEST_sh.sh

其他的unix命令可以后续需要的时候下载!命令下载方式是

sudo apt install command


  • 创建库

1、进入到WRF工作文件夹下的Libraries目录下。

cd ~/WRF_WorkStation/Libraries

mpich-3.0.4
netcdf-4.1.3
Jasper-1.900.1
libpng-1.2.50
zlib-1.2.7

五个压缩包下载到其中,后续可以删掉,也可以保留,随个人喜好。

2、修改~/.bashrc环境配置,这一步必须有!!!注意###后的内容全部都应该在~/.bashrc的尾部加入,然后用source ~/.bashrc生效。

vi ~/.bashrc

###-----------------------WRF installation-----------------###
export DIR=/home/hsy/WRF_WORKSTATION/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include

source ~/.bashrc

3、配置netcdf。

tar xzvf netcdf-4.1.3.tar.gz     #or just .tar if no .gz present
cd netcdf-4.1.3
./configure --prefix=$DIR/netcdf --disable-dap --disable-netcdf-4 --disable-shared
make
make install

vi ~/.bashrc

###--->netcdf<---###
export NETCDF=$DIR/netcdf
export PATH=$NETCDF/bin:$PATH

source ~/.bashrc

nc-config

netcdf安装过程可能会有各种各样的问题,请小心操作,一定要谨慎,不能弄错一步!错了也不要害怕,通过make clean消除编译文件后继续重来。直到看见Congratulations! You have successfully installed netCDF!字眼,且Libraries/netcdf/include/netcdf.inc存在,nc-config --help能用!

4、配置mpich

tar xzvf mpich-3.0.4.tar.gz     #or just .tar if no .gz present
cd mpich-3.0.4
./configure --prefix=$DIR/mpich
make
make install
make check #可省略此步


vi ~/.bashrc

###--->mpich<---###
export MPICH=$DIR/mpich
export PATH=$MPICH/bin:$PATH

source ~/.bashrc

5、配置zlib、jasper以及libpng

tar xzvf zlib-1.2.7.tar.gz     #or just .tar if no .gz present
cd zlib-1.2.7
./configure --prefix=$DIR/grib2
make
make install


tar xzvf libpng-1.2.50.tar.gz     #or just .tar if no .gz present
cd libpng-1.2.50
./configure --prefix=$DIR/grib2
make
make install


tar xzvf jasper-1.900.1.tar.gz     #or just .tar if no .gz present
cd jasper-1.900.1
./configure --prefix=$DIR/grib2
make
make install

进入各自的解压包下,首先配置路径到grib2文件下,./configure --prefix,再make -> make install->make check(可省略)。

最后的库的编译环境(~/.bashrc)如下:


###-----------------------WRF installation-----------------###
export DIR=/home/hsy/WRF_WORKSTATION/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include

###--->netcdf<---###
export NETCDF=$DIR/netcdf
export PATH=$NETCDF/bin:$PATH

###--->mpich<---###
export MPICH=$DIR/mpich
 

###--->zlib<---###
export ZLIB=$DIR/grib2
export PATH=$ZLIB/bin:$PATH

###--->libpng<---###
export LIBPNG=$DIR/grib2
export PATH=$LIBPNG/bin:$PATH

###--->jasper<---###
export JASPER=$DIR/grib2
export PATH=$JASPER/bin:$PATH

###--->WPS Compiler<---###
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH

zlib、libpng以及jasper的配置环境可以省略,因为前面已存在。


  • 库的兼容性测试

首先下载Fortran_C_NETCDF_MPI_tests.tar并解压,然后开始进行两个测试,一个是netcdf的测试,另一个是mpich的测试。

这里注意把设置的NETCDF路径下的netcdf.inc复制到test文件夹下。

tar -xf Fortran_C_NETCDF_MPI_tests.tar

cp ${NETCDF}/include/netcdf.inc .

gfortran -c 01_fortran+c+netcdf_f.f
gcc -c 01_fortran+c+netcdf_c.c
gfortran 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o \
     -L${NETCDF}/lib -lnetcdff -lnetcdf
./a.out

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${NETCDF}/lib -lnetcdff -lnetcdf
mpirun ./a.out

  • 创建WRF

1、首先进入WRF与WPS下载目录下,将WRFv4.2与WPSv4.2安装包解压到WRF工作文件夹下,注意两者一定要在同一文件目录下,即保证解压后的WPSV4.2/与WRFV4.2/均在WRF_WORKSTATION文件目录下。

unzip WPS-4.2.zip -d ~/WRF_WORKSTATION/WPSV4.2/

unzip WRF-4.2.zip -d ~/WRF_WORKSTATION/WRFV4.2/

2、配置编译WRF(必须先编译WRF,才可以编译WPS),首先进入WRFV4.2文件目录下,输入./configure进行配置,选择34(dmpar GNU组合),再选择1(basic),然后再编译。

./configure
34
1
./compile em_real >& log.compile
ls -ls main/*.exe

3、等20min左右,直到出现wrf.exe (model executable)
real.exe (real data initialization)
ndown.exe (one-way nesting)
tc.exe (for tc bogusing--serial only)则证明wrf的real case编译成功了。

若出现libimf.so静态链接库无法连接,请参考下文解决:

error while loading shared libraries: libimf.so: - Intel CommunitiesHi. I cannot complie my program using the makefile. However, if I type the complie command, it can complie. I donot know why this situation happens.icon-default.png?t=M7J4https://community.intel.com/t5/Intel-Fortran-Compiler/error-while-loading-shared-libraries-libimf-so/td-p/740546


  • 创建WPS

1、首先进入WPSV4.2中, ./clean清除WPS文件目录。

2、配置WRF,选择dmpar gfortran。

3、编译WPS。

cd WPSV4.2
./clean
export WRF_DIR=../WRFV4.2

vi ~/.bashrc
###---------- WRF compile -----------###
export WRFIO_NCD_LARGE_FILE_SUPPORT=1

source ~/.bashrc

./configure
3
./compile
ls -ls *.exe

出现三个.exe文件即为成功!

附录:超算安装或者ifort系统安装WRF请参考下文:

使用系统预装的软件 · GitBookhttp://docs.hpc.whu.edu.cn/files/whuhpcdocs.wiki/software_env.html

  • 7
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
WRF (Weather Research and Forecasting Model) 是一款广泛使用的中尺度气象数值模拟模型,用于气候研究和天气预报。在 Linux 系统上安装 WRF 通常需要一些特定的步骤,包括软件依赖、配置环境和编译安装。以下是简要的安装过程概述: 1. **软件环境准备**: - 安装必要的开发工具:如gcc、make、git等。 - 配置并安装NetCDF(用于存储模型数据)和 HDF5(高性能数据格式)库。 - 可能还需要NCAR Command Language (NCL),一种数据操作和可视化语言。 2. **获取源代码**: - 从WRF的官方GitHub仓库 `https://github.com/WRF-Model/WRF` 下载源代码。 3. **构建和配置**: - 进入下载的WRF目录,并创建一个新的 build 目录。 - 运行 `./autogen.sh` 或者 `./configure` 来生成 Makefile,根据系统配置选项。 - 如果需要自定义配置,可以通过编辑 `Makefile` 或使用提供的配置脚本来进行。 4. **编译**: - 运行 `make` 命令开始编译过程。这可能需要一段时间,取决于你的硬件性能。 - 完成编译后,可能会生成一个名为 `wrf.exe` 或 `wrf_d.exe` 的可执行文件,具体取决于你选择的并行架构。 5. **运行测试**: - 在 build 目录下,运行 `make check` 来运行测试案例,确保安装成功。 6. **安装**: - 如果你想将WRF添加到系统路径,你可以选择 `sudo make install`,但请注意,这可能需要 root 权限。 7. **验证安装**: - 使用 `wrf.exe` 或 `wrf_d.exe` 运行简单的例子或执行一个完整的模拟,以确认WRF已经在你的系统上正常运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值