Skip to content

7.5. WRF

Hua Xu edited this page Sep 20, 2023 · 47 revisions

Installation

system check

Create a Test folder

mkdir TESTS
cd TESTS

Download the test cases and start tests, the output of tests should include SUCCESS

wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_tests.tar
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

Create a library folder and install the library

mkdir Build_WRF
cd Build_WRF
mkdir LIBRARIES
cd LIBRARIES

Download and unzip the required libraries.

  1. nedcdf-c-4.9.2
wget -c https://downloads.unidata.ucar.edu/netcdf-c/4.9.2/netcdf-c-4.9.2.tar.gz
tar xzvf netcdf-c-4.9.2.tar.gz
  1. hdf5(you can also install the newest version)
wget -c https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.2/src/hdf5-1.12.2.tar.gz
tar xzvf hdf5-1.12.2.tar.gz
  1. zlib(1.2.11)
wget -c https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.11.tar.gz
tar xzvf zlib-1.2.11.tar.gz
  1. NETCDF-Fortran(4.6.1)
wget https://downloads.unidata.ucar.edu/netcdf-fortran/4.6.1/netcdf-fortran-4.6.1.tar.gz
tar xzvf netcdf-fortran-4.6.1.tar.gz
  1. PnetCDF(1.12.3)
wget https://parallel-netcdf.github.io/Release/pnetcdf-1.12.3.tar.gz
tar xzvf pnetcdf-1.12.3.tar.gz
  1. LibPNG
wget -c https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz
tar xzvf libpng-1.2.50.tar.gz
  1. MPICH
module load mpich

Choice 1: Install the library(with the HDF5 support and without PnetCDF support)

Set the environment variables

export DIR=/PATH/TO/Build_WRF/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export F77=gfortran
module load libxml2
  1. Install the zlib
cd zlib-1.2.11/
./configure --prefix=$DIR
make
make install
  1. Install the hdf5
cd hdf5-1.12.2/
./configure --prefix=$DIR --with-zlib=$DIR --enable-hl --enable-fortran
make check
make install
export HDF5=$DIR
export LD_LIBRARY_PATH=$DIR/lib:$LD_LIBRARY_PATH
  1. Build NETCDF-C
cd netcdf-c-4.9.2
export CPPFLAGS=-I$DIR/include
export LDFLAGS=-L$DIR/lib
 ./configure --prefix=$DIR --disable-dap
make check
make install
export PATH=$DIR/bin:$PATH
export NETCDF=$DIR
  1. Build NetCDF fortran library links with NETCDF-C, after successful installation, netcdf.inc will be ${NETCDF}/include file. For sometimes, it will show C compiler stop working, Please check the environment variable in LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz", make sure netcdf and hdf5 path in the environment variables.
export LD_LIBRARY_PATH=$DIR/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-I${DIR}/include -I/usr/include"
export LDFLAGS="-L${DIR}/lib -L/usr/lib"
export LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz" 
./configure --prefix=$DIR --disable-shared
make check
make install

Library Compatibility Tests( the result should show SUCCESS)

mkdir LibTests
cd libTests
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
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
  1. Install the WRF
cd ..
wget https://github.com/wrf-model/WRF/releases/download/v4.5.1/v4.5.1.tar.gz
tar xvzf 4.5.1.tar.gz
cd WRFV4.5.1
module load adios2
export ADIOS2="/mnt/repo/software/spack/spack/opt/spack/linux-ubuntu22.04-skylake_avx512/gcc-11.3.0/adios2-2.9.0-mmkelnu4f4f4hpejrpdwofyrnguat27y
export HDF5=$DIR
export NETCDF=$DIR
./configure

Please select from among the following Linux x86_64 options: Choose 34(dmpar), Compile for nesting? choose 1. If configure is done, you can see a configure.wrf file in the folder.

./compile em_real
 #./compile em_real >& log.compile
export WRF_DIR=PATH/to/WRF4.5.1

You can see the following information shows the installation is successful.

--->                  Executables successfully built                  <---                                                                                                                                                                      
 -rwxrwxr-x 1 hxu40 hxu40 51667784 Sep 15 12:21 main/ndown.exe                                                           
 -rwxrwxr-x 1 hxu40 hxu40 51794800 Sep 15 12:21 main/real.exe                                                           
 -rwxrwxr-x 1 hxu40 hxu40 50930720 Sep 15 12:21 main/tc.exe                                                              
 -rwxrwxr-x 1 hxu40 hxu40 59885752 Sep 15 12:21 main/wrf.exe                                                                                                                                                                                     

==========================================================================   

To check check whether it was successful

ls -ls main/*.exe

If you compiled a real case, you should see:

wrf.exe (model executable)
real.exe (real data initialization)
ndown.exe (one-way nesting)
tc.exe (for tc bogusing--serial only)

Choice 2: Install the libarary(with both HDF5 support and PnetCDF support)

TODO

Install WPS

Download and install required library

cd $DIR
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gz
tar xzvf libpng-1.2.50.tar.gz
cd libpng-1.2.50
./configure --prefix=$DIR/grib2
make
make install
cd ..
wget https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gz
tar xzvf jasper-1.900.1.tar.gz    
cd jasper-1.900.1
./configure --prefix=$DIR/grib2
make
make install
cd ..

Download WPS and install

#go to WRF folder
mkdir WPS
wget https://github.com/wrf-model/WPS/archive/v4.5.tar.gz
tar -xvzf v4.5.tar.gz
cd WPS-4.5
export JASPERLIB $DIR/grib2/lib
export JASPERINC $DIR/grib2/include
./configure #Option 3 for gfortran and distributed memory
./compile

If the compile successfully, there should be 3 executables in the WPS top-level directory, that are linked to their corresponding src/ directories:

geogrid.exe -> geogrid/src/geogrid.exe
ungrib.exe -> ungrib/src/ungrib.exe
metgrid.exe -> metgrid/src/metgrid.exe

Usage

  1. Download the dataset, here is the website for dataset: (http://www2.mmm.ucar.edu/wrf/users/download/get_sources_wps_geog.html).
gunzip geog.tar.gz
tar -xf geog.tar
mv geog WPS_GEOG
geog_data_path = ´path_to_directory/Build_WRF/WPS_GEOG
Clone this wiki locally