thezealite
Programmer
I'm trying to resurrect an old Fortran 77 program, and I've found something bizarre. If anyone can offer ideas on how to debug this, that'd be perfect.
I call a subroutine (LGRNG) from inside a larger program, and I get about -6e+09 as my answer, when the answer should be more like +2e+06. The subroutine has already been used in several places in this larger program without any trouble, and when I try to test the subroutine in a standalone program with the exact same data (read from the screen right before the subroutine call), it works fine.
This doesn't seem like any familiar programming error. How do I go about investigating this?
SUBROUTINE LGRNGE(X,Y,N,ARG,ANS)
C
C LGRNGE PERFORMS 4 POINT LAGRANGIAN INTERPOLATION
C
DIMENSION X(N),Y(N),XX(4),YY(4)
IF (ARG-X(2)) 10,10,20
10 MM = 1
GO TO 70
20 IF (ARG-X(N-1)) 40,40,30
30 MM = N-3
GO TO 70
40 N1 = N-1
DO 60 I=2,N1
IF (ARG-X(I)) 50,50,60
50 MM = I-2
GO TO 70
60 CONTINUE
70 DO 80 I=1,4
MMM = MM+I-1
XX(I) = X(MMM)
80 YY(I) = Y(MMM)
C1 = ((ARG-XX(2))*(ARG-XX(3))*(ARG-XX(4)))/
1(XX(1)-XX(2))/(XX(1)-XX(3))/(XX(1)-XX(4))
C2 = ((ARG-XX(1))*(ARG-XX(3))*(ARG-XX(4)))/
1(XX(2)-XX(1))/(XX(2)-XX(3))/(XX(2)-XX(4))
C3 = ((ARG-XX(1))*(ARG-XX(2))*(ARG-XX(4)))/
1(XX(3)-XX(1))/(XX(3)-XX(2))/(XX(3)-XX(4))
C4 = ((ARG-XX(1))*(ARG-XX(2))*(ARG-XX(3)))/
1(XX(4)-XX(1))/(XX(4)-XX(2))/(XX(4)-XX(3))
ANS = C1*YY(1)+C2*YY(2)+C3*YY(3)+C4*YY(4)
RETURN
END
The data is
N = 33
X = 0.0000000 6.28372654E-02 0.11555304 0.18770462 0.32124862 0.45034185 0.57765341 0.82983512 1.0806023 1.3308103 1.3808212 1.4308277 1.4808326 1.5308338 1.5808340 1.6308342 1.6808355 1.7308390 1.7808447 1.8308527 2.0809565 2.3312027 2.5816143 2.8321984 3.0829539 3.3338597 3.5849757 3.8362377 4.0876808 4.3392887 4.5911241 4.8431702 5.0954781 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
Y = 0.0000000 1616597.0 1991602.9 2180708.0 2281476.5 2298022.8 2304619.5 2304619.5 2296372.8 2281476.5 2277661.5 2273675.0 2269852.5 2265691.8 2261531.3 2257193.5 2252688.3 2248173.5 2243658.0 2238969.3 2216281.3 2193634.5 2170527.8 2146613.8 2122569.8 2099777.5 2075834.8 2049458.6 2021600.4 1984514.1 1943587.4 1896944.4 1842627.5 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
ARG = 1.6808354854583740
I call a subroutine (LGRNG) from inside a larger program, and I get about -6e+09 as my answer, when the answer should be more like +2e+06. The subroutine has already been used in several places in this larger program without any trouble, and when I try to test the subroutine in a standalone program with the exact same data (read from the screen right before the subroutine call), it works fine.
This doesn't seem like any familiar programming error. How do I go about investigating this?
SUBROUTINE LGRNGE(X,Y,N,ARG,ANS)
C
C LGRNGE PERFORMS 4 POINT LAGRANGIAN INTERPOLATION
C
DIMENSION X(N),Y(N),XX(4),YY(4)
IF (ARG-X(2)) 10,10,20
10 MM = 1
GO TO 70
20 IF (ARG-X(N-1)) 40,40,30
30 MM = N-3
GO TO 70
40 N1 = N-1
DO 60 I=2,N1
IF (ARG-X(I)) 50,50,60
50 MM = I-2
GO TO 70
60 CONTINUE
70 DO 80 I=1,4
MMM = MM+I-1
XX(I) = X(MMM)
80 YY(I) = Y(MMM)
C1 = ((ARG-XX(2))*(ARG-XX(3))*(ARG-XX(4)))/
1(XX(1)-XX(2))/(XX(1)-XX(3))/(XX(1)-XX(4))
C2 = ((ARG-XX(1))*(ARG-XX(3))*(ARG-XX(4)))/
1(XX(2)-XX(1))/(XX(2)-XX(3))/(XX(2)-XX(4))
C3 = ((ARG-XX(1))*(ARG-XX(2))*(ARG-XX(4)))/
1(XX(3)-XX(1))/(XX(3)-XX(2))/(XX(3)-XX(4))
C4 = ((ARG-XX(1))*(ARG-XX(2))*(ARG-XX(3)))/
1(XX(4)-XX(1))/(XX(4)-XX(2))/(XX(4)-XX(3))
ANS = C1*YY(1)+C2*YY(2)+C3*YY(3)+C4*YY(4)
RETURN
END
The data is
N = 33
X = 0.0000000 6.28372654E-02 0.11555304 0.18770462 0.32124862 0.45034185 0.57765341 0.82983512 1.0806023 1.3308103 1.3808212 1.4308277 1.4808326 1.5308338 1.5808340 1.6308342 1.6808355 1.7308390 1.7808447 1.8308527 2.0809565 2.3312027 2.5816143 2.8321984 3.0829539 3.3338597 3.5849757 3.8362377 4.0876808 4.3392887 4.5911241 4.8431702 5.0954781 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
Y = 0.0000000 1616597.0 1991602.9 2180708.0 2281476.5 2298022.8 2304619.5 2304619.5 2296372.8 2281476.5 2277661.5 2273675.0 2269852.5 2265691.8 2261531.3 2257193.5 2252688.3 2248173.5 2243658.0 2238969.3 2216281.3 2193634.5 2170527.8 2146613.8 2122569.8 2099777.5 2075834.8 2049458.6 2021600.4 1984514.1 1943587.4 1896944.4 1842627.5 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000
ARG = 1.6808354854583740