3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 qpsrt (gsl_integration_workspace * workspace);
24 void qpsrt (gsl_integration_workspace * workspace)
26 const size_t last = workspace->size - 1;
27 const size_t limit = workspace->limit;
29 double * elist = workspace->elist;
30 size_t * order = workspace->order;
36 size_t i_nrmax = workspace->nrmax;
37 size_t i_maxerr = order[i_nrmax] ;
39 /* Check whether the list contains more than two error estimates */
45 workspace->i = i_maxerr ;
49 errmax = elist[i_maxerr] ;
51 /* This part of the routine is only executed if, due to a difficult
52 integrand, subdivision increased the error estimate. In the normal
53 case the insert procedure should start after the nrmax-th largest
56 while (i_nrmax > 0 && errmax > elist[order[i_nrmax - 1]])
58 order[i_nrmax] = order[i_nrmax - 1] ;
62 /* Compute the number of elements in the list to be maintained in
63 descending order. This number depends on the number of
64 subdivisions still allowed. */
66 if(last < (limit/2 + 2))
72 top = limit - last + 1;
75 /* Insert errmax by traversing the list top-down, starting
76 comparison from the element elist(order(i_nrmax+1)). */
80 /* The order of the tests in the following line is important to
81 prevent a segmentation fault */
83 while (i < top && errmax < elist[order[i]])
85 order[i-1] = order[i] ;
89 order[i-1] = i_maxerr ;
91 /* Insert errmin by traversing the list bottom-up */
93 errmin = elist[last] ;
97 while (k > i - 2 && errmin >= elist[order[k]])
99 order[k+1] = order[k] ;
105 /* Set i_max and e_max */
107 i_maxerr = order[i_nrmax] ;
109 workspace->i = i_maxerr ;
110 workspace->nrmax = i_nrmax ;