|
Packit |
67cb25 |
/* integration/qpsrt.c
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
static inline void
|
|
Packit |
67cb25 |
qpsrt (gsl_integration_workspace * workspace);
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
static inline
|
|
Packit |
67cb25 |
void qpsrt (gsl_integration_workspace * workspace)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
const size_t last = workspace->size - 1;
|
|
Packit |
67cb25 |
const size_t limit = workspace->limit;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
double * elist = workspace->elist;
|
|
Packit |
67cb25 |
size_t * order = workspace->order;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
double errmax ;
|
|
Packit |
67cb25 |
double errmin ;
|
|
Packit |
67cb25 |
int i, k, top;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
size_t i_nrmax = workspace->nrmax;
|
|
Packit |
67cb25 |
size_t i_maxerr = order[i_nrmax] ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Check whether the list contains more than two error estimates */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (last < 2)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
order[0] = 0 ;
|
|
Packit |
67cb25 |
order[1] = 1 ;
|
|
Packit |
67cb25 |
workspace->i = i_maxerr ;
|
|
Packit |
67cb25 |
return ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
errmax = elist[i_maxerr] ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* This part of the routine is only executed if, due to a difficult
|
|
Packit |
67cb25 |
integrand, subdivision increased the error estimate. In the normal
|
|
Packit |
67cb25 |
case the insert procedure should start after the nrmax-th largest
|
|
Packit |
67cb25 |
error estimate. */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
while (i_nrmax > 0 && errmax > elist[order[i_nrmax - 1]])
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
order[i_nrmax] = order[i_nrmax - 1] ;
|
|
Packit |
67cb25 |
i_nrmax-- ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Compute the number of elements in the list to be maintained in
|
|
Packit |
67cb25 |
descending order. This number depends on the number of
|
|
Packit |
67cb25 |
subdivisions still allowed. */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if(last < (limit/2 + 2))
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
top = last ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
top = limit - last + 1;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Insert errmax by traversing the list top-down, starting
|
|
Packit |
67cb25 |
comparison from the element elist(order(i_nrmax+1)). */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
i = i_nrmax + 1 ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* The order of the tests in the following line is important to
|
|
Packit |
67cb25 |
prevent a segmentation fault */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
while (i < top && errmax < elist[order[i]])
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
order[i-1] = order[i] ;
|
|
Packit |
67cb25 |
i++ ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
order[i-1] = i_maxerr ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Insert errmin by traversing the list bottom-up */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
errmin = elist[last] ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
k = top - 1 ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
while (k > i - 2 && errmin >= elist[order[k]])
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
order[k+1] = order[k] ;
|
|
Packit |
67cb25 |
k-- ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
order[k+1] = last ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
/* Set i_max and e_max */
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
i_maxerr = order[i_nrmax] ;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
workspace->i = i_maxerr ;
|
|
Packit |
67cb25 |
workspace->nrmax = i_nrmax ;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
|