[comp.lang.fortran] Renumbering labels and formats in FORTRAN <long>

khb@chiba.Eng.Sun.COM (Keith Bierman fpgroup) (11/06/90)

...from my dark past....

Subject: SPAG: a Fortran restructuring tool (preliminary notes) 
old review


		    Executive Summary
		   ======================

	If all your Fortran code is brand new, this product is of some
	use, but not wonderful.

	If much of you (and your customers) Fortran code dates back to
	FORTRAN II ... you (they) probably need this product or one
	like it.

	Has some rough edges, but worth serious consideration.

-------------------------- On to the details....


I've just obtained a demo copy of Polyhedron's SPAG tool (and
friends). I've run a few 10K's lines of code through it and have
formed some initial impressions. A full review will come later. 

	Those of you faced with porting huge hunks of ugly f77 are
	invited to send me the source for conversion. The demo copy
	cannot be shared. 

The PRIMS toolkit contains the following:

SPAG:   the real tool, does useful work. Makes the package worthwhile.
	More about this below.

cmake:  jr. make. Real thing is oodles better.

qsplit: Basically fspit, with less power. May be handy due to silly
	SPAG implementation in 2.28. 

qmerge:	Sort of like naming your files .F, to get cpp for conditional
	compilation. Seems suboptimal for Unix; may be of interest for
	those users whose source code is mostly maintained on PC's or
	other systems sans cpp, NSE/SCCS/RCS/real configuration
	control. If you have qmerge actively used, you probably need
	qsplit. 

cram:	Provides a report of who calls who. Checks arg lists for
	consistent number of arguments. Provides a potential overlay
	map (really handy on Virtual Memory systems :>).

===== SPAG

SPAG provides several functions which:

0)   Can make your life easier as you try to port huge hunks of code
     for benchmarking. Can also make optimizations easier to spot ...
     also handy for you benchmarkers out there.

For our customers:

1)   Simple "pretty printing" mode, can be used to help encourage
     (enforce) coding style guidelines. Especially helpful when you
     start out with a Million Lines of raw sewage.

2)   Can be configured to replace all 

	 DO 1 J=1, N ... 1 x=10

     with

         DO j=1, n .... x=10 ; END DO

     Which, as it happens can help to expose good candiates for loop
     fusion, viz.

      DO     4 I=1,20
    4 DPDTT  (I)  =INI
      DO     5 I=1,20
    5 TDPDT  (I)  =INI
      DO     6 I=1,20
    6 DBSOR  (I)  =INI
      DO     7 I=1,20
    7 TSOR   (I)  =INI
becomes
      DO i = 1 , 20
         dpdtt(i) = ini
      ENDDO
      DO i = 1 , 20
         tdpdt(i) = ini
      ENDDO
      DO i = 1 , 20
         dbsor(i) = ini
      ENDDO
which is trivally changed to 

      DO i = 1 , 20
         dpdtt(i) = ini
         tdpdt(i) = ini
         dbsor(i) = ini
      ENDDO

Which executes faster. When we have run out of bigger automatic
optimization wins, and other scheduled work, the compiler will
probably do this for you. But for now, SPAG can help you spot this
sort of thing. Especially probable is that the original code had
assigned goto's and such ... and only after SPAG is this sort of thing
obvious. 

      IF(Z6.GT.ZMAX)GOTO 50
      IF(Z6.LT.ZMIN)GOTO 45
      I6FT=I
      J6FT=J
  45  IF(Z8.GT.ZMAX)GOTO 50
      I8FT=I
      J8FT=J
      GOTO 55
   50 CONTINUE
   55 CONTINUE

becomes

            IF ( z6.LE.zmax ) THEN
               IF ( z6.GE.zmin ) THEN
                  i6ft = i
                  j6ft = j
               ENDIF
               IF ( z8.LE.zmax ) THEN
                  i8ft = i
                  j8ft = j
                  GOTO 100
.... etc.

     Don't get unreasonable expectations, the revised code is likely
     to run a few %faster, but not a lot faster ... and can be
     modestly slower too. The point is that after SPAGization (pity
     they didn't call it DESPAG :>) transformations are likely to be
     easier. 

3)   About 50 user configurable transformations. I suspect that most
     users will pick a transformation and stick to it.

Rough edges:

Documentation isn't slick. Modestly functional, but not slick. No
index. Printed single sided, courier typeface.

A slightly simplistic copy protection scheme is employed. I have made
some suggestions about it to the authors, so I won't belabor the
point. 

Currently the tool is very un-Unix like. The input is compiler like
(viz. spag *.f works) but the output is PC like ... goes to spag.out
unless one uses a non-Unix syntax ... and all *.f > spag.out ... so
qsplit or fsplit is then required to get ones source code back.
Hopefully this will be fixed in a future release.

The tool also produces a huge amount of nattering during normal
operation. This can obsure interesting warning messages. I suggest
spag *.f > bork ; grep -i warning bork 

for now. Probably a rather elaborate shell script for undoing the
bogus cat > spag.out in an automagic fashion. Again, one hopes for
better in the future.

As I said in the opening, I've run a few tens of thousands of lines
through SPAG and to coin a phrase :> ... "It verks" and aside from the
MVS/PC style of interaction it does quite well. The code produced
worked correctly (there were some warnings which the dedicated would
have fixed up) and produced identical answers (although FP arithmetic
being what it is, this could vary a bit ... just as optimization
levels can impact 'em). With the nattering redirected to a file, on a
4/260 operating on NFS mounted files (so it's very like a 4/60), the
conversion rate was a respectable 20Klines/min.

I got my copy from the authors at Polyhedron (they were very fast on
the uptake, and got me a copy very quickly after I requested one for
review purposes ... 10 brownie points for promptness!). It is my
understanding that OTG takes care of normal orders:

	      OTG
	      voice 717 222 9100
	      fax   717 229 9103

Alternatively, one may wish to go to the source

	       Polyhedron Software Ltd
	       Magdalen House
	       98 Abingdon Road
	       Standlake
	       Witney
	       Oxon OX8 7RN

	       Tel 0865 300 579
	       
The distribution was on floppy, though the documentation specified
tape. I suspect that anyone clever enough to code in Fortran (high
performance where it counts :>) is smart enough to know that the
floppy drive is /dev/rfd0 ..... after all I eventually
figured it out ... I suspect that real customers get tapes ... but
snail mail distribution costs being what they are, floppy was just
fine. 

There have been such tools around for many years, typically site
specific, and maintained by the local gurus (remember that most of the
C tools we take for granted, cxref, flow, etc. are based on Fortran
tools which predate them ... but never made it to Unix). Alas, much of
the good culture got left behind when we (as an industry) unplugged
the mainframes and shot all the support staff. This is the first
commerical tool which I've seen running on Sun boxes.

I don't know what the licensee fee structure looks like; I suspect
that they are willing to negotiate sites and have some predefined
prices for single workstations.

Some competing products:

Fortran Development Tools Quibus
(promo lit only review)

Pretty sort of like SPAG. Seems less powerful

Outline: indentation creator with bonus graphic symbols to highlight
	 logic. 

PREP   : another conditional compilation, includization tool.

SPLIT  : yet another fsplit

COMBINE: undo what SPLIT hath wrought.

SEQ/UNSEQ: for those demented souls who think we still have punch
	   cards.

Not exciting as such, but prices start at $500, so it is at least
cheap. 

FOR_STRUC from cobalt-blue.

Like SPAG. No details in my hands. 408 723 0474. cb really pushes
automated fortran->c|c++ xlation which is a very, very bad idea. May
be a great implementation though.

	      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
	       
--
----------------------------------------------------------------
Keith H. Bierman    kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM
SMI 2550 Garcia 12-33			 | (415 336 2648)   
    Mountain View, CA 94043