【数值模型】WRF&WPS环境搭建

WRF&WPS环境搭建

0 机器环境

  • CentOS7系列64位操作系统
# 查看系统,以下任选其一
cat /proc/version
uname -a 
lsb_release -a
cat /etc/issue

1 工具

yum install -y gcc gcc-gfortran gcc-c++ which perl csh git wget make tar m4 libXrender libXext fontconfig

2 创建目录

cd /opt
mkdir Build_WRF Test

3 测试环境

cd Test
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_tests.tar
tar -xf Fortran_C_tests.tar

3.1 test1

gfortran TEST_1_fortran_only_fixed.f
./a.out 

3.2 test2

gfortran TEST_2_fortran_only_free.f90
./a.out

3.3 test3

gcc TEST_3_c_only.c
./a.out

3.4 test4

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

4 Build libraries

4.1 Download compressed files

cd ../Build_WRF
mkdir LIBRARIES
cd LIBRARIES
mkdir tar untar
cd tar

wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/mpich-3.0.4.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/netcdf-4.1.3.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.7.tar.gz

# if it reports errors when commpiling WRF
wget https://ftp.gnu.org/gnu/time/time-1.9.tar.gz

4.2 Set environment variables

# 不推荐 change to Cshell
csh 
setenv DIR /opt/Build_WRF/LIBRARIES
setenv CC gcc
setenv CXX g++
setenv FC gfortran
setenv FCFLAGS -m64
setenv F77 gfortran
setenv FFLAGS -m64
##Netcdf
setenv PATH $DIR/netcdf/bin:$PATH
setenv NETCDF $DIR/netcdf
##Mpich
setenv PATH $DIR/mpich/bin:$PATH
##Grib2
setenv GRIB2 $DIR/grib2
setenv JASPERLIB $GRIB2/lib
setenv JASPERINC $GRIB2/include
setenv LDFLAGS -L$GRIB2/lib
setenv CPPFLAGS -I$GRIB2/include
setenv LD_LIBRARY_PATH $GRIB2/lib
setenv LD_LIBRARY_PATH $NETCDF/lib     # 此处这样配置是不对的,就会覆盖grib2的环境,导致ungrib.exe无法生成

# 推荐使用shell,将以下内容加入到~/.bashrc配置文件中
export DIR=/opt/Build_WRF/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export PATH=$DIR/netcdf/bin:$PATH
export NETCDF=$DIR/netcdf
export PATH=$DIR/mpich/bin:$PATH
export GRIB2=$DIR/grib2
export JASPERLIB=$GRIB2/lib
export JASPERINC=$GRIB2/include
export LDFLAGS=-L$GRIB2/lib
export CPPFLAGS=-I$GRIB2/include
export LD_LIBRARY_PATH=$GRIB2/lib
export LD_LIBRARY_PATH=$GRIB2/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH

source ~/.bashrc

4.3 Compile libraries

# NetCDF
cd /opt/Build_WRF/LIBRARIES/tar
tar -xzf netcdf-4.1.3.tar.gz -C /opt/Build_WRF/LIBRARIES/untar
cd ../untar/netcdf-4.1.3
./configure --prefix=$DIR/netcdf --disable-dap --disable-netcdf-4 --disable-shared
make
make install

# mpich
cd /opt/Build_WRF/LIBRARIES/tar
tar -zxf mpich-3.0.4.tar.gz -C /opt/Build_WRF/LIBRARIES/untar
cd ../untar/mpich-3.0.4
./configure --prefix=$DIR/mpich
make
make install

# zlib
cd /opt/Build_WRF/LIBRARIES/tar
tar -xzf zlib-1.2.7.tar.gz -C /opt/Build_WRF/LIBRARIES/untar 
cd ../untar/zlib-1.2.7
./configure --prefix=$DIR/grib2
make
make install

# libpng
cd /opt/Build_WRF/LIBRARIES/tar
tar -xzf libpng-1.2.50.tar.gz -C /opt/Build_WRF/LIBRARIES/untar 
cd ../untar/libpng-1.2.50
./configure --prefix=$DIR/grib2
make
make install

# JasPer
cd /opt/Build_WRF/LIBRARIES/tar
tar -xzf jasper-1.900.1.tar.gz -C /opt/Build_WRF/LIBRARIES/untar
cd ../untar/jasper-1.900.1
./configure --prefix=$DIR/grib2
make
make install

# if it reports errors when commpiling WRF
# time
cd /opt/Build_WRF/LIBRARIES/tar
tar -xzf time-1.9.tar.gz -C /opt/Build_WRF/LIBRARIES/untar
cd ../untar/time-1.9
./configure --prefix=/usr/
make
make install
ls /usr/bin/time  # check whether it was installed successfully

5 Test compatibility of libraries

5.3 Download test files

cd /opt/Test
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_NETCDF_MPI_tests.tar
tar -xf Fortran_C_NETCDF_MPI_tests.tar

5.3.1 Fortran + C + NetCDF

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

5.3.2 Fortran + C + NetCDF + MPI

# cp ${NETCDF}/include/netcdf.inc .
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

6 Compile WRF and WPS

# WRF
cd /opt/Build_WRF/LIBRARIES/
git clone https://github.com/wrf-model/WRF
cd WRF
./configure  #  choose 34 then 1
./compile em_real >& log.compile
ls -lh main/*.exe

# WPS
cd /opt/Build_WRF/LIBRARIES/
git clone https://github.com/wrf-model/WPS
cd WPS 

./clean
./configure  # choose 1
./compile >& log.compile
ls -lh *.exe

7 其他

# ncl安装
cd ~
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
chmod +x Anaconda3-2021.05-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh
conda create -n ncl -c conda-forge ncl

# ncl使用
conda activate ncl
ncl

# python使用,视具体软连接情况
python3
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

⁣北潇

老板大气!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值