May 24, 2003

FT - Fortran Beautifier

The main use of FT is to tidy up Fortran programs to make them more
readable. Amongst the options are indentation for DO loops and IF-THEN
ENDIF constructs. Labels can be renumbered sequentially, all code put in
upper case or left in its original case. This tidy program is aimed at
the Unisys 2200 Fortran 77 compiler. Special features of that compiler,
include DELETE statements that span subroutines/ functions. Two labels
can have the same number within the same subroutine, if they are
enclosed within mutually exclusive DELETEs.

Many old Fortran 77 programs were written entirely in upper case capitol
letters. This makes reading comments and finding commented out code
difficult. One option, allows conversion of comments from capitol
letters to lower case, except at the beginning of sentences (after full
stops). Another option, allows spell checking of all words in comments.
If a word is not found in the dictionary it is highlighted by being put
into capitol letters, allowing misspellings, program names and variables
to stand out.

A secondary use to convert Unisys 2200 Fortran to standard Fortran
enabeling the programs can be compiled with other compilers.

For example the character string slicer "SUBSTR" can be converted to the
standard character string define.

e.g. SUBSTR(ABC,5,1) is converted to
     ABC (5:5)

Arithmetic IF statements can be converted to normal IFs

e.g.
     IF (ABC-97) ,1234,1234 is converted to
     IF (ABC .GE. 97) GOTO 1234

Hollerith character strings converted to quote enclosed strings.

The spell checker can also be used for character string constants. Any
misspelled strings are output to a separate file, preceded by the line
number. Any words in error are in upper-case.

A full list of the options is given below. Typing "FT" alone will display
the list.

One unusual aspect of the program is that by default it will attempt to
keep as close as possible to the original layout. e.g. on indenting it
will try to move the whole line to the correct starting position, but
will not alter the internal spacing within the line (unless it goes past
column 72.) This can be useful in the data layout of constants,
and items with comments embedded within the code. To obtain full
restructuring use the -F option. This option will recompose the code
line according to internal rules e.g. spaces around "=" signs.

A separate ZIP file contains the source file and dictionary used in
FT.EXE. The program is written in a simple, but efficient way in C/C++.
It has been compiled with different compilers without problems.

The compiled program is 32 bit, designed for command-line use, under
32 bit Windows, e.g. Windows XP

If you find any errors or have any questions, please contact me at the
following address:-

Paul Bennett

PaulEBennett@Onetel.net.uk

It goes without saying (almost) that nothing is perfect, so before using
this program- backup your original program source.

Sample call line:-

FT  myprog.for myprog.ftn -r -i

This will convert myprog.ftn to myprog.ftn, relabeling and indenting.

Full list of options.


Call line:-

FT  input_file  <output_file> <options>

where:-

     input_file  = file to convert.

     output_file = converted file name. If omitted the default is
                   the output file takes the name of the input file, and
                   the input file is renamed with suffix of .BAK.


         The output file can also be with wild cards. E.G.
         "*.NEW" to take the first part of the input name and
         add on suffix ".NEW".

     options:-

          -C   Comments. Capitalize etc.

          -S <dictionary_file_name>  Spell check comments or quotes with
             optional word list file. Words not in word list are
             capitalized. Needs either "Q" or "C" options or both!

          -R<nnnn>/<mm>/<ss> Relabel option.

       <nnnnn> is optional and is start number of new labels
        (default 1010).
       <mm> is increment (optional) 5 is default.
       <ss> is number of labels to leave unassigned between
       subroutines. Default is zero.

          -I<nn>/<mm>/<ss> for auto-indent.

       <nn> is number of columns for IF indent. default is 3. {optional}
       <mm> is number of columns for DO indent, default is 3. {optional}
       <ss> is start column for indentation, default is 7.    {optional}

          -H Convert Hollerith to standard character strings

          -3 Convert three label arithmetic IF to normal IF (.....) GOTO nnnn

          -U Remove unused labels.

          -K Keep all code in original case.
             Without this option all code is in upper case {except text}

          -P Remove text in columns 73 - 80

          -B Remove blank lines

          -M Convert multiple assigns to singles.

          -L Make all comments lower case.

          -G Convert SUBSTR calls to conventional format

          -JL Left justify labels in cols. 1-5
              Note:- This is default when renumbering labels.

          -JR Right justify labels in cols. 1-5

          -Q Spell check Quotes. (Used with "S" option)
             Errors are output in file with extension .spl
             format is input-line-num:' text' 'text'......
             All text is converted to lower case, except for words in
             error.

          -F Full processing, all fortran code is reformatted
             without this option, the code is realigned in correct
             columns and the original spacing is kept as far as possible.

          -$ Converts error return labels from "$9999" format to the
             more conventional "*9999".

          -T Special testing mode.

          -X Make a cross-reference file. Only valid with -R or -U
             options. File name is same as input file with extension
             .XRF

          -E Place "END" at end of every subroutine/function, that needs
             one to make Unisys code compatible with other compilers.

          -A Replace Unisys string concatenation symbol "&" with
             Fortran standard "//".
