Function that fits higher order terms to data containing amplitude as function of l-values and corrects the sum over the evolved l-modes with the contribution from the not evolved l-modes.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | ydat | A 1d-array containing the amplitudes of the -modes. It is assumed, for now, that the data starts at . |
|
integer(kind=ip), | intent(in) | :: | nmodes | The number of -modes. |
||
integer(kind=ip), | intent(in) | :: | startfit | At what -value should the fit begin. |
||
integer(kind=ip), | intent(in) | :: | endfit | At what -value should the fit end. |
||
integer(kind=ip), | intent(in) | :: | order | What is the lowest order term that should be fitted. |
||
integer(kind=ip), | intent(in) | :: | npar | How many terms should be included in the correction. One more term is included in the fit, but the coefficient for the last fit coefficient is only used as an error estimator. |
A 1d-array of size 3 that on return contains the sum of evolved modes (first entry), the corrected sum (second entry) and the error estimate (third entry).
function correct_for_higher_modes ( ydat, nmodes, &
startfit, endfit, order, npar )
!! Function that fits higher order terms to data containing amplitude as
!! function of l-values and corrects the sum over the evolved l-modes with
!! the contribution from the not evolved l-modes.
use gsl_interface
real(wp), dimension(:), intent(in) :: ydat
!! A 1d-array containing the amplitudes of the \(\ell\)-modes. It is
!! assumed, for now, that the data starts at \(\ell=0\).
integer(ip), intent(in) :: nmodes
!! The number of \(\ell\)-modes.
integer(ip), intent(in) :: startfit
!! At what \(\ell\)-value should the fit begin.
integer(ip), intent(in) :: endfit
!! At what \(\ell\)-value should the fit end.
integer(ip), intent(in) :: order
!! What is the lowest order term that should be fitted.
integer(ip), intent(in) :: npar
!! How many terms should be included in the correction. One more term
!! is included in the fit, but the coefficient for the last fit
!! coefficient is only used as an error estimator.
real(wp), dimension(3) :: correct_for_higher_modes
!! A 1d-array of size 3 that on return contains the sum of evolved modes
!! (first entry), the corrected sum (second entry) and the error
!! estimate (third entry).
integer(ip) :: n
real(wp), dimension(npar+1,endfit-startfit+1) :: xm
real(wp), dimension(endfit-startfit+1) :: yv
real(wp), dimension(npar+1) :: cv
real(wp), dimension(npar+1,npar+1) :: covm
real(wp) :: chisq
integer(ip) :: ierr, i, j, l
real(wp) :: c1, c2, c3
n = endfit-startfit+1
do i = 1, n
l = startfit+i-1
yv(i) = ydat(startfit+i)
do j = 1, npar+1
xm(j,i) = ldep(l,order+2*(j-1))
end do
end do
call multifit_linear ( n, npar+1, reshape(xm,(/n*(npar+1)/)), yv, cv, &
reshape(covm,(/(npar+1)*(npar+1)/)), chisq, ierr )
correct_for_higher_modes(1) = sum(ydat)
correct_for_higher_modes(2) = correct_for_higher_modes(1)
do j = 1, npar
correct_for_higher_modes(2) = correct_for_higher_modes(2) + &
cv(j)*lsum(nmodes,order+2*(j-1))
end do
correct_for_higher_modes(3) = cv(npar+1)*lsum(nmodes,order+2*npar)
end function correct_for_higher_modes