Callgraph for Fortran with Doxygen

In this post Ill describe how to generate call graphs for Fortran programs using the doxygen source code documentation tool.

I used version 1.8.3 for this work - you will need a version >= 1.5.6. Note that a complete call graph for the main program is not produced as doxygen treats the program as a module.

Step 0

Install doxygen (>= 1.5.6) from here (or via your Linux distribution mechanism) and graphviz that contains the dot program that draws the call graphs.

Step 1

Run

$> doxygen -g

which creates a Doxyfile that tells doxygen what you want it to do.

Step 2

Edit the Doxyfile. The important entries are:

PROJECT_NAME
OPTIMIZE_FOR_FORTRAN (set to YES)
EXTRACT_ALL (set to YES)
EXTRACT_PRIVATE (set to YES)
EXTRACT_STATIC (set to YES)
INPUT (in my case it is ./code)
FILE_PATTERNS (if extension is not .f90)
HAVE_DOT (set to YES)
CALL_GRAPH (set to YES)
CALLER_GRAPH (set to YES if you want)
DOT_PATH (if the dot program from graphviz is not in your $PATH)

Step 3

Run

$> doxygen Doxyfile

HTML and LaTeX files are created by default in html and latex subdirectories.

Step 4

Open html/index.html in your browser. Click the Files tab and then click the file containing a procedure for which you want the call/caller graphs. Nodes in the graphs are clickable to take you to that function.

Here are a couple of example graphs - first a call graph and then a caller graph:

Example call graph

Example caller graph