C****************************************************************
C* 								*
C*								*
C*	DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY *
C*	EITHER FOR THE CREATION OR FOR THE CLINICAL EFFICACY	*
C*	OF THIS PROGRAM. USERS MUST ASSUME FULL RESPONSIBILITY	*
C*	FOR ANY RESULTS OR DIAGNOSES OBTAINED FROM THE USE	*
C*	OF THIS PROGRAM. QUESTIONS ON THE EXECUTION OF THIS	*
C*	PROGRAM MUST BE REFERRED BACK TO THE ORIGINAL AUTHOR.	*
C*								*
C* AUTHOR:	SALLY FORSTER					*
C*		C/O DEPARTMENT OF NUCLEAR MEDICINE		*
C*		GUY'S HOSPITAL				*
C*		LONDON, ENGLAND					*
C*								*
C*		TEL: 01-407-7600 EXT 2583/4			*
C*								*
C****************************************************************
	FUNCTION POLFIT(IX1,IX2)
	COMMON//IBLK(256),CY(512),CX(512)
	COMMON/WINDOW/IFST,ILST
	COMMON/FIT/CA(4)
	EXTERNAL CPOL
	INTEGER*2 POLFIT
C******FIT A*X^2+B*X+C
	REAL*8 SUMX,SUMY,ARRAY,RESSSQ,A
	DIMENSION SUMX(5),SUMY(3),ARRAY(3,3),A(3)
	POLFIT=0
C*****
C*****ACCUMULATE SUMS
C*****
	CALL POLACC(IX1,IX2,SUMX,SUMY,ARRAY,A,RESSSQ)
C*****
C*****CONSTRUCT MATRICIES AND CALCULATE COEFFICIENTS
C*****
51	DO 54 J=1,3
	DO 54 K=1,3
	N=J+K-1
54	ARRAY(J,K)=SUMX(N)
	DELTA=DETERM(ARRAY)
	IF(DELTA)61,57,61
57	RES=0
	DO 59 J=1,4
59	CA(J)=0
	GOTO 80
61	DO 70 L=1,3
62	DO 66 J=1,3
	DO 65 K=1,3
	N=J+K-1
65	ARRAY(J,K)=SUMX(N)
66	ARRAY(J,L)=SUMY(J)
70	A(L)=DETERM(ARRAY,3)/DELTA
C*****
C*****CALCULATE RESSSQUARE
C*****
71	DO 75 J=1,3
	RESSSQ=RESSSQ-2.*A(J)*SUMY(J)
	DO 75 K=1,3
	N=J+K-1
75	RESSSQ=RESSSQ+A(J)*A(K)*SUMX(N)
77	CA(1)=SNGL(A(3))
	CA(2)=SNGL(A(2))
	CA(3)=SNGL(A(1))
	CA(4)=SNGL(RESSSQ)
	CALL RECONS(CPOL)
	RETURN
80	POLFIT=-1
	RETURN
	END
