美文网首页编程语言
About preprocessing of FORTRAN c

About preprocessing of FORTRAN c

作者: loughsjtu | 来源:发表于2024-01-02 23:15 被阅读0次

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"

相关文章

网友评论

    本文标题:About preprocessing of FORTRAN c

    本文链接:https://www.haomeiwen.com/subject/oojmndtx.html