WRF advanced
Advanced usage
Changing the source code
Conditional compilation
Most Fortran compilers allow passing the source code through a C preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) to allow for conditional compilation. In the C programming language, there are some directives that make it possible to compile portions of the source code selectively.
In the WRF source code, Fortran files have an .F extension. cpp will parse these files and create corresponding .f90 files. The .f90 files will then be compiled by the Fortran compiler.
This means:
1. When editing the source code, always work on the .F files, otherwise changes will be lost on the next compilation.
2. In the .F files, it is possible to include #ifdef
and #ifndef
directives for conditional compilation.
For instance, in dyn_em/module_initialize_ideal.F
, the following bits of code define the model orography for idealized large-eddy simulation runs. Four possibilities are given: MTN
, EW_RIDGE
, NS_RIDGE
, and NS_VALLEY
. If none is selected at compile time (select by adding !
in front of #ifdef and #endif), none of these code lines is compiled and grid%ht(i,j)
(the model orography) is set to 0:
Fortran | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
To control conditional compilation:
1. Search for the variable ARCHFLAGS
in configure.wrf
2. Add the desired define statement at the bottom. For instance, to selectively compile the NS_VALLEY
block above, do the following:
Makefile | |
---|---|
1 2 3 4 5 6 7 |
|
Customizing model output
Adding namelist variables
Running offline nested simulations
Running LES with online computation of resolved-fluxes turbulent fluxes
WRFlux
Created: May 5, 2023