Difference between revisions of "C Preprocessor"

From WikiROMS
Jump to navigationJump to search
Line 14: Line 14:
* The <span class="blue">#include</span> directive allows to insert the contents of another file into the source code. For example:
* The <span class="blue">#include</span> directive allows to insert the contents of another file into the source code. For example:


:<span class="blue">#include</span> <span class="red">"set_bounds.h"</span>
:<span class="blue">#include</span> <span class="red">"[[set_bounds.h]]"</span>


:is used to insert the tile-bounds header file that computes the horizontal sub-domain indices for RHO-, U- and V-type variables.
:is used to insert the tile-bounds header file that computes the horizontal sub-domain indices for RHO-, U- and V-type variables.

Revision as of 22:33, 31 October 2006

ROMS uses extensively C-preprocessing (CPP) during compilation to replace code statements, insert files into the code, and select relevant parts of the code depending on its directives. There are numerous CPP options that can be activated in header files cppdefs.h and globaldefs.h.

Preprocesor Directives:

  • The #define directive associates a symbolic name with some text. The preprocessor will replace the symbolic name with the specified text everywhere in the code. For example,
#define PRIVATE_2D_SCRATCH_ARRAY Istr-3:Iend+3,Jstr-3:Jend+3
is used to set the dimensions of private, automatic 2D arrays.
  • The #include directive allows to insert the contents of another file into the source code. For example:
#include "set_bounds.h"
is used to insert the tile-bounds header file that computes the horizontal sub-domain indices for RHO-, U- and V-type variables.
  • The #ifdef, #endif directive allows to control whether the preprocessor omits and includes part of the source code. For Example:
#ifdef PROFILE
CALL wclock_on (ng, iNLM, 13)
#endif
is used to activate time profiling during execution.
  • The #ifndef, #endif directive is the opposite, it is executed only when the symbol is not defined or activated. For example:
#ifndef TS_FIXED
USE rho_eos_mod, ONLY: rho_eos
#endif
is used to reference to the equation of state module only when the option TS_FIXED is not activated.