1 /* Derived from go/gaussq.f at www.netlib.org. The stuff seems to be
2  * in the public domain.
3  */
4 
5 /*           this set of routines computes the nodes t(j) and weights */
6 /*        w(j) for gaussian-type quadrature rules with pre-assigned */
7 /*        nodes.  these are used when one wishes to approximate */
8 
9 /*                 integral (from a to b)  f(x) w(x) dx */
10 
11 /*                              n */
12 /*        by                   sum w  f(t ) */
13 /*                             j=1  j    j */
14 
15 /*        (note w(x) and w(j) have no connection with each other.) */
16 /*        here w(x) is one of six possible non-negative weight */
17 /*        functions (listed below), and f(x) is the */
18 /*        function to be integrated.  gaussian quadrature is particularly */
19 /*        useful on infinite intervals (with appropriate weight */
20 /*        functions), since then other techniques often fail. */
21 
22 /*           associated with each weight function w(x) is a set of */
23 /*        orthogonal polynomials.  the nodes t(j) are just the zeroes */
24 /*        of the proper n-th degree polynomial. */
25 
26 /*     input parameters (all real numbers are in double precision) */
27 
28 /*        kind     an int between 1 and 6 giving the type of */
29 /*                 quadrature rule: */
30 
31 /*        kind = 1:  legendre quadrature, w(x) = 1 on (-1, 1) */
32 /*        kind = 2:  chebyshev quadrature of the first kind */
33 /*                   w(x) = 1/sqrt(1 - x*x) on (-1, +1) */
34 /*        kind = 3:  chebyshev quadrature of the second kind */
35 /*                   w(x) = sqrt(1 - x*x) on (-1, 1) */
36 /*        kind = 4:  hermite quadrature, w(x) = exp(-x*x) on */
37 /*                   (-infinity, +infinity) */
38 /*        kind = 5:  jacobi quadrature, w(x) = (1-x)**alpha * (1+x)** */
39 /*                   beta on (-1, 1), alpha, beta .gt. -1. */
40 /*                   note: kind=2 and 3 are a special case of this. */
41 /*        kind = 6:  generalized laguerre quadrature, w(x) = exp(-x)* */
42 /*                   x**alpha on (0, +infinity), alpha .gt. -1 */
43 
44 /*        n        the number of points used for the quadrature rule */
45 /*        alpha    real parameter used only for gauss-jacobi and gauss- */
46 /*                 laguerre quadrature (otherwise use 0.d0). */
47 /*        beta     real parameter used only for gauss-jacobi quadrature-- */
48 /*                 (otherwise use 0.d0) */
49 /*        kpts     (int) normally 0, unless the left or right end- */
50 /*                 point (or both) of the interval is required to be a */
51 /*                 node (this is called gauss-radau or gauss-lobatto */
52 /*                 quadrature).  then kpts is the number of fixed */
53 /*                 endpoints (1 or 2). */
54 /*        endpts   real array of length 2.  contains the values of */
55 /*                 any fixed endpoints, if kpts = 1 or 2. */
56 /*        b        real scratch array of length n */
57 
58 /*     output parameters (both double precision arrays of length n) */
59 
60 /*        t        will contain the desired nodes. */
61 /*        w        will contain the desired weights w(j). */
62 
63 /*     underflow may sometimes occur, but is harmless. */
64 
65 /*     references */
66 /*        1.  golub, g. h., and welsch, j. h., "calculation of gaussian */
67 /*            quadrature rules," mathematics of computation 23 (april, */
68 /*            1969), pp. 221-230. */
69 /*        2.  golub, g. h., "some modified matrix eigenvalue problems," */
70 /*            siam review 15 (april, 1973), pp. 318-334 (section 7). */
71 /*        3.  stroud and secrest, gaussian quadrature formulas, prentice- */
72 /*            hall, englewood cliffs, n.j., 1966. */
73 
74 /*        original version 20 jan 1975 from stanford */
75 /*        modified 21 dec 1983 by eric grosse */
76 /*          imtql2 => gausq2 */
77 /*          hex constant => d1mach (from core library) */
78 /*          compute pi using datan */
79 /*          removed accuracy claims, description of method */
80 /*          added single precision version */
81 
82 #ifdef HAVE_CONFIG_H
83 # include "config.h"
84 #endif
85 
86 #include "alberta_intern.h" /* to keep the proto-type in sync */
87 #include "alberta.h"
88 
89 static REAL classical(int kind, int n, REAL alpha, REAL beta, REAL b[], REAL t[]);
90 static REAL solve(REAL shift, int n, REAL a[/*n*/], REAL b[/*n*/]);
91 static int gaussq2(int n, REAL d[/*n*/], REAL e[/*n*/], REAL z[/*n*/]);
92 
93 #if 0
94 static REAL mypow(REAL a, REAL b)
95 {
96   int e = (int)b;
97   REAL res;
98 
99   if ((REAL)e == b) {
100     res = 1.0;
101     while (e--) {
102       res *= a;
103     }
104     return res;
105   } else {
106     return pow(a, b);
107   }
108 }
109 
110 REAL mygamma(REAL x)
111 {
112   int xi = (int)x, fac;
113   REAL res;
114 
115   if ((REAL)xi == x && xi >= 1) {
116     res = 1.0;
117     fac = 1;
118     while (--xi) {
119       res *= (REAL)(fac++);
120     }
121     return res;
122   } else {
123     return tgamma(x);
124   }
125 }
126 #endif
127 
_AI_gauss_quad(int kind,int n,REAL alpha,REAL beta,int kpts,REAL endpts[2],REAL t[],REAL w[])128 void _AI_gauss_quad(int kind, int n, REAL alpha,
129 		    REAL beta, int kpts, REAL endpts[2],
130 		    REAL t[/*n*/], REAL w[/*n*/])
131 {
132   /* Local variables */
133   REAL b[n]; /* scratch */
134   int i;
135   REAL t1, gam;
136   REAL muzero;
137 
138   /* Function Body */
139 /*<       call class (kind, n, alpha, beta, b, t, muzero) >*/
140   muzero = classical(kind, n, alpha, beta, &b[0], &t[0]);
141 
142   /* the matrix of coefficients is assumed to be symmetric.  the array
143    * t contains the diagonal elements, the array b the off-diagonal
144    * elements.  make appropriate changes in the lower right 2 by 2
145    * submatrix.
146    */
147 /*<       if (kpts.eq.0)  go to 100 >*/
148   switch (kpts) {
149   case 0:
150     break;
151   case 1:
152     /* if kpts=1, only t(n) must be changed */
153 /*<       t(n) = solve(endpts(1), n, t, b)*b(n-1)**2 + endpts(1) >*/
154     t[n-1] = solve(endpts[0], n, &t[0], &b[0]) * SQR(b[n-2]) + endpts[0];
155 /*<       go to 100 >*/
156     break;
157   case 2:
158 /*<       if (kpts.eq.2)  go to  50 >*/
159     /* if kpts=2, t(n) and b(n-1) must be recomputed */
160     /*<    50 gam = solve(endpts(1), n, t, b) >*/
161     gam = solve(endpts[0], n, &t[0], &b[0]);
162 /*<       t1 = ((endpts(1) - endpts(2))/(solve(endpts(2), n, t, b) - gam)) >*/
163     t1 = (endpts[0] - endpts[1]) / (solve(endpts[1], n, &t[0], &b[0]) - gam);
164 /*<       b(n-1) = dsqrt(t1) >*/
165     b[n - 1] = sqrt(t1);
166 /*<       t(n) = endpts(1) + gam*t1 >*/
167     t[n-1] = endpts[0] + gam * t1;
168     break;
169   }
170   /* note that the indices of the elements of b run from 0 to n-2 and
171    * thus the value of b[n-1] is arbitrary.  now compute the
172    * eigenvalues of the symmetric tridiagonal matrix, which has been
173    * modified as necessary.  the method used is a ql-type method with
174    * origin shifting
175    */
176 /*<   100 w(1) = 1.0d0 >*/
177   w[0] = 1.0;
178 /*<       do 105 i = 2, n >*/
179   for (i = 1; i < n; ++i) {
180 /*<   105    w(i) = 0.0d0 >*/
181     w[i] = 0.0;
182   }
183 
184 /*<       call gausq2 (n, t, b, w, ierr) >*/
185   gaussq2(n, &t[0], &b[0], &w[0]);
186 /*<       do 110 i = 1, n >*/
187   for (i = 0; i < n; ++i) {
188 /*<   110    w(i) = muzero * w(i) * w(i) >*/
189     w[i] = muzero * SQR(w[i]);
190   }
191 } /* gaussq */
192 
193 /*<       double precision function solve(shift, n, a, b) >*/
194 /*       this procedure performs elimination to solve for the */
195 /*       n-th component of the solution delta to the equation */
196 
197 /*             (jn - shift*identity) * delta  = en, */
198 
199 /*       where en is the vector of all zeroes except for 1 in */
200 /*       the n-th position. */
201 
202 /*       the matrix jn is symmetric tridiagonal, with diagonal */
203 /*       elements a(i), off-diagonal elements b(i).  this equation */
204 /*       must be solved to obtain the appropriate changes in the lower */
205 /*       2 by 2 submatrix of coefficients for orthogonal polynomials. */
solve(REAL shift,int n,REAL a[],REAL b[])206 REAL solve(REAL shift, int n, REAL a[/*n*/], REAL b[/*n*/])
207 {
208   REAL ret_val;
209   /* Local variables */
210   int i;
211   REAL alpha;
212 
213 /*<       double precision shift, a(n), b(n), alpha >*/
214 
215 /*<       alpha = a(1) - shift >*/
216   /* Function Body */
217   alpha = a[0] - shift;
218 /*<       n-1 = n - 1 >*/
219 /*<       do 10 i = 2, n-1 >*/
220   for (i = 1; i < n-1; ++i) {
221 /*<    10    alpha = a(i) - shift - b(i-1)**2/alpha >*/
222 /* L10: */
223     alpha = a[i] - shift - SQR(b[i-1]) / alpha;
224   }
225 /*<       solve = 1.0d0/alpha >*/
226   ret_val = 1.0 / alpha;
227   return ret_val;
228 /*<       end >*/
229 } /* solve */
230 
231 /*<       subroutine classical(kind, n, alpha, beta, b, a, muzero) >*/
232 /*           this procedure supplies the coefficients a(j), b(j) of the */
233 /*        recurrence relation */
234 
235 /*             b p (x) = (x - a ) p   (x) - b   p   (x) */
236 /*              j j            j   j-1       j-1 j-2 */
237 
238 /*        for the various classical (normalized) orthogonal polynomials, */
239 /*        and the zero-th moment */
240 
241 /*             muzero = integral w(x) dx */
242 
243 /*        of the given polynomial's weight function w(x).  since the */
244 /*        polynomials are orthonormalized, the tridiagonal matrix is */
245 /*        guaranteed to be symmetric. */
246 
247 /*           the input parameter alpha is used only for laguerre and */
248 /*        jacobi polynomials, and the parameter beta is used only for */
249 /*        jacobi polynomials.  the laguerre and jacobi polynomials */
250 /*        require the gamma function. */
classical(int kind,int n,REAL alpha,REAL beta,REAL b[],REAL a[])251 REAL classical(int kind, int n, REAL alpha, REAL beta, REAL b[/*n*/], REAL a[/*n*/])
252 {
253   /* Local variables */
254   int i;
255   REAL ab;
256   REAL a2b2, abi, muzero;
257 
258   /* Function Body */
259 /*<       n-1 = n - 1 >*/
260 /*<       go to (10, 20, 30, 40, 50, 60), kind >*/
261   switch (kind) {
262   case 1:
263     /* kind = 1:  legendre polynomials p(x) on (-1, +1), w(x) = 1. */
264 /*<    10 muzero = 2.0d0 >*/
265     muzero = 2.0;
266 /*<       do 11 i = 1, n-1 >*/
267     for (i = 0; i < n-1; ++i) {
268 /*<          a(i) = 0.0d0 >*/
269       a[i] = 0.0;
270 /*<          abi = i >*/
271       abi = (REAL)(i+1);
272 /*<    11    b(i) = abi/dsqrt(4*abi*abi - 1.0d0) >*/
273 /* L11: */
274       b[i] = abi / sqrt(4.0 * SQR(abi) - 1.0);
275     }
276 /*<       a(n) = 0.0d0 >*/
277     a[n-1] = 0.0;
278 /*<       return >*/
279     break;
280   case 2:
281     /* kind = 2: chebyshev polynomials of the first kind t(x) on (-1,
282      * +1), w(x) = 1 / sqrt(1 - x*x)
283      */
284 /*<    20 muzero = pi >*/
285     muzero = M_PI;
286 /*<       do 21 i = 1, n-1 >*/
287     for (i = 0; i < n-1; ++i) {
288 /*<          a(i) = 0.0d0 >*/
289       a[i] = 0.0;
290 /*<    21    b(i) = 0.5d0 >*/
291       b[i] = 0.5;
292     }
293 /*<       b(1) = dsqrt(0.5d0) >*/
294     b[0] = M_SQRT1_2;
295 /*<       a(n) = 0.0d0 >*/
296     a[n-1] = 0.0;
297     break;
298   case 3:
299     /* kind = 3: chebyshev polynomials of the second kind u(x) on (-1,
300      * +1), w(x) = sqrt(1 - x*x)
301      */
302 /*<    30 muzero = pi/2.0d0 >*/
303     muzero = M_PI_2;
304 /*<       do 31 i = 1, n-1 >*/
305     for (i = 0; i < n-1; ++i) {
306 /*<          a(i) = 0.0d0 >*/
307       a[i] = 0.0;
308 /*<    31    b(i) = 0.5d0 >*/
309       b[i] = 0.5;
310     }
311 /*<       a(n) = 0.0d0 >*/
312     a[n-1] = 0.0;
313     break;
314   case 4:
315     /* kind = 4: hermite polynomials h(x) on (-infinity, +infinity),
316      * w(x) = exp(-x**2)
317      */
318 /*<    40 muzero = dsqrt(pi) >*/
319     muzero = sqrt(M_PI);
320 /*<       do 41 i = 1, n-1 >*/
321     for (i = 0; i < n-1; ++i) {
322 /*<          a(i) = 0.0d0 >*/
323       a[i] = 0.0;
324 /*<    41    b(i) = dsqrt(i/2.0d0) >*/
325       b[i] = sqrt((REAL)(i+1) / 2.0);
326     }
327 /*<       a(n) = 0.0d0 >*/
328     a[n-1] = 0.0;
329     break;
330   case 5:
331     /* kind = 5: jacobi polynomials p(alpha, beta)(x) on (-1, +1),
332      * w(x) = (1-x)**alpha * (1+x)**beta, alpha and beta greater than
333      * -1 */
334 /*<    50 ab = alpha + beta >*/
335     ab = alpha + beta;
336 /*<       abi = 2.0d0 + ab >*/
337     abi = ab + 2.0;
338 /*<     muzero = 2.0d0 ** (ab + 1.0d0) * dgamma(alpha + 1.0d0) * dgamma(
339      x beta + 1.0d0) / dgamma(abi)  >*/
340     muzero =
341       pow(2.0, ab + 1.0) * tgamma(alpha + 1.0) * tgamma(beta + 1.0)/tgamma(abi);
342 /*<       a(1) = (beta - alpha)/abi >*/
343     a[0] = (beta - alpha) / abi;
344 /*<  b(1) = dsqrt(4.0d0*(1.0d0 + alpha)*(1.0d0 + beta)/((abi + 1.0d0)*
345      1  abi*abi)) >*/
346     b[0] = sqrt(4.0*(1.0+alpha)*(1.0+beta) / ((abi + 1.0) * SQR(abi)));
347 /*<       a2b2 = beta*beta - alpha*alpha >*/
348     a2b2 = SQR(beta) - SQR(alpha);
349 /*<       do 51 i = 2, n-1 >*/
350     for (i = 1; i < n-1; ++i) {
351 /*<          abi = 2.0d0*i + ab >*/
352       abi = 2.0*(REAL)(i+1) + ab;
353 /*<          a(i) = a2b2/((abi - 2.0d0)*abi) >*/
354       a[i] = a2b2 / ((abi - 2.0) * abi);
355 /*< 51    b(i) = dsqrt (4.0d0*i*(i + alpha)*(i + beta)*(i + ab)/
356      1   ((abi*abi - 1)*abi*abi))   >*/
357       b[i] = sqrt(4.0*(REAL)(i+1)
358 		  *
359 		  ((REAL)(i+1)+alpha)*((REAL)(i+1) + beta) * ((REAL)(i+1) + ab)
360 		  /
361 		  ((SQR(abi) - 1.0) * SQR(abi)));
362     }
363 /*<       abi = 2.0d0*n + ab >*/
364     abi = 2.0*(REAL)n + ab;
365 /*<       a(n) = a2b2/((abi - 2.0d0)*abi) >*/
366     a[n-1] = a2b2 / ((abi - 2.0) * abi);
367     break;
368   case 6:
369     /* kind = 6: laguerre polynomials l(alpha)(x) on (0, +infinity),
370      * w(x) = exp(-x) * x**alpha, alpha greater than -1.
371      */
372 /*<    60 muzero = dgamma(alpha + 1.0d0) >*/
373     muzero = tgamma(alpha + 1.0);
374 /*<       do 61 i = 1, n-1 >*/
375     for (i = 0; i < n-1; ++i) {
376 /*<          a(i) = 2.0d0*i - 1.0d0 + alpha >*/
377       a[i] = 2.0*(REAL)(i+1) - 1.0 + alpha;
378 /*<    61    b(i) = dsqrt(i*(i + alpha)) >*/
379       b[i] = sqrt((REAL)(i+1) * ((REAL)(i+1) + alpha));
380     }
381 /*<       a(n) = 2.0d0*n - 1 + alpha >*/
382     a[n-1] = 2.0*(REAL)n - 1.0 + alpha;
383     break;
384   default:
385     muzero = 0.0;
386   }
387   return muzero;
388 /*<       end >*/
389 } /* class_ */
390 
391 /*     this subroutine is a translation of an algol procedure, */
392 /*     num. math. 12, 377-383(1968) by martin and wilkinson, */
393 /*     as modified in num. math. 15, 450(1970) by dubrulle. */
394 /*     handbook for auto. comp., vol.ii-linear algebra, 241-248(1971). */
395 /*     this is a modified version of the 'eispack' routine imtql2. */
396 
397 /*     this subroutine finds the eigenvalues and first components of the */
398 /*     eigenvectors of a symmetric tridiagonal matrix by the implicit ql */
399 /*     method. */
400 
401 /*     on input: */
402 
403 /*        n is the order of the matrix; */
404 
405 /*        d contains the diagonal elements of the input matrix; */
406 
407 /*        e contains the subdiagonal elements of the input matrix */
408 /*          in its first n-1 positions.  e(n) is arbitrary; */
409 
410 /*        z contains the first row of the identity matrix. */
411 
412 /*      on output: */
413 
414 /*        d contains the eigenvalues in ascending order.  if an */
415 /*          error exit is made, the eigenvalues are correct but */
416 /*          unordered for indices 1, 2, ..., ierr-1; */
417 
418 /*        e has been destroyed; */
419 
420 /*        z contains the first components of the orthonormal eigenvectors */
421 /*          of the symmetric tridiagonal matrix.  if an error exit is */
422 /*          made, z contains the eigenvectors associated with the stored */
423 /*          eigenvalues; */
424 
425 /*        ierr is set to */
426 /*          zero       for normal return, */
427 /*          j          if the j-th eigenvalue has not been */
428 /*                     determined after 30 iterations. */
429 
430 /*< ierr = gaussq2(n, d, e, z) >*/
gaussq2(int n,REAL d[],REAL e[],REAL z[])431 int gaussq2(int n, REAL d[/*n*/], REAL e[/*n*/], REAL z[/*n*/])
432 {
433   FUNCNAME("gaussq2");
434   /* Local variables */
435   REAL b, c, f, g;
436   int i, j, k, l, m;
437   REAL p, r, s;
438   int ii, ierr;
439 
440 /*<       int i, j, k, l, m, n, ii, mml, ierr >*/
441 /*<       real*8 d(n), e(n), z(n), b, c, f, g, p, r, s >*/
442 /*<       real*8 dsqrt, dabs, dsign, d1mach >*/
443 
444 /*<       ierr = 0 >*/
445   ierr = 0;
446 /*<       if (n .eq. 1) go to 1001 >*/
447   if (n == 1) {
448     return ierr;
449   }
450 
451 /*<       e(n) = 0.0d0 >*/
452   e[n-1] = 0.0;
453 /*<       do 240 l = 1, n >*/
454   for (l = 0; l < n; ++l) {
455 /*<          j = 0 >*/
456     j = 0;
457 /*     :::::::::: look for small sub-diagonal element :::::::::: */
458     for (;;) {
459 /*<   105    do 110 m = l, n >*/
460       for (m = l; m < n-1; ++m) {
461 /*<             if (m .eq. n) go to 120 >*/
462       /* put into loop limit */
463 /*< if (dabs(e(m)) .le. machep * (dabs(d(m)) + dabs(d(m+1))))
464      x         go to 120   >*/
465 	if (fabs(e[m]) <= SQR(REAL_EPSILON) * (fabs(d[m]) + fabs(d[m + 1]))) {
466 	  break;
467 	}
468 /*<   110    continue >*/
469 /* L110: */
470       }
471 /*<   120    p = d(l) >*/
472       p = d[l];
473 /*<          if (m .eq. l) go to 240 >*/
474       if (m == l) {
475 	break; /* out of the "infinite" loop */
476       }
477 /*<          if (j .eq. 30) go to 1000 >*/
478       if (j == 30) {
479 	ERROR_EXIT("Iteration limit %d reached\n", 30);
480 	return 1; /* iteration limit reached */
481       }
482 /*<          j = j + 1 >*/
483       ++j;
484 /*     :::::::::: form shift :::::::::: */
485 /*<          g = (d(l+1) - p) / (2.0d0 * e(l)) >*/
486       g = (d[l + 1] - p) / (2.0 * e[l]);
487 /*<          r = dsqrt(g*g+1.0d0) >*/
488       r = sqrt(SQR(g) + 1.0);
489 /*<          g = d(m) - p + e(l) / (g + dsign(r, g)) >*/
490       g = d[m] - p + e[l] / (g + (g >= 0 ? fabs(r) : -fabs(r)));
491 /*<          s = 1.0d0 >*/
492       s = 1.0;
493 /*<          c = 1.0d0 >*/
494       c = 1.0;
495 /*<          p = 0.0d0 >*/
496       p = 0.0;
497 /*<          mml = m - l >*/
498 /*      mml = m - l;*/
499 /*     :::::::::: for i=m-1 step -1 until l do -- :::::::::: */
500 /*<          do 200 ii = 1, mml >*/
501       for (i = m-1; i >= l; --i) {
502 /*<             f = s * e(i) >*/
503 	f = s * e[i];
504 /*<             b = c * e(i) >*/
505 	b = c * e[i];
506 /*<             if (dabs(f) .lt. dabs(g)) go to 150 >*/
507 	if (fabs(f) < fabs(g)) {
508 /*<   150       s = f / g >*/
509 	  s = f / g;
510 /*<             r = dsqrt(s*s+1.0d0) >*/
511 	  r = sqrt(SQR(s) + 1.0);
512 /*<             e(i+1) = g * r >*/
513 	  e[i + 1] = g * r;
514 /*<             c = 1.0d0 / r >*/
515 	  c = 1.0 / r;
516 /*<             s = s * c >*/
517 	  s *= c;
518 	} else {
519 /*<             c = g / f >*/
520 	  c = g / f;
521 /*<             r = dsqrt(c*c+1.0d0) >*/
522 	  r = sqrt(SQR(c) + 1.0);
523 /*<             e(i+1) = f * r >*/
524 	  e[i + 1] = f * r;
525 /*<             s = 1.0d0 / r >*/
526 	  s = 1.0 / r;
527 /*<             c = c * s >*/
528 	  c *= s;
529 /*<             go to 160 >*/
530 	}
531 /*<   160       g = d(i+1) - p >*/
532 	g = d[i + 1] - p;
533 /*<             r = (d(i) - g) * s + 2.0d0 * c * b >*/
534 	r = (d[i] - g) * s + 2.0 * c * b;
535 /*<             p = s * r >*/
536 	p = s * r;
537 /*<             d(i+1) = g + p >*/
538 	d[i + 1] = g + p;
539 /*<             g = c * r - b >*/
540 	g = c * r - b;
541 /*     :::::::::: form first component of vector :::::::::: */
542 /*<             f = z(i+1) >*/
543 	f = z[i + 1];
544 /*<             z(i+1) = s * z(i) + c * f >*/
545 	z[i + 1] = s * z[i] + c * f;
546 /*<   200       z(i) = c * z(i) - s * f >*/
547 /* L200: */
548 	z[i] = c * z[i] - s * f;
549       }
550 
551 /*<          d(l) = d(l) - p >*/
552       d[l] -= p;
553 /*<          e(l) = g >*/
554       e[l] = g;
555 /*<          e(m) = 0.0d0 >*/
556       e[m] = 0.0;
557 /*<          go to 105 >*/
558     } /* for (;;) */
559 /*<   240 continue >*/
560   }
561 
562 /*     :::::::::: order eigenvalues and eigenvectors :::::::::: */
563 /*<       do 300 ii = 2, n >*/
564   for (ii = 1; ii < n; ++ii) {
565 /*<          i = ii - 1 >*/
566     i = ii - 1;
567 /*<          k = i >*/
568     k = i;
569 /*<          p = d(i) >*/
570     p = d[i];
571 
572 /*<          do 260 j = ii, n >*/
573     for (j = ii; j < n; ++j) {
574 /*<             if (d(j) .ge. p) go to 260 >*/
575       if (d[j] >= p) {
576 	continue;
577       }
578 /*<             k = j >*/
579       k = j;
580 /*<             p = d(j) >*/
581       p = d[j];
582 /*<   260    continue >*/
583     }
584 
585 /*<          if (k .eq. i) go to 300 >*/
586     if (k == i) {
587       continue;
588     }
589 /*<          d(k) = d(i) >*/
590     d[k] = d[i];
591 /*<          d(i) = p >*/
592     d[i] = p;
593 /*<          p = z(i) >*/
594     p = z[i];
595 /*<          z(i) = z(k) >*/
596     z[i] = z[k];
597 /*<          z(k) = p >*/
598     z[k] = p;
599 /*<   300 continue >*/
600   }
601 
602   return 0;
603 /*     :::::::::: last card of gaussq2 :::::::::: */
604 /*<       end >*/
605 } /* gausq2_ */
606 
607