Gfortran: treat pure functions as normal functions for debugging?

I need to debug some pure functions in a fortran program compiled with gfortran. Is there a way to ignore pure statements so that I can use write , print , etc. with little effort. In these pure functions? Unfortunately, it is not easy to simply remove the pure statement.

+6
source share
2 answers

You can use the macro and use the -cpp flag.

 #define pure pure subroutine s print *,"hello" end 
+6
source

I usually use a preprocessor for this task:

 #ifdef DEBUG subroutine test(...) #else pure subroutine(...) #endif ! ... #ifdef DEBUG write(*,*) 'Debug output' #endif ! ... end subroutine 

You can then compile your code with gfortran -DDEBUG for verbose output. (In fact, I personally do not set this flag globally, but through #define DEBUG at the beginning of the file I want to debug).

I also have MACRO, which simplifies the use of debugging write statements:

 #ifdef DEBUG #define dwrite write #else #define dwrite ! write #endif 

In doing so, the code above comes down to:

 #ifdef DEBUG subroutine test(...) #else pure subroutine(...) #endif ! ... dwrite (*,*) 'Debug output' ! ... end subroutine 

You can enable the pre-processor with -cpp for -fpp and -fpp for ifort . Of course, when using .F90 or .F preprocessor is enabled by default.

+3
source

Source: https://habr.com/ru/post/954718/


All Articles