Professional Documents
Culture Documents
8 compilation
System Information
Processor: Intel Core i7
Graphics: Gallium 0.4 on NV117
Memory: 16Gb
OS: Ubuntu 16.04 LTS
*It is recommended to be the root user always when running all the given commands
sudo -s
The command prompt will start with a # if you are the root user
gcc
gfortran
cpp
which gfortran
If the code outputs a path similar to something like given below, it means the module is
already available in the computer.
/usr/bin/gfortran
If any of the three components are not available, you should download and install using
the following commands. (Should be connected to the Internet with root privileges)
gfortran --version
The output should be something similar to this but might change with new upgrades
Create a new directory for WRF Tests in the home directory using the following
command
mkdir TEST
cd TEST
Download the test files from a terminal opened from the home directory using the
following command line
wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/Fortran_C_tests.tar
Type the following in the command prompt one after the other
gfortran TEST_1_fortran_only_fixed.f
./a.out
If the test is successful, the following message should be displayed on the screen.
Type the following in the command prompt one after the other
gfortran TEST_2_fortran_only_free.f90
./a.out
If the test is successful, the following message should be displayed on the screen.
Assume Fortran 2003: has FLUSH, ALLOCATABLE, derived type, and ISO C
Binding
SUCCESS test 2 fortran only free format
Test 3 – C Test
Type the following in the command prompt one after the other
gcc TEST_3_c_only.c
./a.out
If the test is successful, the following message should be displayed on the screen
Type the following in the command prompt one after the other
./a.out
If the test is successful, the following message should be displayed on the screen.
The perl and sh scripting languages are included by default in Ubuntu 16.04 LTS OS
but the availability can be checked using the following command.
which perl
which csh
which sh
The output should display the path of the directory they are included.
For example:
/usr/bin/perl
If any of the three languages are missing, use the following commands to download
them and install.
./TEST_csh.csh
If the test is successful, the following message should be displayed on the screen.
./TEST_perl.pl
If the test is successful, the following message should be displayed on the screen.
Test 7 – sh Test
./TEST_sh.sh
If the test is successful, the following message should be displayed on the screen.
SUCCESS sh test
3. Required libraries
Please note that this chapter is only documented for the purpose of introducing the libraries
required for WRF model. The links provided can be used to search more about the libraries
and download them and does not involve any installation step. But in the next chapter (4.
Installation of libraries), every step is followed in command lines including the download
process.
a. NetCDF
This is the most important library which needs to be installed for WRF. NetCDF
(network Common Data Form) is a set of interfaces for array-oriented data access and
a freely distributed collection of data access libraries for C, Fortran, C++, Java, and
other languages. The netCDF libraries support a machine-independent format for
representing scientific data.
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/netcdf-
4.1.3.tar.gz
b. MPICH
MPICH is a high-performance and widely portable implementation of the
MPI-3.1 standard from the Argonne National Laboratory. (MPI = Message Parsing
Interface). This application allows the user to select the number of cores should be
allocated for a WRF task. When WRF is run using mpich, (will be explained how to run
using MPICH in next chapter ) the WRF job will be allocated into each processor as
individual tasks which reduce the overall runtime of the model. If you are not interested
in running WRF in parallel or in other words, using more than one processor, this library
need not be installed.
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/mpich-
3.0.4.tar.gz
c. JasPer
JasPer is a software tool kit for the handling of image data. The software
provides means for representing images, and facilitates the manipulation of image data,
as well as the import/export of such data in numerous formats. This library is vital for the
WPS copmponent of the model since it helps in ungribbing process of GRIB2 files.
A link to download the recommended version of JasPer for WRF is given below.
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-
1.900.1.tar.gz
d. libpng
libpng is an open source development which is created for the purpose to
maintain the reference library for use in applications that read, create and manipulate
PNG (Portable Network Graphics) raster image files. The use of this library for WRF is
that it allows the GRIB2 data manipulation for the compiling of WPS component.
A link to download the recommended version of libpng for WRF is given below.
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-
1.2.50.tar.gz
e. zlib
zlib is a lossless compression format which can be used in almost any hardware
and operating system. This library is vital for WRF since many data sets used in WRF
model are in compressed formats like GRIB2. This library is specially important in
compiling the WPS component of the model.
Although many new versions of zlib are available at present, it is recommended to use
zlib 1.2.7 for compiling WRF v3.8. A link to download the recommended version of zlib
is given below.
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.7.tar.gz
4. Installation of libraries
2- Go to the home directory in linux by clicking on the second icon from the column
of icons in the desktop of Ubuntu 16.04 freshly installed. Once you are in the
home directory, right click and select open in terminal. This is the easiest way to
change the directories in a terminal to go to a specified location on the computer.
If you are familiar with linux command prompt, you can also choose to run the
command given below to change the directory to home in a terminal window.
(You can open the terminal window in ubuntu using the hotkey ctrl+alt+t )
cd /home/
3- Create a new folder for the installation of WRF in the home directory by simply
right click and make new folder or use the following command in the command
prompt
mkdir WRF
4- Copy all the downloaded tar files into this folder which are in the downloads
directory
NetCDF
wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/netcdf-4.1.3.tar.gz
If the .gz extension is not present in your downloaded file, use the command
tar netcdf-4.1.3.tar
To go inside the unzipped file, use the command
cd netcdf-4.1.3
*Important note on using linux command prompt in changing directories – It is easy to change
the path directories by typing cd followed by the folder name. But to avoid mistakes in typing
wrong and to make sure you get to the correct directory, try pressing the Tab button after
typing the first few letters of the folder name. With the tab pressed, it will auto complete the
name of the whole directory and this will give you an idea that such a folder exist and in fact
your command is correct.
Before installing NetCDF, it is very important to follow the below mentioned steps to set
the environment variables.
If you follow the given instructions as given above and use a similar operating system
(Ubuntu 16.04 LTS), you will be working on a bash (bourne-again shell) shell which is
the widely used default at present. If you are using any other shell or operating system,
check the relevant shell and change the script syntax as appropriate. In this manual, we
provide how to manipulate for bash shell and csh (C shell) and also how to find which
shell you are using.
Type the following command to check which shell you are using currently. It will display
which shell you are actively using.
echo $0
If you want to check the default shell you use whenever you login, type the following
command to display the default shell used along with its path directory in the shell
environment variable.
echo $SHELL
Once you find out which shell you are using, you can proceed with the next steps given
below.
Type the following commands on the command prompt with a terminal opened inside
the unzipped NetCDF folder which is in this case the netcdf-4.1.3 folder created by the
unzip command and the command line should display something close to this
depending on your user account names.
Example:
user@user-714-150l:~/WRF3.8/netcdf-4.1.3#
*If you are not the root user, the hash symbol would probably be replaced with a $
symbol. It is always recommended to have the root privileges in compiling WRF.
export CC gcc
export CXX g++
export FC gfortran
export FCFLAGS -m64
export F77 gfortran
export FFLAGS -m64
Configure NetCDF using the following command. These commands are very important
and therefore make sure to the check disable attributes correctly before running the
configuration.
After the configuration of NetCDF above, the next step is to install the library. The
‘make’ command is used followed by ‘make check’ command to check for any errors in
the compilation. Type the following commands in the given sequence. If there is any
error in the configuration of the specific library, it will be displayed on the screen while
the ‘make check’ command is executed.
make
make check
make install
MPICH
cd ..
Wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/mpich-3.0.4.tar.gz
cd mpich-3.0.4
./configure
After the configuration of MPICH, install the library using the following three commands
in sequence.
make
make check
make install
zlib
Move back to the WRF3.8 directory using the following command in the terminal
window.
cd ..
Wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/zlib-1.2.7.tar.gz
Untar the zlib-1.2.7 file using the following command.
cd zlib-1.2.7
./configure
After the configuration of zlib, install the library using the following commands in
sequence.
make
make check
make install
libpng
Move back to the WRF directory using the following command in the terminal window.
cd ..
Wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/libpng-1.2.50.tar.gz
cd libpng-1.2.50
./configure
After the configuration of libpng, install the library using the following commands in
sequence.
make
make check
make install
While installing the libraries, and before configuring, it is advised to see the files inside
the library using the following command to display the files inside the directory
ls
Jasper
Move back to the WRF directory using the following command in the terminal window.
cd ..
Wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/jasper-1.900.1.tar.gz
cd jasper-1.900.1
./configure
After the configuration of Jasper, install the library using the following commands in
sequence.
make
make check
make install
Installing m4
m4 is a macro processor which is either built in or user defined. It is much similar to cpp
(C-pre processor). However m4 is much advanced and powerful when compared with
the abilities of cpp and is a required component to run WRF
The library compatibility tests are run in order to verify that the libraries are able to work
with the compilers that are going to be used for the compilation of WRF and WPS
components. Go to the TESTS folder in the home directory and type the following in the
command prompt to download the test files required.
wget
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_
files/Fortran_C_NETCDF_MPI_tests.tar
Type the following command to copy the netcdf.inc file from the default installation
location to the current directory which is TEST.
cp /usr/local/include/netcdf.inc .
*Notice the last dot (.) placed after the filename to be copied after a space. This is very
important to mak esure the file gets copied to your current address. If the NetCDF has not
installed in the default location, use which command to find its directory and adjust the code
as necessary.
Type the following in the command prompt one after the other
gfortran -c 01_fortran+c+netcdf_f.f
gcc -c 01_fortran+c+netcdf_c.c
./a.out
If the test is successful, the following message should be displayed on the screen.
Type the following command to copy the netcdf.inc file from the default installation
location to the current directory which is TEST.
cp /usr/local/include/netcdf.inc .
Type the following in the command prompt one after the other
mpif90 -c 02_fortran+c+netcdf+mpi_f.f
mpicc -c 02_fortran+c+netcdf+mpi_c.c
mpirun ./a.out
If the test is successful, the following message should be displayed on the screen.
Download the WRF3.8 files using the following command from the WRF directory
wget http://www2.mmm.ucar.edu/wrf/src/WRFV3.8.TAR.gz
gunzip WRFV3.8.TAR.gz
tar –xf WRFV3.8.TAR
Change the directory from WRF to the WRFV3 directory using the following command
cd WRFV3/
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
export NETCDF=/usr/local
export NETCDF_LIB=/usr/local/lib
export NETCDF_INC=/usr/local/include
Then configure WRF according to your desired usage of WRF using the following
command
./configure
A list of options will be displayed from which you can choose one depending on your
compiler and mode of processing
Compilers
There are several compiler options and therefore it is vital to use the same compiler
used to install the libraries for compiling WRF. In this documentation, we recommend
and use gfortra/gcc
Mode of processing
According to our system specifications and compiler used, the option recommended to
choose is 34
34. (dmpar) GNU (gfortran/gcc)
After the selection of the compiler and mode, another selection will be displayed with 4
options for nesting.
The most general two options are the basic (=1) and the vortex following (=3).
The preset (=2) was initially used for testing WRF and therefore it is recommended to
avoid this option.
For basic weather forecasting using meteorological data, it is recommended to use the
basic (=1)
For cyclone tracking applications, the vortex following (=3) option is the most suited.
If the configuration is successful, a message will be displayed with a testing for NetCDF,
C and Fortran compiler.
./compile
This would result in another list of options for which WRF can be compiled as given
below.
Usage:
compile [-j n] wrf compile wrf in run dir (NOTE: no real.exe,
ndown.exe, or ideal.exe generated)
or choose a test case (see README_test_cases for details) :
compile [-j n] em_b_wave
compile [-j n] em_convrad
compile [-j n] em_esmf_exp
compile [-j n] em_fire
compile [-j n] em_grav2d_x
compile [-j n] em_heldsuarez
compile [-j n] em_hill2d_x
compile [-j n] em_les
compile [-j n] em_quarter_ss
compile [-j n] em_real
compile [-j n] em_scm_xy
compile [-j n] em_seabreeze2d_x
compile [-j n] em_squall2d_x
compile [-j n] em_squall2d_y
compile [-j n] em_tropical_cyclone
compile [-j n] exp_real
compile [-j n] nmm_real
compile [-j n] nmm_tropical_cyclone
compile -j n parallel make using n tasks if
supported (default 2)
compile -h help message
The most basic and widely used capability of WRF is the em_real test case which
allows the user to forecast using real meteorological datasets.
The ideal cases can be run to simulate a climatic condition with used defined initial
boundary conditions whereas in the real cases, the initial boundary conditions are
supplied to the WRF through actual meteorological data.
Type the following command with your choice of test case. In here, the test case
compiled for is em_real.
The log.compile command will create a log file for the compilation which will help you
troubleshoot in case of an unsuccessful attempt.
To check for the successful compilation of WRFV3.8, type the following command.
cat log.compile
If the compilation was successful, the following lines will be displayed at the bottom of
the log file.
==========================================================================
build started: Wed Nov 15 15:00:14 +07 2017
build completed: Wed Nov 15 15:06:37 +07 2017
---> Executables successfully built <---
-rwxr-xr-x 1 root root 38340768 Nov 15 15:06 main/ndown.exe
-rwxr-xr-x 1 root root 38217784 Nov 15 15:06 main/real.exe
-rwxr-xr-x 1 root root 37857816 Nov 15 15:06 main/tc.exe
-rwxr-xr-x 1 root root 42000344 Nov 15 15:06 main/wrf.exe
=========================================================================
This is the end of the first component of the WRFV3.8. The next step is to compile
WPS. The compilation is only required for real cases. If you are intending to use WRF
for ideal cases, the WPS compilation is not required.
7. Installing WPS
cd ..
wget http:/www2.mmm.ucar.edu/wrf/src/WPSV3.8.TAR.gz
Unzip the downloaded file using the following two command lines one after the other.
gunzip WPSV3.8.TAR.gz
tar –xf WPSV3.8.TAR
cd WPS/
Exporting Jasper libraries for the installation of WPS with GRIB2 support.
export JASPERLIB=/usr/local/lib
export JASPERINC=/usr/local/include/jasper
Configure WPS using the following command
./configure
If the NetCDF and Jasper libraries are configured properly, following lines will be
displayed on top.
Then the user should select the working platform from the list of supported platforms
given below. In here the selection is 3
--
Configuration successful. To build the WPS, type: compile
----------------------------------------------------------------------
--
After the configuration of WPS, compile WPS using the following command line.
To check whether the compilation of WPS is successful, type the following command.
ls
Check whether the given three components are available and non zero file sized
a) geogrid.exe c) metgrid.exe
b) ungrib.exe
If these three .exe files are available, you can now proceed to the configuration of static
geographic data for WRF.
cd ..
Download the geographical input dataset using the following command line. Make sure
to choose the correct and required dataset suitable for your own task since the data set
size increases as your desired resolution of the forecast increases.
For example, if you need 1km level resolution for your forecast, you can easily use the
following dataset with lowest resolution of each mandatory field for WRF.
wget
http://www2.mmm.ucar.edu/wrf/src/wps_files/geog_minimum.tar.bz2
If you are interested in running the model with a much greater resolution, it is always
recommended to use the complete dataset which accommodates the highest resolution
with the following command.
wget
http://www2.mmm.ucar.edu/wrf/src/wps_files/geog_complete.tar.gz
The difference between these two datasets is in their ability to cater your resolution
needs and the download file size, although the complete dataset accommodates higher
resolution, it comes with the expense of greater file size and hence even the run time for
WPS will be extended depending on your hardware resources.
Chapter 2 – Running the WRF model
There are 4 components that needs to be combined in order to run a successful WRF
real case scenario.
Static Geographical
Data
Geogrid
Metgrid WRF
Ungrib
Meteorological Data
GFS, FNL, etc
Geogrid
Geogrid component uses the static geographical data previously downloaded by the
user before and starts preparing required information to suit the specifications and
attributes listed by the user in the namelist.wps file.
It is important to make sure you have installed the required amount of Static
geographical Data to cater your resolution needs. If there is any data missing, when
running the geogrid, it will ask display an error message saying which files are missing.
These files can be thereafter downloaded from the following link and copied to your
Static Geographical data folder.
http://www2.mmm.ucar.edu/wrf/src/wps_files/
After the geogrid.exe is successfully run, the information required for the metgrid is sent
to be processed with ungrib data
Ungrib
Metgrid
Metgrid component combines the static geographical data and the meteorlogical data
and outputs files in WRF I/O API conforming format. This is the last step in WRF
preprocessing as metgrid operation produces the final input file required for running the
WRF.
Go to the WPS directory and type the following commands in a terminal window.
This will open a text file containing several parameters for different WPS configurations.
The required editing will be explained in the next chapter.
In the text file, there will be one attribute named geog_data_path which should be
configured when running the WPS for the first time. Replace this attribute with the
location address of your geog data.
geog_data_res = '10m','10m','10m',
dx = 9000,
dy = 9000,
map_proj = 'mercator',
ref_lat = 7.5,
ref_lon = 80.3,
truelat1 = 7.4,
stand_lon = 80.2,
geog_data_path = '/home/gic/WRF/geog/'
./geogrid.exe
Once the geogrid.exe is successfully run, type the following command line to link the
meteorological data. Assuming the meteorological data is already downloaded into a
directory named METDATA and the format is GFS,
./link_grib.csh /home/WRF/METDATA/gfs*
Link the variable tables according to the data format you use. (AWIP or GFS). Assuming
you are using GFS data,
./ungrib.exe
After the ungrib process is completed successfully, you can next proceed to the
metgrid.exe using the following command.
./metgrid.exe
After the successful completion of metgrid.exe, you can proceed to the real.exe
assuming that the namelist.input is configured properly. Type the following command
line in a terminal window to change directory to em_real.
cd /home/WRF/WRFV3/test/em_real
Link the metdata to the em_real directory
ln –sf /home/WRF/WPS/met_em.d0* .