SPAG – Questions and Answers
Shouldn’t I just bin this old stuff and start from scratch?
It’s tempting to wash your hands of legacy code, but programs have content as well as form. Old Fortran programs may look awful, and seem impossible to understand, but there is often real treasure buried in them, in the form of algorithms, data, and information of all sorts.
Don’t just throw it away – recondition it! With plusFORT, and a little effort you can rewrite your program to modern standards in a fraction of the time you would have needed for a rewrite.
What happens to comments when the code is restructured?
Comments are presumed to be attached to the statement that follows them, and as the code is restructured, are moved around in the same way as that statement. F95 style end-of-line comments, are an exception, and are attached to the statement with which they share a line. Another exception is comments preceding statements which are removed from the program (e.g. CONTINUE or GOTO statements which are not needed in the unscrambled code). These are attached to the statement following the redundant statement. The net result is that SPAG preserves comments and usually puts them in the right place.
Are there limits on the size of program that can be processed by SPAG?
Not really. You can process any number of subprograms, and each could have many thousands of statements. plusFORT has been used on numerous projects involving millions of lines of code..
Does SPAGged code run slower?
With few exceptions, SPAG does not change the way in which computation is done, but only the way in which control is passed between one computational section of code and another. As a result, there should be little or no change to either the size or speed of the object code when a program is unscrambled.
Can SPAG handle non-standard Extensions to the ISO standard?
Yes. SPAG understands Fortran 95, and much of Fortran 2003 and 2008. It also deals with most proprietary extensions. including VAX Fortran, IBM VS Fortran, Cray pointers, ENCODE/DECODE etc.
How does SPAG restructure spaghetti code?
SPAG transforms spaghetti code by the cumulative effect of thousands of “elemental” operations. These are small changes which improve the structure of the code, but leave the meaning unchanged. An important advantage of this approach is that major changes to program structure are brought about by a small number of relatively simple and thoroughly reliable procedures. Look at the example below: the apparently small change between the initial and final states is in fact the result of five elemental operations.
SPAG elemental operators – A Worked Example
IF ( A.GT.B ) GOTO 10 R1 = 2.0 CALL SUB 10 PRINT * , R1
IF ( A.GT.B ) THEN GOTO 10 ELSE GOTO xx ENDIF xx R1 = 2.0 CALL SUB 10 PRINT * , R1
|Stage 2||Stage 3|
IF ( A.GT.B ) THEN GOTO 10 ELSE R1 = 2.0 CALL SUB GOTO 10 ENDIF 10 PRINT * , R1
IF ( A.GT.B ) THEN ELSE R1 = 2.0 CALL SUB ENDIF GOTO 10 10 PRINT * , R1
|Stage 4||Stage 5|
IF ( A.GT.B ) THEN ELSE R1 = 2.0 CALL SUB ENDIF PRINT * , R1
IF ( a.LE.b ) THEN r1 = 2.0 CALL sub ENDIF PRINT * , r1
Does it just amount to removing all GOTOs?
Of course, there is more to producing readable code than just eliminating GOTOs. Pascal and C programmers know that too much nesting can make programs almost as obscure as too little. SPAG has elemental operators which allow it to reduce nesting by use of the ELSEIF statement. Look at the example below:
Example of Indentation Reduction
IF ( z.NE.'ONE' ) THEN IF ( z.NE.'TWO' ) THEN IF ( z.NE.'THREE' ) THEN IF ( z.EQ.'FOUR' ) THEN x = a(4) ENDIF ELSE x = a(3) ENDIF ELSE x = a(2) ENDIF ELSE x = a(1) ENDIF
IF ( z.EQ.'ONE' ) THEN x = a(1) ELSEIF ( z.EQ.'TWO' ) THEN x = a(2) ELSEIF ( z.EQ.'THREE' ) THEN x = a(3) ELSEIF ( z.EQ.'FOUR' ) THEN x= a(4) ENDIF
Can I be absolutely sure that SPAG will not change the logic of my program?
SPAG is now a mature program. Since it was first released in 1986, SPAG has successfully unscrambled billions of lines of spaghetti Fortran, and it does its job without fuss or incident.
The way SPAG works – by the repeated application of simple operators – makes it inherently robust.
In fact SPAG provides a way to REDUCE the risk which inevitably goes with change. Using SPAG is certainly orders of magnitude safer than changing your code by hand.
The Next Steps
Ready To Buy?
What do our Customers say about us?
At 13-years old, my daughter’s research manuscript has been accepted for publication in a top tier peer-reviewed Environmental Science journal and OriginPro 8.6 will allow her to export the graphs in a wide variety of formats which can meet any publisher’s requirements. Kudos to OriginLab for designing innovative and intuitive software that can span the needs of both a burgeoning young scientist like my daughter to a PhD expert in their field. It is hard to imagine that other products offer this extraordinary level of user versatility.Michael Grimmett, MD, FACP, FACS Ophthalmologist Palm Beach Gardens, Florida
Huge amount learnt, much more than I expected. Appreciate the ability of the programme much more than I did before.PA, Liverpool, UK
Ref: Mathtype 6.6a. I love this product, thanks for decent support on this softwareJT, Derbyshire, UK
Just would like to express my sincere appreciation to both Adept Scientific UK and Vissim Support team on their swift efficient and friendly responses of my problems. This is by far the best customer services I have received. Thank you.SQ, Manchester, UK
For the time being we are unable to offer the following product ranges although we are currently working hard to increase the number of products we can offer in the future. Please contact us to talk about alternative products that we may be able to offer you.