fpt and WinFPT Reference Manual - Command-line Commands

| SimCon Home | Ref Manual Home |

CORRECT INCONSISTENT ARGUMENTS

Syntax:

[DO NOT] CORRECT [INCONSISTENT] ARGUMENTS

[DO NOT] CORRECT [INCONSISTENT] NUMERIC ARGUMENTS

[DO NOT] CORRECT [INCONSISTENT] STRING ARGUMENTS

[DO NOT] CORRECT [INCONSISTENT] HOLLERITH ARGUMENTS

Function:

fpt checks that the actual arguments passed in sub-program calls are consistent with the formal arguments in the sub-program declarations. If an inconsistency is detected, the code at the call site is modified to correct it. The correction is marked in the program text. If no correction is possible, an error is reported to the screen and list file and is marked in the code.

Inconsistencies may arise in:

Corrections are made according to the following rules:

  1. No correction is made if the formal or actual arguments are sub-program names, statement labels, derived types or records. An error is reported.
  2. No correction is made to numeric arguments which differ in protocol.
  3. String arguments passed inconsistently by reference, by address and length and by descriptor are corrected as described below.
  4. Where the formal and actual arguments are whole arrays of different data types or different bounds, no correction is attempted and an error is reported.
  5. Where the formal and actual arguments are whole arrays which differ only in kind or data size, a new temporary array is declared to act as the actual argument, and the original actual argument is copied to or from it as required.
  6. Where the actual argument is a scalar which differs in data type or data size from the formal argument, the correction strategy depends on the access which the sub-program called makes to the formal argument, i.e. on whether the argument is an input argument, an output argument or an input and output argument, as shown in the tables below:

Formal argument an input argument
Actual argument a literal value

\Formal
Actual\
LogicalIntegerRealComplexCharacter
Logicalcopy error error error error
Integererror rewriterewriteerror error
Real error rewriterewriteerror error
Complexerror error error rewriteerror
String %REF %REF %REF %REF copy
Hollerith- - - - rewrite

Formal argument an input argument
Actual argument a variable, a Fortran parameter or expression

\Formal
Actual\
LogicalIntegerRealComplexCharacter
Logicalcopy error error error error
Integererror copy intrin error error
Real error intrin intrin error error
Complexerror error intrin copy error
Character error error error error copy

Formal argument an output or input-output argument
Actual argument of any intent

\Formal
Actual\
LogicalIntegerRealComplexCharacter
Logicalcopy error error error error
Integererror copy copy error error
Real error copy copy error error
Complexerror error error copy error
Charactererrorerror error error copy

The strategies in the table are:

Rewrite:
The literal actual argument is rewritten in the format appropriate to the formal argument. For example:

Actual
Argument
Formal
Argument
Rewritten
Actual Argument
1.0 REAL*8 1.0D0
256 REAL*4 256.0E0
(1.374,-22.71) COMPLEX*16 (0.1374D01,-0.2271D02)
6HRadius CHARACTER*(*) 'Radius'

Intrin:
An intrinsic function is used to convert the actual argument in situ. For example:

Actual Argument
& Type
Formal
Argument
Rewritten
Actual Argument
REAL*8 Y REAL*4 REAL(Y)
REAL*4 X REAL*8 DBLE(X)
REAL*4 X INTEGER*2 IINT(X)

Copy:
The actual argument is copied to and/or copied from a temporary variable of the appropriate data type and size. If necessary, an intrinsic function call is used to make the type conversion. The temporary variable is used as the actual argument.

If no name clash occurs, the temporary variable name is taken from the name of the formal argument with the suffix _arg. A declaration statement for the temporary variable is inserted in the sub-programs which reference it.

For example: Formal argument REAL*4, INTENT(INOUT) :: RANGE

Original statement, with actual argument INTEGER*4 K

CALL add_to_table(k)

Modified code:

range_arg = REAL(k) CALL add_to_table(range_arg) !---------------------------------^-------------------------------------- !!! FPT - 1873 Actual argument has been changed to match formal argument !------------------------------------------------------------------------ k=INT(range_arg)

%REF: Passing of a character argument by reference.

Character arguments are usually passed either by descriptor or by address and length. Descriptors are structures which contain the address and length of the character string. The call site contains, or more usually the system stack receives a single address which is the address of the descriptor. When character arguments are passed by address and length, both the address and the length of the argument are placed on the system stack.

Numeric arguments are normally passed by reference. The call site contains, or the stack receives a single address. If a character argument is passed by descriptor when a numeric is expected, the descriptor is then interpreted as if it were the numeric value and an error occurs. If a character argument is passed by address and length when a numeric value is expected, an additional item is placed on the system stack and eventually causes a stack violation. The program may crash at a site remote from the call site which caused the error.

The correction described here is made when a character argument is passed but the formal argument is numeric. It may be carried out in two ways, controlled by the fpt commands CORRECT INCONSISTENT STRING ARGUMENTS TO HOLLERITHS and CORRECT INCONSISTENT STRING ARGUMENTS BY %REF. In the first case, the string argument is rewritten as an Hollerith constant. In the second it is converted in situ to be passed by reference by the pseudo-function %REF. For example:

Formal argument REAL*8, INTENT(IN) which is used to receive an 8 character Hollerith value:

CALL heading('Weight ')

The modified code, converting to an Hollerith:

CALL heading(8HWeight ) !---------------------------^-------------------------------------------- !!! FPT - 1873 Actual argument has been changed to match formal argument !------------------------------------------------------------------------

Modified code, using %REF:

CALL heading(%REF('Weight ')) !----------------------------------^------------------------------------- !!! FPT - 1873 Actual argument has been changed to match formal argument !------------------------------------------------------------------------

Please note that neither Hollerith constants not the protocol pseudo-function %REF are supported by the Fortran standard. It is possible to create a standard-conforming sub-program which will copy a string to an INTEGER*1 array which may then be passed by reference. This will be implemented in a future version of fpt.


Error:
No correction is attempted and an error is reported.

Code Changes which are Not Standard-Conforming

Argument correction is most commonly carried out during software migration. The best practice is to correct any errors on the original host and re-test before moving the code. The corrections inserted by fpt therefore use extended FORTRAN 77 declaration constructs (e.g. INTEGER*4) and protocol designators (%REF, %VAL and %DESCR). Except for %DESCR these are alll supported by Intel ifort and Compaq visual Fortran which are common migration targets. The extended FORTRAN 77 declaration constructs may be converted to standard form by the fpt command CHANGE DATA SIZES TO KINDS.

Suppressing Argument Correction

Correction of arguments is suppressed for all arguments, or for classes of arguments by the commands:

DO NOT CORRECT INCONSISTENT ARGUMENTS

DO NOT CORRECT INCONSISTENT NUMERIC ARGUMENTS

DO NOT CORRECT INCONSISTENT HOLLERITH ARGUMENTS

DO NOT CORRECT INCONSISTENT STRING ARGUMENTS

Where to Use these Commands

Operating system command line Yes
Configuration file, config.fsp Yes
Specification (fsp) files, *.fsp Yes
Interactively, to FPT> prompt Yes
Interactive command files Yes
Embedded in the Fortran code Yes

Default

Inconsistent arguments are not corrected by default (Note that defaults may be changed in the configuration file).

Examples

The four calls to labval in the program t all contain inconsistent arguments. The formal arguments expected are lab, which is treated as an eight byte Hollerith, and val which is double precision. The actual arguments g and 100.0 are single precision reals, the numeric argument for height, 50, is INTEGER*4 and the argument 'Area    ' is CHARACTER*8.

SUBROUTINE LABVAL(LAB,VAL) DOUBLE PRECISION LAB,VAL WRITE(6,900)LAB,VAL 900 FORMAT(1X,A8,2X,E12.2) END PROGRAM T PARAMETER (G=32.2) CALL LABVAL(8HG ,G) CALL LABVAL(8HHeight ,100.0) CALL LABVAL(8HWidth ,50) CALL LABVAL('Area ',50.0D0*100.0D0) END

fpt corrects the code of the program t as shown below (The diagnostics marking the corrections have been suppressed):

PROGRAM t PARAMETER (g=32.2) CALL labval(8HG ,DBLE(g)) CALL labval(8HHeight ,100.0D0) CALL labval(8HWidth ,50.0D0) CALL labval(8HArea ,50.0D0*100.0D0) END

See Also

CORRECT INCONSISTENT ARGUMENTS TO ...

ARGUMENT CORRECTION TO EMULATE VMS

Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.