Difference between revisions of "C Preprocessor"

From WikiROMS
Jump to navigationJump to search
Line 1: Line 1:
ROMS extensively uses C-preprocessing during compilation to replace code statements,  
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
insert files into the code, and select relevant parts of the code depending on its
directives.
directives. There are numerous CPP options that can be activated in header files [[cppdefs.h]]
and [[globaldefs.h]].


==Preprocesor Directives:==
==Preprocesor Directives:==
Line 9: Line 10:
:<span class="blue">#define</span> <span class="red">PRIVATE_2D_SCRATCH_ARRAY</span> Istr-3:Iend+3,Jstr-3:Jend+3
:<span class="blue">#define</span> <span class="red">PRIVATE_2D_SCRATCH_ARRAY</span> Istr-3:Iend+3,Jstr-3:Jend+3


:is used to set the dimensions of private automatic 2D arrays.
:is used to set the dimensions of private, automatic 2D arrays.


* 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:
Line 15: Line 16:
:<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 subdomain 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.


* The <span class="blue">#ifdef, #endif</span> directive allows to control whether the preprocessor omits and includes part of the source code. For Example:
* The <span class="blue">#ifdef, #endif</span> directive allows to control whether the preprocessor omits and includes part of the source code. For Example:

Revision as of 22:04, 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.