fpt and WinFPT Reference Manual - Command-line Commands
| SimCon Home
| Ref Manual Home |
Systematic Code Changes
fpt analyses the code of a program or suite of programs and reports errors and code metrics. It can also
rewrite the code making systematic changes
fpt always reformats the input code in a style specified by the user. Please see
Code Formatting. For this reason we recommend that the
output files are written to a different directory or directory structure from the input files instead of
overwriting them. Please see
File Handling for a description of the way this is set up.
The output code may be written in free or fixed form. The line length, including and excluding comments, the
indentation rules for declarations and control constructs, the spacing between keywords and symbols and the
upper and lower case spelling of keywords, symbols, Fortran parameters, kind tags and exponent characters may
all be specified.
fpt always writes the output files with file name extensions, upper and lower case spelling and to a directory
structure specified by the user. Again see File Handling for a description.
There is a great deal more to code modernisation than reformatting to free format. The facilities include:
-
Conversion of COMMON blocks to MODULES
-
Removal of statememnt labels in control constructs and removal of labelled FORMAT statements
-
Replacing data size specifications of the form INTEGER*4 by KIND specifications
-
Condensing declaration statements so that all attributes of a symbol are written in one statement
The automatic error corrections include:
-
Almost all mis-matched and missing sub-program arguments. fpt can also correct arguments of the
wrong type or kind in I/O statements.
-
The use of integer variables in logical contexts. The correction takes into account the bit pattern used
for logical variables on the target.
-
Replacement of CALL statements calling functions by function invocations
-
The precision of real literal values, where the context of use implies a different precision (and therefore
kind) to that specified or set by default.
-
Errors in INTENT (IN) specifications. These may be corrected by inserting copy operations.
-
== or .EQ. used for logical objects may be changed to
.EQV. taking the difference in operator precedence into account. So also for the
other comparison operators.
fpt has been used in many software migrations, in particular from VMS to ifort or ifx, and from Gould-SEL MPX
to ifort, ifx or gfortran.
The VMS migration facilities include:
-
Conversion of tab-format code to standard free or fixed format
-
Correction of real arguments. VMS allows 4-byte scalar real objects to be passed to 8-byte arguments and vice-versa.
Most systems do not
-
Conversion of argument passing protocols. In particular, VMS character objects are passed by descriptor.
Linux and Windows compilers pass character arguments by address and length
-
Automatic padding of COMMON, STRUCTURE and derived type constructs to align addresses
-
Conversion of the BYTE data type to INTEGER*1
or INTEGER(1)
-
Recognition of the VMS system library routines and adjustments to use
Sector7's emulation libraries
-
Conversion of ISAM file handling to calls to Sector7's routines
-
Insertion of the TARGET attribute. The memory architecture of VMS usually makes specification of TARGET unnecessary
and it is often omitted
-
Recognition and, where appropriate, conversion of !DEC$ PSECT constructs
-
Recognition and handling of Oracle PRO* FORTRAN constructs, again in collaboration with
Sector7 USA LLC.
-
Facilities to test a migration, including coverage analysis,
detailed comparison of results removing numerical drift and facilities to capture and replay terminal and sub-program input.
The Gould-SEL MPX migration facilities include:
-
Editing of variable names to remove alphabetic colon characters and to allow for name truncation to 8 characters
on the original host
-
Conversion of the DATAPOOL construct to a standard COMMON block
-
Creation of an interactive tool to inspect and change DATAPOOL and COMMON block variables at run-time
-
Removal of extended memory constructs. The Gould-SEL Concept machines had only 18 address bits, so the memory was divided into banks
-
Encapsulation of references to INTEGER*1 variables. The INTEGER*1 type on a Gould-SEL system is untyped
-
Translation of embedded assembler to Fortran
Optimisations include:
-
In-line expansion of sub-programs
-
Loop unrolling
-
Scalarisation of arrays. It was found that splitting arrays into separate scalar objects improves the capacity of
compilers to optimise code
-
Moving small service routines from modules and into contained INCLUDE files. This is a significant optimisation
It is expected that all but the last of these optimisations will be carried out as part of the build procedure for
production code. Development should not be carried out on code with in-line expansion, loop unwinding or
scalarisation.
Many of the code formatting commands are appropriate for code standardisation. In addition:
-
IMPLICIT NONE may be mandated for all sub-programs. When this is done declarations are
inserted for all undeclared objects
-
Data size specifications of the form INTEGER*4 may be changed systematically to
KIND specifications.
-
KIND specifications may be mandated in the declarations of all logical and numeric objects
-
INTENT specifications may be mandated for all sub-program arguments for which they are appropriate
-
Statement labels may be moved from executable statements to CONTINUE statements
-
IF statements with executable sub-statements may be changed to IF-THEN constructs
-
Legacy intrinsic functions may be replaced by their modern Fortran equivalents
-
The '%' type component or field separator may be changed to '.'
or vice-versa. '%' is standard conforming but '.' is preferred by
many users.
-
Tab characters within the code may be changed to spaces
Two research projects in particular required specialised processing by fpt. The first, the conversion of Fortran programs to
run on a highly parallel system implemented on an FPGA, required:
-
In-line expansion of sub-programs
-
Scalarisation - converting all arrays to separate scalar objects, unrolling all loops
-
Reduction to triples. All expressions were split into components of the form a = b .OPERATOR. c.
The second tested the precisions required in real variables and in literal values in existing programs. This required:
-
Replacement of REAL declarations by declarations of derived types which emulated the real values
-
Insertion of a USE statement for a module in every sub-program. The module defined all of the overloads of operators and
intrinsic functions used in the codes.
All of the machinery for this study is included in the fpt distribution, and the fpt commands are available.
Anyone like to guess what this does?
DO IABABH=1,3
AAAJAI(IABABH,1)=AABABC(IABABH,1,2)+AABABC(IABABH,1,3)
AAAJAI(IABABH,2)=AABABC(IABABH,2,1)+AABABC(IABABH,2,3)
AAAJAI(IABABH,3)=AABABC(IABABH,3,1)+AABABC(IABABH,3,2)
DO IABABI=1,3
AABABD(IABABH,IABABI)=AABABE(IABABH,IABABI)
AABABE(IABABH,IABABI)=AABABE(IABABH,IABABI)+(3*AAAJAI(IABABH,
1 IABABI)-AABABF(IABABH,IABABI))*AABAAB*0.5D0
AAAJCA(IABABH,IABABI)=AAAJCA(IABABH,IABABI)+0.5D0*(AABABE(IABABH,
1 IABABI)+AABABD(IABABH,IABABI))*AABAAB
AABABF(IABABH,IABABI)=AAAJAI(IABABH,IABABI)
ENDDO
ENDDO
The answer is here