Dear All
i found a subroutine in the google search for fitting nonliear data, but it seems the subroutine haa a lot of synatix errors, im not a proffessional in fortran
first: any one can help me to solve this errors ,
second: how any one help me to connect this subroutine to a program in order to make an .exe file
Thanks
SUBROUTINE LLSQFVL(NDATA,NPARM,MXPARM,YO,YU,YD,PV,PU,PS,CM,DSE)
INTEGER I,J,K,L,IDF,NDATA,NPARM,MXPARM
REAL*8 YO(NDATA), YU(NDATA), YD(NDATA), PV(NPARM), PU(NPARM),
PS(NPARM), CM(MXPARM,MXPARM), DSE,
PX(301), F95(10), TFACT, S, U
DATA F95/12.7062D0,4.3027D0,3.1824D0,2.7764D0,2.5706D0,2.4469D0,
2.3646D0,2.3060D0,2.2622D0,2.2281D0/
IF((NPARM.GT.MXPARM).OR.(NPARM.GT.301)
.OR.(NPARM.GT.NDATA)) THEN
WRITE(6,601) NDATA,NPARM,MXPARM
STOP
ENDIF
IF(NPARM.LE.0) THEN
DSE= 0.D0
DO 2 I= 1,NDATA
YD(I)= YO(I)
DSE= DSE+ (YD(I)/YU(I))**2
DSE= DSQRT(DSE/DFLOAT(NDATA))
RETURN
ENDIF
TFACT= 0.D0
IF(NDATA.GT.NPARM) THEN
IDF= NDATA-NPARM
IF(IDF.GT.10) TFACT= 1.960D0*DEXP(1.265D0/DFLOAT(IDF))
IF(IDF.LE.10) TFACT= F95(IDF)
ELSE
TFACT= 0.D0
ENDIF
DO 10 I = 1,NPARM
PS(I) = 0.D0
PU(I) = 0.D0
PX(I) = 0.D0
DO 8 J = 1,NPARM
CM(I,J) = 0.D0
CONTINUE
DO 14 I = 1,NDATA
S = 1.D0 / YU(I)
U = YO(I) * S
CALL DYIDPJ(I,PV)
DO 12 J = 1,NPARM
PV(J) = PV(J)*S
CALL QROD(NPARM,MXPARM,MXPARM,CM,PV,PX,U,PS,PU)
CONTINUE
CM(1,1) = 1.D0 / CM(1,1)
DO 20 I = 2,NPARM
L = I - 1
DO 18 J = 1,L
S = 0.D0
DO 16 K = J,L
S = S + CM(K,I) * CM(J,K)
CM(J,I) = -S / CM(I,I)
CM(I,I) = 1.D0 / CM(I,I)
DO 26 I = 1,NPARM
J = NPARM - I + 1
PV(J) = 0.D0
DO 24 K = J,NPARM
PV(J) = PV(J) + CM(J,K) * PX(K)
CONTINUE
DO 30 I = 1,NPARM
DO 30 J = I,NPARM
U = 0.D0
DO 28 K = J,NPARM
U = U + CM(I,K) * CM(J,K)
CM(I,J) = U
DO 36 J = 1,NPARM
PU(J) = DSQRT(CM(J,J))
DO 32 K= J,NPARM
CM(J,K)= CM(J,K)/PU(J)
DO 34 K= 1,J
CM(K,J)= CM(K,J)/PU(J)
CM(J,K)= CM(K,J)
PX(J)= 0.d0
DSE= 0.D0
DO 40 I = 1,NDATA
S = 1.D0 / YU(I)
U = 0.D0
CALL DYIDPJ(I,PS)
DO 38 J = 1,NPARM
PX(J)= PX(J) + (PS(J)*S)**2
U = U + PS(J) * PV(J)
YD(I) = YO(I) - U
DSE= DSE+ (S*YD(I))**2
IF(NDATA.GT.NPARM) THEN
DSE= DSQRT(DSE/(NDATA-NPARM))
ELSE
DSE= 0.d0
ENDIF
U= DSE*0.1d0/DFLOAT(NPARM)
S= DSE*TFACT
DO 44 J = 1,NPARM
PU(J)= S* PU(J)
PS(J)= U*DSQRT(NDATA/PX(J))
RETURN
601 FORMAT(/' *** Dimensioning problems in LLSQF *** (NDATA, NPARM, MX &
1PARM) = (',I5,2(' ,',I5),' )')
END
SUBROUTINE QROD(N,NR,NC,A,R,F,B,GC,GS)
INTEGER I,J,K,N,NC,NR
REAL*8 A(NR,NC), R(N), F(NR), GC(N), GS(N), B, Z(2)
DO 10 I = 1,N
Z(1) = R(I)
J = I - 1
DO 2 K = 1,J
Z(2) = GC(K) * A(K,I) + GS(K) * Z(1)
Z(1) = GC(K) * Z(1) - GS(K) * A(K,I)
A(K,I) = Z(2)
CONTINUE
GC(I) = 1.D0
GS(I) = 0.D0
IF(Z(1) .EQ. 0.D0) GOTO 10
IF(DABS(A(I,I)) .GE. DABS(Z(1))) GOTO 3
Z(2) = A(I,I) / Z(1)
GS(I) = 1.D0 / DSQRT(1.D0 + Z(2) * Z(2))
GC(I) = Z(2) * GS(I)
GOTO 4
Z(2) = Z(1) / A(I,I)
GC(I) = 1.D0 / DSQRT(1.D0 + Z(2) * Z(2))
GS(I) = Z(2) * GC(I)
A(I,I) = GC(I) * A(I,I) + GS(I) * Z(1)
Z(2) = GC(I) * F(I) + GS(I) * B
B = GC(I) * B - GS(I) * F(I)
F(I) = Z(2)
CONTINUE
RETURN
END
SUBROUTINE DYIDPJ(i,PD)
COMMON MXDATA,MXPARM,NPARM,X
REAL*8 PD(MXPARM),X(MXDATA),POWER
POWER= 1.D0
PD(1)= POWER
DO 10 J= 2,NPARM
POWER= POWER*X(I)
PD(J)= POWER
RETURN
END
i found a subroutine in the google search for fitting nonliear data, but it seems the subroutine haa a lot of synatix errors, im not a proffessional in fortran
first: any one can help me to solve this errors ,
second: how any one help me to connect this subroutine to a program in order to make an .exe file
Thanks
SUBROUTINE LLSQFVL(NDATA,NPARM,MXPARM,YO,YU,YD,PV,PU,PS,CM,DSE)
INTEGER I,J,K,L,IDF,NDATA,NPARM,MXPARM
REAL*8 YO(NDATA), YU(NDATA), YD(NDATA), PV(NPARM), PU(NPARM),
PS(NPARM), CM(MXPARM,MXPARM), DSE,
PX(301), F95(10), TFACT, S, U
DATA F95/12.7062D0,4.3027D0,3.1824D0,2.7764D0,2.5706D0,2.4469D0,
2.3646D0,2.3060D0,2.2622D0,2.2281D0/
IF((NPARM.GT.MXPARM).OR.(NPARM.GT.301)
.OR.(NPARM.GT.NDATA)) THEN
WRITE(6,601) NDATA,NPARM,MXPARM
STOP
ENDIF
IF(NPARM.LE.0) THEN
DSE= 0.D0
DO 2 I= 1,NDATA
YD(I)= YO(I)
DSE= DSE+ (YD(I)/YU(I))**2
DSE= DSQRT(DSE/DFLOAT(NDATA))
RETURN
ENDIF
TFACT= 0.D0
IF(NDATA.GT.NPARM) THEN
IDF= NDATA-NPARM
IF(IDF.GT.10) TFACT= 1.960D0*DEXP(1.265D0/DFLOAT(IDF))
IF(IDF.LE.10) TFACT= F95(IDF)
ELSE
TFACT= 0.D0
ENDIF
DO 10 I = 1,NPARM
PS(I) = 0.D0
PU(I) = 0.D0
PX(I) = 0.D0
DO 8 J = 1,NPARM
CM(I,J) = 0.D0
CONTINUE
DO 14 I = 1,NDATA
S = 1.D0 / YU(I)
U = YO(I) * S
CALL DYIDPJ(I,PV)
DO 12 J = 1,NPARM
PV(J) = PV(J)*S
CALL QROD(NPARM,MXPARM,MXPARM,CM,PV,PX,U,PS,PU)
CONTINUE
CM(1,1) = 1.D0 / CM(1,1)
DO 20 I = 2,NPARM
L = I - 1
DO 18 J = 1,L
S = 0.D0
DO 16 K = J,L
S = S + CM(K,I) * CM(J,K)
CM(J,I) = -S / CM(I,I)
CM(I,I) = 1.D0 / CM(I,I)
DO 26 I = 1,NPARM
J = NPARM - I + 1
PV(J) = 0.D0
DO 24 K = J,NPARM
PV(J) = PV(J) + CM(J,K) * PX(K)
CONTINUE
DO 30 I = 1,NPARM
DO 30 J = I,NPARM
U = 0.D0
DO 28 K = J,NPARM
U = U + CM(I,K) * CM(J,K)
CM(I,J) = U
DO 36 J = 1,NPARM
PU(J) = DSQRT(CM(J,J))
DO 32 K= J,NPARM
CM(J,K)= CM(J,K)/PU(J)
DO 34 K= 1,J
CM(K,J)= CM(K,J)/PU(J)
CM(J,K)= CM(K,J)
PX(J)= 0.d0
DSE= 0.D0
DO 40 I = 1,NDATA
S = 1.D0 / YU(I)
U = 0.D0
CALL DYIDPJ(I,PS)
DO 38 J = 1,NPARM
PX(J)= PX(J) + (PS(J)*S)**2
U = U + PS(J) * PV(J)
YD(I) = YO(I) - U
DSE= DSE+ (S*YD(I))**2
IF(NDATA.GT.NPARM) THEN
DSE= DSQRT(DSE/(NDATA-NPARM))
ELSE
DSE= 0.d0
ENDIF
U= DSE*0.1d0/DFLOAT(NPARM)
S= DSE*TFACT
DO 44 J = 1,NPARM
PU(J)= S* PU(J)
PS(J)= U*DSQRT(NDATA/PX(J))
RETURN
601 FORMAT(/' *** Dimensioning problems in LLSQF *** (NDATA, NPARM, MX &
1PARM) = (',I5,2(' ,',I5),' )')
END
SUBROUTINE QROD(N,NR,NC,A,R,F,B,GC,GS)
INTEGER I,J,K,N,NC,NR
REAL*8 A(NR,NC), R(N), F(NR), GC(N), GS(N), B, Z(2)
DO 10 I = 1,N
Z(1) = R(I)
J = I - 1
DO 2 K = 1,J
Z(2) = GC(K) * A(K,I) + GS(K) * Z(1)
Z(1) = GC(K) * Z(1) - GS(K) * A(K,I)
A(K,I) = Z(2)
CONTINUE
GC(I) = 1.D0
GS(I) = 0.D0
IF(Z(1) .EQ. 0.D0) GOTO 10
IF(DABS(A(I,I)) .GE. DABS(Z(1))) GOTO 3
Z(2) = A(I,I) / Z(1)
GS(I) = 1.D0 / DSQRT(1.D0 + Z(2) * Z(2))
GC(I) = Z(2) * GS(I)
GOTO 4
Z(2) = Z(1) / A(I,I)
GC(I) = 1.D0 / DSQRT(1.D0 + Z(2) * Z(2))
GS(I) = Z(2) * GC(I)
A(I,I) = GC(I) * A(I,I) + GS(I) * Z(1)
Z(2) = GC(I) * F(I) + GS(I) * B
B = GC(I) * B - GS(I) * F(I)
F(I) = Z(2)
CONTINUE
RETURN
END
SUBROUTINE DYIDPJ(i,PD)
COMMON MXDATA,MXPARM,NPARM,X
REAL*8 PD(MXPARM),X(MXDATA),POWER
POWER= 1.D0
PD(1)= POWER
DO 10 J= 2,NPARM
POWER= POWER*X(I)
PD(J)= POWER
RETURN
END