For FORTRAN 77, Jonathan Leffler's method will work - as he points out, Fortran 90 and onward also supports COMMON
blocks. However, since you have access to a Fortran 90/Fortran 2003 compiler, then there is no reason to use a COMMON
block - leave them in the ash heap of history along with computed GOTO
and ENTRY
.
The Fortran 90 method for storing a group of related variables (and functions) is no longer the COMMON
block but a MODULE
. For your code, this is relatively straightforward:
module count_calls
integer :: num_calls = 0
end module count_calls
Then, in your subroutines where you want to use num_calls, add
use count_calls
to either the subroutines themselves or the containing scope (i.e. a program
or another module
).