You can use the C like preprocessor. The -cpp
command line option to your command line. That option is not turned on by default (As per Vladimir F comment below), although it looks like using the .F90 filename extension (i.e. capital F
, instead of .f90
) will do the trick without the -cpp
option.
Details about the option:
https://gcc.gnu.org/onlinedocs/gfortran/Preprocessing-Options.html
Then you can do the same as you pointed out, so the:
#ifdef <some-var>
code when <some-var> is true
#elif defined(<other-var>)
code when <other-var> is true
#endif
As required.
There are more examples on this page with actual code.
Also, like with C/C++, you can define macros on your command line with the-D
option:
gfortran -DCASE1=3 ...
This will define CASE1
with the value 3
. If you do not specify the value, then 1
is automatically assigned to the macro. This is documented on the same page.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…