Jump to content
Science Forums

Recommended Posts

Posted

I've recently inherited a somewhat large and poorly documented bit of fortran code. I'm not at all used to working with fortran, so I have some questions

 

This code has a fairly large number of common blocks. Is this fairly common in fortran projects?

 

More importantly, the large number of shared variables is making it hard to follow this (poorly documented) code. I often have difficulty discerning which bits of code store to the common block in which order. Does anyone know of a program to create some sort of documentation, or a tree, etc to get some general sense of the flow of the fortran code? Or is this just going to be a large headache?

-Will

Posted

get a good text editor, one that does syntax highlighting and all, bout as far as i can help you.... unfortunately lots of code is written in that manner, so do all you can to prevent it from happening again, write good code!

Posted
I've recently inherited a somewhat large and poorly documented bit of fortran code. I'm not at all used to working with fortran, so I have some questions...
Its been so long, and Fortran is so baroque, but I'll try...

 

This code has a fairly large number of common blocks. Is this fairly common in fortran projects?
Common blocks have a couple of motivations behind them. As you are aware, they allow sharing of variables between segments of your application. They are properly used as globals when you look at modern programming techniques, thus making sharing data easy. This means you don't have to explicitly pass parameters to functions, but in the old days when pushing them onto the stack for calls was expensive overhead, it made your code run faster too. Similarly, when you were writing programs with explicit recognition of code overlays, you could get some very interesting effects because the common blocks can have different scoping, meaning that they won't necessarily be affected by the subroutines that use them. If you know what you are doing you can use this to interesting effect with pseudo recursion.

 

This latter issue is what means that you can get very non-intuitive results from your code. I so vaguely remember how this works that I won't even try to explain it, but its something that you need to be aware of.

 

More importantly, the large number of shared variables is making it hard to follow this (poorly documented) code. I often have difficulty discerning which bits of code store to the common block in which order. Does anyone know of a program to create some sort of documentation, or a tree, etc to get some general sense of the flow of the fortran code? Or is this just going to be a large headache?

The main thing to realize is that the common blocks only affect program flow to the extent that the flow is controlled by the data within them--and of course with Fortran's wacky "computed goto" statement and the progamming practices it enabled, is indeed likely. But unfortunately, that sort of coding practice makes it *impervious* to analysis, and producing code trees from this kind of Fortran code becomes a perfect example of what Turing was talking about with his Halting Problem....

 

"Inherited code" implies you don't really have much leeway in rewriting, but most of the tools that seem to be out there to do what you want really emphasize rewriting the code rather than giving you and idea of what its doing without changing it. As a result you're left with the usual hacker problem of tweaking and frobbing with judicious instrumentation rather than a major rewrite (where you'd really be better off looking at the code and rewriting it from scratch).

 

You're probably going to be better off with just doing lots of stepping with a symbolic debugger than anything else....

 

NP-complete,

Buffy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...