Home > Archive > Fortran > March 2007 > Fortran90/95 Call tree
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Fortran90/95 Call tree
|
|
| jadoo.dost@gmail.com 2007-03-26, 7:05 pm |
| I am working with a Fortran90/95 Code and would like to view it's call
tree. Is there any free software for that?
How could one understand the flow of a code using grep ?
| |
| glen herrmannsfeldt 2007-03-26, 7:05 pm |
| jadoo.dost@gmail.com wrote:
> I am working with a Fortran90/95 Code and would like to view it's call
> tree. Is there any free software for that?
Ftnchek is available free, and does that, among other things.
> How could one understand the flow of a code using grep ?
grep is very useful while working on a program, but it is
not convenient for generating a flow graph. If you are working
on a routine and wonder 'where is this called from?' grep for
the name, usually with -w to reduce the extra hits.
grep will also find place that a variable is used, which is
also pretty useful.
-- glen
| |
| jadoo.dost@gmail.com 2007-03-26, 7:05 pm |
| would ftnchek do fortran90/95 ???
On Mar 26, 4:11 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
> jadoo.d...@gmail.com wrote:
>
> Ftnchek is available free, and does that, among other things.
>
>
> grep is very useful while working on a program, but it is
> not convenient for generating a flow graph. If you are working
> on a routine and wonder 'where is this called from?' grep for
> the name, usually with -w to reduce the extra hits.
>
> grep will also find place that a variable is used, which is
> also pretty useful.
>
> -- glen
| |
| glen herrmannsfeldt 2007-03-26, 7:05 pm |
| jadoo.dost@gmail.com wrote:
> would ftnchek do fortran90/95 ???
It does seem to be designed for Fortran 77. I had noticed it has
the -f95 option, but that seems to add warnings for Fortran 77 features
not in Fortran 95.
However, if the goal is a call tree and you give it fixed form
source it might still be able to find subroutine, function,
call, and function references, depending on which newer features
being used. (Or the output of a free to fixed form conversion.)
[color=darkred]
[color=darkred]
[color=darkred]
[color=darkred]
(snip)
-- glen
| |
| Bil Kleb 2007-03-26, 10:07 pm |
| jadoo.dost@gmail.com wrote:
> I am working with a Fortran90/95 Code and would like to view it's call
> tree. Is there any free software for that?
Here's a /draft/ bit of Ruby that produces a Graphviz dot file:
ROUTINE = /^\s*(?!(end|!|'|" ))(|\S+\s+)(program|subroutine|function)
\s+(?!procedure)(\w+)\W/i
calls = []
subgraphs = Hash.new{ |h,k| h[k]=[] }
Dir['*.[fF]90'].each do |file|
lines = IO.readlines(file)
while (line = lines.shift) do
subgraphs[file] << $4 if line.match(ROUTINE)
if m = line.match(/\W(call)\s+(\w+)\W/)
called = $2
calls << [routine, called] unless m.pre_match.match(/!/)
end
end
end
calls.uniq!
File.open('calling_tree.dot','w') do |f|
f.puts "digraph G {"
f.puts
calls.each{|c| f.puts " #{c.first}->#{c.last}; "}
f.puts
subgraphs.each do |name,routines|
f.puts " subgraph \"cluster_#{name}\" { label=\"#{name}\"; #{routines.join('; ')}; }"
f.puts
end
f.puts "}"
end
Note: it does not find function invocations.
Later,
--
Bil Kleb
http://funit.rubyforge.org
|
|
|
|
|