I am working with an old fortran program.
My problem is a conflict between variables of REAL*4 and REAL*8 type.
The dummy argument used in the declaration of a subroutine in the program is of the REAL*8 type.
The actual argument used for calling this subroutine is of the REAL*4 type.
When the subroutine is called and executed and control returns back to the main program, the values of the dummy and actual argument turn out to be different.
To illustrate this with a simple program, I wrote a subroutine that assigns values from 2,4,6,8,10,12 to an array. The array is the argument for the subroutine; it is of type REAL*8 as the dummy argument (CP) inside the subroutine and of type REAL*4 while calling this subroutine as the actual argument (AP).
The dummy argument values computed inside the subroutine are:
IN SUBROUTINE REAL*8 CP( 1 )= 2.00000000000000
IN SUBROUTINE REAL*8 CP( 2 )= 4.00000000000000
IN SUBROUTINE REAL*8 CP( 3 )= 6.00000000000000
IN SUBROUTINE REAL*8 CP( 4 )= 8.00000000000000
IN SUBROUTINE REAL*8 CP( 5 )= 10.0000000000000
IN SUBROUTINE REAL*8 CP( 6 )= 12.0000000000000
However while returning back to the main program, the actual argument values are:
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 1 )= 0.0000000E+00
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 2 )= 2.000000
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 3 )= 0.0000000E+00
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 4 )= 2.250000
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 5 )= 0.0000000E+00
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 6 )= 2.375000
Could anyone please explain why the two different sets of values are obtained?
My problem is a conflict between variables of REAL*4 and REAL*8 type.
The dummy argument used in the declaration of a subroutine in the program is of the REAL*8 type.
The actual argument used for calling this subroutine is of the REAL*4 type.
When the subroutine is called and executed and control returns back to the main program, the values of the dummy and actual argument turn out to be different.
To illustrate this with a simple program, I wrote a subroutine that assigns values from 2,4,6,8,10,12 to an array. The array is the argument for the subroutine; it is of type REAL*8 as the dummy argument (CP) inside the subroutine and of type REAL*4 while calling this subroutine as the actual argument (AP).
The dummy argument values computed inside the subroutine are:
IN SUBROUTINE REAL*8 CP( 1 )= 2.00000000000000
IN SUBROUTINE REAL*8 CP( 2 )= 4.00000000000000
IN SUBROUTINE REAL*8 CP( 3 )= 6.00000000000000
IN SUBROUTINE REAL*8 CP( 4 )= 8.00000000000000
IN SUBROUTINE REAL*8 CP( 5 )= 10.0000000000000
IN SUBROUTINE REAL*8 CP( 6 )= 12.0000000000000
However while returning back to the main program, the actual argument values are:
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 1 )= 0.0000000E+00
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 2 )= 2.000000
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 3 )= 0.0000000E+00
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 4 )= 2.250000
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 5 )= 0.0000000E+00
AFTER RETURNING FROM SUBROUTINE REAL*4AP( 6 )= 2.375000
Could anyone please explain why the two different sets of values are obtained?