C========================================================
      subroutine subpoly45(x,y,p1,p2,p3,rmse,xave,yave)
	dimension x(45),y(45) 
	nut=45  ! 45d indices
C  
	s0=45.
	s1=0.
	s2=0.
	s3=0.
	s4=0.
	syx2=0.
	syx=0.
	sy=0.
      DO N=1,nut
	x1=x(N)
	x2=x1*x1
	x3=x1*x2
	x4=x2*x2
	y1=y(N)
	yx=y1*x1
	yx2=y1*x2
	s1=s1+x1
	s2=s2+x2
	s3=s3+x3
	s4=s4+x4
	syx2=syx2+yx2
	syx=syx+yx
	sy=sy+y1
      ENDDO 
C
      d1=(s0*s3-s1*s2)
      c1=(s0*s4-s2*s2)/d1
      c2=(s0*syx2-sy*s2)/d1
	d2=(s0*s2-s1*s1)
      c3=(s0*s3-s1*s2)/d2
      c4=(s0*syx-sy*s1)/d2

C
C p1=a; p2=b; p3=c
C
C polyfit2 coefficients
	p1=(c2-c4)/(c1-c3)
	p2=c2-p1*c1
	p3=(sy-p1*s2-p2*s1)/s0
C RMSE
      sum=0.
	DO N=1,nut
	del=y(N)-(x(N)*(p1*x(N)+p2)+p3)
	sum=sum+del**2
	ENDDO
	rmse=sqrt(sum/nut)
	xave=s1/45.
      yave=sy/45.
C
	RETURN
	END
C

