[comp.lang.fortran] Where to start, How to organize

moshkovi@cb.ecn.purdue.edu (Gennady Moshkovich) (10/13/90)

Thanx evrybody for extencive remarks.  I summarized everything in this
posting.

Fot those who did not read original posting, it was dealing with
my profanity in FORTRAN, and in programming itself.  Some question asked were
Do the flowcharts really help in debugging of the old programs,
How to organize debuging process, How to start it.

I should also say, that I did not find in MS FORTRAN 4.1 option mentioned 
in one of the letters, which would show nesting depth of the loops.
You can generate a list file with line numbering, and variable info
at the end, but it does not say anything about loop nesting.

The program, I am working at is dealing with soil stability analysis in
3-D, it has lots of random generation, and all other numerical analysis
stuff.

Thanx again for your responce.

Gene.


From chidsey@BRL.MIL Wed Oct  3 12:15:08 1990
Received: from cn.ecn.purdue.edu by cb.ecn.purdue.edu (5.61/1.27jrs)
	id AA26401; Wed, 3 Oct 90 12:15:04 -0500
Received: from smoke.brl.mil by cn.ecn.purdue.edu (5.61/1.27jrs)
	id AA03620; Wed, 3 Oct 90 12:14:59 -0500
To: moshkovi@cn.ecn.purdue.edu
Subject: Re: Where to start ? How to organize ?
Newsgroups: comp.lang.fortran
In-Reply-To: <1990Oct3.101835@ecn.purdue.edu>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Cc: 
Date: Wed, 3 Oct 90 13:04:49 EDT
From: chidsey@BRL.MIL
Sender: chidsey@BRL.MIL
Message-Id:  <9010031304.aa29269@SMOKE.BRL.MIL>
Status: OR


	You don't need to do any of these, but they will help you in the
long run.  They will also help the next guy who gets stuck with the job.

	There exist flow charters for fortran that will make long thin
flow charts automaticly.  They arn't pretty, but they will help break
things into manageable pieces.

	Good luck					Irv
-- 
I do not have signature authority.  I am not authorized to sign anything.
I am not authorized to commit the BRL, the DOA, the DOD, or the US Government
to anything, not even by implication.
			Irving L. Chidsey  <chidsey@brl.mil>

From khb@Eng.Sun.COM Wed Oct  3 15:58:43 1990
Received: from cn.ecn.purdue.edu by cb.ecn.purdue.edu (5.61/1.27jrs)
	id AA02401; Wed, 3 Oct 90 15:58:31 -0500
Received: from Sun.COM by cn.ecn.purdue.edu (5.61/1.27jrs)
	id AA22343; Wed, 3 Oct 90 15:58:28 -0500
Received: from Eng.Sun.COM (exodus-bb.Corp.Sun.COM) by Sun.COM (4.1/SMI-4.1)
	id AA21574; Wed, 3 Oct 90 13:58:26 PDT
Received: from chiba.Eng.Sun.COM by Eng.Sun.COM (4.1/SMI-4.1)
	id AA27159; Wed, 3 Oct 90 13:58:24 PDT
Received: by chiba.Eng.Sun.COM (4.1/SMI-4.1)
	id AA13956; Wed, 3 Oct 90 13:58:28 PDT
Date: Wed, 3 Oct 90 13:58:28 PDT
From: khb@Eng.Sun.COM (Keith Bierman - SPD Advanced Languages)
Message-Id: <9010032058.AA13956@chiba.Eng.Sun.COM>
To: moshkovi@cn.ecn.purdue.edu
In-Reply-To: moshkovi@ecn.purdue.edu's message of 3 Oct 90 14:18:35 GMT
Subject: Where to start ? How to organize ?
Status: OR



FOR_STRUCT    Cobolt-Blue 2940 Union Ave Suite C San Jose CA 95124
	      408 723 0474. This is a "reverse engineering tool" to
	      use the COBOL lingo, viz. makes old code more readable
	      and maintainable. I have not used it myself.

This will help clean up the code


SPAG	      I have reviewed SPAG, short overview is that SPAG is
	      quite handy ... alas not very unixlike (fixable with
	      some shell programming). (Sun employees note: Full
	      review is in the file called SPAG in the same directory
	      as this review). I like the results, and recommend this
	      tool with the caveat about non-unix interface...

	      US distributor: OTG
			      voice 717 222 9100
			      fax   717 229 9103

              Authors:
	                 Polyhedron Software Ltd
			 Magdalen House
			 98 Abingdon Road
			 Standlake
			 Witney
			 Oxon OX8 7RN
			 Tel 0865 300 579
	       

As will this.

Also of merit

IPT Fortran lint: 1096 East Meadow Circle, Palo Alto, CA 94303
			     415-494-7500

This will help find errors in the code, and produces tree call graphs.

Also the following similar tools.

FORWARN Quibus Enterprises: Seems similar, from a promo blurb reading.
			    Probably has slightly uglier reporting
			    (one assumes the promo is as good as it
			    gets). 217 356 8876. Primary focus is the
			    PC market, but say unix versions are
			    available. $1200 would appear to be the
			    price, no discount structure info
			    available. 

Flint(tm) Programming Research ltd:

			    Seems like a much more powerful tool (from
			    the promo lit) includes complexity
			    metrics, X11 interface and all sorts of
			    advisories about what constitutes good
			    portable code (beyond standard(s)
			    conformance). FAX 01 336 1151 voice
			    01-942-9242 

FORCHECK Leiden University Box 9604
2300 RC Leiden
The Netherlands
31-71-276804		    Claims similar to IPT's product.
			    Is said to be available on Suns and many
			    other platforms. I have no personal
			    experience with it.

FLOPPY/FLOW		    From CERN. FLOPPY was posted to
			    comp.sources.misc. Sun employees can get
			    it via the usual internal anon ftp site.
			    FLOW was not posted (and is the 'good
			    part'). 

From dscatl!opto!glen@gatech.edu Wed Oct  3 22:15:20 1990
Received: from bank.ecn.purdue.edu by cb.ecn.purdue.edu (5.61/1.27jrs)
	id AA08039; Wed, 3 Oct 90 22:15:14 -0500
Received: from gatech.edu by bank.ecn.purdue.edu (5.61/1.27jrs)
	id AA05587; Wed, 3 Oct 90 22:15:11 -0500
Received: from gatech.UUCP (uucp.gatech.edu) by gatech.edu (4.1/Gatech-9.0)
	id AA25336 for moshkovi@ecn.purdue.edu; Wed, 3 Oct 90 23:15:05 EDT
Received: from dscatl.UUCP by gatech.UUCP (4.1/SMI-4.1)
	id AA03353; Wed, 3 Oct 90 23:13:03 EDT
Received: by dscatl.UUCP (smail2.5)
	id AA02893; 3 Oct 90 22:50:39 EDT (Wed)
Received: by opto.opto.com (3.2/SMI-3.2)
	id AA01230; Wed, 3 Oct 90 22:18:50 EDT
Date: Wed, 3 Oct 90 22:18:50 EDT
From: opto!glen@gatech.edu (Glen Clark)
Message-Id: <9010040218.AA01230@opto.opto.com>
To: dscatl!ecn.purdue.edu!moshkovi
Subject: FORTRAN MESS
Status: OR

Gene:

	Reverse engineering is always a tough nut. Hoare told the
US government to go find another genius to finish the Ada langauge
because they kept changing the spec after major parts of the
code were already in place.

	One thing you didn't mention was whether the code presently
works (i.e. gets the right answers). If not, will it at least 
compile? If yes, you are already ahead of the game. The MICROSOFT
FORTRAN compiler (even the early versions) would generate a
report and write it to disk, during the compile. I forget which 
switch you have to turn to make the compiler do this. It's in the
book, but it is *NOT* the default value. You have to delibertaely
turn it on.

	This generates a copy of the source and .along the left column,
a listing of the current nesting depth of any loops. Program flow
will often become more apparent after studying this. 

	This report generating feature also generates a synopsis
and the end of each subroutine anbd function of useful info.

	Another approach is simply brute force. Lineprint a hardcopy.
If it's longer than you are tall, tear it into segments which are
about 3 or 4 feet long. Tape them side by side on a wall and study
them. Look before you tear. It's far more important to tear at the
end of a subroutine than it is to have every sheet be the same length.
Every place there is a 'GOTO' which refers to a label higher in the
program, draw an arrof from the arrow into the left margin and up to
the referenced label. Do the same for labels lower in the program,
using the right margin. When you're done you should have a bunch of
upward routes in the left margin and downward routes in the right one.
	With luck, none of them will cross and they will be
concentric. You probably won't be that lucky.

	Now stand back and look at it and see if any pattern emerges.
There is no shortcut to disectign spaghetti code. It takes time.
Sometimes you're just better off to define the problem independ-
andtly, and recode. Use the old program to check your answers.

	There there's the obvious. Go find the original author and
see if he can help.

	350K is a small program on a SUN. But on a PC, it's a major
undertaking. I'm curious. What's the program do?

	- Glen Clark

	gatech!dscatl!opto!glen

From fred@BRL.MIL Thu Oct  4 09:25:59 1990
Received: from cn.ecn.purdue.edu by cb.ecn.purdue.edu (5.61/1.27jrs)
	id AA16620; Thu, 4 Oct 90 09:25:55 -0500
Received: from smoke.brl.mil by cn.ecn.purdue.edu (5.61/1.27jrs)
	id AA03523; Thu, 4 Oct 90 09:25:52 -0500
To: moshkovi@cn.ecn.purdue.edu
Subject: Re: Where to start ? How to organize ?
Newsgroups: comp.lang.fortran
In-Reply-To: <1990Oct3.101835@ecn.purdue.edu>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Cc: 
Date: Thu, 4 Oct 90 10:17:09 EDT
From: fred@BRL.MIL
Sender: fred@BRL.MIL
Message-Id:  <9010041017.aa02776@SMOKE.BRL.MIL>
Status: OR


Gene,

1) Re flowcharts - I find I always have to do some free hand flowcharting but
   when it comes to documenting the code, structured pseudo-code is about
   as informative and a lot easier to prepare.
2) Re re-structuring the code. I give low priority to routines that work ok.
   If the routine needs fixing or expanding, then you probably want to
   re-structure it if its short or relevant parts if it's a long routine.
3) Re approach. Here's how I do it on a UNIX machine:
   a) Put all the source in one file
   b) Use the tr utility to make everything lower case
   c) Use a shell file (batch file on DOS) to edit certain keywords. These are
      words that change the order of statement execution and should be hi-lighted
      by being in upper case. They are: SUBROUTINE, FUNCTION, END, DO, CONTINUE,
      IF..THEN, ELSE, ELSEIF, ENDIF, GOTO, STOP.
   d) Use fsplit to split the monolithic source file into one file per routine.
   e) Move all formats before or after executable statements. Formats tend to
      clutter the execuatable code.

	There's probably plenty more I could say. Been writing and cleaning
Fortran programs for 25 years. But that's 'nuf for now.

-fred

From gw043@zeus.unomaha.edu Sat Oct  6 13:10:22 1990
Received: from cn.ecn.purdue.edu by cb.ecn.purdue.edu (5.61/1.27jrs)
	id AA21333; Sat, 6 Oct 90 13:10:17 -0500
Received: from zeus.unomaha.edu by cn.ecn.purdue.edu (5.61/1.27jrs)
	id AA26880; Sat, 6 Oct 90 13:10:15 -0500
Message-Id: <9010061810.AA26880@cn.ecn.purdue.edu>
Date: 6 Oct 90 13:08:00 CDT
From: "CS4220/8226" <gw043@zeus.unomaha.edu>
Subject: Where to start ? How to organize ?
To: "moshkovi" <moshkovi@cn.ecn.purdue.edu>
Status: OR


>I am working on the debugging and improvement of a quite large FORTRAN program
>(~350K executable file) which was written several years ago.  The
>programing was
>done in a very unstructured fasion, and with very few comments.  The
>program
>is written for PC, using MS FORTRAN.
>
>I have to:
>
>1) Decide if I need to write a flowchart diagramm for the programm
>2) Decide if I need to modify program in a structural style
>3) Find the best ways to organize my work.

Gene, I'm not sure what it is your asking.  I have not used FORTRAN on a PC,
but I have had the unpleasant experience of maintaining "ancient" FORTRAN code.
If you are shopping for a new FORTRAN compiler for a PC, I suggest you read the
discussions in this area concerning the advantages/disadvantages of each.  Then,
you should consider whether the improved code you write will have to be port-
able (to another machine environment).  If, as it was in my case, portability
is not an issue (my only requirement was to run under VAX/VMS), then you can
take full advantage of any FORTRAN or system "extensions" that are available to
you. (e.g. some FORTRAN compilers support record structures)

Look closely at the old code, and make sure you understand it before you pro-
ceed.  I found that the original programmers were often ingenious in making the
most of what was available from the language at the time.  There was SOME sense
to the code, but it was not what we consider "structured" today.

As to whether you need a flowchart diagram, I think that is a matter of prefer-
ence (unless your BOSS wants it).  I don't care for flowcharts myself, but I do
use pseudocode extensively for individual program modules.  For the overall flow
I draw boxes and arrows, or a hierarchy chart to show who calls who etc.  I
don't think I even remember how to make the "proper" flowcharts I was taught in
school.  I just use what works for ME to make sense of the code, and then write/
rewrite the code so that it makes sense to ANYBODY.

A thousand times YES, you should re-work the code in a structural manner.  Some
modules may only require comments, others may require total re-writes.  The ad-
vantage of writing clean code is not just for your successors, but for you as
well.  Often, the only way I know what some of my OWN code does is that I have 
commented and written in a structural manner.

Hope this is what you were asking for.

	Jim McMahon



From jrbd@craycos.com Mon Oct  8 11:01:32 1990
Received: from cn.ecn.purdue.edu by cb.ecn.purdue.edu (5.61/1.27jrs)
	id AA08861; Mon, 8 Oct 90 11:01:28 -0500
Received: from aspen.Craycos.COM by cn.ecn.purdue.edu (5.61/1.27jrs)
	id AA04276; Mon, 8 Oct 90 11:01:24 -0500
Received: from copper.craycos.com by aspen.Craycos.COM (4.1/TotalHack-4.0)
	id AA05742; Mon, 8 Oct 90 10:00:25 MDT
Received: from tnt.Craycos.COM by copper.craycos.com (4.0/SMI-4.0)
	id AA25374; Mon, 8 Oct 90 10:00:15 MDT
Date: Mon, 8 Oct 90 10:00:15 MDT
From: jrbd@craycos.com (James Davies)
Message-Id: <9010081600.AA25374@copper.craycos.com>
Received: by tnt.Craycos.COM (4.0/SMI-4.0)
	id AA04677; Mon, 8 Oct 90 10:00:15 MDT
To: moshkovi@cn.ecn.purdue.edu
Subject: Re: Where to start ? How to organize ?
Newsgroups: comp.lang.fortran
In-Reply-To: <1990Oct3.101835@ecn.purdue.edu>
Organization: Cray Computer Corporation
Cc: 
Status: OR

I don't know if this is exactly what you are asking for, but I
wrote some programming tools for Fortran that might help some.
One is a prettyprinter/GOTO restructurer that is part of a larger
package that costs $129 for PCs.  The other is a combination Lint/
cross-reference/calling-tree diagrammer that costs $329 for PCs.
If you want more info, send me a mailing address or call (719) 527-1384
to get brochures, etc.

If you are looking for something that will do flowcharts of
individual routines and such, the stuff I wrote won't do that.  There
are commercially available CASE tools that do these things - you
might check with Programmer's Connection or one of the other big
PC software retailers and see if they know of anything appropriate.

					Jim Davies
					jrbd@craycos.com