C Preprocessor

From WikiROMS
Jump to navigationJump to search

ROMS extensively uses C-preprocessing during compilation to replace code statements, insert files into the code, and select relevant parts of the code depending on its directives.

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 subdomain 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.