编译安装WRF

操作步骤

  1. 执行以下命令解压WRF安装包。

    tar -zxvf WRF-3.9.tar.gz

  2. 执行以下命令进入WRF源码目录。

    cd WRF-3.9

  3. 执行以下命令设置编译前环境。

    export WRFIO_NCD_LARGE_FILE_SUPPORT=1
    export NETCDF=/path/to/install/NETCDF
    export HDF5=/path/to/install/HDF5
    export PNETCDF=/path/to/install/PNETCDF
    export CPPFLAGS="-I$HDF5/include -I$PNETCDF/include -I$NETCDF/include"
    export LDFLAGS="-L$HDF5/lib -L$PNETCDF/lib -L$NETCDF/lib -lnetcdf -lnetcdff -lpnetcdf -lhdf5_hl -lhdf5 -lz"

  4. 执行以下命令修改arch/configure_new.defaults文件。

    vim arch/configure_new.defaults

    在文件#insert new stanza here下面添加:

    ################################################## #########
    #ARCH   Linux   aarch64,clang HYPERMPI#serial smpar dmpar dm+sm
    DESCRIPTION     =       CLANG ($SFC/$SCC)
    DMPARALLEL      =        1
    OMPCPP          =        -D_OPENMP
    OMP             =        -fopenmp
    OMPCC           =        -fopenmp
    SFC             =       flang
    SCC             =       clang
    CCOMP           =       clang
    DM_FC           =       mpif90
    DM_CC           =       mpicc -DMPI2_SUPPORT
    FC              =       CONFIGURE_FC
    CC              =       CONFIGURE_CC
    LD              =       $(FC)
    RWORDSIZE       =       CONFIGURE_RWORDSIZE
    PROMOTION       =       #-fdefault-real-8
    ARCH_LOCAL      =       -DNONSTANDARD_SYSTEM_SUBR  -DWRF_USE_CLM
    CFLAGS_LOCAL    =      -mcpu=native -w -O3 -c -march=armv8.2-a -I/usr/include/tirpc/
    LDFLAGS_LOCAL   = -ltirpc
    CPLUSPLUSLIB    =
    ESMF_LDFLAG     =      $(CPLUSPLUSLIB)
    FCOPTIM         =       -O3 -funroll-loops -march=armv8.2-a
    FCREDUCEDOPT    =       $(FCOPTIM)
    FCNOOPT         =       -O0
    FCDEBUG         =      -g # -fbacktrace -ggdb-fcheck=bounds,do,mem,pointer -ffpe-trap=invalid,zero,overflow
    FORMAT_FIXED    =       -ffixed-form
    FORMAT_FREE     =       -ffree-form -ffree-line-length-0
    FCSUFFIX        =
    BYTESWAPIO      =       -fconvert=big-endian
    FCBASEOPTS_NO_G =       -w $(FORMAT_FREE) $(BYTESWAPIO)
    FCBASEOPTS      =       -mcpu=native $(OMP) $(FCBASEOPTS_NO_G)
    MODULE_SRCH_FLAG =
    TRADFLAG        =      -traditional
    CPP             =      /lib/cpp -P
    AR              =      ar
    ARFLAGS         =      ru
    M4              =      m4 -G
    RANLIB          =      ranlib
    RLFLAGS         =
    CC_TOOLS        =      $(SCC)
    ###########################################################

  1. 执行以下命令生成配置文件。

    ./configure

    输入“4”,再按“enter”键。

    输入“1”,再按“enter”键。

  2. 执行以下命令编译安装。

    ./compile em_real 2>&1 | tee -a compile.log

  3. 执行以下命令验证是否安装成功。

    ls main

    回显生成了“wrf.exe”等可执行文件,表明编译成功。