Fortran re-engineering example (2)

The next step in the re-engineering process involves reading the code. People often forget to read the code. I can see the eyes rolling now… “that may work for small programs, but what if my code is 3000 lines long?”. Yes, I agree, it’s not easy to read a piece of code that long… but what other way is there to understand what is happening? Documentation? – yes that helps, *if* it exists. Maybe it doesn’t. Anyways, let’s look at the code (on paper).


Notice from this analysis that there are two main pieces of unstructured code. The first relates to four goto statements and essentially constructs an if-else if-else statement. In the first if statement, if totdis is greater than 250, then it jumps to the code at label 10. If it is less-than-or-equal-to 250, then if performs the code directly below the if statement, then jumps to label 20, which represents the end of the conditional. Similarly with the next if statement. So by converting this piece of code, four goto statements disappear.

The remaining goto is associated with a global loop, encompassing more of the working code. It’s easy to convert this to a loop. Of course there are a myriad of smaller things, but this analysis has provided a basis for the next step.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s