编程语言

About preprocessing of FORTRAN c

2024-01-02  本文已影响0人  loughsjtu

About preprocessing of FORTRAN code

You can use preprocessing to activate different code sections as needed. E.g.:

Main.F:

#define debug

#ifdef debug

    write(*,*) "hello 1"

#else

    write(*,*) "hello 2"

#endif

By default, the directives begin with # will be treated as comments. If you compile this file directly by ifort Main.F, you will get the following code in Main.for:

    write(*,*) "hello 2"

To active the preprocess directives, you need to add the option of -fpp at compilation step. Here fpp stands for “FORTRAN preprocessor”.

ifort main.F -fpp

or if you use MS visual studio, turn on fpp:

click Project->Console properties:

After compilation, you will get the following code in main.for:

    write(*,*) "hello 1"

if you want to “#define debug” at compilation step instead of hardcoding. You can:

#ifdef debug

    write(*,*) "hello 1"

#else

    write(*,*) "hello 2"

#endif

WIN: ifort Main.F -fpp /Ddebug or Linux: ifort Main.F -fpp -Ddebug

or manually add option “debug” in MS Visual studio as below.

After compilation, you will get the following code in main.for:

    write(*,*) "hello 1"

上一篇下一篇

猜你喜欢

热点阅读