ngse18@castle.ed.ac.uk (J R Evans) (02/11/91)
The question of restructurers comes up quite often, and has recurred several times lately (it must be the prime candidate for an FAQ posting, if someone wants to put one together ...). Here is an account of my own recent experiences, which I hope will help others in the same position. For those about to hit 'n', my main conclusion is: If you deal with Fortran code, you should get a copy of TOOLPACK; it costs next to nothing and does a hell of a lot! ------------------------------------------------------------------------ A few weeks back, an ancient horror reared its head - 5000 lines of unstructured FORTRAN-66. I needed to run it to get some results for a paper, and past experience told me that whilst it normally worked, it had some nasty habits. On previous occasions, I had tidied some of its edges and seen enough of its contents to know that fixing it up manually was going to be an uphill struggle, so I decided to investigate the possibility of using mechanical means to help me improve it. (If it worked better, I'd use it more ...). I began with the two programs which were immediately available to me - FLOPPY, a style analyser and pretty-printer distributed through comp.sources.misc during 1990; and struct, a FORTRAN-66 to ratfor translator, written at Berkeley in the '70s and included with some Unix distributions. These proved of little use, so I investigated also - SPAG, a commercial restructurer and pretty printer; FORCHK, a static analyser, marketed alongside SPAG; and TOOLPACK, a public domain package of Fortran tools and proprietory enhancements distributed by NAG. Lack of time prevented me from investigating other offerings; I would otherwise have wished to evaluate - flint, (and other products) from Programming Research Ltd Here follows a mini-review of each in turn: *** FLOPPY *** Status: Probably copyright, but apparently freely redistributable Source: J Bunn, CERN computer centre, via comp.sources.misc Function: Coding convention checker and pretty-printer Notes: 1. Distributed in Fortran-77 source for IBM, VMS & Unix 2. A tandem program, FLOW, offers structure analysis (not Unix) Review: The distributed version is described as suitable for Ultrix. I compiled it on our Ultrix/RISC system, and found that the pretty-printer function worked as described, but that the resulting layout was restricted to one specific style. The distributed program dumped core when asked to analyse coding conventions; this was easy to fix (simply add SAVE NP to routine ITBIT) but didn't inspire confidence. After meeting various other problems e.g. it rejected perfectly legal statements of the form DO <label> <var> = <expr1>, <expr2>, <expr3> I decided that the expected benefits of getting the convention checking component working did not justify the likely effort required. The Ultrix port appears to be recent, so maybe the VMS version with its associated structure analyser would be both less buggy and more useful. *** struct *** Status: Copyright(?), but widely available. Source: Ultrix/Dynix/etc unsupported distribution. Function: Translates FORTRAN-66 to ratfor. Review: struct did a remarkably good job on my problem code. The resulting ratfor program was very clear. (For those who don't remember it, ratfor is a preprocessor for FORTRAN-66, popular in the '70s, which offered good control structures and free-form input; see, for instance, Kernighan & Plauger's original 'Software Tools'). However, there were drawbacks - struct did not like the one or two simple IF ... THEN ... ELSE ... ENDIF clauses which I had inserted into the source at an earlier round; and attractive as ratfor is, it is restricted by the type structure of its FORTRAN-66 output. I eventually decided that this was not my best route forward, but I have not dismissed struct entirely. The TOOLPACK restructurer that I am now using will not restructure code containing multiple entry loops, and it does not produce very useful diagnostics when this occurs. I am finding the ratfor output of struct helpful in identifying and fixing these problems. *** SPAG & FORCHECK *** Status: Proprietory. Source: Polyhedron Software Ltd. Function: SPAG - code restructurer and pretty-printer FORCHECK - static analyser and standards checker Cost guide: Around UKL900(SPAG) UKL350(FORCHECK) for MS-DOS; mini/mainframe systems according to processor capacity - around UKL3000 for SPAG on a microVAX. Notes: Polyhedron also offer a service, processing customers' code through SPAG/FORCHECK. Review: These two programs are marketed together but originate from entirely different sources. A demonstration diskette for MS-DOS systems (which includes a working version of SPAG restricted to small files) is available from Polyhedron. Prices are high, but substantial discounts are offered to educational institutions. I was unable to put my problem code through a copy of SPAG/FORCHECK, but I did run some similar code through them at a customer site recently and was very impressed with the output. SPAG and FORCHECK are each monolithic programs, with a sizeable array of options, but basically tailored to the specific tasks they set themselves. They are therefore very suitable for use by the occasional programmer, who might feel a little daunted by TOOLPACK. SPAG has the particular advantage over the TOOLPACK restructurer, that it can be instructed to rebuild multiple entry loops, possibly using code duplication techniques. (It is not clear to me from the documentation I have whether SPAG can rebuild them using the alternative technique of adding flag variables.) SPAG also knows about various manufacturers' extensions to the Fortran standards. *** TOOLPACK *** Status: Public domain with NAG enhancements. Source: NAG Function: Extensive collection of Fortran language tools Cost guide: Basic tape - UKL120; VMS tape - UKL240; Manual - UKL40. Review: TOOLPACK must be one of the biggest bargains in the Fortran world. (f2c is another!) It was developed by NAG and Argonne National Laboratory about ten years ago, and the original source is public domain. NAG continue to support the code and the version they distribute contains a number of bug-fixes. They do not restrict copying or use of the current versions, but ask that new organisations obtain copies direct from them, which helps them maintain a database of active users who can be informed of further updates. As well as the basic source tape, NAG offer a range of added-value products tailored to specific architectures/operating systems for which they ask a slightly higher price. They also sell a printed manual, at a cost competitive with that of the materials needed to print a copy from the tape. NAG are apparently developing a new package along the lines of TOOLPACK, which will be available in a few months' time at a rather higher (but still "reasonable") price. TOOLPACK is a suite of programs for developing, analysing and checking Fortran code. At its heart are the various components of a compiler - lexer, parser &c, each functioning as a stand-alone unit. To get the best from TOOLPACK does require an understanding of how compilers work, but the tailored distributions come with some example scripts which allow a user without that knowledge to perform basic operations like pretty- printing, declaration standardisation or restructuring. Alongside the basic components comes a heap of tools to allow you to examine and manipulate the program structure. There is also a simple programming support environment with a Fortran conscious editor (line-oriented, unfortunately), regular expression searcher, 'Software Tools' style (roff) documentation preparer and a macro preprocessor. The package includes Fortran sources for everything. Frankly, I'm kicking myself for not getting a copy of this years ago - it could have saved me a lot of time. I found only two drawbacks in TOOLPACK (both minor, in my view). Firstly, it will only handle standard Fortran-77 programs - it doesn't know about manufacturers' extensions. The one extension that I use regularly is the INCLUDE statement in the VMS form; as distributed, TOOLPACK accepts only its own preprocessor form. However, Ian Hounam at NAG has put together a version of the INCLUDE preprocessor which accepts the VMS form, and sent me a copy of the executables (I'll gladly mail a copy to anyone else who wants them). Secondly, the restructurer will not attempt to rebuild multiple entry loops. Ian tells me that this was a deliberate design decision - both of the two possible strategies (code duplication; introduction of a flag variable) increase the size of the final code over the original, and this was considered undesirable. Unfortunately, when this problem occurs, the resulting diagnostics are not particularly helpful. As mentioned above, I found struct helpful in tracing these problems. -------------------------------------------------------------------------- Conclusions: Despite their evident qualities, I am unable to justify the high cost of the SPAG/FORCHECK products to my employers. TOOLPACK, at trivial cost, offers most of the same features and many more besides. I strongly commend it to all Fortran programmers. Thanks to: Ian Hounam (NAG), Naresh Mooljee (University of Edinburgh), Fred Hopper (NERC) Supplier Addresses: NAG Ltd. Polyhedron Software Ltd Wilkinson House Magdalen House Jordan Hill Road 98 Abingdon Road Oxford OX2 8DR Standlake, Witney, Oxon OX8 7RN Voice: Intl +44 865 511245 Intl +44 86 731 579 Fax: Intl +44 865 310319 Intl +44 86 731 232 Russ Evans British Geological Survey, Edinburgh, UK e_gs18@va.nmh.ac.uk