-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfit.f
56 lines (56 loc) · 1.21 KB
/
fit.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
SUBROUTINE FIT(X,Y,NDATA,SIG,MWT,A,B,SIGA,SIGB,CHI2,Q)
DIMENSION X(NDATA),Y(NDATA),SIG(NDATA)
SX=0.
SY=0.
ST2=0.
B=0.
IF(MWT.NE.0) THEN
SS=0.
DO 11 I=1,NDATA
WT=1./(SIG(I)**2)
SS=SS+WT
SX=SX+X(I)*WT
SY=SY+Y(I)*WT
11 CONTINUE
ELSE
DO 12 I=1,NDATA
SX=SX+X(I)
SY=SY+Y(I)
12 CONTINUE
SS=FLOAT(NDATA)
ENDIF
SXOSS=SX/SS
IF(MWT.NE.0) THEN
DO 13 I=1,NDATA
T=(X(I)-SXOSS)/SIG(I)
ST2=ST2+T*T
B=B+T*Y(I)/SIG(I)
13 CONTINUE
ELSE
DO 14 I=1,NDATA
T=X(I)-SXOSS
ST2=ST2+T*T
B=B+T*Y(I)
14 CONTINUE
ENDIF
B=B/ST2
A=(SY-SX*B)/SS
SIGA=SQRT((1.+SX*SX/(SS*ST2))/SS)
SIGB=SQRT(1./ST2)
CHI2=0.
IF(MWT.EQ.0) THEN
DO 15 I=1,NDATA
CHI2=CHI2+(Y(I)-A-B*X(I))**2
15 CONTINUE
Q=1.
SIGDAT=SQRT(CHI2/(NDATA-2))
SIGA=SIGA*SIGDAT
SIGB=SIGB*SIGDAT
ELSE
DO 16 I=1,NDATA
CHI2=CHI2+((Y(I)-A-B*X(I))/SIG(I))**2
16 CONTINUE
Q=GAMMQ(0.5*(NDATA-2),0.5*CHI2)
ENDIF
RETURN
END