diff options
| author | Christoph Berg <myon@debian.org> | 2025-01-09 22:12:06 +0100 |
|---|---|---|
| committer | Christoph Berg <myon@debian.org> | 2025-01-09 22:12:06 +0100 |
| commit | 992d4b4b8d3f3a630a2cf00d593ee4ce4dfa7ce8 (patch) | |
| tree | fbfdfe6bcb0a8a114be2480dac53d88c977e4869 /lib/polyfit.f90 | |
| parent | 4320ce238aae1fe87fc9f379cdd816e9317885fa (diff) | |
New upstream version 2.7.0~rc8+repackupstream/2.7.0_rc8+repack
Diffstat (limited to 'lib/polyfit.f90')
| -rwxr-xr-x | lib/polyfit.f90 | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/lib/polyfit.f90 b/lib/polyfit.f90 index 55651411..63222304 100755 --- a/lib/polyfit.f90 +++ b/lib/polyfit.f90 @@ -1,72 +1,72 @@ -subroutine polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr)
- implicit real*8 (a-h,o-z)
- real*8 x(npts), y(npts), sigmay(npts), a(nterms)
- real*8 sumx(10), sumy(10), array(10,10)
-
-! Accumulate weighted sums
- nmax = 2*nterms-1
- sumx=0.
- sumy=0.
- chisq=0.
- do i=1,npts
- xi=x(i)
- yi=y(i)
- if(mode.lt.0) then
- weight=1./abs(yi)
- else if(mode.eq.0) then
- weight=1
- else
- weight=1./sigmay(i)**2
- end if
- xterm=weight
- do n=1,nmax
- sumx(n)=sumx(n)+xterm
- xterm=xterm*xi
- enddo
- yterm=weight*yi
- do n=1,nterms
- sumy(n)=sumy(n)+yterm
- yterm=yterm*xi
- enddo
- chisq=chisq+weight*yi**2
- enddo
-
-! Construct matrices and calculate coefficients
- do j=1,nterms
- do k=1,nterms
- n=j+k-1
- array(j,k)=sumx(n)
- enddo
- enddo
-
- delta=determ(array,nterms)
- if(delta.eq.0) then
- chisqr=0.
- a=0.
- else
- do l=1,nterms
- do j=1,nterms
- do k=1,nterms
- n=j+k-1
- array(j,k)=sumx(n)
- enddo
- array(j,l)=sumy(j)
- enddo
- a(l)=determ(array,nterms)/delta
- enddo
-
-! Calculate chi square
-
- do j=1,nterms
- chisq=chisq-2*a(j)*sumy(j)
- do k=1,nterms
- n=j+k-1
- chisq=chisq+a(j)*a(k)*sumx(n)
- enddo
- enddo
- free=npts-nterms
- chisqr=chisq/free
- end if
-
- return
-end subroutine polyfit
+subroutine polyfit(x,y,sigmay,npts,nterms,mode,a,chisqr) + implicit real*8 (a-h,o-z) + real*8 x(npts), y(npts), sigmay(npts), a(nterms) + real*8 sumx(10), sumy(10), array(10,10) + +! Accumulate weighted sums + nmax = 2*nterms-1 + sumx=0. + sumy=0. + chisq=0. + do i=1,npts + xi=x(i) + yi=y(i) + if(mode.lt.0) then + weight=1./abs(yi) + else if(mode.eq.0) then + weight=1 + else + weight=1./sigmay(i)**2 + end if + xterm=weight + do n=1,nmax + sumx(n)=sumx(n)+xterm + xterm=xterm*xi + enddo + yterm=weight*yi + do n=1,nterms + sumy(n)=sumy(n)+yterm + yterm=yterm*xi + enddo + chisq=chisq+weight*yi**2 + enddo + +! Construct matrices and calculate coefficients + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + enddo + + delta=determ(array,nterms) + if(delta.eq.0) then + chisqr=0. + a=0. + else + do l=1,nterms + do j=1,nterms + do k=1,nterms + n=j+k-1 + array(j,k)=sumx(n) + enddo + array(j,l)=sumy(j) + enddo + a(l)=determ(array,nterms)/delta + enddo + +! Calculate chi square + + do j=1,nterms + chisq=chisq-2*a(j)*sumy(j) + do k=1,nterms + n=j+k-1 + chisq=chisq+a(j)*a(k)*sumx(n) + enddo + enddo + free=npts-nterms + chisqr=chisq/free + end if + + return +end subroutine polyfit |
